From 731e5166867c35afa85be8aad8f0f3c1dc0f85b9 Mon Sep 17 00:00:00 2001 From: hanemile Date: Sun, 28 Oct 2018 02:34:21 +0100 Subject: Adding all the game files --- main | Bin 0 -> 2049677 bytes main.go | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++ move.go | 7 ++++ structs/structs.go | 51 +++++++++++++++++++++++++++ 4 files changed, 159 insertions(+) create mode 100755 main create mode 100644 main.go create mode 100644 move.go create mode 100644 structs/structs.go diff --git a/main b/main new file mode 100755 index 0000000..f6fcbd1 Binary files /dev/null and b/main differ diff --git a/main.go b/main.go new file mode 100644 index 0000000..fb04d85 --- /dev/null +++ b/main.go @@ -0,0 +1,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) + + } + } + +} \ No newline at end of file diff --git a/move.go b/move.go new file mode 100644 index 0000000..a83df4e --- /dev/null +++ b/move.go @@ -0,0 +1,7 @@ +package main + +import ( + "./structs" + "fmt" +) + diff --git a/structs/structs.go b/structs/structs.go new file mode 100644 index 0000000..b4ce0e6 --- /dev/null +++ b/structs/structs.go @@ -0,0 +1,51 @@ +package structs + +import "fmt" + +type Lab struct { + Arr [5][5]int +} + +type Coord struct { + X, Y int +} + +func (lab *Lab) Foward(pos Coord) *Lab { + lab.Arr[pos.X][pos.Y] = 0 + lab.Arr[pos.X][pos.Y + 1] = 1 + + fmt.Println(pos.X) + fmt.Println(pos.Y + 1) + + return lab +} + +func (lab *Lab) Backwards(pos Coord) *Lab { + lab.Arr[pos.X][pos.Y] = 0 + lab.Arr[pos.X][pos.Y + 1] = 1 + + fmt.Println(pos.X) + fmt.Println(pos.Y + 1) + + return lab +} + +func (lab *Lab) Left(pos Coord) *Lab { + lab.Arr[pos.X][pos.Y] = 0 + lab.Arr[pos.X][pos.Y + 1] = 1 + + fmt.Println(pos.X) + fmt.Println(pos.Y + 1) + + return lab +} + +func (lab *Lab) Right(pos Coord) *Lab { + lab.Arr[pos.X][pos.Y] = 0 + lab.Arr[pos.X+1][pos.Y] = 1 + + fmt.Println(pos.X) + fmt.Println(pos.Y + 1) + + return lab +} -- cgit 1.4.1