From 5b259c987eeac36c58e3fa43e26d8a3ac605974f Mon Sep 17 00:00:00 2001 From: laurenb-asl Date: Thu, 25 Jan 2018 10:39:31 +0000 Subject: [PATCH 1/3] Here is two of our games. --- org/asl/socketserver/games/Dice.java | 62 ++++++++++++++++ org/asl/socketserver/games/RPS.java | 102 +++++++++++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100644 org/asl/socketserver/games/Dice.java create mode 100644 org/asl/socketserver/games/RPS.java diff --git a/org/asl/socketserver/games/Dice.java b/org/asl/socketserver/games/Dice.java new file mode 100644 index 0000000..4fa83d3 --- /dev/null +++ b/org/asl/socketserver/games/Dice.java @@ -0,0 +1,62 @@ +package org.asl.socketserver.games; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +import org.asl.socketserver.MenuInfo; +import org.asl.socketserver.Servable; + +@MenuInfo(authors = { +"Lauren Brantley and Christina Leonard" }, version = "Winter, 2018", title = "Dice", description = "Throw those DICE!!!") + +public class Dice implements Servable{ + + + @Override + public void serve(BufferedReader input, PrintWriter output) throws IOException { + // TODO Auto-generated method stub + + output.println("GAME OF DICE. Press N for next round or Q to quit."); + String yourPlay = input.readLine().toUpperCase(); + int playerScore = 0; + int computerScore = 0; + String message = ""; + + while (!yourPlay.equals("Q")) { + int MAX = 6; + int MIN = 1; + int yourNumber = (int) (Math.floor((MAX-MIN + 1) * Math.random()) + MIN); + int computerNumber = (int) (Math.floor((MAX-MIN + 1) * Math.random()) + MIN); + + if (yourNumber > computerNumber) { + output.println("You rolled a " + yourNumber + " and the computer rolled a " + computerNumber + ".\nYou win! You get a point."); + playerScore += 1; + } else if (yourNumber < computerNumber) { + output.println("You rolled a " + yourNumber + " and the computer rolled a " + computerNumber + ".\nYou lose :( Computer got the point. "); + computerScore += 1; + } else if (yourNumber == computerNumber) { + output.println("You rolled a " + yourNumber + " and the computer rolled a " + computerNumber + ".\nYou guys tied. You both get a point."); + computerScore += 1; + playerScore += 1; + } + + output.println("Press N for next round or Q to quit."); + yourPlay = input.readLine().toUpperCase().trim(); + + } + + if (playerScore > computerScore) { + output.println("You had " + playerScore + " points. \nThe computer have " + computerScore + " points. You won! Goodbye."); + } else if (playerScore < computerScore) { + output.println("You had " + playerScore + " points. \nThe computer have " + computerScore + " points. You lost :( Goodbye."); + } else if (playerScore == computerScore) { + output.println("You had " + playerScore + " points. \nThe computer have " + computerScore + " points. You tied. Goodbye."); + } + + + } + +} + + diff --git a/org/asl/socketserver/games/RPS.java b/org/asl/socketserver/games/RPS.java new file mode 100644 index 0000000..67d1ffb --- /dev/null +++ b/org/asl/socketserver/games/RPS.java @@ -0,0 +1,102 @@ +package org.asl.socketserver.games; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +import org.asl.socketserver.MenuInfo; +import org.asl.socketserver.Servable; + +@MenuInfo(authors = { +"Lauren Brantley and Christina Leonard" }, version = "Winter, 2018", title = "Rock, Paper, Scissors", description = "The classic wonderful game of Rock, Paper, Scissors") + +public class RPS implements Servable { + + @Override + public void serve(BufferedReader input, PrintWriter output) throws IOException { + // TODO Auto-generated method stub + + output.println("GAME OF ROCK, SCISSORS, PAPERS." + "\n" + "Enter your guess: (Type R for Rock, P for Paper, S for Scissors or Q to quit)"); + String yourPlay = input.readLine().toUpperCase(); + + //if( howMany < 11) + //System.output.println("Sorry, but we aren't allowed to play that many."); + + int yourPoints = 0; + + while(yourPlay != "Q") { + int MIN = 0; + int MAX = 2; + String message = ""; + int play = (int) (Math.floor(MAX-MIN+1) * Math.random() + MIN); + String play1 = ""; + + if(play == 0) { + play1 = "Rock"; + } else if (play == 0) { + play1 = "Paper"; + } else { + play1 = "Scissors"; + } + + String tie = "Computer plays " + play1 + "\n" + "It's a tie!"; + String rockWin = "Computer plays " + play1 + "\n" + "Rock crushes scissors, you win!."; + String rockComputerWin = "Computer plays " + play1 + "\n" + "Rock crushes scissors, computer wins."; + String paperWin = "Computer plays " + play1 + "\n" + "Paper covers rock, you win!"; + String paperComputerWin = "Computer plays " + play1 + "\n" + "Paper covers rock, computer wins."; + String scissorsWin = "Computer plays " + play1 + "\n" + "Scissors cut paper, you win!"; + String scissorsComputerWin = "Computer plays " + play1 + "\n" + "Scissors cut paper, computer wins."; + + + if(yourPlay.equals("R") && play1.equals("Rock")) { + output.println(tie); + //scissor and rock + } else if (yourPlay.equals("S") && play1.equals("Rock")) { + output.println(rockComputerWin); + yourPoints = yourPoints - 1; + //paper and rock + } else if (yourPlay.equals("P") && play1.equals("Rock")) { + output.println(paperWin); + yourPoints = yourPoints + 1; + //rock and paper + } else if (yourPlay.equals("R") && play1.equals("Paper")) { + output.println(paperComputerWin); + yourPoints = yourPoints - 1; + //paper and paper + } else if (yourPlay.equals("P") && play1.equals("Paper")) { + output.println(tie); + //scissor and paper + } else if (yourPlay.equals("S") && play1.equals("Paper")) { + output.println(scissorsWin); + yourPoints = yourPoints + 1; + //rock and scissor + } else if (yourPlay.equals("R") && play1.equals("Scissors")) { + output.println(rockWin); + yourPoints = yourPoints + 1; + //paper and scissors + } else if (yourPlay.equals("P") && play1.equals("Scissors")) { + output.println(scissorsComputerWin); + yourPoints = yourPoints - 1; + //scissors and scissors + } else if (yourPlay.equals("S") && play1.equals("Scissors")) { + output.println(tie); + //creates outcome for what would happen if person wanted to quit the game + } else if (yourPlay.equals("Q")) { + break; + //creating the messages that will be displayed + + } else { + //create alert for any invalid responses + output.println("Invalid Response."); + } + output.println(message); + output.println("GAME OF ROCK, SCISSORS, PAPERS." + "\n" + "Enter your guess: (Type R for Rock, P for Paper, S for Scissors or Q to quit)"); + yourPlay = input.readLine().toUpperCase(); + } + output.println("Your score is " + yourPoints + "." + "\n" + "Goodbye."); + } + + + } + From 086c9c63791d44df4296b94afb87618b9c8c2fa5 Mon Sep 17 00:00:00 2001 From: laurenb-asl Date: Mon, 29 Jan 2018 09:15:35 +0000 Subject: [PATCH 2/3] This is RPS --- org/asl/socketserver/games/RPS.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org/asl/socketserver/games/RPS.java b/org/asl/socketserver/games/RPS.java index 67d1ffb..b31b377 100644 --- a/org/asl/socketserver/games/RPS.java +++ b/org/asl/socketserver/games/RPS.java @@ -9,7 +9,7 @@ import org.asl.socketserver.Servable; @MenuInfo(authors = { -"Lauren Brantley and Christina Leonard" }, version = "Winter, 2018", title = "Rock, Paper, Scissors", description = "The classic wonderful game of Rock, Paper, Scissors") +"Lauren Brantley & Christina Leonard" }, version = "Winter, 2018", title = "Rock, Paper, Scissors", description = "The classic wonderful game of Rock, Paper, Scissors") public class RPS implements Servable { From 0db3dd26c08434633da487d1951c3e15630f63a2 Mon Sep 17 00:00:00 2001 From: laurenb-asl Date: Mon, 29 Jan 2018 09:16:06 +0000 Subject: [PATCH 3/3] This is our game of Dice --- org/asl/socketserver/games/Dice.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org/asl/socketserver/games/Dice.java b/org/asl/socketserver/games/Dice.java index 4fa83d3..b289e58 100644 --- a/org/asl/socketserver/games/Dice.java +++ b/org/asl/socketserver/games/Dice.java @@ -8,7 +8,7 @@ import org.asl.socketserver.Servable; @MenuInfo(authors = { -"Lauren Brantley and Christina Leonard" }, version = "Winter, 2018", title = "Dice", description = "Throw those DICE!!!") +"Lauren Brantley & Christina Leonard" }, version = "Winter, 2018", title = "Dice", description = "Throw those DICE!!!") public class Dice implements Servable{