Help Need for Java netbean ??

saysuzu

High Supremacy Member
Joined
Oct 31, 2007
Messages
27,562
Reaction score
2
Basically i am stuck at :

int[][] boardGame = new int[10][10];
/**
* above is the 2D array constructor
*/

for (int row = 0; row < 10; row++)
{
for (int col = 0; col < 10; col++)
{
boardGame[row][col] = 0;
}

hmm, that's probably a good start

let me add in some:

since it mention this:

The following are the initial number of pieces for the entire game:

Piece Quantity
Settler 20
Castle 5
Tower 10
Mine 10

you probably need to define constant value for those variables, so that you can use it to check whether you have exceed the above values

Then, the program should simulate the game play as follows:

• At each turn, the current state of the game board should be displayed
• At each turn, each computer player rolls a dice. Then, the program must also generate two random numbers that represent the x and y position in the 2D array.
• The rules to follow for placing an item on the game board is as follows:
o If the dice value is between 1 and 3, inclusive, and there are “settler” pieces available, place a “settler” piece at [x][y] position on the game board
o If the dice value is 4 and there are “castle” pieces available, place a “castle” piece at [x][y] position on the game board
o If the dice value is 5 and there are “tower” pieces available, place a “tower” piece at [x][y] position on the game board
o If the dice value is 6 and there are “mine” pieces available, place a “mine” piece at [x][y] position on the game board
• If the [x][y] position on the game board is occupied, the computer player skips its turn.

you need to generate a random number for X and Y, where the value for both X and Y are between 1 to 10 (or 0 to 9 depending on your understanding of array). once done, you also need to generate a random number for the dice value so to place the respective piece on the board. You can use a switch case (or if else) to check which piece you want to put. Finally, you also need to check whether the spot is occupied or not, how you do it is up to you


the rest of the rules that is mentioned in your thread should be pretty simple though, just follow through and you can complete this stuff in no time
 

epxyhades

Junior Member
Joined
Aug 3, 2013
Messages
1
Reaction score
0
Well, technically, you shouldnt declare the gameBoard as int. I believe you need 2 array; 1 char array and 1 int array.

Char array to store the piece while the int array store which player own the piece.
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,301
Well, technically, you shouldnt declare the gameBoard as int. I believe you need 2 array; 1 char array and 1 int array.

Char array to store the piece while the int array store which player own the piece.

Not really true. Bits and just bits, it is very easy to use masking of bits to store both of these informations into a 32bits integers. :) 32bits have sufficient space to store both piece of information into the same element.
 

lycheas

Member
Joined
Apr 24, 2000
Messages
113
Reaction score
0
There are 4 parts to your assignment
1. The modeling of the game board
- a class that contains each cell in the board
- attributes of teh class that you manipulate, example, ownership, type of settlements

2. The rules engine
- the engine codify the result when the game controller runs through all teh cells in the game board

3. The game controller
- the class that does the setup of the cells, process the rules at each turn, executes the presentation

4. Presentation
- the class that manipulates the UI
- at the beginning, you may just want to print out the values in each cell, then enhance it with better graphics once you have master your rule engine, controller and cells
 
Last edited:
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top