cram.java
来自「java版的数据结构的完全代码 免费提供了 学习数据结构的请下载」· Java 代码 · 共 46 行
JAVA
46 行
// 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 + =
减小字号Ctrl + -
显示快捷键?