diff --git a/GuessGame.java b/GuessGame.java new file mode 100644 index 0000000..c57cb9d --- /dev/null +++ b/GuessGame.java @@ -0,0 +1,49 @@ +public class GuessGame{ +//Final code for the Guess project + + + // public GuessGame(String choice){ + // this.choice = choice; + // } + // public GuessGame(int limit){ + + // } + + //public int getHint(int guess1){ + public static void main(String[] args) { + String choice; + System.out.println("What limit do you want?"); + int choice2 = (int) Math.random() * limit + 1; + choice = choice2; + //get number of tries, num of tries should be equal to the hidden number except for the fir st digit + //so if the hidden number is 180 then you should guess that number in 80 tries + String num = Integer.toString(choice); + String tries1 = num.substring(1); + int tries = (int)tries1; + int numTries = 0; + String end = ""; + String message1 = "Im thinking of a number between 1 and " + limit + ". Now you try to guess what it is."; + System.out.println(message1); + for(int i = 0; i < choice + 100; i++){ + if(guess1 < choice){ + numTries++; + end = "Too low. Try a bigger number."; + }else if(guess1 > choice){ + numTries++; + end = "Too high. Try a smaller number."; + }else if(guess1 = choice){ + numTries++; + end = "That's it! You got it in " + numTries + " tries."; + } + System.out.println(end); + } + + String finalMessage = ""; + if(guess1 = choice && numTries <= tries){ + finalMessage = "Very good."; + }else if(guess1 = choice && numTries > tries){ + finalMessage = "You should have been able to get it in " + tries + " tries."; + } + return finalMessage; + } +} \ No newline at end of file diff --git a/RockPaperScissors.java b/RockPaperScissors.java new file mode 100644 index 0000000..de26059 --- /dev/null +++ b/RockPaperScissors.java @@ -0,0 +1,73 @@ +public class RPS{ + private String choice; + + public RPS(String choice){ + this.choice = choice; + } + public RPS(){ + int choice2 = (int) Math.random() * 3 + 1; + //will the code above make the random number a range from 1-3? + choice = choice2; + } + public int getNumGames(int guess1){ + System.out.println("How many games?"); + String message = ""; + int numberGames = 0; + if(guess1 > 10){ + message = "Sorry, but we aren't allowed to play that many"; + }else if{ + numberGames = guess1; + } + System.out.println(message); + return numberGames; + } + public String getHint(String guess2, int numberGames){ + String gameNum = "This is game number " + numberGames; + System.out.println(gameNum); + for(int i = 0; i < numberGames; i++){ + String message = "3 = rock, 2 = scissors, 1 = paper. What's your choice?" + String message2 = "This my choice " + choice; + String end = ""; + int ties = 0; + int win = 0; + int humanWin = 0; + if(choice = guess2){ + //tie + ties++; + end = "Tie game, no winner"; + }else if(choice = 2 && guess2 = 3{ + //guess wins + humanWin++ + //rock trumps scissors + end = "You win!!"; + }else if(choice = 3 && guess2 = 1{ + //guess wins + humanWin++ + //paper trumps rock + end = "You win!!"; + }else if(choice = 2 && guess2 = 1{ + //choice wins + win++ + //scissors trump paper + end = "Wow. I win!!"; + }else if(choice = 3 && guess2 = 2{ + //choice wins + win++ + //rock trumps scissors + end = "Wow. I win!!"; + }else if(choice = 1 && guess2 = 2{ + //guess wins + humanWin++ + //scissors trump paper + end = "You win!!"; + }else if(choice = 1 && guess2 = 3{ + //choice wins + win++ + //paper trumps rock + end = "Wow. I win!!"; + } + System.out.println(end); + } + String finalMessage = "Here's the final game score: I have won " + win " game(s). You have won " + humanWin " game(s). And " + ties + " game(s) ended in a tie."; + return finalMessage; + } \ No newline at end of file diff --git a/org/asl/socketserver/games/GuessGame.java b/org/asl/socketserver/games/GuessGame.java new file mode 100644 index 0000000..f10ff6a --- /dev/null +++ b/org/asl/socketserver/games/GuessGame.java @@ -0,0 +1,67 @@ +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 = { +"Naz Ozturk" }, version = "Winter, 2018", title = "Guessing Game", description = "A guessing game for a number between 1 and a limit of your choice.") + + +public class GuessGame implements Servable { + // Final code for the Guess project + + @Override + public void serve(BufferedReader input, PrintWriter out) throws IOException { + // TODO Auto-generated method stub + int choice = 0; + out.println("What limit do you want?"); + int limit = Integer.parseInt(input.readLine().trim()); + int choice2 = (int) (Math.random() * limit + 1); + choice = choice2; + // get number of tries, num of tries should be equal to the hidden number except + // for the first digit + // so if the hidden number is 180 then you should guess that number in 80 tries + String num = choice + ""; + String tries1 = num.substring(1); + int tries = Integer.parseInt(tries1); + int numTries = 0; + String end = ""; + String message1 = ""; + int guess1 = 0; + + for (int i = 0; i < choice; i++) { + message1 = "Im thinking of a number between 1 and " + limit + ". Now you try to guess what it is."; + out.println(message1); + guess1 = Integer.parseInt(input.readLine().trim()); + if (guess1 < choice) { + numTries++; + end = "Too low. Try a bigger number."; + out.println(end); + } else if (guess1 > choice) { + numTries++; + end = "Too high. Try a smaller number."; + out.println(end); + } else if (guess1 == choice) { + numTries++; + end = "That's it! You got it in " + numTries + " tries."; + out.println(end); + break; + } + // out.println(end); + } + + String finalMessage = ""; + if (guess1 == choice && numTries <= tries) { + finalMessage = "Very good."; + } else if (guess1 == choice && numTries > tries) { + finalMessage = "You should have been able to get it in " + tries + " tries."; + } + out.println(finalMessage); + + } +} \ No newline at end of file diff --git a/org/asl/socketserver/games/GuessGameFinal.java b/org/asl/socketserver/games/GuessGameFinal.java new file mode 100644 index 0000000..33e7405 --- /dev/null +++ b/org/asl/socketserver/games/GuessGameFinal.java @@ -0,0 +1,67 @@ +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 = { +"Naz Ozturk and lorenzo" }, version = "Winter, 2018", title = "Guessing Game", description = "A guessing game for a number between 1 and a limit of your choice.") + + +public class GuessGameFinal implements Servable { + // Final code for the Guess project + + @Override + public void serve(BufferedReader input, PrintWriter out) throws IOException { + // TODO Auto-generated method stub + int choice = 0; + out.println("What limit do you want?"); + int limit = Integer.parseInt(input.readLine().trim()); + int choice2 = (int) (Math.random() * limit + 1); + choice = choice2; + // get number of tries, num of tries should be equal to the hidden number except + // for the first digit + // so if the hidden number is 180 then you should guess that number in 80 tries + String num = choice + ""; + String tries1 = num.substring(1); + int tries = Integer.parseInt(tries1); + int numTries = 0; + String end = ""; + String message1 = ""; + int guess1 = 0; + + for (int i = 0; i < choice; i++) { + message1 = "Im thinking of a number between 1 and " + limit + ". Now you try to guess what it is."; + out.println(message1); + guess1 = Integer.parseInt(input.readLine().trim()); + if (guess1 < choice) { + numTries++; + end = "Too low. Try a bigger number."; + out.println(end); + } else if (guess1 > choice) { + numTries++; + end = "Too high. Try a smaller number."; + out.println(end); + } else if (guess1 == choice) { + numTries++; + end = "That's it! You got it in " + numTries + " tries."; + out.println(end); + break; + } + // out.println(end); + } + + String finalMessage = ""; + if (guess1 == choice && numTries <= tries) { + finalMessage = "Very good."; + } else if (guess1 == choice && numTries > tries) { + finalMessage = "You should have been able to get it in " + tries + " tries."; + } + out.println(finalMessage); + + } +} \ No newline at end of file diff --git a/org/asl/socketserver/games/RPS.java b/org/asl/socketserver/games/RPS.java new file mode 100644 index 0000000..1517983 --- /dev/null +++ b/org/asl/socketserver/games/RPS.java @@ -0,0 +1,104 @@ +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 = { +"Naz Ozturk" }, version = "Winter, 2018", title = "Rock Paper Scissors", description = "A game of Rock Paper Scissors between you and the computer.") + +public class RPS implements Servable{ +//final code for rock paper scissors project + //public static void main(String[] args) { + + @Override + public void serve(BufferedReader input, PrintWriter out) throws IOException { + //Scanner input = new Scanner(System.in); + out.println("How many games?"); + int guess1 = Integer.parseInt(input.readLine().trim()); + String message = ""; + int numberGames = 0; + if(guess1 > 10){ + message = "Sorry, but we aren't allowed to play that many"; + }else{ + numberGames = guess1; + } + out.println(message); + + + int ties = 0; + int win = 0; + int humanWin = 0; + String message2 = ""; + String message3 = ""; + int guess2 = 0; + int choice = 0; + int choice2 = 0; + int number = 0; + String choice3 = ""; + String gameNum = ""; + + for(int i = 0; i < numberGames; i++){ + choice2 = (int) (Math.random() * 3 + 1); + choice = choice2; + if(choice == 1) { + choice3 = "Paper"; + }else if(choice == 2) { + choice3 = "Scissors"; + }else if(choice == 3) { + choice3 = "Rock"; + } + number ++; + gameNum = "This is game number " + number; + out.println(gameNum); + message2 = "3 = rock, 2 = scissors, 1 = paper. What's your choice?"; + out.println(message2); + guess2 = Integer.parseInt(input.readLine().trim()); + message3 = "This my choice: " + choice3; + out.println(message3); + String end = ""; + if(choice == guess2){ + //tie + ties ++; + end = "Tie game, no winner"; + }else if(choice == 2 && guess2 == 3){ + //guess wins + humanWin ++; + //rock trumps scissors + end = "You win!!"; + }else if(choice == 3 && guess2 == 1){ + //guess wins + humanWin ++; + //paper trumps rock + end = "You win!!"; + }else if(choice == 2 && guess2 == 1){ + //choice wins + win ++; + //scissors trump paper + end = "Wow. I win!!"; + }else if(choice == 3 && guess2 == 2){ + //choice wins + win ++; + //rock trumps scissors + end = "Wow. I win!!"; + }else if(choice == 1 && guess2 == 2){ + //guess wins + humanWin ++; + //scissors trump paper + end = "You win!!"; + }else if(choice == 1 && guess2 == 3){ + //choice wins + win ++; + //paper trumps rock + end = "Wow. I win!!"; + } + out.println(end); + } + String finalMessage = "Here's the final game score: I have won " + win + " game(s). You have won " + humanWin + " game(s). And " + ties + " game(s) ended in a tie."; + out.println(finalMessage); + } +} \ No newline at end of file diff --git a/org/asl/socketserver/games/RPSFinal.java b/org/asl/socketserver/games/RPSFinal.java new file mode 100644 index 0000000..cf0c4d6 --- /dev/null +++ b/org/asl/socketserver/games/RPSFinal.java @@ -0,0 +1,104 @@ +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 = { +"Naz Ozturk and lorenzo" }, version = "Winter, 2018", title = "Rock Paper Scissors", description = "A game of Rock Paper Scissors between you and the computer.") + +public class RPSFinal implements Servable{ +//final code for rock paper scissors project + //public static void main(String[] args) { + + @Override + public void serve(BufferedReader input, PrintWriter out) throws IOException { + //Scanner input = new Scanner(System.in); + out.println("How many games?"); + int guess1 = Integer.parseInt(input.readLine().trim()); + String message = ""; + int numberGames = 0; + if(guess1 > 10){ + message = "Sorry, but we aren't allowed to play that many"; + }else{ + numberGames = guess1; + } + out.println(message); + + + int ties = 0; + int win = 0; + int humanWin = 0; + String message2 = ""; + String message3 = ""; + int guess2 = 0; + int choice = 0; + int choice2 = 0; + int number = 0; + String choice3 = ""; + String gameNum = ""; + + for(int i = 0; i < numberGames; i++){ + choice2 = (int) (Math.random() * 3 + 1); + choice = choice2; + if(choice == 1) { + choice3 = "Paper"; + }else if(choice == 2) { + choice3 = "Scissors"; + }else if(choice == 3) { + choice3 = "Rock"; + } + number ++; + gameNum = "This is game number " + number; + out.println(gameNum); + message2 = "3 = rock, 2 = scissors, 1 = paper. What's your choice?"; + out.println(message2); + guess2 = Integer.parseInt(input.readLine().trim()); + message3 = "This my choice: " + choice3; + out.println(message3); + String end = ""; + if(choice == guess2){ + //tie + ties ++; + end = "Tie game, no winner"; + }else if(choice == 2 && guess2 == 3){ + //guess wins + humanWin ++; + //rock trumps scissors + end = "You win!!"; + }else if(choice == 3 && guess2 == 1){ + //guess wins + humanWin ++; + //paper trumps rock + end = "You win!!"; + }else if(choice == 2 && guess2 == 1){ + //choice wins + win ++; + //scissors trump paper + end = "Wow. I win!!"; + }else if(choice == 3 && guess2 == 2){ + //choice wins + win ++; + //rock trumps scissors + end = "Wow. I win!!"; + }else if(choice == 1 && guess2 == 2){ + //guess wins + humanWin ++; + //scissors trump paper + end = "You win!!"; + }else if(choice == 1 && guess2 == 3){ + //choice wins + win ++; + //paper trumps rock + end = "Wow. I win!!"; + } + out.println(end); + } + String finalMessage = "Here's the final game score: I have won " + win + " game(s). You have won " + humanWin + " game(s). And " + ties + " game(s) ended in a tie."; + out.println(finalMessage); + } +} \ No newline at end of file