├── README.md └── AdvindiancoderVinayKumar └── LaunchGame.java /README.md: -------------------------------------------------------------------------------- 1 | # Number Guessing Game 🎲 2 | 3 | A simple number guessing game implemented in Java. The game involves a guesser and three players who try to guess a number. The umpire collects the guesses and determines the winners. 4 | 5 | ## Table of Contents 6 | - 📜 [Introduction](#introduction) 7 | - 🏗️ [Classes](#classes) 8 | - 🎮 [Game Rules](#game-rules) 9 | - 🕹️ [How to Play](#how-to-play) 10 | - 🤝 [Contributing](#contributing) 11 | - ⚖️ [License](#license) 12 | 13 | ## Introduction 14 | The Number Guessing Game is a Java program that allows a guesser and three players to participate in a thrilling guessing game. The guesser provides a number, and the players try to guess the same number. The umpire compares the guesses and determines the winners based on the game rules. 15 | 16 | ## Classes 17 | - 💡 `Guesser`: Represents the guesser in the game. It prompts the user to input a number as their guess. 18 | - 💡 `Player`: Represents a player in the game. It prompts the user to input a number as their guess. 19 | - 💡 `Umpire`: Handles the collection of guesses from the guesser and players, and compares them to determine the winners. 20 | - 💡 `LaunchGame`: The main class that initiates the game by creating an instance of the `Umpire` class and calling its methods. 21 | 22 | ## Game Rules 23 | - The guesser provides a number as their guess. 24 | - Each player provides a number as their guess. 25 | - The umpire compares the guesser's number with each player's number and determines the winners based on the following rules: 26 | - If the guesser's number matches a player's number, the player wins. 27 | - If multiple players guess the same number as the guesser, they both win. 28 | - If no player guesses the same number as the guesser, the game is lost. 29 | 30 | ## How to Play 31 | 1. 🏁 Run the `LaunchGame` class. 32 | 2. 🎯 The guesser will be prompted to enter a number as their guess. 33 | 3. 🎯 Each player will be prompted to enter a number as their guess. 34 | 4. 🏅 The umpire will compare the guesses and display the winners or inform that the game is lost. 35 | 36 | ## Contributing 37 | Contributions to this project are welcome! If you have any suggestions, improvements, or bug fixes, please submit a pull request. For major changes, please open an issue first to discuss your ideas. 38 | 39 | ## License 40 | This project is licensed under the 📜 [MIT License](LICENSE). Feel free to use, modify, and distribute this code as per the terms of the license. 41 | -------------------------------------------------------------------------------- /AdvindiancoderVinayKumar/LaunchGame.java: -------------------------------------------------------------------------------- 1 | package com.AdvindiancoderVinayKumar; 2 | 3 | import java.util.Scanner; 4 | class Guesser 5 | { 6 | int guessNum; 7 | public int guessNumber() 8 | { 9 | Scanner sc=new Scanner(System.in); 10 | System.out.print("Guesser kindly guess the number = "); 11 | guessNum=sc.nextInt(); 12 | return guessNum; 13 | } 14 | } 15 | 16 | class Player 17 | { 18 | int guessNum; 19 | public int guessNumber() 20 | { 21 | Scanner sc=new Scanner(System.in); 22 | System.out.print("Player! kindly guess the number = "); 23 | guessNum=sc.nextInt(); 24 | return guessNum; 25 | } 26 | } 27 | 28 | class Umpire 29 | { 30 | 31 | int numFromGuesser; 32 | int numFromPlayer1; 33 | int numFromPlayer2; 34 | int numFromPlayer3; 35 | 36 | 37 | public void collectNumFromGuesser() 38 | { 39 | Guesser g=new Guesser(); 40 | numFromGuesser=g.guessNumber(); 41 | } 42 | 43 | 44 | public void collectNumFromPlayer() 45 | { 46 | Player p1=new Player(); 47 | Player p2=new Player(); 48 | Player p3=new Player(); 49 | 50 | 51 | numFromPlayer1=p1.guessNumber(); 52 | numFromPlayer2=p2.guessNumber(); 53 | numFromPlayer3=p3.guessNumber(); 54 | } 55 | 56 | void compare() 57 | { 58 | 59 | if(numFromGuesser==numFromPlayer1) 60 | { 61 | if(numFromGuesser==numFromPlayer2 && numFromGuesser==numFromPlayer3) 62 | { 63 | System.out.println("Game tied all three players guessed correctly"); 64 | } 65 | else if(numFromGuesser==numFromPlayer2) 66 | { 67 | System.out.println("Player 1 and Player2 won the game"); 68 | } 69 | else if(numFromGuesser==numFromPlayer3) 70 | { 71 | System.out.println("Player 1 and Player3 won "); 72 | } 73 | else 74 | { 75 | 76 | System.out.println("Player 1 won the game"); 77 | } 78 | } 79 | 80 | else if(numFromGuesser==numFromPlayer2) 81 | { 82 | 83 | if(numFromGuesser==numFromPlayer3) 84 | { 85 | System.out.println("Player 2 and Player3 won the game"); 86 | } 87 | else 88 | { 89 | System.out.println("Player 2 won the game"); 90 | } 91 | } 92 | else if(numFromGuesser==numFromPlayer3) 93 | { 94 | System.out.println("Player 3 won the game"); 95 | } 96 | else 97 | { 98 | System.out.println("Game lost! try again"); 99 | } 100 | } 101 | 102 | } 103 | public class LaunchGame 104 | { 105 | public static void main(String[] args) 106 | { 107 | Umpire u=new Umpire(); 108 | u.collectNumFromGuesser(); 109 | u.collectNumFromPlayer(); 110 | u.compare(); 111 | } 112 | } --------------------------------------------------------------------------------