Board game in Java

Guismos Posted messages 18 Status Membre -  
Eltorosam137 Posted messages 33 Status Membre -
Hello,

I want to make a small board game in Java. Do you have any advice for me to get started? I would like to know how to organize my classes (which types of classes to group together, etc... for example for buttons, for the board interface, ...). And where should I begin? Is it more interesting to implement the interface first, or the functionalities? Finally, if anyone has some good tips for me (websites to check out, ...) that would be great, thank you :)
Configuration: Windows XP Internet Explorer 7.0

4 réponses

kij_82 Posted messages 4102 Registration date   Status Contributeur Last intervention   857
 
Hello,

You have already understood that it is important to separate the graphic aspect from the engine of your future application, which is a good thing.

As for the organization of your classes, indeed, it is best to group them into packages related to their functionality. One (or more) package(s) / sub-packages for everything that relates to the graphical interface. The same goes for the application engine, and others for "utilities," for example, in which you group constant interfaces, abstract classes for context-independent functionalities (basic functions, etc.).

When it comes to knowing where to start, it depends on the individuals and their preferences, but I would tend to say that you should always focus on the program itself and its functionalities rather than the graphic aspect.
However, this does not prevent you from thinking about one while considering the other; on the contrary, you should be able to develop both aspects together according to your final goal.

For example, let's say you are developing a checkers game: to devise your pawn movement function, you will need to have thought about how you are going to display your components graphically (squares, pawns, etc.).

In the end, I would say that you should start by defining everything that your project must do, how it will do it, the resources you want to put into it (you can do that in 2D or 3D for the graphic aspect, for example), etc.
Then build the engine, and finally the graphics. (or both in parallel)

--

~ Don't forget the "Resolved" tag when your problem is... resolved :) ~
0
Guismos Posted messages 18 Status Membre
 
Sure, thank you.

My game is therefore a board game, it has 25 squares and there are 13 tokens, with 2 types of different tokens. My idea is to create a base token class, which would be inherited by 2 classes type1token and type2token. But I'm not quite sure how to organize the movement on my board.
Let me explain: if I want to move a token from square x to square y (assuming I've created a position class that grids the board and establishes a position for each square), should I create a special class for movements? Or maybe a database in which to store all the positions of each piece, but I haven't done that before so I'd rather not dive into that...

Since I am really in the midst of a project where no one tells me anything, do you have any implementation ideas to establish a board, configure the allowed or forbidden movements/positions, ... I know it’s not always easy to provide outside code like that, but do you have any websites that offer examples of similar games with ideas? My essential need right now is to have ideas to kick start my game...
0
kij_82 Posted messages 4102 Registration date   Status Contributeur Last intervention   857
 
Mum ok I see.
When I was a student, I had to create a checkers game in Java (among other things), which is similar to your problem.

The issue of how to move a piece from one square to another can be broken down as follows:
- you have the graphical aspect (a board with pieces on it)
- you have the memory aspect (similar to the board (usually a 2D array) with objects of type piece)

The way to generate a piece movement is quite simple in itself:
- on the user side, they must click on the square where the piece to be moved is located, and then on the final square where the piece should be placed.
- on the program side:
+ graphical interface: the squares occupied by pieces must be clickable (only those where there are pieces, so you don't have to check for the presence of a piece on the square after the click, you know it's already the case). After the first click, the "available" squares must be clickable. The concept of "available" needs to be defined according to your application/game. For example, for a chess game, you will need an algorithm to determine which square is possible for the movement depending on the type of piece to be moved (knight, queen, etc.). For a checkers game, these will be the adjacent diagonal squares, even those a bit further away if an opponent's piece is on one of the adjacent squares or if you are moving a queen.
+ engine/program = memory aspect: Each graphical square corresponds to a square in your memory array (which roughly represents your chessboard/graphical board). Each square can either be empty or contain an object of class Piece (which you have described yourself). Thus, the goal of your program will be to move these piece objects from square to square as the requested movements occur. The reconstruction/updating of the graphical board should always be done on this memory array at a given time, thereby limiting the information to a single place: the memory array. If for example you encounter a bug while playing: a piece is misplaced graphically, you know that the error comes from the memory management/movement of your objects because the graphical construction is always the same and does not depend on external factors/related to the game.

Here you go, a little explanation, hoping it’s not incomprehensible ^^
Try to work on your project with others, get help, it will be easier (if only to obtain information)

--

~ Don't forget the "Resolved" tag when your problem is... resolved :) ~
0
Guismos Posted messages 18 Status Membre
 
Thank you very much, that already gives me some concrete ideas that I was desperately missing ;) I'm already working on my project with other people, and the problem is that we're all in the same situation, which is to say, new to this (we have programmed in other languages and Java seems unknown to us today). Anyway, thank you for your advice and explanations!
0
Eltorosam137 Posted messages 33 Status Membre 7
 
I'm definitely a bit late to the discussion, but I also have a board game project in JAVA, and I had already integrated the concepts mentioned by kij_82.
But I have a problem: how to define which squares are available or not; I can create my available squares, but if I'm at the edge of the board, my pieces can still go off, which is an algorithmic error, I recognize that ... so, does anyone know how to help me with this obstacle I'm facing? :S

Thank you :)
0