
-----------------------------------
KukuriChan
Fri Mar 19, 2004 11:11 am

Taking Turns in A Dice Game Question
-----------------------------------
I'm doing my dice game right now but I don't know a good way to alternate between characters in the game.  Since, the number of char changes every single time in the game, I'm really confused about what I can do so that the players would take turns rolling the die.  I did think about using arrays but I'm still not sure what to do.  Please help me. ^^ [/code]

-----------------------------------
recneps
Fri Mar 19, 2004 11:25 am


-----------------------------------
Use a counter, after someone goes, the counter goes up by one like
loop
rolldice
c+=1
end loop

then, in the loop, have it mod the counter by the number of people.
eg. num ppl = 4
if c mod ppl =0 then
put "Player 1's turn."
elsif c mod ppl =1 then
put "player 2's turn"
elsisf c mod ppl = 2 then
put "Player 3's turn"
elsif c mod ppl = 3 then
put "player 4's turn."
end if


and so on, that should work. ;)

-----------------------------------
KukuriChan
Fri Mar 19, 2004 11:31 am


-----------------------------------
So, if the number of characters differ each time it's played, do I just make a counted loop?

-----------------------------------
KukuriChan
Fri Mar 19, 2004 11:39 am


-----------------------------------
I did that. But there's something wrong.  :( Here's the code. 

var roll, count, numplayers : int
count := 0

put "Number of players: " ..
get numplayers

loop
delay (200)
    count += 1
    for i : 1 .. numplayers
        if count mod numplayers = 0 then
            put "Player 1's turn"
        elsif count mod numplayers = 1 then
            put "Player 2's turn"
        elsif count mod numplayers = 2 then
            put "Player 3's turn"
        elsif count mod numplayers = 3 then
            put "Player 4's turn"
        end if
    end for
end loop


-----------------------------------
Paul
Fri Mar 19, 2004 11:50 am


-----------------------------------
The way you set up your code, each player goes 4 times? I dunno, if your doing this for your flight game, each player rolls once each turn right? There can only be 4 players, so you should limit it.

Heres a simple example showing however number of players within 4, taking turns rolling the die

var players, roll: int
loop
put "Enter number of players 1-4"
get players
if players >0 and players = 2 and players  0 and numpawns 