日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

《第13章 猜拳游戏》

發布時間:2025/5/22 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 《第13章 猜拳游戏》 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

import java.util.Scanner;


public class Game {
Scanner input=new Scanner(System.in);
boolean FLAG = true;
Computer computer = new Computer();
User user = new User();

public class Computer {

int cNum = 0;//電腦出拳的序號
String cChoose;//電腦出的拳
int score = 0;
String computerName=null;

/*
* 電腦出拳的方法
* */
public int startGame() {
cNum = (int) (Math.random() * (4 - 1)) + 1;// 電腦選擇的出拳序號;
switch (cNum) {
case 1:

cChoose = "剪刀";
System.out.println("電腦出拳:" + cChoose);

break;
case 2:

cChoose = "石頭";
System.out.println("電腦出拳:" + cChoose);

break;
case 3:

cChoose = "布";
System.out.println("電腦出拳:" + cChoose);

break;

default:
break;
}
return cNum;

}

}



public class User {

Scanner input = new Scanner(System.in);
int uNum = 0;// 選擇的出拳序號
int score =0;//積分
String uChoose = null;// 出剪刀還是石頭布
String userName=null;//用戶名

/*
* 用戶開始游戲方法
*/
public int startGame() {

System.out.println("請出拳:1、剪刀2、石頭3、布(請輸入相應數字)");
uNum = input.nextInt();

switch (uNum) {
case 1:

uChoose = "剪刀";
System.out.println("你出拳:" + uChoose);
System.out.println(uNum);

break;

case 2:

uChoose = "石頭";
System.out.println("你出拳:" + uChoose);
System.out.println(uNum);

break;

case 3:

uChoose = "布";
System.out.println("你出拳:" + uChoose);
System.out.println(uNum);

break;

default:
break;
}
return uNum;

}

}

?



public void initial(){
System.out.println("-----------------歡迎進入游戲世界----------------");
System.out.println(" ******************");
System.out.println(" **猜拳,開始**");
System.out.println(" ******************");
System.out.println("出拳規則:1.剪刀 2.石頭 3.布(輸入相應的數字):");
}


public void startGame(){
int count=0; //對戰次數
String juese=" ";
int JueSeNum=0;
System.out.println("請選擇對方的角色(1. 孫悟空 2. 豬八戒 3. 沙僧");
JueSeNum=input.nextInt();
switch ( JueSeNum) {
case 1:
juese="孫悟空";
System.out.println("您選擇了"+juese+"對戰");

break;
case 2:
juese="豬八戒";
System.out.println("您選擇了"+juese+"對戰");

break;
case 3:
juese="沙僧";
System.out.println("您選擇了"+juese+"對戰");

break;

default:
break;
}
System.out.println("請輸入你的昵稱:");
user.userName=input.next();
System.out.println(user.userName+"\t"+"VS"+"\t"+juese);
System.out.println("要開始嗎?(y/n)");
String isPlay = input.next();
if (isPlay.equals("y")) {


while (FLAG) {


int uNum = user.startGame();//接受用戶開始游戲方法的出拳序號的返回值

int cNum = computer.startGame();

if (uNum==1&&cNum==3||
uNum==2&&cNum==1||
uNum==3&&cNum==2) {

System.out.println("結果說:^-^!你贏了!恭喜!!!");
user.score += 2;
count++;


} else if(uNum==cNum){

System.out.println("結果說:^-^!平局!加油!!!");
user.score += 1;
computer.score += 1;
count++;

}else {

System.out.println("結果說:-^-!你輸了!真笨!!!");
computer.score += 2;
count++;
}

System.out.println("是否開啟下一輪?(y/n)");
String is = input.next();

if (is.equals("y")) {

} else {

FLAG = false;

}

}



}else if (isPlay.equals("n")) {




} else {

System.out.println("你在想些什么啊,怎么選的啊……");

}

System.out.println("用戶得分:"+user.score);
System.out.println("電腦得分:"+computer.score);
System.out.println("對戰次數:"+count);
System.out.println("歡迎下次再來^_^!!");


}

}






?

?

?

?

?

?

public class aa {
public static void main(String[] args) {


Game game=new Game();
game.initial();
game.startGame();
}
}

轉載于:https://www.cnblogs.com/dqn-1996-02/p/5105916.html

總結

以上是生活随笔為你收集整理的《第13章 猜拳游戏》的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。