Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Opoly works this way: The board is a circular track of variable length (the user

ID: 3676993 • Letter: O

Question

Opoly works this way: The board is a circular track of variable length (the user determines the length when the game app runs). There is only one player, who begins the game at position 0.
Thus, if the board length is 20, then the board locations start at position 0 and end at position 19. The player starts with a reward of 100, and the goal of the game is to reach or exceed reward value 1000. When this reward value is reached or exceeded, the game is over. When the game ends, your program should report the number of turns the player has taken, and the final reward amount attained.

In Opoly the game piece advances via a spinner - a device that takes on one of the values 1, 2, 3, 4, 5 at random, with each of the five spin values equally likely.


Although the board is circular, you should draw the state of the board as a single "line", using an 'o' to represent the current player position, and * represent all other positions.
Thus if the board size is 10, then this board drawing:

**o******

means that the player is at location 2 on the board.

Here are the other Opoly game rules:

If your board piece lands on a board cell that is evenly divisible by 7, your reward doubles.

If you land on the final board cell, you must go back 3 spaces. Thus if the board size is 20, the last position is position 19, and if you land there, you should go back to position 16. (If the position of the last cell is evenly divisible by 7, no extra points are added, but if the new piece location, 3 places back, IS evenly divisible by 7, then extra points ARE added).

If you make it all the way around the board, you get 100 points. Note that if you land exactly on location 0, you first receive 100 extra points (for making it all the around), and then your score is doubled, since 0 is evenly divisible by 7,

Every tenth move (that is, every tenth spin of the spinner, move numbers 10,20,30,... etc.), reduces the reward by 50 points. This penalty is applied up front, as soon as the 10th or 20th or 30th move is made, even if other actions at that instant also apply. Notice that with this rule it's possible for the reward amount to become negative.


Here is the driver class for the game:
import java.util.*;

public class OpolyDriver{

public static void main(String[] args){
System.out.println("Enter an int > 3 - the size of the board");
Scanner s = new Scanner(System.in);
int boardSize = s.nextInt();
System.out.println("Board Size: " + boardSize);
Opoly g = new Opoly(boardSize);
g.playGame();
}
}

Explanation / Answer

/*****************OpolyDriver.java***************/

import java.util.*;

public class OpolyDriver{

public static void main(String[] args){
System.out.println("Enter an int > 3 - the size of the board");
Scanner s = new Scanner(System.in);
int boardSize = s.nextInt();
System.out.println("Board Size: " + boardSize);
Opoly g = new Opoly(boardSize);
g.playGame();
}
}

/**************Opoly.java*************/

public class Opoly{

private static int size; //how big the board is
private static int spin; //value of the spinner
private static int reward; //total points
private static int turnNumber; //how many turns have passed
private static char[] board; //the array of the board and holding the position of the player
private static boolean first; //temp variable to create the array with *'s and o

public Opoly(int s){ //constructor
size = s; //sets the size passed by the main method defined by the user
reward = 100; //startes player with 100 points
turnNumber = 0; //sets turn number to 0
board = new char[size]; //creates the array
first = true; //temp variable to create the array with *'s and o
}

public void playGame(){
Opoly.drawBoard(); //prints out board for the first time
while (Opoly.isGameOver()){ //checks when the player has recieved 1000 points or more
Opoly.spinAndMove(); //spins, moves, and adds points
Opoly.drawBoard(); //prints out the updated board and reward
}
Opoly.displayReport(); //displays the stats when the game is over
}

public static void spin(){
spin = (1 + (int)(Math.random() * 5)); //generates a number from 1 to 5
}

public static void move(){
if (turnNumber % 10 == 0) //RULE #4 - Every tenth move, reduces the reward by 50 points.
reward = reward - 50;

for (int k = 0; k < size; k++){ //finds the position of the player
if (board[k] == 'o'){
board[k] = '*';

if (k == (size - 1)){ //RULE #2 (condition 1) - If you land on the final board cell, you must go back 3 spaces.
board[k] = '*';
board[k - 3] = 'o';
if (((k - 3) % 7 == 0) && (k - 3 != 0)) //RULE #2 (condition 2 & 3) - If the position of the last cell is evenly divisible by 7, no extra points are added. If the new piece location, 3 places back, IS evenly divisible by 7, then extra points ARE doubled
reward = reward * 2;

if (((k - 3) + spin) >= size){ //brings the array back in bounds to cirlce the position of the player
board[k - 3] = '*';
reward = reward + 100; //RULE #3 - If you make it all the way around the board, you get 100 points.
board[((k - 3) + spin) - size] = 'o';
}
else if (((k - 3) + spin) <= size){ //moves the position when player is in bounds of array
board[k - 3] = '*';
board[(k - 3) + spin] = 'o';
}
}
else if ((k + spin) >= size){ //brings the array back in bounds to cirlce the position of the player
reward = reward + 100; //RULE #3 - If you make it all the way around the board, you get 100 points.
board[(k + spin) - size] = 'o';
}
else if ((k + spin) <= size) //moves the position when player is in bounds of array
board[k + spin] = 'o';

k = size; //resets k
}
}
}

public static void spinAndMove(){
turnNumber++; //adds a turn
Opoly.spin(); //sets a number to the spin variable
Opoly.move(); //moves the position
for (int k = 0; k < size; k++){ //adds points
if (board[k] == 'o'){
if (k == 0) //RULE #1 - Score is doubled, since 0 is evenly divisible by 7,
reward = reward * 2;
else if ((k % 7 == 0) && (k != (size - 1))) //RULE #1 - Score is doubled when it is evenly divisible by 7,
reward = reward * 2;
}
}
}

public static boolean isGameOver(){
boolean isOver = true; //checks if game is over
if (reward >= 1000) //if the reward is 1000 points or over than the game is over
isOver = false;
return isOver;
}

public static void drawBoard(){
if (first){ //temp variable is used to create the board for the first time
board[0] = 'o';
for(int i = 1; i < size; i++)
board[i] = '*';
}

for(int i = 0; i < size; i++) //for loop that prints out the updated board
System.out.print(board[i]);

System.out.println(" " + reward); //prints out the reward

first = false; //temp variable set to flase so it wont recreate the board again
}

public static void displayReport(){ //displays stats
System.out.println("game over");
System.out.println("rounds of play: " + turnNumber);
System.out.println("final reward: " + reward);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote