Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How to go about coding a board game...
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
n_n




PostPosted: Tue Dec 13, 2005 7:01 pm   Post subject: How to go about coding a board game...

Hi, I'm here for some suggestions. My comp sci teacher switched from Turing to Java and so I decided to sharpen my skills. I have used Java last year so I'm rather rusty, which is why I'm going to try to do a board game. I'm just wondering how I should go about doing it. Okay, as a preliminary, there are spots on the board on which the player can move, and certain spots where he is blocked by something. At first, I was thinking of several multi-dimensional arrays. I'm having doubts of its efficiency. If I wanted something like a 10 x 10 board, I need a 10 dimensional array and haven't tried using something that big before.

Then I got to thinking, maybe a tileset? When I was using Turing I had just started playing around with tilesets and got some bare-bone RPG map working as a test. I'm wondering if it's possible and/or efficient to use that for a board in a board game.

Now, when I used Java I didn't do that much graphic stuff, but I am very proficient with GUI (particularly the often frustrating GridBag) so if there's some way to incorporate that into making a board I should have no problem.

So here's where I open it to suggestions. Any suggestion with a brief description would be helpful. I'll try to figure out any suggestions on my own, but if I need help I'll ask here again.

Thanks a lot in advanced, if there's any other information (I don't have too many specifics yet, I just want to try to get a board and pieces moving first) you'd like to know, I'll be more than happy to give it to you. Thank you again.
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Tue Dec 13, 2005 7:13 pm   Post subject: (No subject)

You have a 10x10 grid, right?

So you need at most a 2 dimensional array.

Something like the following might be your start:

Java:
class Board {
   private SomeBoardStateType[][] boardState;

   public Board() {
      for (int row = 0; row < 10; ++row)
         for (int col = 0; col < 10; ++col)
            boardState[row][col] = defaultState;
   }
}
n_n




PostPosted: Tue Dec 13, 2005 7:32 pm   Post subject: (No subject)

Oh, wow I'm stupid. I was thinking of having an array for each row Embarassed Okay, I'll try it out tomorrow (after I finish up an assignment, I end up having like 2 weeks extra anyways). Thanks a lot.
McKenzie




PostPosted: Tue Dec 13, 2005 9:34 pm   Post subject: (No subject)

You don't need GridBag for a simple 10x10 grid, just use GridLayout. From what I understand Sun didn't intend humans to use GridBag, it's for Swing editors.
wtd




PostPosted: Tue Dec 13, 2005 9:52 pm   Post subject: (No subject)

It's not that bad. It's just insanely un-java-like.
n_n




PostPosted: Wed Dec 14, 2005 7:40 am   Post subject: (No subject)

Okay, thanks for the help. Now, like I've said, I didn't get around to using too many graphics with Java. Would I need to get some tiles and just lay them on the grid? How does Java handle something like a game piece on top of a tile. I know with Turing it was easy, by default it would just lie on top of the picture below. Is it the same with Java? Thanks again.
McKenzie




PostPosted: Wed Dec 14, 2005 9:34 pm   Post subject: (No subject)

Well you need to seperate the game logic from the visual representation of it. The game logic is the same regardless or the language you use (well, give or take.) As far as how you would actually go about doing the graphics in Java I think you need to start with one basic choice. Do you want to use Swing components or do you want to draw things from scratch with the Graphics (Graphics2D?) class. By the sounds of it, Swing components might work well for you, ImageIcons on JButtons, but I don't know all of the details. Sun has solid tutorials for using Swing have a look at them.
1of42




PostPosted: Wed Dec 14, 2005 9:55 pm   Post subject: (No subject)

McKenzie wrote:
You don't need GridBag for a simple 10x10 grid, just use GridLayout. From what I understand Sun didn't intend humans to use GridBag, it's for Swing editors.


Hehe... because Swing editors aren't humans. Wink
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: