Browse Source

git test

master
Patrik Kriska 2 years ago
parent
commit
690fcb36e0

BIN
out/production/Interaktion Projekt/GameClass.class View File


BIN
out/production/Interaktion Projekt/RockPaperScissors.class View File


+ 1
- 1
src/GameClass.java View File

public class GameClass { public class GameClass {


public static void main(String[] args){ public static void main(String[] args){
for (int i = 0; i < 7; i++) RockPaperScissors.runGame();
while (RockPaperScissors.playerScore < 7 ) RockPaperScissors.runGame();
} }
} }

+ 9
- 1
src/RockPaperScissors.java View File

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


public class RockPaperScissors { public class RockPaperScissors {
static int computerScore = 0;
static int playerScore = 0;


public static void runGame() { public static void runGame() {
int computerInput = letComputerChoose(); int computerInput = letComputerChoose();


public static void checkResults(int computerInput, int userInput) { public static void checkResults(int computerInput, int userInput) {



if (computerInput == userInput) { if (computerInput == userInput) {
System.out.println("Draw!"); System.out.println("Draw!");
} else if (computerInput == 1 && userInput == 2 } else if (computerInput == 1 && userInput == 2
|| computerInput == 2 && userInput == 3 || computerInput == 2 && userInput == 3
|| computerInput == 3 && userInput == 1) { || computerInput == 3 && userInput == 1) {
playerScore = playerScore + 1;
System.out.println("You win!"); System.out.println("You win!");


} else if (computerInput == 2 && userInput == 1 } else if (computerInput == 2 && userInput == 1
|| computerInput == 3 && userInput == 2 || computerInput == 3 && userInput == 2
|| computerInput == 1 && userInput == 3) { || computerInput == 1 && userInput == 3) {
computerScore = computerScore + 1;
System.out.println("Computer wins!"); System.out.println("Computer wins!");

} else { } else {
System.out.println("Incorrect inputs: round void"); System.out.println("Incorrect inputs: round void");
} }
System.out.println("The score is: " + playerScore + ":" + computerScore);
} }


private static String convertToWordUser(int userInput) { private static String convertToWordUser(int userInput) {


public static int letComputerChoose() { public static int letComputerChoose() {
Random rgen = new Random(); Random rgen = new Random();
int computerInput = rgen.nextInt(1, 3);
int computerInput = rgen.nextInt(1,3);
return computerInput; return computerInput;
} }

} }

Loading…
Cancel
Save