Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package chess;
- import java.util.Stack;
- public enum Player {
- BLACK, WHITE;
- public Integer MOVENUM = 0;
- private Stack<Player> stack = new Stack<Player>();
- /**
- * Return the {@code Player} whose turn is next.
- *
- * @return the {@code Player} whose turn is next
- */
- public Player next() {
- Player temp = this;
- if (temp == BLACK) {
- temp = WHITE;
- temp.MOVENUM = this.MOVENUM;
- temp.MOVENUM ++;
- } else {
- temp = BLACK;
- temp.MOVENUM = this.MOVENUM;
- temp.MOVENUM ++;
- }
- stack.push(temp);
- return temp;
- }
- public Player previous() {
- Player temp;
- if(!stack.empty()) {
- temp = stack.pop();
- }
- else {
- temp = WHITE;
- temp.MOVENUM = 0;
- }
- return temp;
- }
- public Integer fetch(){
- return this.MOVENUM;
- }
- public void set(Integer num){
- this.MOVENUM = num;
- }
- public void inc() {
- this.MOVENUM ++;
- }
- public void dec() {
- this.MOVENUM --;
- }
- @Override
- public String toString() {
- return super.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement