 Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki Blog Search Turing Chat Room Members
Taking Turns in A Dice Game Question       Author Message
KukuriChan Posted: Fri Mar 19, 2004 11:11 am   Post subject: 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  Posted: Fri Mar 19, 2004 11:25 am   Post subject: (No subject)

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 Posted: Fri Mar 19, 2004 11:31 am   Post subject: (No subject)

So, if the number of characters differ each time it's played, do I just make a counted loop? KukuriChan Posted: Fri Mar 19, 2004 11:39 am   Post subject: (No subject)

I did that. But there's something wrong. Here's the code.

 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  Posted: Fri Mar 19, 2004 11:50 am   Post subject: (No subject)

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
 code: var players, roll: int loop put "Enter number of players 1-4" get players if players >0 and players <=4 then cls exit end if cls end loop loop for a: 1..players randint (roll, 1,6) if a=1 then put "Player ", a, " Rolled a ", roll elsif a=2 then put "Player ", a, " Rolled a ",roll elsif a=3 then put "Player ", a, " Rolled a ", roll elsif a=4 then put "Player ", a, " Rolled a ", roll end if delay (1000) end for cls end loop KukuriChan Posted: Fri Mar 19, 2004 12:09 pm   Post subject: (No subject)

Hey it worked! Plus, it's what I want. Thanks Paul.You're such a big help. You too recneps.  recneps  Posted: Fri Mar 19, 2004 1:57 pm   Post subject: (No subject)

Yeah, well Paul's is simpler ;D oh well, thats how i did mine for tic tac toe, i had it mod 2, if its 0, then its player 1 turn, if its 1 then player 2 turn ;D SuperGenius Posted: Fri Mar 19, 2004 2:14 pm   Post subject: (No subject)

 code: for a: 1..players randint (roll, 1,6) if a=1 then put "Player ", a, " Rolled a ", roll elsif a=2 then put "Player ", a, " Rolled a ",roll elsif a=3 then put "Player ", a, " Rolled a ", roll elsif a=4 then put "Player ", a, " Rolled a ", roll end if

just nitpicking, but this if structure isnt required is it?
Couldnt this be replaced with

 code: for a: 1..players randint (roll, 1,6) put "Player ", a, " Rolled a ", roll end if    KukuriChan Posted: Fri Mar 19, 2004 5:34 pm   Post subject: (No subject)

It could be but then there's a lot of other things I have to check for:

(1) If the player rolls a 6, then it can move either a pawn in the waitng area or move a pawn that's already out(since there's a limit. The maximum number of pawns you can have is 4.) Once you have all four out, you can choose which pawn you want to move. If the player doesn't get a six, then it can't move and it goes on to the next player <-- that means that I have to have a loop and then make a lot of if statements right?
(2) There are 4 different colours that can be chosen : red, blue, green, or yellow. When the game starts, each player chooses a colour. Then it goes into the actual game where you start rolling the die.
(3) There are different colours on the board. If the player lands on the colour that they chose, they can skip to the next colour square that they chose.
and some other things I have to check for.

So I think the if statement structure is perfect. But... I'm stuck on the first part where I have to check for stuff. I have part of it in code but there's some error in it, and I don't know how to fix it. ^^

 code: var players, roll, move1, move2, move3, move4, pawn, numpawns : int var player1, player2, player3, player4 : boolean := false move1 := 0 move2 := 0 move3 := 0 move4 := 0 loop     put "Enter number of players 1-4"     get players     put "Enter number of pawns 1-4"     get numpawns     if players >= 2 and players <= 4 and numpawns > 0 and numpawns <= 4 then         cls         exit     end if     cls end loop loop     for a : 1 .. players         randint (roll, 1, 6)         if a = 1 then             put "Player ", a, " Rolled a ", roll             if roll = 6 then                 player1 := true                 put "Which Pawn do you want to move?"                 get pawn                 put "Pawn", pawn, "moved into 'Start Flying' mode"                 exit             end if             if roll <= 5 and player1 = true then                 put "Which Pawn do you want to move?"                 get pawn                 assert pawn > 0                 if pawn = 1 then                     move1 := move1 + roll                     put "Pawn ", pawn, " moved", move1                 elsif pawn = 2 then                     move2 := move2 + roll                     put "Pawn ", pawn, " moved", move2                 elsif pawn = 3 then                     move3 := move3 + roll                     put "Pawn ", pawn, " moved", move3                 elsif pawn = 4 then                     move4 := move4 + roll                     put "Pawn ", pawn, " moved", move4                 end if                 exit             end if         elsif a = 2 then             put "Player ", a, " Rolled a ", roll             if roll = 6 then                 player2 := true                 put "Which Pawn do you want to move?"                 get pawn                 assert pawn > 0                 put "Pawn ", pawn, " moved into 'Start Flying' mode"                 exit             end if             if roll <= 5 and player2 = true then                 put "Which Pawn do you want to move?"                 get pawn                 assert pawn > 0                 if pawn = 1 then                     move1 := move1 + roll                     put "Pawn ", pawn, " moved", move1                 elsif pawn = 2 then                     move2 := move2 + roll                     put "Pawn ", pawn, " moved", move2                 elsif pawn = 3 then                     move3 := move3 + roll                     put "Pawn ", pawn, " moved", move3                 elsif pawn = 4 then                     move4 := move4 + roll                     put "Pawn ", pawn, " moved", move4                 end if                 exit             end if         elsif a = 3 then             put "Player ", a, " Rolled a ", roll             if roll = 6 then                 player3 := true                 put "Which Pawn do you want to move?"                 get pawn                 assert pawn > 0                 put "Pawn ", pawn, " moved into 'Start Flying' mode"                 exit             end if             if roll <= 5 and player3 = true then                 put "Which Pawn do you want to move?"                 get pawn                 if pawn = 1 then                     move1 := move1 + roll                     put "Pawn ", pawn, " moved", move1                 elsif pawn = 2 then                     move2 := move2 + roll                     put "Pawn ", pawn, " moved", move2                 elsif pawn = 3 then                     move3 := move3 + roll                     put "Pawn ", pawn, " moved", move3                 elsif pawn = 4 then                     move4 := move4 + roll                     put "Pawn ", pawn, " moved", move4                 end if                 exit             end if         elsif a = 4 then             put "Player ", a, " Rolled a ", roll             if roll = 6 then                 player4 := true                 put "Which Pawn do you want to move?"                 get pawn                 assert pawn > 0                 put "Pawn ", pawn, " moved into 'Start Flying' mode"                 exit             end if         elsif roll <= 5 and player4 = true then             put "Which Pawn do you want to move?"             get pawn             if pawn = 1 then                 move1 := move1 + roll                 put "Pawn ", pawn, " moved", move1                             elsif pawn = 2 then                 move2 := move2 + roll                 put "Pawn ", pawn, " moved", move2             elsif pawn = 3 then                 move3 := move3 + roll                 put "Pawn ", pawn, " moved", move3             elsif pawn = 4 then                 move4 := move4 + roll                 put "Pawn ", pawn, " moved", move4                  exit             end if                         delay (1000)         end if         cls     end for end loop Thuged_Out_G Posted: Fri Mar 19, 2004 5:37 pm   Post subject: (No subject)

but in your code, you only allow 2-4 players....i dont even understand wahts going on in the game Paul  Posted: Fri Mar 19, 2004 5:39 pm   Post subject: (No subject)

that would be simpler, but I was going for the one thats ez to understand yes? KukuriChan Posted: Fri Mar 19, 2004 5:43 pm   Post subject: (No subject)

I forgot to mention that the game has to have at least 2 people playing. ^^ That's why I put 2-4 people in the code. Paul  Posted: Fri Mar 19, 2004 6:21 pm   Post subject: (No subject)

Yea, I kinda figured that after, but hey, I use to play this by myself when I was sick back then  KukuriChan Posted: Fri Mar 19, 2004 7:47 pm   Post subject: (No subject)

I can't seem to figure out how I can fix the error though..... I mean, I changed the number of characters but then it keeps on repeating the same player over and over again. I don't know how I can fix it.  SuperGenius Posted: Fri Mar 19, 2004 8:09 pm   Post subject: (No subject)

I've improved on the form of this signifigantly I think, and as you can see the number on lines is a lot less this way. It's just more convenient.
By the way, You are trying to make the game Parchesi, are you not?
 code: var players, roll, move1, move2, move3, move4, pawn, numpawns, playernum : int var player : array 1 .. 4 of boolean move1 := 0 move2 := 0 move3 := 0 move4 := 0 for a : 1 .. 4     player (a) := false end for proc movedecisions     put "Player ", playernum, " Rolled a ", roll     if roll = 6 then         player (playernum) := true         put "Which Pawn do you want to move?"         get pawn         put "Pawn", pawn, "moved into 'Start Flying' mode"     end if     if roll <= 5 and player (playernum) = true then         put "Which Pawn do you want to move?"         get pawn         assert pawn > 0         if pawn = 1 then             move1 := move1 + roll             put "Pawn ", pawn, " moved", move1         elsif pawn = 2 then             move2 := move2 + roll             put "Pawn ", pawn, " moved", move2         elsif pawn = 3 then             move3 := move3 + roll             put "Pawn ", pawn, " moved", move3         elsif pawn = 4 then             move4 := move4 + roll             put "Pawn ", pawn, " moved", move4         end if     end if end movedecisions loop     put "Enter number of players 1-4"     get players     put "Enter number of pawns 1-4"     get numpawns     if players >= 2 and players <= 4 and numpawns > 0 and numpawns <= 4 then         cls         exit     end if     cls end loop loop     for a : 1 .. players         randint (roll, 1, 6)         playernum := a         movedecisions         delay (1000)         cls     end for end loop Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First        Page 1 of 2  [ 22 Posts ]
Goto page 1, 2  Next
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: