Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (754)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (842)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Taking turns?  (Read 4289 times)
0 Members and 1 Guest are viewing this topic.
Offline punstress

Innocent Bystander

« Posted 2010-12-06 01:37:33 »

Hey all, I'm a newbie both to this forum and pretty new to Java. Please don't be too harsh!

For my first try, I want to make a little dice game called Pig. A player rolls the dice and accumulates points until she either holds or "craps out" by rolling a 1, playing against the computer.

I've got a lot of it on paper, not coding much yet because I keep getting hung up on how to take turns. I've got to know who the active player is obviously, so they can move, and each time the play shifts to another player, the dice score has to be reset, and the totals may change, etc.

I've thought of passing the active player to methods as a parameter, or creating an activePlayer object that alternately points to one player, or using some kind of boolean for my Player class like isActive, etc. Looking for code examples has been a lot harder than I thought it would be.

Is there any kind of system that's been established as the best?
Offline CyanPrime
« Reply #1 - Posted 2010-12-06 03:41:27 »

Well, a boolean or int should be used to keep track of turns. If it's just one player you could just have 2 values for scores, and when the player rolls just set the enemies turn after that.

Also you should look into arrays, as that'll really help you out.
Offline dbotha

Senior Newbie

« Reply #2 - Posted 2010-12-06 07:58:28 »

Is there any kind of system that's been established as the best?

Nope. You'll probably find that given the same problem most people approach it in their own slightly different way. Granted some solutions will be better than others, but this will all come down to experience Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline fireside

Senior Newbie

« Reply #3 - Posted 2010-12-06 22:08:22 »

I'm working on a little turn based game and I keep the players in an array.  Then I can just do players[playerNum].doTurn();
If you are working on a two player game, it wouldn't be very important, but with more players, and different types, it becomes more useful.  You might want to set up a finite state machine if the player has choices and does different things for the ai part.  Actually, it would be completely unnecessary for a two player because the computer has to have ai and the human has to do input.  The human probably ended his/her turn on some input and then it's the ai turn.
Pages: [1]
  ignore  |  Print  

DesertCoockie (33 views)
2018-05-13 18:23:11

nelsongames (75 views)
2018-04-24 18:15:36

nelsongames (70 views)
2018-04-24 18:14:32

ivj94 (752 views)
2018-03-24 14:47:39

ivj94 (82 views)
2018-03-24 14:46:31

ivj94 (622 views)
2018-03-24 14:43:53

Solater (98 views)
2018-03-17 05:04:08

nelsongames (179 views)
2018-03-05 17:56:34

Gornova (405 views)
2018-03-02 22:15:33

buddyBro (1065 views)
2018-02-28 16:59:18
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!