I WILL AWARD 3000 FOR THIS QUESTION The objective of this assignment is to build
ID: 648364 • Letter: I
Question
I WILL AWARD 3000 FOR THIS QUESTION
The objective of this assignment is to build a simple board game. You are going to run a simulation of two players (cat and dog) playing a complete game and determining who the winner is. On the instruction page following the game board, this assignment is broken into several small steps so you don?t get confused. Just follow the instructions carefully. The game board:
Consists of 22 squares
Each square either:
Gives treats to the player
Star: Win 5 treats
Smiley: Win 10 treats o
Takes treats away from the player
Lightning: Lose 5 treats
X: Lose 10 treats
Does nothing ?
All players start on the first square (START)
A player takes a turn by rolling one die, and then moves ahead the number of squares indicated by the die roll.
If the player lands on a non-??blank square, treats are added or taken away from the player. A PLAYER MAY NOT GO NEGATIVE ? e.g. if a player owns 5 treats and lands on the ?lose 10 treats? square, it brings the players treat count to zero.
A player continues to roll the die and move on the board until reaching the END square.
If a player rolls a number greater than the number required to land on the last square, the player must move backward the number of squares indicated by the die. That player will continue to move forward on the next turn. Until the player gets the exact roll required to land on the last square, they may continue to go backward and forward several times.
After the first player completes the board, the second player goes to completion.
After both players have landed on the END square, display the total treats owned by each player and display the name of the winner. Note: Some authors use UNDERSCORES in method names to identify static methods; but we will use underscores to identify the CONSTRUCTOR methods.
1. Create a landOn method in cell which returns the score amount to be added to the player?s score when landed on. The Cell class should return a score of zero. (It represents a blank cell.)
2. The toString method in Cell should return ?Blank?.
3. Create four subclasses of the class Cell. Each should override the landOn method to return the score of that cell subtype. Also override the toString method in each subclass to return the name of the type of cell it is:
a. Star: +5
b. Smiley: +10
c. Lightning: -5 d. X: -10
4. The buildBoard method in the class BoardGame should create instances of the correct type of Cell for each location on the board. Use the superclass Cell for blank cells, and use the appropriate subclass for the other four types of cell.
5. Create a new class called Player that maintains the name and score of each player.
6. Create an ArrayList of Player objects.
7. In the constructor for BoardGame, create a separate Player object for each player name.
8. The simulation code should handle multiple Player objects from the players ArrayList.
I WILL AWARD 3000 FOR THIS QUESTION The objective of this assignment is to build a simple board game. You are going to run a simulation of two players (cat and dog) playing a complete game and determining who the winner is. On the instruction page following the game board, this assignment is broken into several small steps so you don??t get confused. Just follow the instructions carefully. The game board: Consists of 22 squares Each square either: Gives treats to the player Star: Win 5 treats Smiley: Win 10 treats o Takes treats away from the player Lightning: Lose 5 treats X: Lose 10 treats Does nothing ? All players start on the first square (START) A player takes a turn by rolling one die, and then moves ahead the number of squares indicated by the die roll. If the player lands on a non-blank square, treats are added or taken away from the player. A PLAYER MAY NOT GO NEGATIVE ?? e.g. if a player owns 5 treats and lands on the ??lose 10 treats?? square, it brings the players treat count to zero. A player continues to roll the die and move on the board until reaching the END square. If a player rolls a number greater than the number required to land on the last square, the player must move backward the number of squares indicated by the die. That player will continue to move forward on the next turn. Until the player gets the exact roll required to land on the last square, they may continue to go backward and forward several times. After the first player completes the board, the second player goes to completion. After both players have landed on the END square, display the total treats owned by each player and display the name of the winner. Note: Some authors use UNDERSCORES in method names to identify static methods; but we will use underscores to identify the CONSTRUCTOR methods. 1. Create a landOn method in cell which returns the score amount to be added to the player??s score when landed on. The Cell class should return a score of zero. (It represents a blank cell.) 2. The toString method in Cell should return ??Blank??. 3. Create four subclasses of the class Cell. Each should override the landOn method to return the score of that cell subtype. Also override the toString method in each subclass to return the name of the type of cell it is: a. Star: +5 b. Smiley: +10 c. Lightning: -5 d. X: -10 4. The buildBoard method in the class BoardGame should create instances of the correct type of Cell for each location on the board. Use the superclass Cell for blank cells, and use the appropriate subclass for the other four types of cell. 5. Create a new class called Player that maintains the name and score of each player. 6. Create an ArrayList of Player objects. 7. In the constructor for BoardGame, create a separate Player object for each player name. 8. The simulation code should handle multiple Player objects from the players ArrayList.Explanation / Answer
class GameTester
public class GameTester
{
public static void main(String[] args)
{
BoardGame b=new BoardGame();
b.runSimulation();
}
}
class BoardGame
import java.util.ArrayList;
public class BoardGame
{
private ArrayList<Cell> cell;
private ArrayList<Player> player;
private Die dice;
public BoardGame()
{
dice = new Die();
player = new ArrayList<Player>();
player.add(new Player("Dog"));
player.add(new Player("Cat"));
}
public void buildBoard()
{
cell = new ArrayList<Cell>(22);
cell.add(new Cell());
cell.add(new Cell());
cell.add(new Star());
cell.add(new X());
cell.add(new Smiley());
cell.add(new Cell());
cell.add(new Star());
cell.add(new Lightning());
cell.add(new Cell());
cell.add(new X());
cell.add(new Cell());
cell.add(new Cell());
cell.add(new Star());
cell.add(new Lightning());
cell.add(new Cell());
cell.add(new Star());
cell.add(new Cell());
cell.add(new X());
cell.add(new Lightning());
cell.add(new Smiley());
cell.add(new Star());
cell.add(new Cell());
}
public void runSimulation()
{
System.out.println("STARTING THE GAME:");
int score1=takeTurn(player.get(0));
int score2=takeTurn(player.get(1));
if(score1>score2){
System.out.println("Player 1 won");
}else{
System.out.println("Player 2 won");
}
}
public int takeTurn(Player player)
{
if(score<0)
score=0;
else
score+=1;
return score;
}
public String toString()
{}
}
class Player
public class Player
{
private String name;
private int score;
public Player(String nm)
{
name=nm;
score=0;
}
public int getScore()
{
return score;
}
public void setScore(int sc)
{
score += sc;
}
public String toString()
{
return name;
}
}
class Die
public class Die
{
private int faceValue;
private ArrayList<Integer> face;
public Die()
{
roll();
Random r=new Random();
faceValue=r.nextInt(6);
face =new ArrayList<Integer>(6);
face.add( new Integer(1));
face.add( new Integer(2));
face.add( new Integer(3));
face.add( new Integer(4));
face.add( new Integer(5));
face.add( new Integer(6));
}
public int roll()
{
faceValue=(int)(Math.random()*6 + 1);
return faceValue;
}
public String toString()
{
return "Rolled "+faceValue;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.