java简单的人机猜拳小游戏
来源:互联网 发布:化学物质数据库 编辑:程序博客网 时间:2024/05/18 07:36
今天翻以前的代码,偶然看见了自己刚学java的时候写的一个简单的猜拳小游戏,非常基础,不过挺有意思的,也包括了积分制,贴到这里让大家看看
package game;public class Computer {static int i;public static int shownum() {i = (int) (Math.random() * 3);return i;}public static String showFist() {String a[] = { "剪刀", "石头", "布" };return a[i];}public static String choos(int a) {String b = null;switch (a) {case 1:b = "刘备";break;case 2:b = "孙权";break;case 3:b = "曹操";break;}return b;}// public static void main(String[] args) {// System.out.println(Computer.guess());// }}
package game;/* * 我们自己定义类的时候,要考虑的问题 * 1: 要职责明确 一个类,就干自己专长的事情 * 2: IPO * *//* * customer 类 是做什么用的,处理游戏 */public class Customer {static String name = "玩家";static int score;public static String getFirst(int c) {String d = null;switch (c) {case 1:d = "剪刀";break;case 2:d = "石头";break;case 3:d = "布";break;}return d;}}
package game;import java.util.Scanner;public class Game {public static void starGame() {System.out.println("---------欢迎进入游戏世界---------");System.out.println("\t***************");System.out.println("\t****猜拳开始****");System.out.println("\t***************");System.out.println("请选择你想和谁对战(1:刘备2:孙权3:曹操)");int computerjifen=0;int gamerjifen=0;int equ=0;int count=0;Scanner sd = new Scanner(System.in);int a = sd.nextInt();Computer.choos(a);System.out.print("要开始吗y/n:");String b=sd.next();do{Computer.shownum();int x=Computer.shownum()+1;Computer.showFist();if(b.equals("y")){//boolean f;System.out.print("\n请出拳:1.剪刀2.石头3.布(请输入相应数字)");int num = sd.nextInt();System.out.println("你出拳:"+Customer.getFirst(num));System.out.println(Computer.choos(a)+"出拳:"+Computer.showFist());if(x==num){System.out.println("此局:平局,嘿嘿,你等着瞧吧!");equ++;}else if(x==1&&num==2){System.out.println("结果,你赢了");gamerjifen++;}else if(x==1&&num==3){System.out.println("结果,你输了");computerjifen++;}else if(x==2&&num==1){System.out.println("结果,你输了");computerjifen++;}else if(x==2&&num==3){System.out.println("结果,你赢了");gamerjifen++;}else if(x==3&&num==1){System.out.println("结果,你赢了");gamerjifen++;}else if(x==3&&num==2){System.out.println("结果,你输了");computerjifen++;}count++;System.out.println("-------------------");System.out.println("\n是否开始下一轮y/n");String r=sd.next();//if(r.equals("y")){//f=true;//}if(r.equals("n")){if(computerjifen>gamerjifen){System.out.println("-------------------");System.out.println(Computer.choos(a)+"vs玩家");System.out.println(Computer.choos(a)+"的积分为"+computerjifen+",玩家的积分为"+gamerjifen);System.out.println("对战次数"+count+",出的一样的情况有"+equ+"次");System.out.println("结果,你输了");break;}else if(computerjifen<gamerjifen){System.out.println("-------------------");System.out.println(Computer.choos(a)+"vs玩家");System.out.println(Computer.choos(a)+"的积分为"+computerjifen+",玩家的积分为"+gamerjifen);System.out.println("对战次数"+count+",出的一样的情况有"+equ+"次");System.out.println("结果,你赢了");break;}else{System.out.println("-------------------");System.out.println(Computer.choos(a)+"vs玩家");System.out.println(Computer.choos(a)+"的积分为"+computerjifen+",玩家的积分为"+gamerjifen);System.out.println("对战次数"+count+",出的一样的情况有"+equ+"次");System.out.println("结果,平局");break;}}}else if(b.equals("n")){if(computerjifen>gamerjifen){System.out.println("-------------------");System.out.println(Computer.choos(a)+"vs玩家");System.out.println(Computer.choos(a)+"的积分为"+computerjifen+",玩家的积分为"+gamerjifen);System.out.println("对战次数"+count+",出的一样的情况有"+equ+"次");System.out.println("结果,你输了");break;}else if(computerjifen<gamerjifen){System.out.println("-------------------");System.out.println(Computer.choos(a)+"vs玩家");System.out.println(Computer.choos(a)+"的积分为"+computerjifen+",玩家的积分为"+gamerjifen);System.out.println("对战次数"+count+",出的一样的情况有"+equ+"次");System.out.println("结果,你赢了");break;}else{System.out.println("-------------------");System.out.println(Computer.choos(a)+"vs玩家");System.out.println(Computer.choos(a)+"的积分为"+computerjifen+",玩家的积分为"+gamerjifen);System.out.println("对战次数"+count+",出的一样的情况有"+equ+"次");System.out.println("结果,平局");break;}}else{System.out.println("请重新开始!!!!");break;}}while(true);sd.close();}}
package game;//import java.util.Scanner;public class GameTest {public static void main(String[] args) {Game.starGame();}}
1 0
- java简单的人机猜拳小游戏
- 简单的人机猜拳小游戏
- java小游戏-人机猜拳
- JAVA语言实现人机猜拳小游戏
- java 小游戏人机猜拳 关键代码
- 人机猜拳之Java面向对象小游戏
- 小游戏 人机猜拳
- 第十二章 人机猜拳小游戏
- OC小游戏-人机大战-猜拳
- 人机猜拳小游戏(面向对象的方法)
- 基于java的人机猜拳游戏
- java练习--人机猜拳
- Java人机猜拳大战
- Java 第十三章 人机猜拳
- 猜拳的银魂(Java小游戏)
- Java猜拳小游戏
- java猜拳小游戏
- JAVA 猜拳小游戏
- ResNet论文笔记
- getline() 函数详解
- 配置jdk和类源码问题
- atexit 详解
- RecycleView(样例Phone)
- java简单的人机猜拳小游戏
- sourceInsight 查找某个变量或函数 调用了谁,或者被谁调用了
- Thrift简单例子
- Codeforces Round #398 (Div. 2) D. Cartons of milk
- [弦图最小染色] BZOJ1006: [HNOI2008]神奇的国度
- openssl+tomcat7使用简明笔记
- 树莓派Ubuntu mate15.10图形界面 用root账号登录登录
- Please open the about:config page and disable the "security.fileuri.strict_origin_policy" option
- caffe在ubuntu16.04下的配置