-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEngine.java
More file actions
58 lines (53 loc) · 2.18 KB
/
Engine.java
File metadata and controls
58 lines (53 loc) · 2.18 KB
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
package byow.Core;
import byow.TileEngine.TERenderer;
import byow.TileEngine.TETile;
public class Engine {
TERenderer ter = new TERenderer();
public static final int WIDTH = 80;
public static final int HEIGHT = 30;
/**
* Method used for exploring a fresh world. This method should handle all inputs,
* including inputs from the main menu.
*/
public void interactWithKeyboard() {
TETile[][] finalWorldFrame = new TETile[WIDTH][HEIGHT];
ter.initialize(WIDTH, HEIGHT);
InputHandler p = new InputHandler(finalWorldFrame, ter);
p.handleInput("");
}
/**
* Method used for autograding and testing your code. The input string will be a series
* of characters (for example, "n123sswwdasdassadwas", "n123sss:q", "lwww". The engine should
* behave exactly as if the user typed these characters into the engine using
* interactWithKeyboard.
*
* Recall that strings ending in ":q" should cause the game to quite save. For example,
* if we do interactWithInputString("n123sss:q"), we expect the game to run the first
* 7 commands (n123sss) and then quit and save. If we then do
* interactWithInputString("l"), we should be back in the exact same state.
*
* In other words, running both of these:
* - interactWithInputString("n123sss:q")
* - interactWithInputString("lww")
*
* should yield the exact same world state as:
* - interactWithInputString("n123sssww")
*
* @param input the input string to feed to your program
* @return the 2D TETile[][] representing the state of the world
*/
public TETile[][] interactWithInputString(String input) {
TETile[][] finalWorldFrame = new TETile[WIDTH][HEIGHT];
InputHandler p = new InputHandler(finalWorldFrame, ter);
p.handleInput(input);
return finalWorldFrame;
}
public static void main(String[] args) {
Engine e = new Engine();
e.interactWithKeyboard();
TETile[][] frame = e.interactWithInputString("RDDD:Q");
System.out.println(TETile.toString(frame));
e.ter.initialize(WIDTH, HEIGHT);
e.ter.renderFrame(frame);
}
}