-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
67 lines (49 loc) · 1.26 KB
/
main.go
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
package main
import (
"log"
"math/rand"
"net/http"
)
func main() {
http.HandleFunc("/", simulateCar)
log.Println(http.ListenAndServe(":8000", nil))
}
func simulateCar(res http.ResponseWriter, req *http.Request) {
// log.Println()
res.Write([]byte("<html>"))
// make a new car
car := NewCar(res)
res.Write([]byte("Bruce Wayne goes to the dealership and buys himself a 1998 " + car.Color + " " + car.Company + " " + car.Model + "<br>\n"))
//begin car simulation
for {
//Park the car in the garage after 30 years
car.Age()
if car.Years >= 30 {
break
}
//Change tires from drifting
if car.Tires > 0 {
res.Write([]byte("Bruce has to change the tires from being a boss<br>\n"))
car.Tires = 0
continue
}
//Change the oil when car hits 3000 miles
if car.Mileage >= 3000 {
res.Write([]byte("Time for Bruce to change the oil<br>\n"))
car.Oil()
continue
}
choiceNumber := rand.Intn(4) // 4 being the number of things that bruce does with the car
switch choiceNumber + 1 {
case 1:
car.Drive()
case 2:
car.Park()
case 3:
car.Wash()
case 4:
car.Drift()
}
}
res.Write([]byte("Bruce drove the crap out of that Skyline.....let's not run it in the ground...time to park it...she is only for shows now<br>\n"))
}