-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_state.ml
139 lines (123 loc) · 4.92 KB
/
test_state.ml
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
open OUnit2
open State
open Types
let lst_to_tuple lst =
if List.length lst = 2 then
(float (List.nth lst 0), float (List.nth lst 1))
else raise (Failure "invalid lst to tuple")
let initial_player = {
id = 0;
name = Player;
action = Stand;
size = (15., 15.);
speed = 5.;
location = {coordinate = (160., 160.); room = "start"};
health = (100., 100.);
kill_count = 0;
direction = South;
moves = [{id = "sword"; unlocked = true; frame = 5}];
moving = false;
params = {
img = "sprites/spritesheet.png";
frame_size = (15., 16.);
offset = (0., 0.);
};
counter = 0;
max_count = 10;
frame_count = 1;
max_frame = 1;
image = "sprites/spritesheet.png";
has_won = false;
}
let init_enemy1 = {
id = 1;
name = Enemy Blind;
action = Stand;
size = (15., 15.);
speed = 1.;
location = {coordinate = (160., 140.); room = "start"};
health = (1., 1.);
kill_count = 0;
direction = North;
moves = [{id = "sword"; unlocked = false; frame = 5}];
moving = false;
params = {
img = "sprites/enemysprites.png";
frame_size= (12.,16.);
offset = (133., 91.);
};
counter = 0;
max_count = 0;
frame_count = 0;
max_frame = 1;
image = "sprites/enemysprites.png";
has_won = false;
}
let initial_state = {
all_sprites = [initial_player; init_enemy1;];
attack = (0.0,0.0), {coordinate = (0., 0.); room = "NONE"};
has_won = false;
all_rooms =
[{room_id = "start"; width = 8.; height = 5.;
obj_lst =
[Portal { location = {coordinate = ( 26. *. 7., 7.*. 26.) ; room = "start"};
teleport_to = {coordinate = ( 26. *. 2., 6.*. 26.) ; room = "next"}};
Obstacle {coordinate = ( 26. *. 4., 3.*. 26.) ; room = "start"};
Obstacle {coordinate = ( 26. *. 4., 4.*. 26.) ; room = "start"};
Obstacle {coordinate = ( 26. *. 4., 5.*. 26.) ; room = "start"};
Obstacle {coordinate = ( 26. *. 4., 6.*. 26.) ; room = "start"};
Obstacle {coordinate = ( 26. *. 4., 7.*. 26.) ; room = "start"};
]};
{room_id = "next"; width = 6.; height = 6.;
obj_lst =
[ Texture {coordinate = ( 26. *. 5., 0.*. 26.) ; room = "next"};
Texture {coordinate = ( 26. *. 5., 1.*. 26.) ; room = "next"};
Texture {coordinate = ( 26. *. 5., 2.*. 26.) ; room = "next"};
Texture {coordinate = ( 26. *. 5., 3.*. 26.) ; room = "next"};
Texture {coordinate = ( 26. *. 5., 4.*. 26.) ; room = "next"};
Texture {coordinate = ( 26. *. 5., 5.*. 26.) ; room = "next"};
Portal { location = {coordinate = ( 26. *. 2., 5.*. 26.) ; room = "next"};
teleport_to = {coordinate = ( 26. *. 7., 6.*. 26.) ; room = "start"}};
End {coordinate = ( 26. *. 5., 6.*. 26.) ; room = "next"};
Obstacle {coordinate = ( 26. *. 3., 1.*. 26.) ; room = "next"}
]}
];
current_room_id = "start"}
let r1 = {room_id = "start"; width = 8.; height = 5.;
obj_lst =
[Portal { location = {coordinate = ( 26. *. 7., 7.*. 26.) ; room = "start"};
teleport_to = {coordinate = ( 26. *. 2., 6.*. 26.) ; room = "next"}};
Obstacle {coordinate = ( 26. *. 4., 3.*. 26.) ; room = "start"};
Obstacle {coordinate = ( 26. *. 4., 4.*. 26.) ; room = "start"};
Obstacle {coordinate = ( 26. *. 4., 5.*. 26.) ; room = "start"};
Obstacle {coordinate = ( 26. *. 4., 6.*. 26.) ; room = "start"};
Obstacle {coordinate = ( 26. *. 4., 7.*. 26.) ; room = "start"};
]}
let r2 = {room_id = "next"; width = 6.; height = 6.;
obj_lst =
[ Texture {coordinate = ( 26. *. 5., 0.*. 26.) ; room = "next"};
Texture {coordinate = ( 26. *. 5., 1.*. 26.) ; room = "next"};
Texture {coordinate = ( 26. *. 5., 2.*. 26.) ; room = "next"};
Texture {coordinate = ( 26. *. 5., 3.*. 26.) ; room = "next"};
Texture {coordinate = ( 26. *. 5., 4.*. 26.) ; room = "next"};
Texture {coordinate = ( 26. *. 5., 5.*. 26.) ; room = "next"};
Portal { location = {coordinate = ( 26. *. 2., 5.*. 26.) ; room = "next"};
teleport_to = {coordinate = ( 26. *. 7., 6.*. 26.) ; room = "start"}};
End {coordinate = ( 26. *. 5., 6.*. 26.) ; room = "next"};
Obstacle {coordinate = ( 26. *. 3., 1.*. 26.) ; room = "next"}
]}
let st = initial_state
let check_spriteid st =
st.id
let tests =
[
"not_win" >:: (fun _ -> assert_equal false st.has_won);
"correct_sprites" >:: (fun _ -> assert_equal [initial_player; init_enemy1]
st.all_sprites);
"correct_start_room" >:: (fun _ -> assert_equal "start" st.current_room_id);
"all_rooms" >:: (fun _ -> assert_equal [r1; r2] st.all_rooms);
]
let suite =
"Legend test suite"
>::: tests
let _ = run_test_tt_main suite