import java.util.Scanner; /** * Class that can be used to play an interactive game of Skip-3 Solitaire. * @author Dave Reed * @version 11/20/06 */ public class Skip3 { private DeckOfCards deck; private RowOfPiles row; /** * Constructs a new game (with a new, shuffled deck and empty row). */ public Skip3() { this.restart(); } /** * Resets the game to start fresh. */ public void restart() { this.deck = new DeckOfCards(); this.deck.shuffle(); this.row = new RowOfPiles(); } /** * Plays an interactive game of Skip-3 Solitaire. * The player is repeatedly shown the row of piles and must then enter * a command, either "deal", "move ?? ??" (where ?? represents a card), * or "end". */ public void playGame() { Scanner input = new Scanner(System.in); boolean gameOver = false; while (!gameOver) { System.out.println(this.row); System.out.print("Action? "); char response = input.next().toLowerCase().charAt(0); if (response == 'd') { if (this.deck.cardsRemaining() > 0) { this.row.addPile(this.deck.dealCard()); } } else if (response == 'm') { String from = input.next(); String to = input.next(); this.row.movePile(new Card(from), new Card(to)); } else if (response == 'e') { gameOver = true; } } } }