尝试制作一个石头剪纸游戏,只运行一个游戏/枚举编码混乱 import java.util.Scanner; 导入java.util.Random; 公营部门{ 公共静态void main(字符串[]args){ //TODO自动生成的方法存根 枚举手势{ 摇滚乐, 纸张 剪刀 } 扫描仪tKeyboard=新扫描仪(System.in); System.out.println(“剪刀请输入“S”,石头请输入“R”,纸请输入“P”); int tChoice=tKeyboard.nextInt(); System.out.println(tChoice); 随机tRNG=新随机(); int tX=下一次试验(3); 如果(tX>) System.out.println(“你输了”); 否则如果(tXsignature.getType()){ System.out.println(“你输了”); } else if(computerDraw)???此外,不能在方法内声明枚举。请发布一个可以编译的代码!由于“环绕”性质,简单的不能用于RPS,分配R=1,P=2,S=3,S输给R(其中S>R),但S aso赢给P(其中S>P)。将输入(包括计算机选择)与作战/输赢分辨率完全分离也更为简洁。 package gui; import java.util.Random; import java.util.Scanner; public class test { enum Gesture { rock(1), paper(2), scissors(3); private int type; Gesture(int type) { this.type = type; } public int getType(){ return type; } } public static void main(String[] args) { final Scanner keyboard = new Scanner(System.in); System.out.println("Please enter “S” for scissors, “R” for rock, or “P” for paper."); final String choice = keyboard.next(); if (choice.equals("S")) { generateDraw(Gesture.scissors); } else if (choice.equals("R")) { generateDraw(Gesture.rock); } else if (choice.equals("P")) { generateDraw(Gesture.paper); } keyboard.close(); } public static void generateDraw(Gesture gesture) { final Random random = new Random(); final int computerDraw = random.nextInt(3); System.out.println(computerDraw); if (computerDraw > gesture.getType()) { System.out.println("You lose."); } else if (computerDraw < gesture.getType()) { System.out.println("You win."); } else { System.out.println("It is a tie."); } } }

尝试制作一个石头剪纸游戏,只运行一个游戏/枚举编码混乱 import java.util.Scanner; 导入java.util.Random; 公营部门{ 公共静态void main(字符串[]args){ //TODO自动生成的方法存根 枚举手势{ 摇滚乐, 纸张 剪刀 } 扫描仪tKeyboard=新扫描仪(System.in); System.out.println(“剪刀请输入“S”,石头请输入“R”,纸请输入“P”); int tChoice=tKeyboard.nextInt(); System.out.println(tChoice); 随机tRNG=新随机(); int tX=下一次试验(3); 如果(tX>) System.out.println(“你输了”); 否则如果(tXsignature.getType()){ System.out.println(“你输了”); } else if(computerDraw)???此外,不能在方法内声明枚举。请发布一个可以编译的代码!由于“环绕”性质,简单的不能用于RPS,分配R=1,P=2,S=3,S输给R(其中S>R),但S aso赢给P(其中S>P)。将输入(包括计算机选择)与作战/输赢分辨率完全分离也更为简洁。 package gui; import java.util.Random; import java.util.Scanner; public class test { enum Gesture { rock(1), paper(2), scissors(3); private int type; Gesture(int type) { this.type = type; } public int getType(){ return type; } } public static void main(String[] args) { final Scanner keyboard = new Scanner(System.in); System.out.println("Please enter “S” for scissors, “R” for rock, or “P” for paper."); final String choice = keyboard.next(); if (choice.equals("S")) { generateDraw(Gesture.scissors); } else if (choice.equals("R")) { generateDraw(Gesture.rock); } else if (choice.equals("P")) { generateDraw(Gesture.paper); } keyboard.close(); } public static void generateDraw(Gesture gesture) { final Random random = new Random(); final int computerDraw = random.nextInt(3); System.out.println(computerDraw); if (computerDraw > gesture.getType()) { System.out.println("You lose."); } else if (computerDraw < gesture.getType()) { System.out.println("You win."); } else { System.out.println("It is a tie."); } } },java,random,Java,Random,这是到目前为止我的代码,我知道它非常缺乏,但我有不同的东西,我无法理解。 我需要玩一个石头剪刀游戏。它应该首先要求用户输入一个选项,石头布或剪刀。 然后,计算机应该随机地将一个数字放在对方队伍旁边:0、1或2 之后,应制作一个枚举,将这些数值分配给枚举中的实际变量-石头、布和剪刀。 在这之后,用户的选择应该与使用if/else语句的对方球队的随机选择进行比较,这样就可以根据一个普通的石头剪刀纸牌游戏选出获胜者。您要求的是一个角色,但要求的是一个整数。 然而,这应该会帮助你。尽管游戏的玩法有点奇怪

这是到目前为止我的代码,我知道它非常缺乏,但我有不同的东西,我无法理解。
我需要玩一个石头剪刀游戏。它应该首先要求用户输入一个选项,石头布或剪刀。
然后,计算机应该随机地将一个数字放在对方队伍旁边:0、1或2
之后,应制作一个枚举,将这些数值分配给枚举中的实际变量-石头、布和剪刀。

在这之后,用户的选择应该与使用if/else语句的对方球队的随机选择进行比较,这样就可以根据一个普通的石头剪刀纸牌游戏选出获胜者。

您要求的是一个角色,但要求的是一个整数。 然而,这应该会帮助你。尽管游戏的玩法有点奇怪,但这是可行的

import java.util.Scanner;
import java.util.Random;

public class Branches {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        enum Gesture {
            rock,
            paper,
            scissors
        }

        Scanner tKeyboard = new Scanner(System.in);
        System.out.println("Please enter “S” for scissors, “R” for rock, or “P” for paper.");
        int tChoice = tKeyboard.nextInt();
        System.out.println(tChoice);
        Random tRNG = new Random();
        int tX = tRNG.nextInt(3);
        if (tX > )
            System.out.println("You lose.");
        else if (tX < tChoice)
            System.out.println("You win.");
        else 
            System.out.println("It is a tie.");     

    }

}
packagegui;
导入java.util.Random;
导入java.util.Scanner;
公开课考试{
枚举手势
{
岩石(1),
文件(2),
剪刀(3);
私有int型;
手势(int型){
this.type=type;
}
public int getType(){return type;}
}
公共静态void main(字符串[]args){
最终扫描仪键盘=新扫描仪(System.in);
System.out.println(“剪刀请输入“S”,石头请输入“R”,纸请输入“P”);
最终字符串选择=keyboard.next();
如果(选择等于(“S”)){
生成刀(手势、剪刀);
} 
else if(选择等于(“R”)){
generateDraw(手势、摇滚);
} 
else if(选择等于(“P”)){
生成图纸(手势、纸张);
}
键盘关闭();
}
公共静态void generateDraw(手势){
最终随机数=新随机数();
最终int computerDraw=random.nextInt(3);
系统输出打印LN(计算机绘图);
if(computerDraw>signature.getType()){
System.out.println(“你输了”);
}
else if(computerDraw
不是(或完整)答案,而是。无论做什么,都要在函数中隐藏逻辑,然后
int result=fight(firstPlayerChoice,secondPlayerChoice);if(result==…)
可以简单使用,其中(例如)所说的“fight”函数返回-1[第一名玩家获胜]、0[平局]或1[第二名玩家获胜]。您要求用户输入一个字符,但您读取的是integer
tKeyboard.nextInt()
if(tX>)
???此外,不能在方法内声明枚举。请发布一个可以编译的代码!由于“环绕”性质,简单的
不能用于RPS,分配R=1,P=2,S=3,S输给R(其中S>R),但S aso赢给P(其中S>P)。将输入(包括计算机选择)与作战/输赢分辨率完全分离也更为简洁。
package gui;

import java.util.Random;
import java.util.Scanner;

public class test {

    enum Gesture 
    {
        rock(1),
        paper(2),
        scissors(3);

        private int type;
        Gesture(int type) {
            this.type = type;
        }

        public int getType(){ return type; }
    }



    public static void main(String[] args) {
        final Scanner keyboard = new Scanner(System.in);
        System.out.println("Please enter “S” for scissors, “R” for rock, or “P” for paper.");
        final String choice = keyboard.next();

        if (choice.equals("S")) {
             generateDraw(Gesture.scissors);
        } 
        else if (choice.equals("R")) {
            generateDraw(Gesture.rock);
        } 
        else if (choice.equals("P")) {
            generateDraw(Gesture.paper);
        }

        keyboard.close();
    }

    public static void generateDraw(Gesture gesture) {
        final Random random = new Random();
        final int computerDraw = random.nextInt(3);
        System.out.println(computerDraw);

        if (computerDraw > gesture.getType()) {
            System.out.println("You lose.");
        }
        else if (computerDraw < gesture.getType()) {
             System.out.println("You win.");
        }  
        else {
                System.out.println("It is a tie.");


        }
    }
}