java猜拳
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java猜拳,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2711字,纯文字阅读大概需要4分钟。
内容图文
![java猜拳](/upload/InfoBanner/zyjiaocheng/852/b4dd9a50543c482c968fc2a27d5c3395.jpg)
import java.util.Scanner; public class startGuess { Person jia; Computer yi; int count; public void initial() { jia = new Person(); yi = new Computer(); count = 0; } public void showout12() { 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 con = input.next(); while (con.equals("y")) { int per; int com; if (con.equals("y")) { per = jia.showout(); com = yi.showout11(); if ((per == 1 && com == 1) || (per == 2 && com == 2) || (per == 3 && com == 3)) { System.out.println("结果:和局,真衰!"); } else if ((per == 1 && com == 3) || (per == 2 && com == 1) || (per == 3 && com == 2)) { System.out.println("结果:恭喜,你赢了!"); jia.Score++; } else { System.out.println("结果说:^_^,你输了,真笨!"); yi.Score++; } count++; } System.out.println("是否进行下一轮.y:是 n:否"); con = input.next(); } showgg(); } public void showgg() { 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("-----------------------------"); } } }
public class Person { String name; int Score; public int showout() { 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; } }
public class Computer { String name; int Score; Computer out; public int showout11() { 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; } }
import java.util.*; public class startGame { public static void main(String[] args) { Person a = new Person(); startGuess b = new startGuess(); b.showout12(); Computer c = new Computer(); } }
内容总结
以上是互联网集市为您收集整理的java猜拳全部内容,希望文章能够帮你解决java猜拳所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。
来源:【匿名】