熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java核心技術 >> 正文

用JAVA做的一個石頭,剪刀,布的游戲

2022-06-13   來源: Java核心技術 

  /*

  * 創建一個類Game石頭剪刀布的游戲

  */

  public class Game {

  /**

  * @param args

  */

  String[] s ={石頭剪刀};

  //獲取電腦出拳

  String getComputer(int i)

  {

  String computerGuess = s[i];

  return computerGuess;

  }

  //判斷人出拳是否為石頭剪刀

  boolean isOrder(String guess)

  {

  boolean b = false;

  for(int x = ;x < slength; x++)

  {

  if(guessequals(s[x]))

  {

  b = true;

  break;

  }

  }

  return b;

  }

  //比較

  void winOrLose(String guessString guess)

  {

  if(guessequals(guess))

  {

  Systemoutprintln(你出 + guess + 電腦出 + guess + 平了);

  }else if(guessequals(石頭))

  {

  if(guessequals(剪刀))

  {

  Systemoutprintln(你出 + guess + 電腦出 + guess + You Win!);

  }else

  {

  Systemoutprintln(你出 + guess + 電腦出 + guess + You Lose!);

  }

  }else if(guessequals(剪刀))

  {

  if(guessequals())

  {

  Systemoutprintln(你出 + guess + 電腦出 + guess + You Win!);

  }else

  {

  Systemoutprintln(你出 + guess + 電腦出 + guess + You Lose!);

  }

  }else if(guessequals())

  {

  if(guessequals(石頭))

  {

  Systemoutprintln(你出 + guess + 電腦出 + guess + You Win!);

  }else

  {

  Systemoutprintln(你出 + guess + 電腦出 + guess + You Lose!);

  }

  }

  }

  public static void main(String[] args) {

  Game my = new Game();

  Game computer = new Game();

  Game game = new Game();

  String myGuess = javaxswingJOptionPaneshowInputDialog(輸入石頭剪刀);

  String computerGuess = computergetComputer((int)(Mathfloor(Mathrandom()*)));

  if(myisOrder(myGuess))

  {

  gamewinOrLose(myGuess computerGuess);

  }else

  {

  Systemoutprintln(你輸入的不是石頭剪刀布!);

  }

  }

  }


From:http://tw.wingwit.com/Article/program/Java/hx/201311/26003.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.