Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Controls the stack of sticks used in GameEngine. Contains methods to
- * manipulate the stack of sticks.
- *
- * @author belinus & timmyt
- * @version 0.1
- */
- public class Sticks
- {
- // Instance variables
- private int maxNoOfSticks;
- private int sticksLeft;
- // Constructors
- public Sticks( int n )
- {
- maxNoOfSticks = n;
- }
- public Sticks()
- {
- this(21);
- }
- // Methods
- public void newGame()
- {
- sticksLeft = maxNoOfSticks;
- }
- public int sticksLeft()
- {
- return sticksLeft;
- }
- public int take( int n )
- {
- if( n == 1 || n == 2 )
- {
- sticksLeft = sticksLeft - n;
- return sticksLeft;
- }
- else
- {
- // Invalid move
- return -1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement