java猜拳游戲

package com.utils;

import java.util.Scanner;

public class Scissors_Stone_Cloth{

? ? public static void main(String[] args) {

? ? ? ? while (true) {

? ? ? ? ? ? System.out.println("----猜拳游戲開始----");

? ? ? ? ? ? System.out.println("請按要求輸入:1.石頭? 2.剪刀? 3.布");

? ? ? ? ? ? String marks ="石頭";

? ? ? ? ? ? String marks2 ="石頭";

? ? ? ? ? ? while (true) {

? ? ? ? ? ? ? ? Scanner in =new Scanner(System.in);

? ? ? ? ? ? ? ? int person = in.nextInt();

? ? ? ? ? ? ? ? if (person !=1 && person !=2 && person !=3) {

? ? ? ? ? ? ? ? ? ? System.out.println("請正確出拳,1,2,3");

break;

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? int computer =(int) (Math.random() *3 +1);

? ? ? ? ? ? ? ? switch (person) {

? ? ? ? ? ? ? ? ? ? case 1:

marks ="石頭";

break;

? ? ? ? ? ? ? ? ? ? case 2:

marks ="剪刀";

break;

? ? ? ? ? ? ? ? ? ? case 3:

marks ="布";

break;

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? switch (computer) {

? ? ? ? ? ? ? ? ? ? case 1:

marks2 ="石頭";

break;

? ? ? ? ? ? ? ? ? ? case 2:

marks2 ="剪刀";

break;

? ? ? ? ? ? ? ? ? ? case 3:

marks2 ="布";

break;

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? if (computer == person) {

? ? ? ? ? ? ? ? ? ? System.out.println("您出的是" + marks +"\n電腦出的是" + marks2 +"\n-----平局=_=");

break;

? ? ? ? ? ? ? ? } else if ((person ==1 && computer ==2) ||(person ==2 && computer ==3) ||(person ==3 && computer ==1)) {

? ? ? ? ? ? ? ? ? ? System.out.println("您出的是" + marks +"\n電腦出的是" + marks2 +"\n-----恭喜您,您贏了!^_^");

break;

? ? ? ? ? ? ? ? } else {

? ? ? ? ? ? ? ? ? ? System.out.println("您出的是" + marks +"\n電腦出的是" + marks2 +"\n-----對不起,您輸了!QAQ");

break;

? ? ? ? ? ? ? ? }

}

}

}

}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內容