aboutsummaryrefslogtreecommitdiff
path: root/src/esieequest/controller/GameEngine.java
blob: fed79d697f0566fc226e4eddf3cf1702064ce3ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package esieequest.controller;

import esieequest.controller.commands.Command;
import esieequest.model.Game;
import esieequest.model.Text;
import esieequest.model.characters.MovingCharacter;
import esieequest.view.Viewable;

/**
 * The game main controller class.
 * 
 * @author Pacien TRAN-GIRARD
 * @author Benoît LUBRANO DI SBARAGLIONE
 */
public class GameEngine {

	private final Game game;
	private final Viewable view;

	/**
	 * Instantiates a game engine with the given model and view.
	 * 
	 * @param game
	 *            the game model
	 * @param view
	 *            the view
	 */
	public GameEngine(final Game game, final Viewable view) {
		this.game = game;
		this.view = view;

		this.view.setController(this);

		this.view.show();
	}

	/**
	 * Interprets a command.
	 * 
	 * @param commandString
	 *            the command String
	 */
	public void interpret(final String inputString) {
		final Input input = new Input(inputString);

		final Command command = input.getCommand();
		if (command == null) {
			this.view.echo(Text.UNKNOWN_COMMAND.getText());
			return;
		}

		final String argument = input.getArgument();

		this.executeRoutines();
		command.execute(argument, this.game, this.view);
	}

	/**
	 * Actions executed every time a Command is entered.
	 */
	private void executeRoutines() {
		MovingCharacter.moveAll();
	}

}