-
Notifications
You must be signed in to change notification settings - Fork 0
/
teste.rb
executable file
·97 lines (88 loc) · 2.41 KB
/
teste.rb
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
# Imprime array
def print_array ( map )
for i in 0...map.size do
for j in 0...map[i].size do
print "#{map[i][j]} "
end
puts
end
end
# Função de Explosão (recursiva)
# c_end = false, b_end = false, e_end = false, d_end = false
def explod ( map, x, y, exp, player_x, player_y, area = [], i = 1, cima_livre = true, baixo_livre = true, esq_livre = true, dir_livre = true) # x , y : player; i : expansao; exp : taxa de exp
if (cima_livre)
if ( ( (map [x - i][y] != '#') and ( (x - i) >= 0 ) ) and (exp > 0))
map[x - i][y] = 'x' #boom
area << [x-i, y]
puts "exp [#{x - i}][#{y}] "
exp -= 1
else
puts "encerrando cima (#{i})"
cima_livre = false
end
cima_livre = false if ((x - i) == 0)
end
if (baixo_livre)
if ( ( (map [x + i][y] != '#') and ( (x + i) < map.size ) ) and (exp > 0))
map[x + i][y] = 'x' #boom
area << [x+i, y]
puts "exp [#{x + i}][#{y}] "
exp -= 1
else
puts "encerrando baixo (#{i})"
baixo_livre = false
end
baixo_livre = false if ((x + i) == map.size - 1)
end
if (esq_livre)
if ( ( (map [x][y - i] != '#') and ( (y - i) >= 0 ) ) and (exp > 0))
map[x][y - i] = 'x' #boom
area << [x, y-i]
puts "exp [#{x}][#{y - i}] "
exp -= 1
else
puts "encerrando esq (#{i})"
esq_livre = false
end
esq_livre = false if ((y - i) == 0)
end
if (dir_livre)
if ( ( (map [x][y + i] != '#') and ( (y + i) < map[x].size ) ) and (exp > 0))
map[x][y + i] = 'x' #boom
area << [x, y + i]
puts "exp [#{x}][#{y + i}] "
exp -= 1
else
puts "encerrando dir (#{i})"
dir_livre = false
end
dir_livre = false if ((y + i) == map[x].size - 1)
end
puts "#{cima_livre}#{baixo_livre}#{esq_livre}#{dir_livre}"
if ( (exp > 0) and (cima_livre or baixo_livre or esq_livre or dir_livre))then
puts "and here we go..."
explod( map, x, y, exp, player_x, player_y, area, i + 1, cima_livre, baixo_livre, esq_livre, dir_livre)
else
puts "end!"
map[x][y] = 'x'
area << [x,y]
puts exp
return area
end
end
map = [ ['-','-','-','-','-','-'],
['-','-','-','o','-','-'],
['-','-','-','o','-','-'],
['-','-','#','-','o','o'],
['-','-','-','-','-','-'],
['-','-','-','#','-','-'],
['-','-','-','-','-','-'],
['-','-','-','-','-','-'] ]
# Arguments
# map : mapa; x , y : bomb; i : expansao; exp : taxa de exp; player_x, player_y : pos do player
print_array map
explod(map,3,3,9,6,3)
print_array map
puts
puts "oi: #{map.size}"
puts "io: #{map[0].size}"