Java Rock Paper Scissors游戏

时间:2018-04-16 02:24:19

标签: java java.util.scanner

只是想知道为什么我的方法(结果)已经关闭。它只输出所有的syso(),无论播放什么。顺便说一句,这是一个不完整的程序,只是在继续之前测试它。我还担心任何更有效的方式来编写代码。我是一个相当新的编码,所以不寻找太复杂的东西。但主要是试图弄清楚为什么这种结果方法不起作用。

package main;
import java.util.Random;
import java.util.Scanner;

//Description: Create a program that plays rock, paper, scissors with the 
user then states who the winner is in the output

public class RPS
{

//Declaring variables
char playerMove, R, P, S;
int pcMoveNum;
String name, pcMove = "";
Scanner scan = new Scanner(System.in);
Random random = new Random();

public void input()
{
    System.out.println("Hello, whats your name?");
    name = scan.nextLine();
    System.out.println("Okay "+name+" lets play rock, paper scissors!");
    System.out.println("(R = rock, P = paper and S = scissors.)");
    System.out.println("Type R, P, or S to make your move");
    playerMove = scan.nextLine().charAt(0);
}


public void computerMove()
{
    pcMoveNum = random.nextInt(3)+1;

    if (pcMoveNum == 1);
    {
        pcMove = "R";
    }
    if (pcMoveNum == 2);
    {
        pcMove = "P";
    }

    if (pcMoveNum == 3);
    {
        pcMove = "S";
    }
}

public void outcome()
{
    if(playerMove == R); //Player chooses rock
    {
        if(pcMove == "R"); //If PC also chooses rock - use this output 
        {
            System.out.println("Its a Tie :I The computer choose rock and you choose rock.");
            if(pcMove == "P");
            {
                System.out.println("You Lose! :( The computer choose paper and you choose rock.");
                if(pcMove == "S");
                {
                    System.out.println("You Won :) The computer choose scissors and you choose rock.");
                }
            }
        }   
    }
}


public static void main(String[] args)
{
    RPS phill = new RPS();
    phill.input();
    phill.computerMove();
    phill.outcome();
}

}

0 个答案:

没有答案