Guest User

Untitled

a guest
Feb 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. public class Opoly{
  2.  
  3. private int BoardSize;
  4. public int Position = 0;
  5. public int Score = 12;
  6. public int roundCount = 0;
  7.  
  8. public Opoly(int size){
  9. BoardSize = size;
  10. }
  11.  
  12. public int spin(){
  13. return ((int)(Math.random()*5) + 1);
  14. }
  15.  
  16. public void move(){
  17. int b = spin();
  18. if(Position + b <= BoardSize){
  19. Position = Position + b;
  20. if (Position == BoardSize -1){
  21. Score = Score/5;
  22. Position = 0;
  23. }
  24. else{
  25. if(Position%5==0){
  26. Score*=2;
  27. }
  28. }
  29. }
  30.  
  31. roundCount ++;
  32. }
  33.  
  34. public boolean isGameOver(){
  35. if(Position == BoardSize){
  36. return true;
  37. }
  38. else{
  39. return false;
  40. }
  41. }
  42.  
  43. public void drawBoard(){
  44. for(int p = 0; p <= BoardSize; p++){
  45. if(p == Position)
  46. System.out.print(0);
  47. else
  48. System.out.print("*");
  49.  
  50. }
  51. System.out.println(Score);
  52. }
  53.  
  54. public void displayReport(){
  55. System.out.println(" Game Over");
  56. System.out.println("You played " + roundCount + " rounds!");
  57. System.out.println("Your final score is " + Score);
  58. }
  59.  
  60. public void playGame(){
  61. while(isGameOver() == false){
  62. this.move();
  63. this.drawBoard();
  64. }
  65. this.displayReport();
  66. }
  67.  
  68. }
Add Comment
Please, Sign In to add comment