a_maze_ing 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3edd41e7fd24f8fb2506c7db520a388d58caf90b
4
- data.tar.gz: c7680068fae51197596d4fb830b54025b87ffbc2
3
+ metadata.gz: 358455708afc8984eb3c53cd4a2379ff01163ad6
4
+ data.tar.gz: 787780722056a3509e45ac5cdea12ab500048310
5
5
  SHA512:
6
- metadata.gz: 224a956b4532db187001112a262e5d495b0fab5949ed11326472dc7378574a531ebbc35ec4fb922d3ea46837bdd83eb94790d2bf6b906cd1c320b82c01667668
7
- data.tar.gz: 7b4b918cde9ddc697650bef0cc4f08a55d3df9c6ec12f0d7a65c4f6239b2ba550732c0c2437acfb984a46989419cfe05439191654c079425614c6b2ba3052090
6
+ metadata.gz: 051fbc907631bd8fa8320d595347d1fd80e09aab014cb088fdd68073b112043dfc771efe33bfe86b5c5d467641adba2fa5cf456cdaee3dd3d5570d6f19d7f7fc
7
+ data.tar.gz: 3c5570b4297e01c6e05990287235be693cca65bcf14f1b1c895b678ce06e753931c0a3418bed5b6d7e20050ac6b80a36c9cc7abe64db174b69e6044f3e25355b
data/README.md CHANGED
@@ -8,7 +8,9 @@ Classic mode | Multiplayer mode
8
8
 
9
9
  Annoying Friend mode | Time Hunter mode
10
10
  :-------------------------:|:-------------------------:
11
- ![](./images/annoying_friend.jpg?raw=true) | Incomming
11
+ ![](./images/annoying_friend.jpg?raw=true) | Comming soon, I'm working on it
12
+
13
+
12
14
 
13
15
  ## Requirements
14
16
 
@@ -8,21 +8,84 @@ require "observer"
8
8
  module AMazeIng
9
9
  DIMENSION = 700
10
10
  SIDE_BAR = 180
11
-
11
+ PLAYER_COLOR_PRIMARY = Color::GREEN
12
+ PLAYER_COLOR_SECONDARY = Color::AQUA
13
+ PLAYER_COLOR_ANGRY = Color::RED
12
14
  class GameWindow < Window
13
15
  $rows = $cols = 10
14
16
  def initialize(full_screen, game_mode)
15
17
  @game_mode = game_mode
16
- super DIMENSION + SIDE_BAR, DIMENSION, full_screen, 1
18
+ super DIMENSION + SIDE_BAR, DIMENSION, full_screen, 30
17
19
  self.caption = "Maze"
18
20
 
21
+ #---------------------------------------------------------------------------------#
22
+ # create code block (update, player_draw and new_player) for different game mode #
23
+ #---------------------------------------------------------------------------------#
24
+ if @game_mode == 1
25
+ @update_lambda = lambda {
26
+ check_for_finish(@player)
27
+ @player.move
28
+ }
29
+ @player_draw_lambda = lambda {
30
+ @player.draw
31
+ }
32
+ @new_player_lambda = lambda {
33
+ @player = Player.new(1, 0, PLAYER_COLOR_PRIMARY)
34
+ }
35
+ elsif @game_mode == 2
36
+ @update_lambda = lambda {
37
+
38
+ if check_for_finish(@player)
39
+ @infor.player_1_point += 1
40
+ end
41
+ @player.move
42
+ if check_for_finish(@player_2)
43
+ @infor.player_2_point += 1
44
+ end
45
+ @player_2.move
46
+
47
+ }
48
+ @player_draw_lambda = lambda {
49
+ @player.draw
50
+ @player_2.draw
51
+ }
52
+ @new_player_lambda = lambda {
53
+ @player = Player.new(1, 0, PLAYER_COLOR_PRIMARY)
54
+ @player_2 = Player.new(0, 1, PLAYER_COLOR_SECONDARY)
55
+ }
56
+ elsif @game_mode == 3
57
+ @update_lambda = lambda {
58
+
59
+ if check_for_finish(@player)
60
+ @infor.player_1_point += 1
61
+ end
62
+ @player.move
63
+ if check_for_collision(@player, @player_2)
64
+ @infor.player_2_point += 1
65
+ end
66
+ @player_2.move
67
+
68
+ }
69
+ @player_draw_lambda = lambda {
70
+ @player.draw
71
+ @player_2.draw
72
+ }
73
+ @new_player_lambda = lambda {
74
+ @player = Player.new(1, 0, PLAYER_COLOR_PRIMARY)
75
+ @player_2 = Player.new($cols-1, 0, PLAYER_COLOR_ANGRY)
76
+ }
77
+ end
78
+ #-------------------------#
79
+ # end create code block #
80
+ #-------------------------#
81
+
19
82
  new_round
20
83
  if @game_mode == 1
21
84
  @infor = Infor.new
22
85
  elsif @game_mode == 2
23
- @infor = Infor.new(Color::GREEN, Color::AQUA)
86
+ @infor = Infor.new(PLAYER_COLOR_PRIMARY, PLAYER_COLOR_SECONDARY)
24
87
  elsif @game_mode == 3
25
- @infor = Infor.new(Color::GREEN, Color::RED)
88
+ @infor = Infor.new(PLAYER_COLOR_PRIMARY, PLAYER_COLOR_ANGRY)
26
89
  end
27
90
 
28
91
  end
@@ -32,16 +95,7 @@ module AMazeIng
32
95
  $cols += 2
33
96
  @maze = Maze.new
34
97
  @maze.generate_maze
35
- if @game_mode == 1
36
- @player = Player.new(1, 0, Color::GREEN)
37
- elsif @game_mode == 2
38
- @player = Player.new(1, 0, Color::GREEN)
39
- @player_2 = Player.new(0, 1, Color::AQUA)
40
- elsif @game_mode == 3
41
- @player = Player.new(1, 0, Color::GREEN)
42
- @player_2 = Player.new($cols-1, 0, Color::RED)
43
- end
44
-
98
+ @new_player_lambda.call
45
99
  end
46
100
 
47
101
  def draw_target(cell)
@@ -56,7 +110,7 @@ module AMazeIng
56
110
  end
57
111
 
58
112
  def check_for_finish(player)
59
- if player.cell_index_x == $cells[-1].cell_index_x && player.cell_index_y == $cells[-1].cell_index_y
113
+ if player.cell_index_x == $cells[-1].cell_index_x and player.cell_index_y == $cells[-1].cell_index_y
60
114
  new_round
61
115
  @infor.level += 1
62
116
  return true
@@ -76,43 +130,19 @@ module AMazeIng
76
130
  end
77
131
 
78
132
  def update
79
-
80
- if @game_mode == 1
81
- check_for_finish(@player)
82
- @player.move
83
- elsif @game_mode == 2
84
- if check_for_finish(@player)
85
- @infor.player_1_point += 1
86
- end
87
- @player.move
88
- if check_for_finish(@player_2)
89
- @infor.player_2_point += 1
90
- end
91
- @player_2.move
92
- elsif @game_mode == 3
93
- if check_for_finish(@player)
94
- @infor.player_1_point += 1
95
- end
96
- @player.move
97
- if check_for_collision(@player, @player_2)
98
- @infor.player_2_point += 1
99
- end
100
- @player_2.move
101
- end
102
-
133
+ @update_lambda.call
103
134
  @infor.update
104
- end
135
+ end
105
136
 
106
137
  def draw
107
138
  $cells.each do |cell|
108
139
  if cell.visited
109
140
  cell.draw($cell_size, Color::BLUE)
110
141
  else
111
- cell.draw($cell_size, Color::GREEN)
142
+ cell.draw($cell_size, PLAYER_COLOR_PRIMARY)
112
143
  end
113
144
  end
114
- @player.draw
115
- @player_2.draw if @game_mode == 2 or @game_mode == 3
145
+ @player_draw_lambda.call
116
146
  @infor.draw
117
147
  draw_target($cells[-1])
118
148
  end
@@ -171,7 +201,5 @@ module AMazeIng
171
201
  super
172
202
  end
173
203
  end
174
-
175
-
176
204
  end
177
205
  end
@@ -3,8 +3,13 @@ module AMazeIng
3
3
  attr_accessor :level, :player_1_point, :player_2_point
4
4
  def initialize(*player_color)
5
5
  @player_color = player_color
6
+
7
+
8
+ #---------------------------------------------------------------------------------#
9
+ # create code block (initial, update and draw) for different game mode #
10
+ #---------------------------------------------------------------------------------#
6
11
  if @player_color.length == 2
7
- @initial_block = lambda {
12
+ @initial_lambda = lambda {
8
13
  @player_1_color = player_color[0]
9
14
  @player_2_color = player_color[1]
10
15
 
@@ -13,7 +18,7 @@ module AMazeIng
13
18
  @label = 'LEVEL'
14
19
  @label_image = Gosu::Image.from_text @label, 40
15
20
 
16
- @x = center_x(@label_image.width)
21
+ @x = center_by_x(@label_image.width)
17
22
  @y_1 = 210
18
23
  @y_2 = 290
19
24
 
@@ -23,14 +28,14 @@ module AMazeIng
23
28
  @player_1_point_image = Gosu::Image.from_text @player_1_point.to_s, 36
24
29
  @player_2_point_image = Gosu::Image.from_text @player_2_point.to_s, 36
25
30
  }
26
- @update_block = lambda {
31
+ @update_lambda = lambda {
27
32
  @level_image = Gosu::Image.from_text @level.to_s, 36
28
33
  @player_1_point_image = Gosu::Image.from_text @player_1_point.to_s, 36
29
34
  @player_2_point_image = Gosu::Image.from_text @player_2_point.to_s, 36
30
35
  }
31
- @draw_block = lambda {
32
- @label_image.draw(center_x(@label_image.width), 80, 1)
33
- @level_image.draw(center_x(@level_image.width), 130, 1)
36
+ @draw_lambda = lambda {
37
+ @label_image.draw(center_by_x(@label_image.width), 80, 1)
38
+ @level_image.draw(center_by_x(@level_image.width), 130, 1)
34
39
 
35
40
  draw_quad @x, @y_1, @player_1_color,
36
41
  @x+30, @y_1, @player_1_color,
@@ -45,55 +50,38 @@ module AMazeIng
45
50
  @player_1_point_image.draw(@x + 60, @y_1, 1)
46
51
  @player_2_point_image.draw(@x + 60, @y_2, 1)
47
52
  }
48
- end
49
-
50
- if @player_color.length == 0
51
- @initial_block = lambda {
53
+ elsif @player_color.length == 0
54
+ @initial_lambda = lambda {
52
55
  @level = 1
53
56
  @label = 'LEVEL'
54
57
  @label_image = Gosu::Image.from_text @label, 40
55
58
  }
56
- @update_block = lambda {
59
+ @update_lambda = lambda {
57
60
  @level_image = Gosu::Image.from_text @level.to_s, 36
58
61
  }
59
- @draw_block = lambda {
60
- @label_image.draw(center_x(@label_image.width), 80, 1)
61
- @level_image.draw(center_x(@level_image.width), 130, 1)
62
+ @draw_lambda = lambda {
63
+ @label_image.draw(center_by_x(@label_image.width), 80, 1)
64
+ @level_image.draw(center_by_x(@level_image.width), 130, 1)
62
65
  }
63
66
  end
64
- @initial_block.call
67
+ #-------------------------#
68
+ # end create code block #
69
+ #-------------------------#
70
+
71
+
72
+ @initial_lambda.call
65
73
  end
66
74
 
67
- def center_x(width)
75
+ def center_by_x(width)
68
76
  return $dimension + SIDE_BAR/2 - width/2
69
77
  end
70
78
 
71
79
  def update
72
- @update_block.call
73
- # @level_image = Gosu::Image.from_text @level.to_s, 36
74
- # @player_1_point_image = Gosu::Image.from_text @player_1_point.to_s, 36
75
- # @player_2_point_image = Gosu::Image.from_text @player_2_point.to_s, 36
80
+ @update_lambda.call
76
81
  end
77
82
 
78
83
  def draw
79
- @draw_block.call
80
- # @label_image.draw(center_x(@label_image.width), 80, 1)
81
- # @level_image.draw(center_x(@level_image.width), 130, 1)
82
-
83
- # draw_quad @x, @y_1, @player_1_color,
84
- # @x+30, @y_1, @player_1_color,
85
- # @x+30, @y_1+30, @player_1_color,
86
- # @x, @y_1+30, @player_1_color
87
-
88
- # draw_quad @x, @y_2, @player_2_color,
89
- # @x+30, @y_2, @player_2_color,
90
- # @x+30, @y_2+30, @player_2_color,
91
- # @x, @y_2+30, @player_2_color
92
-
93
- # @player_1_point_image.draw(@x + 60, @y_1, 1)
94
- # @player_1_point_image.draw(@x + 60, @y_2, 1)
95
-
96
-
84
+ @draw_lambda.call
97
85
  end
98
86
  end
99
87
  end
@@ -1,3 +1,3 @@
1
1
  module AMazeIng
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: a_maze_ing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - at-cuongtran