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
|
# File 'lib/a_maze_ing/game_window.rb', line 28
def initialize(full_screen, game_mode)
@game_mode = game_mode
super DIMENSION + SIDE_BAR, DIMENSION, full_screen, 30
self.caption = "Maze"
if @game_mode == 1
@update_lambda = lambda {
check_for_finish(@player)
@player.move
}
@player_draw_lambda = lambda {
@player.draw
}
@new_player_lambda = lambda {
@player = Player.new(1, 0, PLAYER_COLOR_PRIMARY)
}
elsif @game_mode == 2
@update_lambda = lambda {
if check_for_finish(@player)
@infor.player_1_point += 1
end
@player.move
if check_for_finish(@player_2)
@infor.player_2_point += 1
end
@player_2.move
}
@player_draw_lambda = lambda {
@player.draw
@player_2.draw
}
@new_player_lambda = lambda {
@player = Player.new(1, 0, PLAYER_COLOR_PRIMARY)
@player_2 = Player.new(0, 1, PLAYER_COLOR_SECONDARY)
}
elsif @game_mode == 3
@update_lambda = lambda {
if check_for_finish(@player)
@infor.player_1_point += 1
end
@player.move
if check_for_collision(@player, @player_2)
@infor.player_2_point += 1
end
@player_2.move
}
@player_draw_lambda = lambda {
@player.draw
@player_2.draw
}
@new_player_lambda = lambda {
@player = Player.new(1, 0, PLAYER_COLOR_PRIMARY)
@player_2 = Player.new($cols-1, 0, PLAYER_COLOR_ANGRY)
}
end
new_round
if @game_mode == 1
@infor = Infor.new
elsif @game_mode == 2
@infor = Infor.new(PLAYER_COLOR_PRIMARY, PLAYER_COLOR_SECONDARY)
elsif @game_mode == 3
@infor = Infor.new(PLAYER_COLOR_PRIMARY, PLAYER_COLOR_ANGRY)
end
end
|