2-6 player game help

I have to make a text based game for 2-6 players that simulates the roll of die by

generating a random number then

- asks player1 a question,

- asks the user if the question was answered correctly

- moves the representation of player1 across a board if the answer was correct

- and begins the process again for player 2, and so on.

I have written a methods to get the number of players, to generate the dice roll and another to access a random question from the bank of questions and these work fine. Now I am ready to make the representation of the board and I do not know how to proceed.

The suggested output is:

(before any dice rolls)

Player1

[x][][][][][][][][][][][][]

Player2

[x][][][][][][][][][][][][]

player3

[x][][][][][][][][][][][][]

Question here

Was question answered correctly(y/n)

y

(after roll and correct answer for player1)

player 1 rolled a 3

Player1

[][][][x][][][][][][][][][]

Player2

[x][][][][][][][][][][][][]

player3

[x][][][][][][][][][][][][]

I have two questions - how to move from one player to the next after each question and how to best represent the board? This is for class so I am not looking for the code just suggestions on how to proceed.

Thanks

[1358 byte] By [lsjgha] at [2007-11-26 23:39:52]
# 1
Sorry, forgot to copy in the top part of post:"Hi,I am really new to java and to programming in general so forgive me if the answer to this is really simple."Don't want to be rude. Especially not in my first post :)
lsjgha at 2007-7-11 15:06:01 > top of Java-index,Java Essentials,New To Java...
# 2
I'd represent the board by a length (number of positions) and for each player, the current position. Suppose the length is n and the current position for a player is x, then you can generate the board by first placing (x-1) the "[]" part, then a "[x]" and then (n - x) times "[]".
Simeona at 2007-7-11 15:06:01 > top of Java-index,Java Essentials,New To Java...
# 3

And you can use a variable, like currentPlayer, to store the current player. Suppose there are three players and player 2 is currently playing. Does modulo 3 say anything to you? Because you could add one to currentPlayer (mod 3) each time the next player has to play.

You could update this variable by doing: currentPlayer = currentPlayer % 3 + 1. This will keep the variable in the 1 - 3 range all the time and you can check that variable to see which player is currently playing.

Simeona at 2007-7-11 15:06:01 > top of Java-index,Java Essentials,New To Java...
# 4

> I'd represent the board by a length (number of positions) and for each >player, the current position. Suppose the length is n and the current >position for a player is x, then you can generate the board by first >placing (x-1) the "[]" part, then a "[x]" and then (n - x) times "[]".

And you can use a variable, like currentPlayer, to

> store the current player. Suppose there are three

> players and player 2 is currently playing. Does

> modulo 3 say anything to you? Because you could add

> one to currentPlayer (mod 3) each time the next

> player has to play.

>

> You could update this variable by doing:

> currentPlayer = currentPlayer % 3 + 1. This will keep

> the variable in the 1 - 3 range all the time and you

> can check that variable to see which player is

> currently playing.

modulo 3 means nothing to me. I googled it and got more maths than I am able for :) this is a really basic course so the answer needs to be basic too. When you talked about length and position for each player did you mean that I should make an array for each player? So I could have all the possible positions, then add each dice roll and then something like

if totalDiceRoll = x

System.out.println(player1Array[x])

would this be the right direction to go in?

Thanks

lsjgha at 2007-7-11 15:06:01 > top of Java-index,Java Essentials,New To Java...
# 5

Well, I assume you simply want to print this on the screen right: [][][][x][][][][][][][][][] ? Why would you need an array to store that? Because to create that String, all you need to know is the length (the number of times you need to print a []) and the position of the player (where to print the x). For example, try the following:

String playerOneBoard = "";

int length = 10;

int positionPlayerOne = 3;

for (int i = 1; i <= length; i++) {

if (i != positionPlayerOne) {

playerOneBoard += "[]";

} else {

playerOneBoard += "[x]";

}

}

System.out.println(playerOneBoard);

You could store the positions of the players in an array if you want.

Simeona at 2007-7-11 15:06:01 > top of Java-index,Java Essentials,New To Java...
# 6
I think I see. I will try this.Thank you
lsjgha at 2007-7-11 15:06:01 > top of Java-index,Java Essentials,New To Java...