UG_RRobots 2.0 → 2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +20 -4
- data/bin/rrobots +48 -17
- data/config/locales/en.yml +4 -2
- data/config/locales/fr.yml +3 -1
- data/doc/install.rdoc +20 -20
- data/doc/install_fr.rdoc +20 -20
- data/lib/GUI/gosu.rb +237 -0
- data/lib/GUI/tk.rb +215 -0
- data/lib/battlefield.rb +2 -0
- data/lib/mines.rb +36 -0
- data/lib/misc.rb +7 -4
- data/lib/robotrunner.rb +4 -0
- data/medias/gosu/images/blue_body000.bmp +0 -0
- data/medias/gosu/images/blue_radar000.bmp +0 -0
- data/medias/gosu/images/blue_turret000.bmp +0 -0
- data/medias/gosu/images/bullet.png +0 -0
- data/medias/gosu/images/explosion00.bmp +0 -0
- data/medias/gosu/images/explosion01.bmp +0 -0
- data/medias/gosu/images/explosion02.bmp +0 -0
- data/medias/gosu/images/explosion03.bmp +0 -0
- data/medias/gosu/images/explosion04.bmp +0 -0
- data/medias/gosu/images/explosion05.bmp +0 -0
- data/medias/gosu/images/explosion06.bmp +0 -0
- data/medias/gosu/images/explosion07.bmp +0 -0
- data/medias/gosu/images/explosion08.bmp +0 -0
- data/medias/gosu/images/explosion09.bmp +0 -0
- data/medias/gosu/images/explosion10.bmp +0 -0
- data/medias/gosu/images/explosion11.bmp +0 -0
- data/medias/gosu/images/explosion12.bmp +0 -0
- data/medias/gosu/images/explosion13.bmp +0 -0
- data/medias/gosu/images/explosion14.bmp +0 -0
- data/medias/gosu/images/lime_body000.bmp +0 -0
- data/medias/gosu/images/lime_radar000.bmp +0 -0
- data/medias/gosu/images/lime_turret000.bmp +0 -0
- data/medias/gosu/images/mine.png +0 -0
- data/medias/gosu/images/red_body000.bmp +0 -0
- data/medias/gosu/images/red_radar000.bmp +0 -0
- data/medias/gosu/images/red_turret000.bmp +0 -0
- data/medias/gosu/images/space.png +0 -0
- data/medias/gosu/images/toolbox.png +0 -0
- data/medias/gosu/images/white_body000.bmp +0 -0
- data/medias/gosu/images/white_radar000.bmp +0 -0
- data/medias/gosu/images/white_turret000.bmp +0 -0
- data/medias/gosu/images/yellow_body000.bmp +0 -0
- data/medias/gosu/images/yellow_radar000.bmp +0 -0
- data/medias/gosu/images/yellow_turret000.bmp +0 -0
- data/medias/gosu/music/song.mod +0 -0
- data/medias/gosu/sounds/shotborn.wav +0 -0
- data/medias/gosu/sounds/sunexp.wav +0 -0
- data/{images → medias/tk/images}/explosion00.gif +0 -0
- data/{images → medias/tk/images}/explosion01.gif +0 -0
- data/{images → medias/tk/images}/explosion02.gif +0 -0
- data/{images → medias/tk/images}/explosion03.gif +0 -0
- data/{images → medias/tk/images}/explosion04.gif +0 -0
- data/{images → medias/tk/images}/explosion05.gif +0 -0
- data/{images → medias/tk/images}/explosion06.gif +0 -0
- data/{images → medias/tk/images}/explosion07.gif +0 -0
- data/{images → medias/tk/images}/explosion08.gif +0 -0
- data/{images → medias/tk/images}/explosion09.gif +0 -0
- data/{images → medias/tk/images}/explosion10.gif +0 -0
- data/{images → medias/tk/images}/explosion11.gif +0 -0
- data/{images → medias/tk/images}/explosion12.gif +0 -0
- data/{images → medias/tk/images}/explosion13.gif +0 -0
- data/{images → medias/tk/images}/explosion14.gif +0 -0
- data/medias/tk/images/mine.gif +0 -0
- data/{images → medias/tk/images}/red_body000.gif +0 -0
- data/{images → medias/tk/images}/red_body010.gif +0 -0
- data/{images → medias/tk/images}/red_body020.gif +0 -0
- data/{images → medias/tk/images}/red_body030.gif +0 -0
- data/{images → medias/tk/images}/red_body040.gif +0 -0
- data/{images → medias/tk/images}/red_body050.gif +0 -0
- data/{images → medias/tk/images}/red_body060.gif +0 -0
- data/{images → medias/tk/images}/red_body070.gif +0 -0
- data/{images → medias/tk/images}/red_body080.gif +0 -0
- data/{images → medias/tk/images}/red_body090.gif +0 -0
- data/{images → medias/tk/images}/red_body100.gif +0 -0
- data/{images → medias/tk/images}/red_body110.gif +0 -0
- data/{images → medias/tk/images}/red_body120.gif +0 -0
- data/{images → medias/tk/images}/red_body130.gif +0 -0
- data/{images → medias/tk/images}/red_body140.gif +0 -0
- data/{images → medias/tk/images}/red_body150.gif +0 -0
- data/{images → medias/tk/images}/red_body160.gif +0 -0
- data/{images → medias/tk/images}/red_body170.gif +0 -0
- data/{images → medias/tk/images}/red_body180.gif +0 -0
- data/{images → medias/tk/images}/red_body190.gif +0 -0
- data/{images → medias/tk/images}/red_body200.gif +0 -0
- data/{images → medias/tk/images}/red_body210.gif +0 -0
- data/{images → medias/tk/images}/red_body220.gif +0 -0
- data/{images → medias/tk/images}/red_body230.gif +0 -0
- data/{images → medias/tk/images}/red_body240.gif +0 -0
- data/{images → medias/tk/images}/red_body250.gif +0 -0
- data/{images → medias/tk/images}/red_body260.gif +0 -0
- data/{images → medias/tk/images}/red_body270.gif +0 -0
- data/{images → medias/tk/images}/red_body280.gif +0 -0
- data/{images → medias/tk/images}/red_body290.gif +0 -0
- data/{images → medias/tk/images}/red_body300.gif +0 -0
- data/{images → medias/tk/images}/red_body310.gif +0 -0
- data/{images → medias/tk/images}/red_body320.gif +0 -0
- data/{images → medias/tk/images}/red_body330.gif +0 -0
- data/{images → medias/tk/images}/red_body340.gif +0 -0
- data/{images → medias/tk/images}/red_body350.gif +0 -0
- data/{images → medias/tk/images}/red_radar000.gif +0 -0
- data/{images → medias/tk/images}/red_radar010.gif +0 -0
- data/{images → medias/tk/images}/red_radar020.gif +0 -0
- data/{images → medias/tk/images}/red_radar030.gif +0 -0
- data/{images → medias/tk/images}/red_radar040.gif +0 -0
- data/{images → medias/tk/images}/red_radar050.gif +0 -0
- data/{images → medias/tk/images}/red_radar060.gif +0 -0
- data/{images → medias/tk/images}/red_radar070.gif +0 -0
- data/{images → medias/tk/images}/red_radar080.gif +0 -0
- data/{images → medias/tk/images}/red_radar090.gif +0 -0
- data/{images → medias/tk/images}/red_radar100.gif +0 -0
- data/{images → medias/tk/images}/red_radar110.gif +0 -0
- data/{images → medias/tk/images}/red_radar120.gif +0 -0
- data/{images → medias/tk/images}/red_radar130.gif +0 -0
- data/{images → medias/tk/images}/red_radar140.gif +0 -0
- data/{images → medias/tk/images}/red_radar150.gif +0 -0
- data/{images → medias/tk/images}/red_radar160.gif +0 -0
- data/{images → medias/tk/images}/red_radar170.gif +0 -0
- data/{images → medias/tk/images}/red_radar180.gif +0 -0
- data/{images → medias/tk/images}/red_radar190.gif +0 -0
- data/{images → medias/tk/images}/red_radar200.gif +0 -0
- data/{images → medias/tk/images}/red_radar210.gif +0 -0
- data/{images → medias/tk/images}/red_radar220.gif +0 -0
- data/{images → medias/tk/images}/red_radar230.gif +0 -0
- data/{images → medias/tk/images}/red_radar240.gif +0 -0
- data/{images → medias/tk/images}/red_radar250.gif +0 -0
- data/{images → medias/tk/images}/red_radar260.gif +0 -0
- data/{images → medias/tk/images}/red_radar270.gif +0 -0
- data/{images → medias/tk/images}/red_radar280.gif +0 -0
- data/{images → medias/tk/images}/red_radar290.gif +0 -0
- data/{images → medias/tk/images}/red_radar300.gif +0 -0
- data/{images → medias/tk/images}/red_radar310.gif +0 -0
- data/{images → medias/tk/images}/red_radar320.gif +0 -0
- data/{images → medias/tk/images}/red_radar330.gif +0 -0
- data/{images → medias/tk/images}/red_radar340.gif +0 -0
- data/{images → medias/tk/images}/red_radar350.gif +0 -0
- data/{images → medias/tk/images}/red_turret000.gif +0 -0
- data/{images → medias/tk/images}/red_turret010.gif +0 -0
- data/{images → medias/tk/images}/red_turret020.gif +0 -0
- data/{images → medias/tk/images}/red_turret030.gif +0 -0
- data/{images → medias/tk/images}/red_turret040.gif +0 -0
- data/{images → medias/tk/images}/red_turret050.gif +0 -0
- data/{images → medias/tk/images}/red_turret060.gif +0 -0
- data/{images → medias/tk/images}/red_turret070.gif +0 -0
- data/{images → medias/tk/images}/red_turret080.gif +0 -0
- data/{images → medias/tk/images}/red_turret090.gif +0 -0
- data/{images → medias/tk/images}/red_turret100.gif +0 -0
- data/{images → medias/tk/images}/red_turret110.gif +0 -0
- data/{images → medias/tk/images}/red_turret120.gif +0 -0
- data/{images → medias/tk/images}/red_turret130.gif +0 -0
- data/{images → medias/tk/images}/red_turret140.gif +0 -0
- data/{images → medias/tk/images}/red_turret150.gif +0 -0
- data/{images → medias/tk/images}/red_turret160.gif +0 -0
- data/{images → medias/tk/images}/red_turret170.gif +0 -0
- data/{images → medias/tk/images}/red_turret180.gif +0 -0
- data/{images → medias/tk/images}/red_turret190.gif +0 -0
- data/{images → medias/tk/images}/red_turret200.gif +0 -0
- data/{images → medias/tk/images}/red_turret210.gif +0 -0
- data/{images → medias/tk/images}/red_turret220.gif +0 -0
- data/{images → medias/tk/images}/red_turret230.gif +0 -0
- data/{images → medias/tk/images}/red_turret240.gif +0 -0
- data/{images → medias/tk/images}/red_turret250.gif +0 -0
- data/{images → medias/tk/images}/red_turret260.gif +0 -0
- data/{images → medias/tk/images}/red_turret270.gif +0 -0
- data/{images → medias/tk/images}/red_turret280.gif +0 -0
- data/{images → medias/tk/images}/red_turret290.gif +0 -0
- data/{images → medias/tk/images}/red_turret300.gif +0 -0
- data/{images → medias/tk/images}/red_turret310.gif +0 -0
- data/{images → medias/tk/images}/red_turret320.gif +0 -0
- data/{images → medias/tk/images}/red_turret330.gif +0 -0
- data/{images → medias/tk/images}/red_turret340.gif +0 -0
- data/{images → medias/tk/images}/red_turret350.gif +0 -0
- data/{images → medias/tk/images}/toolbox.gif +0 -0
- metadata +168 -128
- data/lib/tkarena.rb +0 -194
data/lib/GUI/tk.rb
ADDED
@@ -0,0 +1,215 @@
|
|
1
|
+
require 'tk'
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
def load_gui(battlefield, xres, yres, speed_multiplier)
|
5
|
+
arena = GUI::TkArena.new(battlefield, xres, yres, speed_multiplier)
|
6
|
+
game_over_counter = battlefield.teams.all?{|k,t| t.size < 2} ? 250 : 500
|
7
|
+
outcome_printed = false
|
8
|
+
arena.on_game_over{|battlefield|
|
9
|
+
unless outcome_printed
|
10
|
+
print_outcome(battlefield)
|
11
|
+
outcome_printed = true
|
12
|
+
end
|
13
|
+
exit 0 if game_over_counter < 0
|
14
|
+
game_over_counter -= 1
|
15
|
+
}
|
16
|
+
arena.run
|
17
|
+
end
|
18
|
+
|
19
|
+
module GUI
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
TkRobot = Struct.new(:body, :gun, :radar, :speech, :info, :status)
|
24
|
+
|
25
|
+
class TkArena
|
26
|
+
|
27
|
+
|
28
|
+
attr_reader :engine
|
29
|
+
attr_reader :battlefield, :xres, :yres
|
30
|
+
attr_accessor :speed_multiplier, :on_game_over_handlers
|
31
|
+
attr_accessor :canvas, :boom, :robots, :bullets, :explosions, :colors, :toolboxes, :toolbox_img, :mines, :mine_img
|
32
|
+
attr_accessor :default_skin_prefix, :path_prefix
|
33
|
+
|
34
|
+
def initialize battlefield, xres, yres, speed_multiplier
|
35
|
+
@engine = 'tk'
|
36
|
+
@battlefield = battlefield
|
37
|
+
@xres, @yres = xres, yres
|
38
|
+
@speed_multiplier = speed_multiplier
|
39
|
+
@text_colors = ['#ff0000', '#00ff00', '#0000ff', '#ffff00', '#00ffff', '#ff00ff', '#ffffff', '#777777']
|
40
|
+
@path_prefix = "#{gem_path}/medias/#{@engine}"
|
41
|
+
@default_skin_prefix = "images/red_"
|
42
|
+
@on_game_over_handlers = []
|
43
|
+
init_canvas
|
44
|
+
init_simulation
|
45
|
+
end
|
46
|
+
|
47
|
+
def on_game_over(&block)
|
48
|
+
@on_game_over_handlers << block
|
49
|
+
end
|
50
|
+
|
51
|
+
def read_gif name, c1, c2, c3
|
52
|
+
data = nil
|
53
|
+
open(name, 'rb') do |f|
|
54
|
+
data = f.read()
|
55
|
+
ncolors = 2**(1 + data[10][0] + data[10][1] * 2 + data[10][2] * 4)
|
56
|
+
ncolors.times do |j|
|
57
|
+
data[13 + j * 3 + 0], data[13 + j * 3 + 1], data[13 + j * 3 + 2] =
|
58
|
+
data[13 + j * 3 + c1], data[13 + j * 3 + c2], data[13 + j * 3 + c3]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
TkPhotoImage.new(:data => Base64.encode64(data))
|
62
|
+
end
|
63
|
+
|
64
|
+
def init_canvas
|
65
|
+
@canvas = TkCanvas.new(:height=>yres, :width=>xres, :scrollregion=>[0, 0, xres, yres], :background => '#000000').pack
|
66
|
+
@colors = []
|
67
|
+
[[0,1,1],[1,0,1],[1,1,0],[0,0,1],[1,0,0],[0,1,0],[0,0,0],[1,1,1]][0...@battlefield.robots.length].zip(@battlefield.robots) do |color, robot|
|
68
|
+
bodies, guns, radars = [], [], []
|
69
|
+
image_path = robot.skin_prefix || @default_skin_prefix
|
70
|
+
image_path = "#{@path_prefix}/#{image_path}"
|
71
|
+
reader = robot.skin_prefix ? lambda{|fn| TkPhotoImage.new(:file => fn) } : lambda{|fn| read_gif(fn, *color)}
|
72
|
+
36.times do |i|
|
73
|
+
bodies << reader["#{image_path}body#{(i*10).to_s.rjust(3, '0')}.gif"]
|
74
|
+
guns << reader["#{image_path}turret#{(i*10).to_s.rjust(3, '0')}.gif"]
|
75
|
+
radars << reader["#{image_path}radar#{(i*10).to_s.rjust(3, '0')}.gif"]
|
76
|
+
end
|
77
|
+
@colors << GUI::TkRobot.new(bodies << bodies[0], guns << guns[0], radars << radars[0])
|
78
|
+
end
|
79
|
+
|
80
|
+
@boom = (0..14).map do |i|
|
81
|
+
TkPhotoImage.new(:file => "#{path_prefix}/images/explosion#{i.to_s.rjust(2, '0')}.gif")
|
82
|
+
end
|
83
|
+
@toolbox_img = TkPhotoImage.new(:file => "#{path_prefix}/images/toolbox.gif")
|
84
|
+
@mine_img = TkPhotoImage.new(:file => "#{path_prefix}/images/mine.gif")
|
85
|
+
end
|
86
|
+
|
87
|
+
def init_simulation
|
88
|
+
@robots, @bullets, @explosions, @toolboxes, @mines = {}, {}, {}, {}, {}
|
89
|
+
TkTimer.new(20, -1, Proc.new{
|
90
|
+
begin
|
91
|
+
draw_frame
|
92
|
+
rescue => err
|
93
|
+
puts err.class, err, err.backtrace
|
94
|
+
raise
|
95
|
+
end
|
96
|
+
}).start
|
97
|
+
end
|
98
|
+
|
99
|
+
def draw_frame
|
100
|
+
simulate(@speed_multiplier)
|
101
|
+
draw_battlefield
|
102
|
+
end
|
103
|
+
|
104
|
+
def simulate(ticks=1)
|
105
|
+
@explosions.reject!{|e,tko| @canvas.delete(tko) if e.dead; e.dead }
|
106
|
+
@bullets.reject!{|b,tko| @canvas.delete(tko) if b.dead; b.dead }
|
107
|
+
@toolboxes.reject!{|t,tko| @canvas.delete(tko) if t.dead; t.dead }
|
108
|
+
@mines.reject!{|m,tko| @canvas.delete(tko) if m.dead; m.dead }
|
109
|
+
@robots.reject! do |ai,tko|
|
110
|
+
if ai.dead
|
111
|
+
tko.status.configure(:text => I18n.t('gui.ai_name_dead', :ai_name => ai.name.ljust(20)))
|
112
|
+
tko.each{|part| @canvas.delete(part) if part != tko.status}
|
113
|
+
true
|
114
|
+
end
|
115
|
+
end
|
116
|
+
ticks.times do
|
117
|
+
if @battlefield.game_over
|
118
|
+
@on_game_over_handlers.each{|h| h.call(@battlefield) }
|
119
|
+
unless @game_over
|
120
|
+
winner = @robots.keys.first
|
121
|
+
whohaswon = if winner.nil?
|
122
|
+
I18n.t('gui.draw')
|
123
|
+
elsif @battlefield.teams.all?{|k,t|t.size<2}
|
124
|
+
I18n.t('gui.no_team_won', :winner_name => winner.name)
|
125
|
+
else
|
126
|
+
I18n.t('gui.team_won', :winner_team => winner.team)
|
127
|
+
end
|
128
|
+
text_color = winner ? winner.team : 7
|
129
|
+
@game_over = TkcText.new(canvas,
|
130
|
+
:fill => @text_colors[text_color],
|
131
|
+
:anchor => 'c', :coords => [400,400], :font=>'courier 36', :justify => 'center',
|
132
|
+
:text => I18n.t('gui.game_over').concat("\n#{whohaswon}"))
|
133
|
+
end
|
134
|
+
end
|
135
|
+
@battlefield.tick
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def draw_battlefield
|
140
|
+
draw_toolboxes
|
141
|
+
draw_mines
|
142
|
+
draw_robots
|
143
|
+
draw_bullets
|
144
|
+
draw_explosions
|
145
|
+
end
|
146
|
+
|
147
|
+
def draw_robots
|
148
|
+
@battlefield.robots.each_with_index do |ai, i|
|
149
|
+
next if ai.dead
|
150
|
+
@robots[ai] ||= GUI::TkRobot.new(
|
151
|
+
TkcImage.new(@canvas, 0, 0),
|
152
|
+
TkcImage.new(@canvas, 0, 0),
|
153
|
+
TkcImage.new(@canvas, 0, 0),
|
154
|
+
TkcText.new(@canvas,
|
155
|
+
:fill => @text_colors[ai.team],
|
156
|
+
:anchor => 's', :justify => 'center', :coords => [ai.x / 2, ai.y / 2 - ai.size / 2]),
|
157
|
+
TkcText.new(@canvas,
|
158
|
+
:fill => @text_colors[ai.team],
|
159
|
+
:anchor => 'n', :justify => 'center', :coords => [ai.x / 2, ai.y / 2 + ai.size / 2]),
|
160
|
+
TkcText.new(@canvas,
|
161
|
+
:fill => @text_colors[ai.team],
|
162
|
+
:anchor => 'nw', :coords => [10, 15 * i + 10], :font => TkFont.new("courier 9")))
|
163
|
+
@robots[ai].body.configure( :image => @colors[ai.team].body[(ai.heading+5) / 10],
|
164
|
+
:coords => [ai.x / 2, ai.y / 2])
|
165
|
+
@robots[ai].gun.configure( :image => @colors[ai.team].gun[(ai.gun_heading+5) / 10],
|
166
|
+
:coords => [ai.x / 2, ai.y / 2])
|
167
|
+
@robots[ai].radar.configure(:image => @colors[ai.team].radar[(ai.radar_heading+5) / 10],
|
168
|
+
:coords => [ai.x / 2, ai.y / 2])
|
169
|
+
@robots[ai].speech.configure(:text => "#{ai.speech}",
|
170
|
+
:coords => [ai.x / 2, ai.y / 2 - ai.size / 2])
|
171
|
+
@robots[ai].info.configure(:text => "#{ai.name}\n#{'|' * (ai.energy / 5)}",
|
172
|
+
:coords => [ai.x / 2, ai.y / 2 + ai.size / 2])
|
173
|
+
@robots[ai].status.configure(:text => "#{ai.name.ljust(20)} #{'%.1f' % ai.energy}")
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def draw_bullets
|
178
|
+
@battlefield.bullets.each do |bullet|
|
179
|
+
@bullets[bullet] ||= TkcOval.new(
|
180
|
+
@canvas, [-2, -2], [3, 3],
|
181
|
+
:fill=>'#'+("%02x" % (128+bullet.energy*14).to_i)*3)
|
182
|
+
@bullets[bullet].coords(
|
183
|
+
bullet.x / 2 - 2, bullet.y / 2 - 2,
|
184
|
+
bullet.x / 2 + 3, bullet.y / 2 + 3)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
def draw_mines
|
189
|
+
@battlefield.mines.each do |mine|
|
190
|
+
@mines[mine] ||= TkcImage.new(@canvas, mine.x / 2, mine.y / 2)
|
191
|
+
@mines[mine].image(mine_img)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def draw_explosions
|
196
|
+
@battlefield.explosions.each do |explosion|
|
197
|
+
@explosions[explosion] ||= TkcImage.new(@canvas, explosion.x / 2, explosion.y / 2)
|
198
|
+
@explosions[explosion].image(boom[explosion.t])
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def draw_toolboxes
|
203
|
+
@battlefield.toolboxes.each do |toolbox|
|
204
|
+
@toolboxes[toolbox] ||= TkcImage.new(@canvas, toolbox.x / 2, toolbox.y / 2)
|
205
|
+
@toolboxes[toolbox].image(toolbox_img)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
def run
|
210
|
+
Tk.mainloop
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
data/lib/battlefield.rb
CHANGED
data/lib/mines.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
class Mine
|
2
|
+
attr_accessor :x
|
3
|
+
attr_accessor :y
|
4
|
+
attr_accessor :t
|
5
|
+
attr_accessor :dead
|
6
|
+
attr_accessor :energy
|
7
|
+
attr_accessor :origin
|
8
|
+
|
9
|
+
def initialize bf, x, y, energy, origin
|
10
|
+
@x, @y, @origin = x, y, origin
|
11
|
+
@battlefield, @energy, @dead = bf, energy, false
|
12
|
+
end
|
13
|
+
|
14
|
+
def state
|
15
|
+
{:x=>x, :y=>y, :energy=>energy}
|
16
|
+
end
|
17
|
+
|
18
|
+
def tick
|
19
|
+
@battlefield.robots.each do |robot|
|
20
|
+
if (robot != origin) && (Math.hypot(@y - robot.y, robot.x - @x) < 40) && (!robot.dead)
|
21
|
+
explosion = Explosion.new(@battlefield, robot.x, robot.y)
|
22
|
+
@battlefield << explosion
|
23
|
+
damage = robot.hit(self)
|
24
|
+
origin.damage_given += damage
|
25
|
+
origin.kills += 1 if robot.dead
|
26
|
+
robot.trigged_mines += 1
|
27
|
+
@dead = true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def destroy
|
33
|
+
@dead = true
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
data/lib/misc.rb
CHANGED
@@ -2,12 +2,15 @@
|
|
2
2
|
def gem_path(path='')
|
3
3
|
# TODO : Perhaps a better way to do it ...
|
4
4
|
# regarder Rubygems pour avoir le path direct ..
|
5
|
+
res = Array::new
|
6
|
+
|
5
7
|
table_map = Gem.location_of_caller.first.split('/')
|
6
|
-
|
7
|
-
|
8
|
+
table_map.each do |item|
|
9
|
+
res.push item
|
10
|
+
break if item =~ /UG_RRobots/
|
8
11
|
end
|
9
|
-
|
10
|
-
path_prefix =
|
12
|
+
res.push path unless path.empty?
|
13
|
+
path_prefix = res.join('/')
|
11
14
|
return false unless File::exist?(path_prefix)
|
12
15
|
return path_prefix
|
13
16
|
end
|
data/lib/robotrunner.rb
CHANGED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
Binary file
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|