package main import ( "log" "os" "math/rand" ) func NewGame(width int, height int) (*Game) { var game Game if width % 2 == 0 { log.Fatal("NewGame: width must be odd") } if height % 2 == 0 { log.Fatal("NewGame: height must be odd") } game.Width = width game.Height = height game.Enemies = make(map[Position]*Thing) game.Loot = make(map[Position]*Thing) game.Level = make(Map, height, height) game.Paths = make(Paths, height, height) game.Player = Thing{20, Position{1,1}, 4, 0} 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 { enemy := new(Thing) enemy.HP = 10 enemy.Pos = pos enemy.Damage = 4 game.Enemies[pos] = enemy } } } func (game *Game) PlaceLoot(places []Position) { for _, pos := range places { if !game.Occupied(pos) { loot := new(Thing) loot.Healing = 10 game.Loot[pos] = loot } } } func (game *Game) Restart() { game.SetStatus("YOU DIED! Try again.") game.Player.HP = 20 game.Player.Pos = Position{1,1} clear(game.Enemies) game.FillPaths(game.Paths, PATH_LIMIT) game.NewMap() game.Render() } func (game *Game) WorldGenerator() { // clear the map to all '#' game.NewMap() // first generate a maze to get dead ends dead_ends := game.NewMaze() // this clears the previous map game.NewMap() // then use the dead_ends to create rooms room_pos := game.AddRooms(dead_ends) // re-run the maze gen, and it'll work around the rooms dead_ends = game.NewMaze() // finally place enemies inside the rooms game.PlaceEnemies(room_pos) game.PlaceLoot(room_pos) }