-
Notifications
You must be signed in to change notification settings - Fork 1
/
game.go
68 lines (57 loc) · 1.65 KB
/
game.go
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
package main
import (
"fmt"
"math/rand"
"strings"
)
const (
PLAYER = "┃"
GATE = "┃"
)
type Difficulty string
const (
EASY_LEVEL Difficulty = "easy"
MEDIUM_LEVEL Difficulty = "medium"
HARD_LEVEL Difficulty = "hard"
)
func (b *board) checkWin() bool {
if b.playerXPos == b.gateXPos && b.playerYPos == b.gateYPos {
return true
}
return false
}
func getDifficultyLevel() string {
var difficulty string
validDifficultyLevels := []Difficulty{EASY_LEVEL, MEDIUM_LEVEL, HARD_LEVEL}
for {
fmt.Print("Choose a difficulty level (easy, medium, or hard): ")
fmt.Scanln(&difficulty)
difficulty = strings.ToLower(difficulty)
for _, validLevel := range validDifficultyLevels {
if difficulty == string(validLevel) {
return difficulty
}
}
fmt.Println("Invalid difficulty level. Please choose from easy, medium, or hard.")
}
}
func initializeBoard(difficultyLevel string) *board {
var b *board
switch difficultyLevel {
case "hard":
width, height := 32, 16
b = &board{cells: initializeCells(width, height), playerXPos: (rand.Intn(width) * 2) + 1, playerYPos: (rand.Intn(height) * 2) + 1}
case "medium":
width, height := 24, 10
b = &board{cells: initializeCells(width, height), playerXPos: (rand.Intn(width) * 2) + 1, playerYPos: (rand.Intn(height) * 2) + 1}
case "easy":
width, height := 12, 6
b = &board{cells: initializeCells(width, height), playerXPos: (rand.Intn(width) * 2) + 1, playerYPos: (rand.Intn(height) * 2) + 1}
}
b.cells.carve(b.playerXPos, b.playerYPos)
gateX, gateY := findFarthestPoint(b.cells, b.playerXPos, b.playerYPos)
b.gateXPos = gateX
b.gateYPos = gateY
b.cells[gateY][gateX].isWall = false
return b
}