Want more features on Pastebin? Sign Up, it's FREE!
Guest

GameLogic

By: a guest on Mar 23rd, 2013  |  syntax: Java  |  size: 0.84 KB  |  views: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data