Advertisement
Guest User

Untitled

a guest
Sep 26th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. /**
  2.  * Controls the stack of sticks used in GameEngine. Contains methods to
  3.  *   manipulate the stack of sticks.
  4.  *
  5.  * @author belinus & timmyt
  6.  * @version 0.1
  7.  */
  8. public class Sticks
  9. {
  10.   // Instance variables
  11.   private int maxNoOfSticks;
  12.   private int sticksLeft;
  13.  
  14.   // Constructors
  15.   public Sticks( int n )
  16.   {
  17.     maxNoOfSticks = n;
  18.   }
  19.   public Sticks()
  20.   {
  21.     this(21);
  22.   }
  23.  
  24.   // Methods
  25.   public void newGame()
  26.   {
  27.     sticksLeft = maxNoOfSticks;
  28.   }
  29.  
  30.   public int sticksLeft()
  31.   {
  32.     return sticksLeft;
  33.   }
  34.  
  35.   public int take( int n )
  36.   {
  37.        
  38.         if( n == 1 || n == 2 )
  39.     {
  40.       sticksLeft = sticksLeft - n;
  41.       return sticksLeft;
  42.     }
  43.     else
  44.     {
  45.       // Invalid move
  46.       return -1;
  47.     }
  48.   }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement