GameModel.java
/*
* Copyright © 2012 Nokia Corporation. All rights reserved.
* Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation.
* Oracle and Java are trademarks or registered trademarks of Oracle and/or its
* affiliates. Other product and company names mentioned herein may be trademarks
* or trade names of their respective owners.
* See LICENSE.TXT for license information.
*/
package com.nokia.example.amaze.model;
/**
* The container for the game logic.
*/
public class GameModel {
// Constants
private final static int POSITION_TOLERANCE = 10;
public final static int MAZE_CORRIDOR_COUNT = 10;
public final static float MAZE_SIDE_LENGTH = 200f; // Defines the overall size of the maze
public final static float WALL_HEIGHT = 10.f; // Height of the walls
public final static float DEFAULT_STEP_LENGTH_PER_AXIS = 3.0f; // Amount to advance on each step
public final static float DEFAULT_STEP_LENGTH =
DEFAULT_STEP_LENGTH_PER_AXIS * DEFAULT_STEP_LENGTH_PER_AXIS;
// Members
private static GameModel _instance = null;
private Maze _maze = null;
private final MarbleModel _marble;
private boolean _goalReached = false;
/**
* @return The singleton instance of the game model.
*/
public static GameModel instance() {
if (_instance == null) {
_instance = new GameModel();
}
return _instance;
}
/**
* Constructor.
*/
private GameModel() {
_maze = new Maze(MAZE_CORRIDOR_COUNT, MAZE_SIDE_LENGTH, WALL_HEIGHT);
_marble = new MarbleModel();
_marble.setPosition(0f, 2 * WALL_HEIGHT + 3f, 0f);
}
/**
* @return The maze.
*/
public final Maze maze() {
return _maze;
}
/**
* @return The marble.
*/
public final MarbleModel marble() {
return _marble;
}
/**
* @param goalReached
*/
public void setGoalReached(boolean goalReached) {
_goalReached = goalReached;
}
/**
* @return True if the goal in the game has been reached, false otherwise.
*/
public final boolean goalReached() {
return _goalReached;
}
/**
* @return True if the marble has reached the end (goal), false otherwise.
*/
public final boolean isAtEnd() {
final float[] position = _marble.position();
return _maze.isAtTheEnd(position[0], position[2], POSITION_TOLERANCE);
}
}