Advertisement
NelloRizzo

[GTN] GuessTheNumber

Jan 11th, 2018
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. package local.example.guessthenumber;
  2.  
  3. import android.util.Log;
  4.  
  5. import java.util.Random;
  6.  
  7. /**
  8.  * Created by Nello on 11/01/2018.
  9.  */
  10.  
  11. public class Game {
  12.  
  13.     public static final int LESS = 0;
  14.     public static final int GREATER = 1;
  15.     public static final int WIN = 2;
  16.     public static final int GAME_OVER = -1;
  17.  
  18.     private final String TAG = "GAME";
  19.  
  20.     private int target;
  21.     private int attempts;
  22.  
  23.     public int getAttempts() {
  24.         return attempts;
  25.     }
  26.  
  27.     public Game() {
  28.         target = new Random().nextInt(1000) + 1;
  29.         Log.d(TAG, "Target: " + target);
  30.         attempts = 1;
  31.     }
  32.  
  33.     public int makeAttempt(int number) {
  34.         if (attempts == 10) return GAME_OVER;
  35.         ++attempts;
  36.         if (number == target) return WIN;
  37.         if (number < target) return LESS;
  38.         return GREATER;
  39.     }
  40.  
  41.     public int getTarget() {
  42.         if (attempts == 10) return  target;
  43.         return 0;
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement