一个简单游戏

  • 格式:txt
  • 大小:2.65 KB
  • 文档页数:1
+"Good Luck!");
}
static int playerMove(int numberOfStones)
{int move=getUserMove(numberOfStones);
numberOfStones=numberOfStones-move;
+"stone.\n"
+"There are 21 stones in the pile to start with.\n"
பைடு நூலகம் +"You may remove from 1to 3 stones on each move.\n"
一个关于搬21块砖的游戏
其代码是用Java写的
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.*/
//import ng.Integer;
*/
public static void main(String[] args) {
// TODO code application logic here
printInstruction();
int numberOfStones =21;
return numberOfStones;
}
static int getUserMove(int numberOfStones)
{System.out.println("your move-how many stones"
+" do you wish to remove?");
+" do you wish to remove?");
move=scanner.nextInt();
}
return move;
}
}
System.out.println("恭喜你,你赢了!");
else
System.out.println("祝你下次好运!");
}
static void printInstruction()
{System.out.println(" The object of this game is to remove the last "
{int move;
if(numberOfStones<=3)
move=numberOfStones;
else
{move=numberOfStones%4;
if(move==0)
move=1;
if(numberOfStones>0)
{numberOfStones=computerMove(numberOfStones);
playerMovedLast=false;
}
}
if(playerMovedLast)
System.out.println("There are "+numberOfStones+" stones remaining.");
return numberOfStones;
}
static int computerMove(int numberOfStones)
package myjava;
/**
*
* @author Administrator
*/
import java.util.*;
public class TwentyOnePickup {
/**
* @param args the command line arguments
Scanner scanner=new Scanner(System.in);
int move=scanner.nextInt();
if ((move>3) || (move<1))
{
System.err.println("sorry,"+
"you can remove only 1 to 3 stones.");
System.out.print("\n");
System.out.println("How many stones"
}
numberOfStones=numberOfStones-move;
System.out.println("The computer removes"+ move
+" stones leaving "+ numberOfStones +".");
boolean playerMovedLast = false;
while(numberOfStones>0)
{
numberOfStones=playerMove(numberOfStones);
playerMovedLast=true;

下载文档原格式

  / 1