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
98
99
100
101
|
package main
import (
"./structs"
"fmt"
"os"
)
func printDie() {
fmt.Println("BOOOOOOOOOOOOM")
fmt.Println("BOOOOOOOOOOOOM")
fmt.Println("BOOOOOOOOOOOOM")
fmt.Println("BOOOOOOOOOOOOM")
fmt.Println("BOOOOOOOOOOOOM")
fmt.Println("\n YOU DIE \n\n\n")
fmt.Println("Game Over!")
}
func testDie(lab structs.Lab, position structs.Coord) {
if (lab.Arr[position.X][position.Y] == 2) {
printDie()
os.Exit(0)
}
}
func main() {
fmt.Println("The LAB: Reach 3 without dying! You are the 1 and only player!")
lab := structs.Lab{
Arr: [5][5]int{
{0, 0, 0, 2, 0},
{0, 1, 0, 2, 3},
{0, 0, 0, 2, 0},
{0, 2, 2, 2, 0},
{0, 0, 0, 0, 0},
},
}
position := structs.Coord{1, 1}
for {
// Print the game
for i := range lab.Arr {
fmt.Println(lab.Arr[i])
}
// Print a delimiter
fmt.Println("---")
fmt.Printf("Current position: (%d, %d)\n", position.X, position.Y)
fmt.Print("Enter movement (fw, bw, le, ri): ")
var text string
fmt.Scanln(&text)
switch text {
case "fw":
lab.Arr[position.X][position.Y] = 0
position.X = position.X - 1
position.Y = position.Y
testDie(lab, position)
lab.Arr[position.X][position.Y] = 1
case "bw":
lab.Arr[position.X][position.Y] = 0
position.X = position.X + 1
position.Y = position.Y
testDie(lab, position)
lab.Arr[position.X][position.Y] = 1
case "le":
lab.Arr[position.X][position.Y] = 0
position.X = position.X
position.Y = position.Y - 1
testDie(lab, position)
lab.Arr[position.X][position.Y] = 1
case "ri":
lab.Arr[position.X][position.Y] = 0
position.X = position.X
position.Y = position.Y + 1
testDie(lab, position)
lab.Arr[position.X][position.Y] = 1
}
if (position == structs.Coord{1, 4}) {
fmt.Println("YOU WIN!")
os.Exit(0)
}
}
}
|