Results 1 to 12 of 12
Thread: [SOLVED] How to create a Grid?
- 11-09-2008, 10:19 PM #1
Member
- Join Date
- Oct 2008
- Location
- Aberystwyth
- Posts
- 55
- Rep Power
- 0
[SOLVED] How to create a Grid?
Hi all again. Not long been given some work to do by the University but I'm having trouble setting up my grid for the game to play on. I have to create a terminal based snake game with a grid sized 31x31. However, i haven't a clue how to create a grid.
Any help here would be grateful.
Thanks in advance.
Nak.
-
and I'm afraid to say that neither do I. You may wish to provide more information, a lot more.i haven't a clue how to create a grid.
- 11-09-2008, 10:28 PM #3
Member
- Join Date
- Oct 2008
- Location
- Aberystwyth
- Posts
- 55
- Rep Power
- 0
theres not really much more i could say. Its a Snake game similar to the snake games on the phones. :)
I need to create a simple grid for the game to basically be set on. The grid will have to be 31x31.
The snake will move one space at a time i think and will eventually eat some food which is then randomly placed on the grid somewhere else.
Thats the basis of level 1 out of 5. But at the moment all i need to do is create a 2D grid for it all to go onto. I think i would have to use arrays. But im not sure how to create a grid using them.
- 11-09-2008, 10:56 PM #4
Are you talking about a GUI thing or an internal container in your program?
In the program you could use a 2 dim array:
Type[][] twoDim = new Type[31][31]; // 31x31 grid
-
Either way, they'd be best off creating an internal "data" grid first and then could use this in a GUI or (my guess is more likely given her first post where she mentions "terminal") in console output.
- 11-09-2008, 11:05 PM #6
Member
- Join Date
- Oct 2008
- Location
- Aberystwyth
- Posts
- 55
- Rep Power
- 0
- 11-09-2008, 11:20 PM #7
Member
- Join Date
- Oct 2008
- Location
- Aberystwyth
- Posts
- 55
- Rep Power
- 0
Is there anyway to get the grid to display? i would also like your opinion on my basic code so far. I'm not entirely sure if I'm going about this the right way. If you see something that would be best done differently then feel free to comment.
Java Code:public class SnakeGame { public static void main(String[] args) { } public class Grid { Grid[][] twoDimGrid = new Grid[31][31]; // 31x31 grid } public class Snake { //Creating the different parts of the snake(Head and main body) char SnakeHead = '*'; char Snake = '~'; } }
- 11-09-2008, 11:57 PM #8
Lots of ways. What are your requirements? Do you have a design?Is there anyway to get the grid to display?
Where/how do you want to display? Using println() or in a GUI?
- 11-10-2008, 12:59 PM #9
Member
- Join Date
- Oct 2008
- Location
- Aberystwyth
- Posts
- 55
- Rep Power
- 0
Just using print() would be good enough. I'm basically creating a terminal game of Snake. However, each time the snake moves the grid wont auto update. Is there someway of refreshing it after every key press?
- 11-10-2008, 02:01 PM #10
By terminal I thought you meant that the output was via println() to a console screen.creating a terminal game
No, you would have to print the whole grid again.someway of refreshing it after every key press
You'll want to look into using a GUI. One way would be to use a JPanel, override its paintComponent() method and draw the grid,etc using the appropriate Graphics draw... method.
There are several examples here on how to do that. Use search for paintComponent. Copy a simple one to your PC and play with it to see how it works.
- 11-11-2008, 01:33 AM #11
Member
- Join Date
- Oct 2008
- Location
- Aberystwyth
- Posts
- 55
- Rep Power
- 0
- 11-12-2008, 10:45 AM #12
Member
- Join Date
- Oct 2008
- Location
- Aberystwyth
- Posts
- 55
- Rep Power
- 0
Argh. Call me stupid if you like, but i cannot get the grid to print to the terminal. my grid is still empty but it should still work just not display anything.
Is it possible to have more help on printing this grid please?
Here is what i've got so far:
Java Code:public class SnakeGame { //create main method(All Java prgrams need one to run ;)) public static void main(String[] args) { } //Create a 2D grid for the game to be played on public class Grid { Grid[][] twoDimGrid = new Grid[31][31]; // 31x31 grid } void print() { print(Grid.twoDimGrid(this)); } }
Similar Threads
-
how to get the grid values
By jazz2k8 in forum Advanced JavaReplies: 2Last Post: 11-06-2008, 02:11 PM -
Grid layout frames GUI
By fritz1474 in forum AWT / SwingReplies: 1Last Post: 10-15-2008, 02:04 AM -
J2ME Canvas grid
By bartosz666 in forum CLDC and MIDPReplies: 0Last Post: 07-12-2008, 03:13 AM -
Help creating a changing grid
By adlb1300 in forum New To JavaReplies: 11Last Post: 10-24-2007, 01:41 PM -
Help with Grid Layout
By coco in forum AWT / SwingReplies: 1Last Post: 08-06-2007, 08:03 PM


LinkBack URL
About LinkBacks


Bookmarks