Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Opoly{
- private int BoardSize;
- public int Position = 0;
- public int Score = 12;
- public int roundCount = 0;
- public Opoly(int size){
- BoardSize = size;
- }
- public int spin(){
- return ((int)(Math.random()*5) + 1);
- }
- public void move(){
- int b = spin();
- if(Position + b <= BoardSize){
- Position = Position + b;
- if (Position == BoardSize -1){
- Score = Score/5;
- Position = 0;
- }
- else{
- if(Position%5==0){
- Score*=2;
- }
- }
- }
- roundCount ++;
- }
- public boolean isGameOver(){
- if(Position == BoardSize){
- return true;
- }
- else{
- return false;
- }
- }
- public void drawBoard(){
- for(int p = 0; p <= BoardSize; p++){
- if(p == Position)
- System.out.print(0);
- else
- System.out.print("*");
- }
- System.out.println(Score);
- }
- public void displayReport(){
- System.out.println(" Game Over");
- System.out.println("You played " + roundCount + " rounds!");
- System.out.println("Your final score is " + Score);
- }
- public void playGame(){
- while(isGameOver() == false){
- this.move();
- this.drawBoard();
- }
- this.displayReport();
- }
- }
Add Comment
Please, Sign In to add comment