Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pianotiles.logic;
- import java.util.LinkedList;
- import java.util.Random;
- import pianotiles.logic.exceptions.InvalidInputException;
- public class Game {
- private static final int TILE_WIDTH = 150, TILE_HEIGHT = 200;
- private boolean gameOver;
- private static Game instance = null;
- public Player player;
- public int score;
- public LinkedList<Tile> tiles;
- public Level level;
- public static Game getInstance() {
- if (instance == null) {
- try {
- setNewGame("No name");
- } catch (InvalidInputException e) {
- }
- }
- return instance;
- }
- private Game(Player pPlayer) {
- this.player = pPlayer;
- this.level = Level.Training;
- this.tiles = new LinkedList<>();
- }
- public void addTileOnTop(){
- Tile tile = new Tile();
- tile.setSize(TILE_WIDTH, TILE_HEIGHT);
- int r = (new Random().nextInt(4))*150 + 100;
- tile.setLocation(r, -TILE_HEIGHT);
- tile.increase = Level.getLevel(score).speed;
- this.tiles.add(tile);
- }
- public void nukeTheGame() {
- this.gameOver = false;
- this.score = 0;
- }
- public void setScore() {
- if (!gameOver) {
- score += new Random().nextInt(3)+1;
- this.level = Level.getLevel(score);
- for (Tile tile : this.tiles){
- tile.increase = this.level.speed;
- }
- }
- }
- public void setGameOver() {
- gameOver = true;
- }
- public boolean isGameOver() {
- return gameOver;
- }
- public static void setNewGame(String playerName) throws InvalidInputException {
- Player player = new Player(playerName);
- Game.instance = new Game(player);
- }
- public enum Level {
- Training(-1, 50, 4.0f, 500),
- Beginner(50, 100, 4.2f, 475),
- Intermediate(100, 250, 4.5f, 450),
- Advanced(250, 350, 5.5f, 425),
- Expert(350, 450, 6.5f, 400),
- Professional(450, 600, 7f, 375),
- OLIVETO_BOSS(600, Integer.MAX_VALUE, 7.5f, 350);
- public int minRange, maxRange, sleep;
- public float speed;
- private Level(int r1, int r2, float i, int sleep) {
- this.minRange = r1;
- this.maxRange = r2;
- this.speed = i;
- this.sleep = sleep;
- }
- public static Level getLevel(int score){
- for (Level level : Level.values()){
- if (score > level.minRange && score <= level.maxRange){
- return level;
- }
- }
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement