Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import javax.swing.JOptionPane;
- /**
- * Write a description of class GameBoardController here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class GameBoardController
- {
- private GameBoard game ;
- private Scanner scan ;
- private Stack<GameBoard> undoStack;
- public GameBoardController(){
- game = new GameBoard();
- scan = new Scanner(System.in);
- undoStack = new Stack<GameBoard>();
- }
- public void startGame(){
- game.populateGameCells();
- game.printGameBoard();
- gameMenu();
- }
- public void gameMenu(){
- char choice;
- int row;
- int row2;
- int finalCellRow;
- int holdingCellRow;
- undoStack.push(new GameBoard(game)); // saving game state here <-----------------------
- System.out.println("What would you like to do?");
- System.out.println("A: Move from stack of cards to another stack of cards\n"
- + "B: Move Card from Stack to Holding Row\n"
- + "C: Move Card from Holding Row to Stack of Cards\n"
- + "D: Move Card from Stacks to Final Row\n"
- + "E: Move Card from Holding Row to Final Row\n"
- + "F: Undo");
- choice = scan.next().toUpperCase().charAt(0);
- try{
- switch (choice) {
- case 'A':
- System.out.println("Enter Row nubmer to get card from");
- row = scan.nextInt();
- System.out.println("Enter Row numer to place card on");
- row2 = scan.nextInt();
- game.rowToRow(row2, row);
- break;
- case 'B':
- System.out.println("Enter Row nubmer to get card from");
- row = scan.nextInt();
- System.out.println("Enter holding cell nubmer to place card on");
- row2 = scan.nextInt();
- game.rowToHoldingCell(row2, row);
- break;
- case 'C':
- System.out.println("Enter Holding Row nubmer to get card from");
- row = scan.nextInt();
- System.out.println("Enter Row of Stack of Card to put card on");
- row2 = scan.nextInt();
- game.holdingCellToRow(row2, row);
- break;
- case 'D':
- System.out.println("Enter Row nubmer to get card from");
- row = scan.nextInt();
- System.out.println("Enter final cell nubmer to place card on");
- row2 = scan.nextInt();
- game.rowToFinalCell(row2, row);
- break;
- case 'E':
- System.out.println("Enter Holding Row nubmer to get card from");
- row = scan.nextInt();
- System.out.println("Enter Final row number to put card on");
- row2 = scan.nextInt();
- game.holdingCellToFinalCell(row2, row);
- break;
- case 'F':
- undo();
- break;
- default:
- JOptionPane.showMessageDialog(null, "Letters are required!");
- break;
- }
- }catch(InputMismatchException e){
- JOptionPane.showMessageDialog(null, "Numbers are required!");
- }
- game.printGameBoard();
- gameMenu();
- }
- public void undo(){
- game = undoStack.pop(); // Changing game state here
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement