Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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 1777 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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

BurntPizza (14 views)
2014-09-19 03:14:18

Dwinin (32 views)
2014-09-12 09:08:26

Norakomi (58 views)
2014-09-10 13:57:51

TehJavaDev (80 views)
2014-09-10 06:39:09

Tekkerue (40 views)
2014-09-09 02:24:56

mitcheeb (62 views)
2014-09-08 06:06:29

BurntPizza (45 views)
2014-09-07 01:13:42

Longarmx (31 views)
2014-09-07 01:12:14

Longarmx (37 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!