So my counselor signed me up in an AP Computer Science class this year(YES, I'm the only girl). I had no idea that I would be programming in Java, and I was pretty scared since I didn't take any of the introductory classes. Anyway, we were given a project, and although I have come a long way from what I started, I have no idea how to do it. Please help?
For this assignment, your job is to create a kind of lobotomized version of a board game (such as Monopoly) called Opoly.
Opoly works this way: The board is a circular track of variable length (you determine the length when you start up the game). 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 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:
1) If your board piece lands on a board cell that is evenly divisible by 7, your reward doubles.
2) 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).
3) 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,
4) 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();
}
}
Here is a sample run:
> java OpolyDriver
Enter an int - the size of the board
[DrJava Input Box]
Board Size: 17
o**************** 100
*o*************** 100
*****o*********** 100
**********o****** 100
************o**** 100
o**************** 400 // 100 added to reward, then score is doubled at location 0
****o************ 400
********o******** 400
**********o****** 400
*************o*** 400
o**************** 900 // 10th turn - so reward reduced by 50; then 100 added; then score doubled
***o************* 900
*******o********* 1800 // at location 7, so score doubled
game over
rounds of play: 12
final reward: 1800
A requirement: your Opoly class must include and MAKE ESSENTIAL USE OF the following methods, in addition to the Opoly constructor and principal method playGame(). These are:
* spin - generates an integer value from 1 to 5 at random
* move - advances the piece
* spinAndMove - spins the spinner and then advances the piece according to the rules of the game (uses spin, move methods)
* isGameOver - checks if game termination condition has been met
* drawBoard - draws the board using *'s and an o to mark the current board position. Following each board display you should also report the current reward.
* displayReport - reports the end of the game, and gives the number of rounds of play, and the final reward
How to proceed:
* First, decide on the attributes for the Opoly class. At any instant, what is the "state" of the board? What do you need to keep track of to give the final report? The answers to these questions will tell you what the attributes to Opoly can be.
* Second, write the Opoly constructor.
* Third, try to write the playGame method using the methods outlined above. A good way to proceed is to write a "dummy" drawBoard method first - instead of having it draw anything, merely have it print the current position. Once you're satisfied with the general running of the game in this format, then work on the drawing part. Another simplification to start with: just implement the rule that increases the reward by 100 every time you circle the board. You can add the other rules later.
Paste your Opoly class code in the box below:
NOTE: you may NOT use any import statements in your class. Use the Math class random method to generate your random numbers. Do NOT import the java.util library. Do NOT implement your solution using arrays.