-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScreen
More file actions
178 lines (152 loc) · 3.91 KB
/
Screen
File metadata and controls
178 lines (152 loc) · 3.91 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package com.cs2114.dungeonEscape;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import sun.misc.IOUtils;
import java.io.StringWriter;
import java.io.InputStream;
import android.content.res.AssetManager;
import sofia.app.Screen;
import java.awt.Point;
import java.awt.Button;
// -------------------------------------------------------------------------
/**
* The screen
*
* @author Joe Bruzek, Yash Pant, Marcus Stewart
* @version Dec 5, 2013
*/
public class DungeonEscapeScreen
extends Screen
{
private CircularLinkedList<Level> levelList;
private Level level;
private Button resetLevel;
private Button next;
private Button previous;
private int size;
/**
* Create a new DungeonEscapeScreen object.
*/
public DungeonEscapeScreen()
{
levelList = new CircularLinkedList<Level>();
for (int i = 0; i < 5; i++)
{
levelList.add(new Level(getLevelString(i)));
}
levelList.next();
level = levelList.getCurrent();
}
// ----------------------------------------------------------
/**
* Returns a string representation of the level from text files
*
* @param i
* @return string that represents the level
*/
public String getLevelString(int i)
{
String levelString = null;
String fileName;
switch (i)
{
case 0:
fileName = "level1.txt";
case 1:
fileName = "level2.txt";
case 2:
fileName = "level3.txt";
case 3:
fileName = "level4.txt";
case 4:
fileName = "level5.txt";
}
AssetManager am = getAssets();
try
{
InputStream is = am.open(levelString);
BufferedReader reader =
new BufferedReader(new InputStreamReader(is));
StringBuilder out = new StringBuilder();
String line;
while ((line = reader.readLine()) != null)
{
out.append(line);
}
levelString = out.toString();
reader.close();
}
catch (Exception ex)
{
ex.printStackTrace();
}
return levelString;
}
/**
* return the level associated with the game
*
* @return the level
*/
public Level getLevel()
{
return level;
}
/**
* animate
*/
public void animate()
{
Location destination = level.getPath().frontItem();
if (destination != level.getCurrentLocation())
{
Point point = getCoordinates(destination);
if (destination.x() == level.getCurrentLocation().x())
{
// animate to point.y();
}
else
{
// animate to point.x();
}
}
}
/**
* get the x and y coordinates of a point on the screen by comparing to a
* location
*
* @param loc
* the location
* @return point the point on the screen
*/
public Point getCoordinates(Location loc)
{
// To do -
// (location.x / size) * width of the level on the screen
// (location.y / size) * height of the level + buffer
// new Point with the above coordinates
return null;
}
/**
* reset the level
*/
public void resetLevelClicked()
{
level.restart();
}
/**
* move to the next level
*/
private void nextClicked()
{
levelList.next();
level = levelList.getCurrent();
}
/**
* move to the previous level
*/
public void previousClicked()
{
levelList.previous();
level = levelList.getCurrent();
}
}