猜拳

import java.util.Scanner;

public class TestGame {
int count;
String name;
String name1;
int jifen1;
int jifen2;

// 游戏
public void startGame() {
	Scanner input = new Scanner(System.in);
	System.out.print("请输入用户姓名:");
	name1 = input.next();
	System.out.println();
	System.out.println("出拳规则:1.剪刀 2.石头 3.布");
	System.out.print("请选择对手角色(1:刘备 2:孙权 3:曹操):");
	int juese = input.nextInt();
	switch (juese) {
	case 1:
		System.out.println("你选择了刘备对战\n");
		break;
	case 2:
		System.out.println("你选择了孙权对战\n");
		break;
	case 3:
		System.out.println("你选择了曹操对战\n");
		break;

	default:
		System.out.println("输入错误!\n");
		break;
	}
	if (juese == 1) {
		name = "刘备";
	} else if (juese == 2) {
		name = "孙权";
	} else if (juese == 3) {
		name = "曹操";
	}
	System.out.print("要开始吗?(y/n)");
	String con = input.next();
	System.out.println();
	while (true) {
		if (con.equals("y")) {
			count++;
			System.out.print("请出拳:1剪刀 2.石头 3.布");
			int chuquan = input.nextInt();
			switch (chuquan) {
			case 1:
				System.out.println("你出拳:剪刀");
				break;
			case 2:
				System.out.println("你出拳:石头");
				break;
			case 3:
				System.out.println("你出拳:布");
				break;

			default:
				System.out.println("输入错误!");
				break;
			}
			int random = (int) (Math.random() * 3 + 1);
			switch (random) {
			case 1:
				System.out.println(name + "出拳:剪刀");
				break;
			case 2:
				System.out.println(name + "出拳:石头");
				break;
			case 3:
				System.out.println(name + "出拳:布");
				break;

			default:
				System.out.println("输入错误!");
				break;
			}
			if (chuquan == 1 && random == 1 || chuquan == 2 && random == 2
					|| chuquan == 3 && random == 3) {
				System.out.println("结果:和局,真衰!\n\n");
			} else if (chuquan == 1 && random == 3 || chuquan == 2
					&& random == 1 || chuquan == 3 && random == 2) {
				System.out.println("结果:恭喜,你赢了!\n\n");
				jifen1++;
			} else {
				System.out.println("结果:你输了,真笨\n\n");
				jifen2++;
			}
		} else {
			break;
		}
		System.out.print("是否开始下一轮(y/n):");
		con = input.next();
		System.out.println();
	}
	System.out
			.println("-----------------------------------------------------------------------");
	System.out.println(name + "\tVS\t" + name1);
	System.out.println("对战次数:" + count);
	System.out
			.println("-----------------------------------------------------------------------\n");
	System.out.println(name1 + "的积分是" + jifen1);
	System.out.println(name + "的积分是" + jifen2);
}

}
public class TestGame {
public static void main(String[] args) {
System.out.println("----------欢迎进入游戏世界----------\n\n");
System.out.println("\t**************************\t");
System.out.println("\t**\t猜拳,开始\t**");
System.out.println("\t**************************\t\n\n");

	TestGame game = new TestGame();
	game.count = 0;
	game.name = "";
	game.jifen1 = 0;
	game.jifen2 = 0;
	game.startGame();

}

}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
抱歉,我是一个AI语言模型,无法演示猜拳JavaScript游戏。但是,我可以为您提供一个简单的猜拳游戏代码示例,供您参考: HTML代码: ``` <!DOCTYPE html> <html> <head> <title>猜拳游戏</title> </head> <body> <h1>猜拳游戏</h1> <p>请选择一个选项:</p> <button id="rock" onclick="play('rock')">石头</button> <button id="paper" onclick="play('paper')">剪刀</button> <button id="scissors" onclick="play('scissors')">布</button> <p id="result"></p> <script src="game.js"></script> </body> </html> ``` JavaScript代码: ``` function play(playerChoice) { var choices = ['rock', 'paper', 'scissors']; var computerChoice = choices[Math.floor(Math.random() * 3)]; if (playerChoice === computerChoice) { document.getElementById('result').innerHTML = "平局!你和电脑都选择了" + playerChoice + "。"; } else if (playerChoice === 'rock' && computerChoice === 'scissors' || playerChoice === 'paper' && computerChoice === 'rock' || playerChoice === 'scissors' && computerChoice === 'paper') { document.getElementById('result').innerHTML = "恭喜你获胜!你选择了" + playerChoice + ",电脑选择了" + computerChoice + "。"; } else { document.getElementById('result').innerHTML = "很遗憾,你输了!你选择了" + playerChoice + ",电脑选择了" + computerChoice + "。"; } } ``` 这个游戏使用了HTML和JavaScript,通过点击按钮来选择石头、剪刀或布,然后与电脑随机选择的选项进行比较,输出胜利、平局或失败的结果。您可以在自己的网站上使用此代码,或者根据自己的需求进行修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值