Хорошо, так что мне нужно создать код, необходимый для создания игры с ножницами с ножницами, с примером вывода, выглядящего примерно так: < /p>
RockPaperScissors pick your weapon[R,P,S]:: R
player had rock
computer had paper
!Computer wins <
>!
Do you want to play again? y
RockPaperScissors pick your weapon[R,P,S]:: R
player had rock
computer had scissors
!Player wins !
Do you want to play again? y
RockPaperScissors pick your weapon[R,P,S]:: R
player had rock
computer had rock
!Draw Game!
Do you want to play again? n
< /code>
Так что я в основном полностью озадачен, и я не совсем уверен, что делать отсюда, код должен иметь возможность позволить пользователю выбирать R, P или S и позволить компьютеру определять случайный экземпляр такого. Я не прошу вас, ребята, сделать все это для меня (но не стесняйтесь), но просто какое -то направление/помощь будет очень признателен, так что вот что у меня есть:
Rockpaperscissors Class:
import java.util.Scanner;
import static java.lang.System.*;
import java.util.Random;
public class RockPaperScissors
{
private String playChoice;
private String compChoice;
public RockPaperScissors
{
playChoice=null; //same as playChoice="";
compChoice=null;
}
//loaded constructor
public RockPaperScissors(String player)
{
//add code here to call the setPlayers method
}
//set playChoice based on player choice and compChoice based on random number
public void setPlayers (String player)
{
//switch case
//R-player="rock"
//P-player="paper"
//S-player="scissors"
//int num=random number 0 1 or 2
//switch case
//0-computer="rock"
//1-computer="paper"
//2-computer="scissors"
}
//using logic and possible player and computer choices, determine a winner and return the string that informs the player who won
public String determineWinner()
{
String winner="";
//if playChoice is the same as compChoice no winner (draw)
//else-if-else if statements to compare playChoice and compChoice to find the winner
return winner;
}
public String toString()
{
String output="";
output=output + "player had " + playChoice+"\n;
output+="computer had "+ compChoice;
return output;
}
}
< /code>
и класс Runner: < /p>
import java.util.Scanner;
import static java.lang.System.*;
public class RPSRunner
{
public static void main(String args[])
{
weapon[R,P,S]:: ");
RockPaperScissors(keyboard.next());
Scanner keyboard = new Scanner(System.in);
char response;
do{
System.out.print("RockPaperScissors pick your
RockPaperScissors test = new
System.out.println(test); //uses toString method
System.out.println(test.determineWinner()+"\n");
System.out.print("Do you want to play again? ");
response = keyboard.next().charAt(0);
}while(response=='Y'||response=='y');
}
}
< /code>
Спасибо за любую помощь. Создайте случайный выбор < /p>
для компьютерного игрока. Далее, Человек сделает выбор. Наконец, вы принимаете два варианта < /p>
и видите, какой из игроков является победителем. Вам нужно будет использовать случайные числа.
Подробнее здесь: https://stackoverflow.com/questions/336 ... ssors-game