|
|
@@ -3,6 +3,7 @@ package main
|
|
|
import (
|
|
|
"fmt"
|
|
|
"log"
|
|
|
+ "math/rand"
|
|
|
|
|
|
"github.com/gdamore/tcell/v2"
|
|
|
)
|
|
|
@@ -12,14 +13,22 @@ func gameinit() {
|
|
|
if err != nil {
|
|
|
log.Fatalln("Initilization error: ", err)
|
|
|
}
|
|
|
- go gameDirector(&game)
|
|
|
- keyboardProcessor(&game)
|
|
|
+ go game.gameDirector()
|
|
|
+ game.keyboardProcessor()
|
|
|
|
|
|
// Quit the screen
|
|
|
quit(&game)
|
|
|
|
|
|
// Give closure
|
|
|
- fmt.Println("You get rekt lol.")
|
|
|
+ if game.gameover == 1 {
|
|
|
+ fmt.Println("You get rekt by a robot")
|
|
|
+ } else if game.gameover == 2 {
|
|
|
+ fmt.Println("You took the easy way out")
|
|
|
+ }
|
|
|
+
|
|
|
+ fmt.Println("Score:", game.player.score)
|
|
|
+ fmt.Println("Moves:", game.player.moves)
|
|
|
+ fmt.Println("Teleports:", game.player.teleports)
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -51,6 +60,7 @@ func initialize() (Game, error) {
|
|
|
moves: 0,
|
|
|
teleports: 0,
|
|
|
},
|
|
|
+ level: 1,
|
|
|
// robots: []Robot, // I need this maybe
|
|
|
// trash: []Position, // I will need this
|
|
|
gameover: 0,
|
|
|
@@ -59,7 +69,7 @@ func initialize() (Game, error) {
|
|
|
return game, err
|
|
|
}
|
|
|
|
|
|
-func gameDirector(game *Game) {
|
|
|
+func (game *Game) gameDirector() {
|
|
|
defer quit(game)
|
|
|
|
|
|
for {
|
|
|
@@ -68,11 +78,15 @@ func gameDirector(game *Game) {
|
|
|
game.screen.Clear()
|
|
|
|
|
|
// Draw starter conditions
|
|
|
- game.drawBox(game)
|
|
|
- game.drawPlayer(game)
|
|
|
- game.drawCoords(game)
|
|
|
+ game.drawBox()
|
|
|
+ game.drawPlayer()
|
|
|
+ game.drawCoords()
|
|
|
|
|
|
// Draw robots??
|
|
|
+ if len(game.robots) == 0 {
|
|
|
+ game.initRobots()
|
|
|
+ }
|
|
|
+ game.drawRobots()
|
|
|
|
|
|
// Draw the screen
|
|
|
game.screen.Show()
|
|
|
@@ -84,7 +98,7 @@ func gameDirector(game *Game) {
|
|
|
|
|
|
}
|
|
|
|
|
|
-func keyboardProcessor(game *Game) {
|
|
|
+func (game *Game) keyboardProcessor() {
|
|
|
defer close(game.keypresses)
|
|
|
|
|
|
for {
|
|
|
@@ -97,6 +111,7 @@ func keyboardProcessor(game *Game) {
|
|
|
case *tcell.EventKey:
|
|
|
// Keys to bug out
|
|
|
if ev.Key() == tcell.KeyEscape || ev.Key() == tcell.KeyCtrlC {
|
|
|
+ game.gameover = 2
|
|
|
return
|
|
|
|
|
|
// Screen management
|
|
|
@@ -126,18 +141,32 @@ func keyboardProcessor(game *Game) {
|
|
|
game.keypresses <- teleport
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- if game.gameover != 0 {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func quit(game *Game) {
|
|
|
+ game.screen.Clear()
|
|
|
maybePanic := recover()
|
|
|
game.screen.Fini()
|
|
|
if maybePanic != nil {
|
|
|
panic(maybePanic)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func (game *Game) randPos() Position {
|
|
|
+ var safe bool
|
|
|
+ var pos Position
|
|
|
+
|
|
|
+ for !safe {
|
|
|
+ x := rand.Intn(80)
|
|
|
+ y := rand.Intn(24)
|
|
|
+
|
|
|
+ if x == 0 || x == 79 || y == 0 || y == 23 {
|
|
|
+ safe = false
|
|
|
+ } else {
|
|
|
+ pos = Position{x: x, y: y}
|
|
|
+ safe = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return pos
|
|
|
+}
|