Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. /**
  2. * This is a board game implemented
  3. * as a doubly linked list. The list
  4. * starts with the first Space. The game
  5. * has only a single player, whose
  6. * position is stored in the playerSpace
  7. * variable.
  8. *
  9. */
  10. public class Boardgame
  11. {
  12. private Space first;
  13.  
  14. private Space playerSpace;
  15.  
  16. public Boardgame()
  17. {
  18. first = null;
  19. playerSpace = null;
  20. }
  21.  
  22. public Space getPlayerSpace()
  23. {
  24. return playerSpace;
  25. }
  26.  
  27. /**
  28. * add. Append Space s to the end of the doubly-linked
  29. * list.
  30. *
  31. * @param s the space to add
  32. */
  33. public void add(Space s)
  34. {
  35. // YOUR CODE HERE
  36.  
  37. if(first == null)
  38. {
  39. first = s;
  40. }
  41. else
  42. {
  43.  
  44. }
  45.  
  46.  
  47. }
  48.  
  49. /**
  50. * get. Get the space at index i, return it.
  51. *
  52. * @param i
  53. * @return
  54. */
  55. public Space get(int i)
  56. {
  57. Space tempSpace = first;
  58. if(i == 0)
  59. {
  60. return tempSpace;
  61. }
  62. else
  63. {
  64. for(int j = 0; j < i; j++)
  65. {
  66.  
  67. tempSpace = tempSpace.next;
  68. }
  69. return tempSpace;
  70. }
  71.  
  72. }
  73.  
  74.  
  75. /**
  76. * remove. Remove the Space at the index i.
  77. *
  78. * @param i the index at which to remove
  79. */
  80. public void remove(int i)
  81. {
  82. Space tempSpace = first;
  83. if(i == 0)
  84. {
  85. first = first.next;
  86. }
  87. else
  88. {
  89. for(int j = 0; j < i; j++)
  90. {
  91.  
  92. tempSpace = tempSpace.next;
  93. }
  94. // return tempSpace;
  95. }
  96.  
  97. }
  98.  
  99. /**
  100. * movePlayer. Move the player reference by the
  101. * given number of spaces. If the player reaches
  102. * the end, or goes past it, then leave them at
  103. * the last node.
  104. *
  105. * The moveBy may be negative, which would send
  106. * the player backwards. The player should stay
  107. * at the first space if they move backwards
  108. * beyond the first space.
  109. *
  110. * The player should start on first. So if they
  111. * move by 1, then they will be on the space
  112. * at index 1.
  113. *
  114. * @param moveBy the number of spaces by which to move
  115. */
  116. public void movePlayer(int moveBy)
  117. {
  118. // YOUR CODE HERE
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement