Class: GamesParadise::GUI::Memory::PlayGame
- Inherits:
-
Base
- Object
- Base
- GamesParadise::GUI::Memory::PlayGame
show all
- Includes:
- Memory
- Defined in:
- lib/games_paradise/gui/gosu/memory/play_game.rb
Constant Summary
collapse
- GOSU_USE_THIS_FONT =
Gosu::Font.new(20, {name: USE_THIS_FONT_FAMILY})
- USE_N_CARDS =
#
USE_N_CARDS
You can specify how many cards are to be used here, by default.
#
24
- POSITION =
#
POSITION
This hash will store the positions of the cards in use.
#
{
0 => [ 2, 2, 1],
1 => [ 69, 2, 1],
2 => [136, 2, 1],
3 => [203, 2, 1],
4 => [270, 2, 1],
5 => [ 2, 69, 1],
6 => [ 69, 69, 1],
7 => [136, 69, 1],
8 => [203, 69, 1],
9 => [270, 69, 1],
10 => [ 2, 136, 1],
11 => [ 69, 136, 1],
12 => [136, 136, 1],
13 => [203, 136, 1],
14 => [270, 136, 1],
15 => [ 2, 203, 1],
16 => [ 69, 203, 1],
17 => [136, 203, 1],
18 => [203, 203, 1],
19 => [270, 203, 1]
}
Constants included
from Memory
Memory::ARRAY_IMAGES_FOR_THE_MEMORY_GAME, Memory::FILE_BLACK_BACKGROUND, Memory::FILE_CAMEL_HEAD, Memory::FILE_CARD_RANDOM, Memory::FILE_DONKEY, Memory::FILE_FROG, Memory::FILE_LION, Memory::FILE_NEW_GAME, Memory::FILE_OCTOPUS, Memory::FILE_SAD_CRAB, Memory::FILE_SHEEP, Memory::FILE_SNAIL, Memory::FILE_SPERM_WHALE, Memory::FILE_UNICORN, Memory::GAME_MESSAGE_YOU_WON, Memory::IMAGES_DIRECTORY, Memory::SCREENHEIGHT, Memory::SCREENWIDTH, Memory::TITLE, Memory::USE_THIS_FONT_FAMILY
Constants inherited
from Base
Base::CONTROL_C_CODE, Base::N
Instance Method Summary
collapse
Methods inherited from Base
#cat, #commandline_arguments?, #efancy, #eparse, #first_argument?, #forestgreen, #gold, #lightblue, #lightgreen, #mediumorchid, #mediumslateblue, #opnn, #peru, #register_sigint, #rev, #royalblue, #set_commandline_arguments, #sfile, #steelblue, #teal, #tomato, #yellow
Methods included from BaseModule
#cliner, #commandline_arguments?, #first_argument?, #infer_the_namespace, #namespace?, #rename_file, #reset_the_internal_hash, #return_pwd, #set_commandline_arguments
Constructor Details
#initialize(commandline_arguments = ARGV, run_already = true) ⇒ PlayGame
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/games_paradise/gui/gosu/memory/play_game.rb', line 98
def initialize(
commandline_arguments = ARGV,
run_already = true
)
reset
set_commandline_arguments(
commandline_arguments
)
run if run_already
end
|
Instance Method Details
192
193
|
# File 'lib/games_paradise/gui/gosu/memory/play_game.rb', line 192
def button_down(id)
end
|
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
# File 'lib/games_paradise/gui/gosu/memory/play_game.rb', line 198
def button_up(id)
case id
when Gosu::MsLeft game_instance = game_instance?
POSITION.each { |k, arr|
if game_instance.mouse_x > arr[0] &&
game_instance.mouse_x < arr[0]+64 &&
game_instance.mouse_y > arr[1] &&
game_instance.mouse_y < arr[1]+64 &&
!@cards[k].nil? &&
(@last_clicked_card != k)
@last_clicked_card = k if @last_clicked_card
@click += 1
if @click.odd?
@first_card_opened = k
else
@second_card_opened = k
end
end
}
if @first_card_opened &&
@second_card_opened &&
@click.even? &&
(@cards[@first_card_opened] == @cards[@second_card_opened]) &&
(@first_card_opened != @second_card_opened)
@cards[@first_card_opened] = nil
@cards[@second_card_opened] = nil
@first_card_opened = nil
@second_card_opened = nil
end
if game_ended
::GamesParadise::GUI::Memory.current_game = GameEnded.new(game_instance)
end
end
end
|
#do_draw_the_current_time(i = @current_time) ⇒ Object
#
do_draw_the_current_time
#
155
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/games_paradise/gui/gosu/memory/play_game.rb', line 155
def do_draw_the_current_time(
i = @current_time
)
@font.draw_text(
i, 395, 30, 1, 1, 1,
::Gosu::COLOUR_GOLD
) end
|
#draw ⇒ Object
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
# File 'lib/games_paradise/gui/gosu/memory/play_game.rb', line 170
def draw
do_draw_the_current_time
@use_n_cards.times { |entry|
if !@cards[entry]
next
elsif (@second_card_opened == entry) && @click.even?
@cards[@second_card_opened].draw(*POSITION[@second_card_opened])
elsif @first_card_opened == entry
@cards[@first_card_opened].draw(*POSITION[@first_card_opened])
else
@card_back.draw(*POSITION[entry])
end
}
end
|
#game_ended ⇒ Object
246
247
248
249
250
251
252
253
|
# File 'lib/games_paradise/gui/gosu/memory/play_game.rb', line 246
def game_ended
if @cards[0..19] == Array.new(20)
if game_instance?.best_time > @current_time
game_instance?.best_time = @current_time
end
return true
end
end
|
#game_instance? ⇒ Boolean
258
259
260
|
# File 'lib/games_paradise/gui/gosu/memory/play_game.rb', line 258
def game_instance?
$w
end
|
#load_cards ⇒ Object
#
load_cards
This will fill up the pool of available cards.
#
293
294
295
296
297
298
299
300
301
|
# File 'lib/games_paradise/gui/gosu/memory/play_game.rb', line 293
def load_cards
_ = ::GamesParadise::GUI::Memory.available_images?
2.times {
1.upto(10) { |i|
@cards << _[i]
}
}
@cards.shuffle! end
|
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
# File 'lib/games_paradise/gui/gosu/memory/play_game.rb', line 265
def (
i = @commandline_arguments
)
if i.is_a? Array
i.each {|entry| (entry) }
else
case i
when /^-?-?ncards=(\d+)/i
set_n_cards($1)
end
end
end
|
#reset ⇒ Object
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
|
# File 'lib/games_paradise/gui/gosu/memory/play_game.rb', line 112
def reset
@font = GOSU_USE_THIS_FONT
@use_n_cards = USE_N_CARDS
@cards = []
@current_time = 0
@click = 0
@start_time = Gosu.milliseconds/1000
@last_clicked_card = nil
@first_card_opened = nil
@second_card_opened = nil
@card_back = ::GamesParadise::GUI::Memory.available_images?['card_back']
end
|
#run ⇒ Object
306
307
308
309
|
# File 'lib/games_paradise/gui/gosu/memory/play_game.rb', line 306
def run
load_cards
end
|
#set_n_cards(i) ⇒ Object
284
285
286
|
# File 'lib/games_paradise/gui/gosu/memory/play_game.rb', line 284
def set_n_cards(i)
@use_n_cards = i.to_i
end
|
#update ⇒ Object
#
update (update tag)
The current time will be re-calculated whenever update() is called.
#
239
240
241
|
# File 'lib/games_paradise/gui/gosu/memory/play_game.rb', line 239
def update
@current_time = (Gosu.milliseconds / 1000) - @start_time
end
|