Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. package chess;
  2.  
  3. import java.util.Stack;
  4.  
  5. public enum Player {
  6. BLACK, WHITE;
  7.  
  8. public Integer MOVENUM = 0;
  9.  
  10. private Stack<Player> stack = new Stack<Player>();
  11. /**
  12. * Return the {@code Player} whose turn is next.
  13. *
  14. * @return the {@code Player} whose turn is next
  15. */
  16. public Player next() {
  17. Player temp = this;
  18. if (temp == BLACK) {
  19. temp = WHITE;
  20. temp.MOVENUM = this.MOVENUM;
  21. temp.MOVENUM ++;
  22. } else {
  23. temp = BLACK;
  24. temp.MOVENUM = this.MOVENUM;
  25. temp.MOVENUM ++;
  26. }
  27. stack.push(temp);
  28. return temp;
  29. }
  30. public Player previous() {
  31. Player temp;
  32. if(!stack.empty()) {
  33. temp = stack.pop();
  34. }
  35. else {
  36. temp = WHITE;
  37. temp.MOVENUM = 0;
  38. }
  39. return temp;
  40. }
  41.  
  42.  
  43. public Integer fetch(){
  44. return this.MOVENUM;
  45. }
  46.  
  47. public void set(Integer num){
  48. this.MOVENUM = num;
  49. }
  50.  
  51. public void inc() {
  52. this.MOVENUM ++;
  53. }
  54.  
  55. public void dec() {
  56. this.MOVENUM --;
  57. }
  58.  
  59.  
  60. @Override
  61. public String toString() {
  62. return super.toString();
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement