Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This is a board game implemented
- * as a doubly linked list. The list
- * starts with the first Space. The game
- * has only a single player, whose
- * position is stored in the playerSpace
- * variable.
- *
- */
- public class Boardgame
- {
- private Space first;
- private Space playerSpace;
- public Boardgame()
- {
- first = null;
- playerSpace = null;
- }
- public Space getPlayerSpace()
- {
- return playerSpace;
- }
- /**
- * add. Append Space s to the end of the doubly-linked
- * list.
- *
- * @param s the space to add
- */
- public void add(Space s)
- {
- // YOUR CODE HERE
- if(first == null)
- {
- first = s;
- }
- else
- {
- }
- }
- /**
- * get. Get the space at index i, return it.
- *
- * @param i
- * @return
- */
- public Space get(int i)
- {
- Space tempSpace = first;
- if(i == 0)
- {
- return tempSpace;
- }
- else
- {
- for(int j = 0; j < i; j++)
- {
- tempSpace = tempSpace.next;
- }
- return tempSpace;
- }
- }
- /**
- * remove. Remove the Space at the index i.
- *
- * @param i the index at which to remove
- */
- public void remove(int i)
- {
- Space tempSpace = first;
- if(i == 0)
- {
- first = first.next;
- }
- else
- {
- for(int j = 0; j < i; j++)
- {
- tempSpace = tempSpace.next;
- }
- // return tempSpace;
- }
- }
- /**
- * movePlayer. Move the player reference by the
- * given number of spaces. If the player reaches
- * the end, or goes past it, then leave them at
- * the last node.
- *
- * The moveBy may be negative, which would send
- * the player backwards. The player should stay
- * at the first space if they move backwards
- * beyond the first space.
- *
- * The player should start on first. So if they
- * move by 1, then they will be on the space
- * at index 1.
- *
- * @param moveBy the number of spaces by which to move
- */
- public void movePlayer(int moveBy)
- {
- // YOUR CODE HERE
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement