Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Game;
- import utils.ConsoleUtils;
- public class GameLogic {
- private static int hiddenNumber;
- private static boolean isGameOver;
- private static int attempts;
- public void start(){
- hiddenNumber = ConsoleUtils.getNumeric("Enter a number between 0 & 100 for the other player to guess.");
- if ( hiddenNumber < 0 || hiddenNumber > 100 ) {
- System.out.println("Opps, please enter a valid number");
- start();
- }
- isGameOver = false;
- attempts = 0;
- }
- public void makeGuess() {
- int guessNumber = ConsoleUtils.getNumeric("Make a guess");
- if ( guessNumber == hiddenNumber ) {
- isGameOver = true;
- } else {
- attempts += 1;
- }
- }
- public int getAttempts(){
- return attempts;
- }
- public boolean isGameOver() {
- return isGameOver;
- }
- public void endGame() {
- isGameOver = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement