-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisplay.jl
83 lines (70 loc) · 2.27 KB
/
display.jl
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
import Base: show
const tab = " "
function show(io::IO, engine::Engine, depth::Integer = 0)
if get(io, :compact, false)
print(io, "Engine($(name(engine)))")
else
println(io, tab^depth, "engine:")
depth += 1
println(io, tab^depth, "name = ", name(engine))
println(io, tab^depth, "thrust = ", thrust(engine))
println(io, tab^depth, "Isp = ", Isp(engine))
end
end
function show(io::IO, tank::Tank, depth::Integer = 0)
if get(io, :compact, false)
print(io, "Tank($(tank.dry_mass))")
else
println(io, tab^depth, "tank:")
depth += 1
println(io, tab^depth, "dry = ", tank.dry_mass)
println(io, tab^depth, "total = ", tank.total_mass)
end
end
function print_stage(io::IO, rocket::Rocket, depth::Number)
println(io, tab^depth, "throttle = ", rocket.throttle)
println(io, tab^depth, "propellant = ", rocket.propellant)
println(io)
show(io, rocket.tank, depth)
println(io)
show(io, rocket.engine, depth)
println(io)
end
function print_stage(io::IO, payload::Payload, depth::Number)
println(io, tab^depth, payload)
println(io)
end
function show(io::IO, payload::Payload, depth::Number)
print(io, tab^depth, payload)
end
function show(io::IO, ship::SpaceVehicle)
if get(io, :compact, false)
print(io, "SpaceVehicle($(position(ship)), $(velocity(ship)))")
else
println(io, "position = ", position(ship))
println(io, "velocity = ", velocity(ship))
println(io)
stages = collect(ship)
for i in length(stages):-1:1
println(io, "stage ", i, ": ")
print_stage(io, stages[i], 1)
end
end
end
function show(io::IO, r::Rocket, depth::Integer = 0)
if get(io, :compact, false)
print(io, "Rocket($(r.throttle), $(r.propellant))")
else
println(io, tab^depth, "Rocket:")
depth += 1
println(io, tab^depth, "throttle = ", r.throttle)
println(io, tab^depth, "propellant = ", r.propellant)
println(io)
show(io, r.tank, depth)
println(io)
show(io, r.engine, depth)
println(io)
println(io, tab^depth , "Payload:")
show(io, r.payload, depth + 1)
end
end