資源簡介
次程序是用JAVA編寫的火柴游戲。電腦有一定的智能。
代碼片段和文件信息
import?java.util.*;
public?class?cc?{
/**
?*?@param?args
?*/
public?static?void?main(String[]?args)
{
//?TODO?Auto-generated?method?stub
?System.out.println(“游戲說明:計算機會隨機生成一個火柴數目,玩家和計算機依次從里面抽取火柴,每次火柴數目必須少于3根。誰最先抽到最后一根就算贏?!埃?
int?a=(int)((50-20)*Math.random()+20);?
????????int?mancom=0count=0;
????????System.out.println(“現在有“+a+“根火柴“);
????????while(a!=0)
????????{System.out.println(“請從中抽取火柴,火柴數必須少于3根:“);
???????? Scanner?s=new?Scanner(System.in);
???????? man=s.nextInt();
???????? while(man>3||man<=0)
???????? {System.out.println(“火柴數少于3根,你白癡啊?!埃?
???????? System.out.println(“重新輸入吧。要不直接按關閉算了:“);
???????? man=s.nextInt();}
???????? System.out.println(“你抽了“+man+“根火柴。“);
???????? count=count+1;
???????? a=a-man;
???????? if(a<=0)
???????? {System.out.println(“還剩下0根
評論
共有 條評論