コード例 #1
0
 public boolean moveCLI(KeyboardReader kr) {
   int max = 3;
   if (nSticks < 3) max = nSticks;
   kr.prompt("Input a number between 1 and " + max + ": ");
   int num = kr.getKeyboardInteger();
   return takeSticks(num);
 } // moveCLI()
コード例 #2
0
 // *** Implement methods of PlayableCLI interface ***
 public void initCLI(KeyboardReader kr) {
   kr.display("\n*** The Rules of One Row Nim ***\n");
   kr.display("(1) A number of sticks between 7 and 21 is chosen.\n");
   kr.display("(2) Two players alternate making moves.\n");
   kr.display("(3) A move consists of subtracting 1, 2,\n");
   kr.display("   or 3 from the current number of sticks.\n");
   kr.display("(4) A player who cannot leave a positive\n");
   kr.display(" number of sticks for the other player loses.\n");
   int num = -1;
   while ((num < 7) || (num > 21)) {
     kr.prompt("Input a number between 7 and 21:");
     num = kr.getKeyboardInteger();
   } // while
   setSticks(num);
   setPlayer(1);
 } // initCLI()