PigGame

ok, now i have to make this game called pig, where i have to call upon this class called pair of dice.

publicclass PairOfDice

{

privatefinalint MAX = 6;

privateint faceValue1, faceValue2, Sum;

private Die die1, die2;

public PairOfDice()

{

die1 =new Die();

die2 =new Die();

}

publicint getValue1()

{

faceValue1 = die1.roll();

return faceValue1;

}

publicint getValue2()

{

faceValue2 = die2.roll();

return faceValue2;

}

publicvoid setFaceValue1(int die1)

{

faceValue1 = die1;

}

publicvoid setFaceValue2(int die2)

{

faceValue2 = die2;

}

publicint getSum()

{

Sum = faceValue1 + faceValue2;

return Sum;

}

}

and this is how i have my pig game started.

import java.io.*;

class PigGame

{

publicstaticvoid main (String[] args)throws IOException

{

int initialplayer1 = 0;

int initialplayer2 = 0;

int totalplayer1 = 0;

int totalplayer2 = 0;

String play ="y";

and here is the die class that pairofdice is calling on

publicclass Die

{

privatefinalint MAX = 6;

privateint faceValue;

public Die()

{

faceValue = 1;

}

publicint roll()

{

faceValue = (int)(Math.random() * MAX) + 1;

return faceValue;

}

publicvoid setFaceValue (int value)

{

faceValue = value;

}

publicint getFaceValue()

{

return faceValue;

}

public String toString()

{

String result = Integer.toString(faceValue);

return result;

}

}

now what do i need to get the game to callupon the pairofdice class

I also need to create a while loop that asks if a human player wants to take his/her turn, if the player says no then the game is given to the computer. and the computer plays until it wins, or if it misses its turn.

How should i start this while loop?

Can AnyOne HELP!!!!

[4717 byte] By [bebopa] at [2007-10-2 5:39:29]
# 1

you would instantiate your class PairOfDice in your main method...

PairOfDice pd = new PairOfDice();

and call it methods in you loop...

example...

while ( some condtion){

int dieOneValue = pd.getValue1();

// more code...

}

granted that this is just as an example... you code will look different...

have fun...

- MaxxDmg...

- ' He who never sleeps... '

MaxxDmga at 2007-7-16 1:49:49 > top of Java-index,Java Essentials,Java Programming...
# 2

here are the rules for the game. i still annot figure out what to make the condition for the while statement. i need the human player to go first, and for the computer to follow.

The user plays against the computer. At the beginning, each has a total score of zero and the user plays first. The user rolls 2 dice. Say a "2" and a "5" are rolled. The user's current round score is 7. The user can roll again, or pass the two die to the computer. If the user rolls again, and a "1" shows up on either die, the user's current round score becomes zero and control of the dice passes to the computer. If the user rolls a "1" and a "1", then both the total score and current round score are set to zero, and control of the dice passes to the computer. If the user at any point voluntarily gives up control of the dice, the user's current round score is added to their total score, current round score is reset to zero, and the computer has control of the dice. The user and computer alternate control of the dice according to the above rules. The first player to reach 100 wins! The computer always gives up control of the dice after accumulating >= 20 points in a round. Implement a GUI for the game.

bebopa at 2007-7-16 1:49:49 > top of Java-index,Java Essentials,Java Programming...
# 3
can anyone give me a hand with this, ive been working on this all day, and i dont know what to do.
bebopa at 2007-7-16 1:49:49 > top of Java-index,Java Essentials,Java Programming...
# 4

break the problem down to it's logical steps...

example...

1.The user rolls 2 dice.

2. If the user dice roll equals 7

3. prompt the user with a choice where they can roll again, or pass the two die to the computer

and so on...

the logic will emerge as you break it down and you will be able to figure out the code...

- MaxxDmg...

- ' He who never sleeps... '

MaxxDmga at 2007-7-16 1:49:49 > top of Java-index,Java Essentials,Java Programming...
# 5

this is my code so far

import java.io.*;

import java.util.Scanner;

class PigGame

{

public static void main (String[] args) throws IOException

{

int initialplayer1 = 0;

int initialplayer2 = 0;

int totaldieplayer1 = 0;

int totaldieplayer2 = 0;

String play = "y";

PairOfDice dice = new PairOfDice();

while ( // i need a while statement here)

int die1value = dice.getValue1;

int die2value = dice.getValue2;

System.out.println ("Die one has a value of: " + die1value);

System.out.println ("Die two has a value of: " + die2value);

totaldieplayer1 = die1value + die2value;

if (die1value.equals(1) && die2.equals(1))

{

initialplayer1 = 0

totaldieplayer1 =0

System.out.println ("You rolled two ones: You lose your turn and all of your points.");

}

if (die1value.equals(1) || die2value.equals(1));

{

initialplayer1 = 0;

System.out.println ("You rolled a one with one of the dice: you lose your turn, and the points accumulated for this round");

}

int POINTSPLAYER1 = initialplayer1 + totaldieplayer1;

if ( //i need an if statement here)

can anyone help me fill in some of the spaces where i posted comments. and let me know anywhere else i am going wrong.

bebopa at 2007-7-16 1:49:49 > top of Java-index,Java Essentials,Java Programming...
# 6
does anyone have any ideas?I really needhelp with this!!!
bebopa at 2007-7-16 1:49:49 > top of Java-index,Java Essentials,Java Programming...
# 7
> does anyone have any ideas?> I really needhelp with this!!!You have no specific questions. The only implied questions I see are "will someone please finish/fix my homework for me?". And you've been busy doing that, apparantly.
warnerjaa at 2007-7-16 1:49:49 > top of Java-index,Java Essentials,Java Programming...
# 8

... also I see that out of the 25 original duke dollars you were given when you signed up, you have a total of 21 yet-to-be-awarded points that you've attached across 3 different topics. I can't tell if you ever awarded the other 4 anywhere, but I'm making a safe assumption that you haven't. Though they are worthless, it is still pretty darn rude of you to attach them to your subjects with no apparant intention of actually awarding them to any of the nice folks who have attempted to answer you so far.

Obviously I'm not including myself in that bunch. But I think I'm saying the sentiments on their behalf.

warnerjaa at 2007-7-16 1:49:49 > top of Java-index,Java Essentials,Java Programming...
# 9
The question i am trying to ask is can anyone give me a hand in trying to figure out what these while statements should be. I am only new at programming, and i do not know many of the commands.
bebopa at 2007-7-16 1:49:49 > top of Java-index,Java Essentials,Java Programming...
# 10

> The question i am trying to ask is can anyone give me

> a hand in trying to figure out what these while

> statements should be.

i already given you a hint in how to figure out your conditional boolean expressions that you would use for both your loops and if statements...

break the description into it basic logical components...

here is a example...

the task - you will add two numbers together until you reach the sum 50 or more...

so breaking it down...

1. until the sum is 50 or more

2. add two numbers together

next is to write out the steps in pseudo code...

1. while sum is less than 50 execute the next steps in loop body...

2. begin loop body

3. add two numbers together and assign it to a sum variable

4. end loop body

granted this is kinda verbose, but you get the ideal... next it to write the code...

while ( sum < 50 )

{ // begin while loop body

sum = sum + number1 + number2; // adds two numbers and adds it to the sum...

} //end while loop body

and there you have a while loop constructed...

part of programming is knowing how to solve word problems like you had to when you took math class... heheh... :-p

so break down the problem description into smaller chunks and solve those and soon you will have the foundation to start writing code...

have fun... :-)

- MaxxDmg...

- ' He who never sleeps... '

MaxxDmga at 2007-7-16 1:49:49 > top of Java-index,Java Essentials,Java Programming...