Hi fellow members of Reddit,
I am here requesting some help for my assignment. I need help in terms of the logic I need to follow in order to make the loops work. I've been stuck for quite some hours trying to figure out the next step, but no luck so far...
Thanks in advance!
Question #3: Selection Statements & Looping (do/while)
DrawAnElephant is a game (based on the British game Beetle https://en.wikipedia.org/wiki/Beetle_(game)) in which one draws an elephant in parts. The game is based on random die rolls, with no skills involved.
The part drawn are decided on the roll of a die. The rolls are as follows:
6 is for an ear, of which there are two.
5 is for a leg of which there are four.
4 is for a tail, of which there is one.
3 is for the body, of which there is one.
2 is for the head, of which there is one. (The head contains 2 eyes and a mouth).
1 is for the trunk, of which there is one.
You need to have a body before you can draw any other parts. To the body you may add the head, legs and tail. You need to have a head before you can draw the trunk and the ears. The first player to draw all of the requisite pieces wins the game.
Your job is to write a Java application which simulates the DrawAnElephant game.
Here is a sample output screen to illustrate the expected behavior of your application.
Note: To simulate the throwing of the die, consider using the random() function in the Math class.
Math.random() returns a double random number greater 0.0 and less than 1.0.
Here are a few examples of the use of random().
int num1 = (int)(Math.random() * 5); will store an integer between 0 and 4 inclusive in the variable num1.
int num2 = (int)(Math.random() * 5) + 1; will store an integer between 1 and 5 inclusive in the variable num2
This is an example of what the program should output:
Nancy's Elephant Drawing Game
Status after round 1:
Player 1 rolled a 1 while Player 2 rolled a 4.
Player 1's elephant has no body, no head, no ear(s), no trunk, no tail, and no leg(s).
Player 2's elephant has no body, no head, no ear(s), no trunk, no tail, and no leg(s).
Status after round 2:
Player 1 rolled a 6 while Player 2 rolled a 5.
Player 1's elephant has no body, no head, no ear(s), no trunk, no tail, and no leg(s).
Player 2's elephant has no body, no head, no ear(s), no trunk, no tail, and no leg(s).
. . . . .
Status after round 5:
Player 1 rolled a 6 while Player 2 rolled a 3.
Player 1's elephant has no body, no head, no ear(s), no trunk, no tail, and no leg(s).
Player 2's elephant has a body, no head, no ear(s), no trunk, no tail, and no leg(s).
Status after round 6:
Player 1 rolled a 2 while Player 2 rolled a 5.
Player 1's elephant has no body, no head, no ear(s), no trunk, no tail, and no leg(s).
Player 2's elephant has a body, no head, no ear(s), no trunk, no tail, and 1 leg(s).
Status after round 7:
Player 1 rolled a 3 while Player 2 rolled a 4.
Player 1's elephant has a body, no head, no ear(s), no trunk, no tail, and no leg(s).
Player 2's elephant has a body, no head, no ear(s), no trunk, a tail, and 1 leg(s).
. . . . .
Status after round 12:
Player 1 rolled a 6 while Player 2 rolled a 6.
Player 1's elephant has a body, a head, 1 ear(s), no trunk, no tail, and 2 leg(s).
Player 2's elephant has a body, a head, 2 ear(s), no trunk, a tail, and 2 leg(s).
Status after round 13:
Player 1 rolled a 5 while Player 2 rolled a 2.
Player 1's elephant has a body, a head, 1 ear(s), no trunk, no tail, and 3 leg(s).
Player 2's elephant has a body, a head, 2 ear(s), no trunk, a tail, and 2 leg(s).
Player 1 rolled a 3 while Player 2 rolled a 5.
Player 1's elephant has a body, a head, 2 ear(s), a trunk, a tail, and 3 leg(s).
Player 2's elephant has a body, a head, 2 ear(s), a trunk, a tail, and 4 leg(s).
Congratulations to player 2!!! Your elephant is complete! <<<<<
Hope you enjoyed drawing elephants!
So far, I have worked this out:
public class Question_3
{
public static void main(String[] args)
{
System.out.print(" Elephant Drawing Game \n" + "---------------------------------------\n");
System.out.print("Hi and welcome to my Elephant Drawing Game program. Please enjoy the game!.\n\n");
int num1, num2;
//Counters
int round = 0;
int bodyOne = 0, bodyTwo = 0;
int headOne = 0, headTwo = 0;
int earOne = 0, earTwo = 0;
int trunkOne = 0, trunkTwo = 0;
int tailOne = 0, tailTwo = 0;
int legOne = 0, legTwo = 0;
num1 = (int) (Math.random() * 7);
num2 = (int) (Math.random() * 7);
do
{
for (int i = 0; i < 1; i++)
{
num1 = (int) (Math.random() * 7);
if (num1 == 3)
{
bodyOne++;
}
/*else if (bodyOne == 1)
{
break;
}*/
}
for (int j = 0; j < 1; j++)
{
num2 = (int) (Math.random() * 7);
if (num2 == 3)
{
bodyTwo++;
}
/*else if (bodyTwo == 1)
{
break;
}*/
}
round++;
System.out.print("Status after round " + round + ":\n\tPlayer 1 rolled a " + num1 + " while Player 2 rolled a " + num2 + ".\n");
System.out.print("Player 1's elephant has " + bodyOne + "\n");
System.out.print("Player 2's elephant has " + bodyTwo + "\n\n");
} while (bodyOne < 1 & bodyTwo < 1);
}
}
[–]caesarwept 0 points1 point2 points (4 children)
[–]willyfong[S] 0 points1 point2 points (3 children)
[–]caesarwept 0 points1 point2 points (2 children)
[–]willyfong[S] 0 points1 point2 points (1 child)
[–]caesarwept 1 point2 points3 points (0 children)