关于JAVA写一个猜拳游戏

编程入门 行业动态 更新时间:2024-10-08 14:47:51

关于JAVA写一个<a href=https://www.elefans.com/category/jswz/34/1751261.html style=猜拳游戏"/>

关于JAVA写一个猜拳游戏

1.关于准备工作

      打开你的IDEA新建一个package(软件包),在这个package中新建四个java类,分别用来表示”人“ ”计算机“ ”控制“ ”main“这四个

最后是这样子。

2.关于“人”

在你用来表示”人“的类中写

package workbag;//我的软件包 import java.util.Scanner; //调用的包public class humen {int name;   int number;void Name(){Scanner scanner=new Scanner(System.in);System.out.print("请选择你的角色:(1.沸羊羊 2.暖羊羊 3.美羊羊):"+"  ");name=scanner.nextInt();}void chuquan(){System.out.print("请出拳:1.石头 2.剪刀 3.布:  ");Scanner scanner=new Scanner(System.in);number=scanner.nextInt();}
}

3.关于“计算机”

package workbag;import java.util.Random;
import java.util.Scanner;public class computer {int name;int number;void Name(){Scanner scanner=new Scanner(System.in);System.out.print("请选择电脑的角色:(1.沸羊羊 2.暖羊羊 3.美羊羊):"+"  ");name=scanner.nextInt();}void chuquan(){Random random=new Random();int a=random.nextInt(100);this.number=a%3+1;}
}

4.关于“控制”

package workbag;public class control {int a;int b;String b_name;void panduan(){switch(a){case 1:System.out.println("你出拳为:石头");break;case 2:System.out.println("你出拳为:剪刀");break;case 3:System.out.println("你出拳为:布");break;}switch(b){case 1:System.out.println(b_name+ "出拳为:石头");break;case 2:System.out.println(b_name+"出拳为:剪刀");break;case 3:System.out.println(b_name+"出拳为:布");break;}if((a==1)&&(b==2)||(a==2)&&(b==3)||(a==3)&&(b==1)){System.out.println("你赢了");}else if(a==b){System.out.println("平局");}else{System.out.println("计算机赢了");}}}

5.关于"main"

package workbag;public class main {public static void main(String[] args) {int n=38;while(n-->0) System.out.print("--");System.out.print("欢迎来到蜡笔小新的游戏");//改自己的名字n=38;while(n-->0) System.out.print("--");n=5;while(n-->0) System.out.println(" ");n=35;while(n-->0) System.out.print("  ");n=31;while(n-->0) System.out.print("*");System.out.println(" ");n=35;while(n-->0) System.out.print("  ");System.out.print("**");n=27;while(n-->0) System.out.print(" ");System.out.print("**");System.out.println(" ");n=35;while(n-->0) System.out.print("  ");System.out.print("**");n=10;while(n-->0) System.out.print(" ");System.out.print("游戏开始");n=10;while(n-->0) System.out.print(" ");System.out.println("**");n=35;while(n-->0) System.out.print("  ");System.out.print("**");n=27;while(n-->0) System.out.print(" ");System.out.print("**");System.out.println(" ");n=35;while(n-->0) System.out.print("  ");n=31;while(n-->0) System.out.print("*");System.out.println(" ");humen a=new humen();computer b=new computer();a.Name();b.Name();control c=new control();switch(b.name){case 1: c.b_name="沸羊羊"; break;case 2: c.b_name="暖羊羊"; break;case 3: c.b_name="美羊羊"; break;}int std;a.chuquan();b.chuquan();c.a=a.number;c.b=b.number;std=c.panduan();if(std==1){a.score+=1;}else if(std==0){b.score+=1;}System.out.println("你的积分为:"+a.score);System.out.println(c.b_name+"的得分为:"+b.score);System.out.println(" ");}
}

更多推荐

关于JAVA写一个猜拳游戏

本文发布于:2024-02-26 01:39:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1700939.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:猜拳   游戏   JAVA

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!