Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package local.example.guessthenumber;
- import android.util.Log;
- import java.util.Random;
- /**
- * Created by Nello on 11/01/2018.
- */
- public class Game {
- public static final int LESS = 0;
- public static final int GREATER = 1;
- public static final int WIN = 2;
- public static final int GAME_OVER = -1;
- private final String TAG = "GAME";
- private int target;
- private int attempts;
- public int getAttempts() {
- return attempts;
- }
- public Game() {
- target = new Random().nextInt(1000) + 1;
- Log.d(TAG, "Target: " + target);
- attempts = 1;
- }
- public int makeAttempt(int number) {
- if (attempts == 10) return GAME_OVER;
- ++attempts;
- if (number == target) return WIN;
- if (number < target) return LESS;
- return GREATER;
- }
- public int getTarget() {
- if (attempts == 10) return target;
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement