Advertisement
Guest User

GameLogic

a guest
Mar 23rd, 2013
737
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. package Game;
  2.  
  3. import utils.ConsoleUtils;
  4.  
  5. public class GameLogic {
  6.     private static int hiddenNumber;
  7.     private static boolean isGameOver;
  8.     private static int attempts;
  9.    
  10.     public void start(){
  11.         hiddenNumber = ConsoleUtils.getNumeric("Enter a number between 0 & 100 for the other player to guess.");
  12.        
  13.         if ( hiddenNumber < 0 || hiddenNumber > 100 ) {
  14.             System.out.println("Opps, please enter a valid number");
  15.             start();
  16.         }
  17.        
  18.         isGameOver = false;
  19.         attempts = 0;
  20.     }
  21.    
  22.     public void makeGuess() {
  23.         int guessNumber = ConsoleUtils.getNumeric("Make a guess");
  24.        
  25.         if ( guessNumber == hiddenNumber ) {
  26.             isGameOver = true;
  27.         } else {
  28.             attempts += 1;
  29.         }
  30.     }
  31.    
  32.     public int getAttempts(){
  33.         return attempts;
  34.     }
  35.    
  36.     public boolean isGameOver() {
  37.         return isGameOver;
  38.     }
  39.  
  40.     public void endGame() {
  41.         isGameOver = true;
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement