For this assignment, your job is to create a version of a
carnival game in which mechanical dogs race along a track. The
racing game is called DogTrack. DogTrack is also the name of the
java source file you must submit to complete the assignment. The
DogTrack class should be written so that the driver class below,
DogDriver, works as intended.
A dog track has N discrete positions, 0 through N-1. The value of N
is determined interactively in the application driver (below) once
your program begins running.
There are three dogs, named Fido, Spot, and Rover. Each starts at
position 0. A spinner selects (returns) a random value from among
the values 1-2-3-4-5; these values are equally likely. Each dog
advances by a separate spin of the spinner. In general a dog
advances 1 space when the spinner spins a 1, 2 spaces when the
spinner spins a 2, and so forth. The game is over when (at least)
one of the dog crosses the finish line, that is, when at least one
dog reaches a board value that is greater than or equal to
(N-1).
A special condition: if a dog lands exactly at position number N/3
or position number 2N/3, where N is the size of the track, then
that dog returns to its position before the move was made, and then
moves back one more square, if possible. Because there are no
negative positions, a dog at 0 that advances to N/3 on the first
move does NOT go to (negative) position -1; after the move it
should simply remain at position 0. See sample run below for an
example.
At each round, the track should be drawn, using the symbol o, and
the letters F, S, and R (for Fido, Spot, and Rover).
You should draw the state of the race as three "lines", one for
each dog, using an 'o' to represent unoccupied positions, and F,R,
and S to represent dog positions. These 3 line groups should be
separated by a row of dashes, as shown in the sample run below. If
the track size is 10, then this drawing
ooooooSooo
means that the dog Spot is at location 6 on the track, with earlier
positions 0-5 unoccupied (dog tracks always begin with position
0).
A requirement: your DogTrack class must include and MAKE ESSENTIAL USE OF the following methods, in addition to the DogTrack constructor and principal method playGame(). These are:
* spin - generates an integer value from 1 to 5 at random
* move - advances the pieces (alternative: instead of a move method write 3 separate methods, moveRover, moveSpot, moveFido)
* isOver - checks if race termination condition has been met
* showTrack - draws the three tracks using 'o' and a dog letter to indicate dog position. Should insert a row of dashes after the three tracks are displayed.
* showWinners - reports the winning dog or dogs when the race ends (see example above.)
//DogTrack.java
public class DogTrack
{
//create private spin variables for s,r and f
private int s;
private int r;
private int f;
int trackSize; //declare a track size
//constructor that sets the size
public DogTrack(int size)
{
trackSize = size;
s=0;
r=0;
f=0;
}
//The method playGame that calls the spin and
corrspodning dog to advance
//the positiono of dog until the game is over
//if game is over then the game stops and display the
track
//adn winner
public void playGame()
{
while (isOver()==false)
{
spin();
moveRover();
spin();
moveSpot();
spin();
moveFido();
showTrack();
}
if (isOver()==true)
{
showTrack();
showWinners();
}
}
//The metod moveRover calls th spin to get the
random value between 1 and 5
public void moveRover()
{
r = r + spin();
}
//The metod moveSpin calls th spin to get the random
value between 1 and 5
public void moveSpot()
{
s = s + spin();
}
//The metod moveFido calls th spin to get the random
value between 1 and 5
public void moveFido()
{
f = f + spin();
}
//Return a random value between 1 and 5
public int spin ()
{
return
1+(int)(Math.random()*5);
}
//check if the dog crosss the track size
public boolean isOver()
{
if(r >= (trackSize - 1) || s
>= (trackSize - 1) || f >= (trackSize -1))
return
true;
else
return
false;
}
//Displays the tracks of three dogs
public void showTrack()
{
String rover = "";
for (int x = 0; x <trackSize;
x++)
{
if(r >=
x)
rover = rover + "R";
else
rover = rover + "o";
}
String spot = "";
for (int x = 0; x <trackSize;
x++)
{
if(s >=
x)
spot = spot + "S";
else
spot = spot + "o";
}
String fido = "";
for (int x = 0; x <trackSize;
x++)
{
if(f >=
x)
fido = fido + "F";
else
fido = fido + "o";
}
System.out.println(rover);
System.out.println(spot);
System.out.println(fido);
}
//Displays winner of the game
public void showWinners()
{
String winner = "";
if (r>=(trackSize-1))
winner= "Rover
Wins!";
else if (s>=(trackSize-1))
winner= "Spot
Wins!";
else if (f>=(trackSize-1))
winner= "Fido
Wins!";
System.out.println(winner);
}
}
-------------------------------------------------------------------------------------------------------------------
//The program prompts user to enter the size of the track
//and prints the winner of the game with locations of dogs
//DogDriver.java
import java.util.Scanner;
public class DogDriver
{
public static void main(String[] args)
{
System.out.println("Enter an int > 3: size of
the track");
Scanner s = new
Scanner(System.in);
int trackSize =
s.nextInt();
System.out.println("track Size: " +
trackSize);
DogTrack d = new
DogTrack(trackSize);
d.playGame();
}
}
-------------------------------------------------------------------------------------------------------------------
sample ouput:
Enter an int > 3: size of the track
6
track Size: 6
RRRRoo
SSSSSS
FFoooo
RRRRoo
SSSSSS
FFoooo
Spot Wins!
Hope this helps you
For this assignment, your job is to create a version of a carnival game in which...
For this assignment, your job is to create a simple game called
Opoly.
The objectives of this assignment are to:
Break down a problem into smaller, easier problems.
Write Java methods that call upon other methods to accomplish
tasks.
Use a seed value to generate random a sequence of random
numbers.
Learn the coding practice of writing methods that perform a
specific task.
Opoly works this way: The board is a circular track of variable
length (the user determines the...
2. One the last exam, you analyzed a mini-version of the board game Chutes and Ladders. For your reference, this information is repeated on the next page. (a) Give the one-step transition matrix P for the Markov chain {Xn,n 2 0]. (This is the same question that was on the exam) (b) What is the expected length (number of spins) of a game? (c) In which square should the player expect to spend the most time? (d) In which square...
For this assignment, you will create a command-line version of the game Hangman. For this assignment you will research on StringBuilder Class (Use this link) and use it in your code. Please finish the program in Java Language Your game should have a list of at least ten phrases of your choosing (appropriate to all audiences please!) The game chooses a random phrase from the list. This is the phrase the player tries to guess. (10) ● The phrase is...
(C++) Please create a tic tac toe game. Must write a Player class to store each players’ information (name and score) and to update their information (increase their score if appropriate) and to retrieve their information (name and score).The players must be called by name during the game. The turns alternate starting with player 1 in the first move of round 1. Whoever plays last in a round will play second in the next round (assuming there is one).The rows...
JAVA Program The Game This is a simple game played on a linear board with squares numbered from 0 to 100. The player starts at position 0, and the object of the game is to land on position 100 exactly. Objectives By the end of this program, the student will have demonstrated the ability to Write static methods Call a static method in another class Pass parameters to a method Return values from a method Write loops Write if statements...
Assignment - Battleship In 1967, Hasbro toys introduced a childrens game named “Battleship”. In the next two assignments you will be creating a one-player version of the game. The game is extremely simple. Each player arranges a fleet of ships in a grid. The grid is hidden from the opponent. Here is an ASCII representation of a 10x10 grid. The ‘X’s represent ships, the ‘~’s represent empty water. There are three ships in the picture: A vertical ship with a...
6.2 all parts please
Problems Consider an array of nine drives in which X0 through X7 contain data an parity disk. Provide an equation that describes the relationship between data and par- ity bits. 6.1 d X8 is the 62 Consider a disk with N tracks numbered from 0 to (N 1) and assume that requested sectors are distributed randomly and evenly over the disk. We want to calculate the average number of tracks traversed by a seek. a. First,...
Write a class named FBoard for playing a game...
PLEASE USE C++
PLEASE DO NOT USE "THIS -->". NOT
ALLOWED
PLEASE PROVIDE COMMENTS AND OUTPUT!
Write a class named FBoard for playing a game, where player x is trying to get her piece to row 7 and player o is trying to make it so player x doesn't have any legal moves. It should have: An 8x8 array of char for tracking the positions of the pieces. A data member...
== Programming Assignment == For this assignment you will write a program that controls a set of rovers and sends them commands to navigate on the Martian surface where they take samples. Each rover performs several missions and each mission follows the same sequence: deploy, perform one or more moves and scans, then return to base and report the results. While on a mission each rover needs to remember the scan results, in the same order as they were taken,...