📄 cram.java
字号:
// Introduced in Chapter 3/** The game of Cram. */public class Cram extends Domineering { /** No special initialization is required. */ public Cram() { super(); } /** Play until someone wins. */ public void play() { int player = 1; while (true) { System.out.println("\n" + this); System.out.println("Player " + player + " to play"); if (!(hasLegalMoveFor(HORIZONTAL) || hasLegalMoveFor(VERTICAL))) { System.out.println("No legal moves -- you lose!"); return; } System.out.print("Row: "); int row = INPUT.nextInt(); System.out.print("Column: "); int column = INPUT.nextInt(); INPUT.nextLine(); // To clear out input System.out.print("Play horizontally (y/n)? "); boolean direction; if (INPUT.nextLine().charAt(0) == 'y') { direction = HORIZONTAL; } else { direction = VERTICAL; } playAt(row, column, direction); player = 3 - player; } } /** Create and play the game. */ public static void main(String[] args) { System.out.println("Welcome to Cram."); Cram game = new Cram(); game.play(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -