-
Notifications
You must be signed in to change notification settings - Fork 1
/
map.rb
57 lines (49 loc) · 1.17 KB
/
map.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
class Map
attr_reader :height
attr_reader :width
# Take integer as the size of the map
def initialize(n)
@height = n
@width = n
@projection = Array.new(@width) { Array.new(@height) { "." } }
end
# Print map into the screen
def projection
y = @height
batas = @height
print "y"
while y >= 0
x = 0
print "| " if y< @height
while x < batas
print "#{@projection[x][y]} "
x+=1
end
puts ""
y-=1
end
puts "0-" + "=-" * batas + "x"
nil
end
# Adding user position into the map
def addUser(user)
@projection[user.x - 1 ][user.y - 1] = "#"
end
# Removing user position from the map (In case user traveling)
def removeUser(user)
@projection[user.x - 1 ][user.y - 1] = "."
end
# Adding drivers position into the map
def addDrivers(drivers)
drivers.each { |d| @projection[d.coordinate.x - 1][d.coordinate.y - 1] = "#{d.name[0]}"}
end
# Clearing everything from the map
def clearMap
@projection = Array.new(@width) { Array.new(@height) { "." } }
end
def addRoute(order)
arr = order.route.routeArray
arr.each { |r| @projection[r[0] - 1][r[1] - 1] = "o"}
nil
end
end