13章 人机猜拳
来源:互联网 发布:js去重方法 编辑:程序博客网 时间:2024/05/19 16:51
package com.dd;import java.util.Scanner;public class guess {String name;int Score;public int showguess() {System.out.println("请出拳:1.剪刀 2.石头 3.布(请输入相应数字):");Scanner input = new Scanner(System.in);int g = input.nextInt();switch (g) {case 1:System.out.println("你出拳:剪刀");break;case 2:System.out.println("你出拳:石头");break;case 3:System.out.println("你出拳:布");break;}return g;}}******************************
package com.dd;public class computer {String name;int Score;computer guess;public int showcomputer() {int random = (int) (Math.random() * 3 + 1);switch (random) {case 1:System.out.println("电脑出拳:剪刀");break;case 2:System.out.println("电脑出拳:石头");break;case 3:System.out.println("电脑出拳:布");break;}return random;}}
游戏类package com.dd;import java.util.Scanner;public class games {guess jia;computer yi;int count;public void initial() {jia = new out();yi = new out11();count = 0;}public void showgames() {initial();System.out.println("----------欢迎进入游戏世界-----------");System.out.println("**********************************");System.out.println("*** 猜拳,开始 ***");System.out.println("**********************************");System.out.println("出拳规则:1.剪刀 2.石头 3.布");System.out.println("请选择对方角色(1:刘备 2:孙权 3:曹操):");Scanner input = new Scanner(System.in);int h = input.nextInt();switch (h) {case 1:yi.name = "刘备";break;case 2:yi.name = "孙权";break;case 3:yi.name = "曹操";break;}System.out.println("请输入你的名字:");jia.name = input.next();System.out.println("你选择了" + yi.name + "对战");System.out.println("要开始吗?y:是 n:否");String sum = input.next();while (sum.equals("y")) {int y;int y1;if (sum.equals("y")) {y = jia.showout();y1 = yi.showout11();if ((y == 1 && y1 == 1) || (y == 2 && y1 == 2)|| (y == 3 && y1== 3)) {System.out.println("结果:和局,真衰!");} else if ((y == 1 && y1== 3) || (y == 2 && y1 == 1)|| (y== 3 && y1== 2)) {System.out.println("结果:恭喜,你赢了!");jia.Score++;} else {System.out.println("结果说:^_^,你输了,真笨!");yi.Score++;}count++;}System.out.println("是否进行下一轮.y:是 n:否");sum = input.next();}showmm();}public void showmm() {System.out.println("-----------------------------");System.out.println(jia.name + " VS " + yi.name);System.out.println("对战次数:" + count);System.out.println("姓名" + "\t" + "积分");System.out.println(jia.name + "\t" + jia.Score);System.out.println(yi.name + "\t" + yi.Score);if (jia.Score > yi.Score) {System.out.println("客户赢了");} else if (jia.Score < yi.Score) {System.out.println("电脑赢了");System.out.println("-----------------------------");}}}
显示方法<pre class="java" name="code">package com.dd;import java.util.Scanner;public class dada{public static void main(String[] args) {guess guess= new guess();games games = new games();games.showgames();computer computer = new computer();}}
0 0
- 13章 人机猜拳
- 13章 人机猜拳游戏
- 第十二章 人机猜拳
- 第十三章:人机猜拳
- 第十三章人机猜拳
- 第十三章 人机猜拳
- 第十二章 人机猜拳小游戏
- Java 第十三章 人机猜拳
- 人机猜拳
- 人机猜拳
- 人机猜拳
- 人机猜拳
- 人机猜拳
- 人机猜拳
- 人机猜拳
- 第一本十三章人机猜拳
- 人机猜拳游戏
- Java_人机猜拳游戏
- bfs简单题----Knight Moves(hdu 1372)
- ROS Learning-029 (提高篇-007 A Mobile Base-05) 控制移动平台 --- (Python编程)控制虚拟机器人的移动(精确的制定目标位置)
- cell的高度自适应cell里lable的高度
- java 抽象类实现接口是什么设计模式
- source insight窗口恢复默认
- 13章 人机猜拳
- AndroidStudio 从基本到高级使用技巧
- android studio 改编译区背景色
- SQLite数据库
- 向数据库表中插入图片信息
- 利用MUI+个推实现APP消息推送
- system函数错误返回-1 错误原因NO child processes
- 15. 16. 18.3Sum 4sum
- 关于CH375芯片的简介以及其与51单片机的连接