首页 技术 正文
技术 2022年11月18日
0 收藏 836 点赞 3,146 浏览 1706 个字

package test;
import java.util.Scanner;
import java.util.Random;
public class caiquan {
public static void main(String[] args){
Game g=new Game();
g.begin();
}

//将这个类定义为静态就好了,也就说改成 static class Game
class Game{
public void begin(){
System.out.println(“********************”);
System.out.println(“A finger-guessing game”);
System.out.println(“********************”);
System.out.println(“Start game(1/0)”);
Scanner input = new Scanner(System.in);
int result = input.nextInt();
if(result==1){
System.out.println(“请输入猜拳次数:”);
int num = input.nextInt();
play(num);
}else{
System.out.println(“Go Fuck Yourself!”);
}
}
public void play(int num){
int userScore=0;//人赢的次数
int pcScore=0;//pc赢的次数
Random r = new Random();
Scanner input = new Scanner(System.in);
while(num>0){
int x = r.nextInt(100)%3+1;
System.out.println(“请输入(1,剪刀 2,石头 3,布)”);
int s = input.nextInt();

if(s>=4||s==0){
System.out.println(“瓜娃子看不懂嗦,只能输入1,2,3!”);
}

if(s==1){
switch(x){
case 1:
System.out.println(“平局,你出剪刀,电脑出剪刀”);
case 2:
System.out.println(“你输了,你出剪刀,电脑出石头”);
pcScore++;
case 3:
System.out.println(“你赢了,你出剪刀,电脑出布”);
userScore++;
}
}
if(s==2){
switch(x){
case 1:
System.out.println(“你赢了,你出石头,电脑出剪刀”);
userScore++;
break;
case 2:
System.out.println(“平局,你出石头,电脑出石头”);
break;
case 3:
System.out.println(“你输了,你出石头,电脑出布”);
pcScore++;
break;
}
}
if(s==3){
switch(x){
case 1:
System.out.println(“你输了,你出布,电脑出剪刀”);
pcScore++;
break;
case 2:
System.out.println(“你赢了,你出布,电脑出石头”);
userScore++;
break;
case 3:
System.out.println(“平局,你出布,电脑出布”);
break;
}
}
num–;
}
System.out.println(“**************”);
System.out.println(“你赢了:”+userScore+”次!”);
System.out.println(“电脑赢了:”+pcScore+”次!”);
if(userScore==pcScore){
System.out.println(“平局!”);
}else if(userScore>pcScore){
System.out.println(“你赢了!”);
}else{
System.out.println(“电脑赢了!”);
}
}
}
}

//在Java中,类中的静态方法不能直接调用动态方法。只有将某个内部类修饰为静态类,然后才能够在静态类中调用该类的成员变量与成员方法

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,075
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,551
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,399
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,811
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,892