A Go version of the https://lcthw.dev/learn-code-the-hard-way/curseyou-python-rogue that makes a tiny Rogue in Go.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
555 B
34 lines
555 B
package main
|
|
|
|
import (
|
|
"os"
|
|
"math/rand"
|
|
)
|
|
|
|
func NewGame(width int, height int) (*Game) {
|
|
var game Game
|
|
|
|
game.Width = width
|
|
game.Height = height
|
|
game.Enemies = make(map[Position]*Enemy)
|
|
game.Level = make(Map, height, height)
|
|
game.Player = Enemy{20, Position{1,1}, 4}
|
|
|
|
return &game
|
|
}
|
|
|
|
func (game *Game) Exit() {
|
|
if RENDER {
|
|
game.Screen.Fini()
|
|
}
|
|
|
|
os.Exit(0)
|
|
}
|
|
|
|
func (game *Game) PlaceEnemies(places []Position) {
|
|
for _, pos := range places {
|
|
if rand.Int() % 2 == 0 {
|
|
game.Enemies[pos] = &Enemy{10, pos, 4}
|
|
}
|
|
}
|
|
}
|
|
|