forked from noops-challenge/pathbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrid.go
104 lines (91 loc) · 3.34 KB
/
grid.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"fmt"
"github.com/logrusorgru/aurora"
"strings"
)
func NewGrid() *Grid {
return &Grid{}
}
type Grid struct {
Grid [][]Tile
}
type Tile struct {
Status string `json:"status"`
Message string `json:"message"`
Description string `json:"description"`
Active bool
RawExits []string `json:"exits"`
Exits struct {
North bool
East bool
South bool
West bool
}
MazeExitDirection string `json:"mazeExitDirection"`
MazeExitDistance int `json:"mazeExitDistance"`
LocationPath string `json:"locationPath"`
}
func (grid Grid) Render() {
currentRowStart := 0
width := 16
height := 6
renderMap := make([]string, height)
for row := 0; row < len(grid.Grid[0]); row ++ {
renderMap = append(renderMap, make([]string, height)...)
for column := 0; column < len(grid.Grid); column ++ {
tile := grid.Grid[column][row]
borderBlock := " "
bodyBlock := " "
titleRowFilling := strings.Repeat(bodyBlock, width-2)
bottomRowFilling := titleRowFilling
emptyRowFilling := strings.Repeat(bodyBlock, width-2)
redBorder := aurora.BgBrightRed(borderBlock).String()
leftBottomCorner := redBorder
rightBottomCorner := redBorder
rightUpperCorner := redBorder
leftUpperCorner := redBorder
leftBorder := redBorder
rightBorder := redBorder
distanceString := fmt.Sprintf(bodyBlock+"Distance: %v"+bodyBlock, tile.MazeExitDistance)
directionString := fmt.Sprintf(bodyBlock+"Direction: %v"+bodyBlock, tile.MazeExitDirection)
distanceRowFilling := distanceString + strings.Repeat(bodyBlock, (width-2)-len(distanceString))
directionRowFilling := directionString + strings.Repeat(bodyBlock, (width-2)-len(directionString))
if tile.Active {
distanceRowFilling = aurora.White(aurora.BgGreen(distanceRowFilling).String()).String()
directionRowFilling = aurora.White(aurora.BgGreen(directionRowFilling).String()).String()
emptyRowFilling = aurora.BgGreen(emptyRowFilling).String()
} else {
distanceRowFilling = aurora.Black(aurora.BgWhite(distanceRowFilling).String()).String()
directionRowFilling = aurora.Black(aurora.BgWhite(directionRowFilling).String()).String()
emptyRowFilling = aurora.BgWhite(emptyRowFilling).String()
}
if tile.Exits.North {
titleRowFilling = aurora.BgBrightWhite(titleRowFilling).String()
} else {
titleRowFilling = aurora.BgBrightRed(titleRowFilling).String()
}
if tile.Exits.South {
bottomRowFilling = aurora.BgBrightWhite(bottomRowFilling).String()
} else {
bottomRowFilling = aurora.BgBrightRed(bottomRowFilling).String()
}
if tile.Exits.West {
leftBorder = aurora.BgBrightWhite(leftBorder).String()
}
if tile.Exits.East {
rightBorder = aurora.BgBrightWhite(rightBorder).String()
}
renderMap[currentRowStart] += leftUpperCorner + titleRowFilling + rightUpperCorner
renderMap[currentRowStart+1] += leftBorder + emptyRowFilling + rightBorder
renderMap[currentRowStart+2] += leftBorder + distanceRowFilling + rightBorder
renderMap[currentRowStart+3] += leftBorder + directionRowFilling + rightBorder
renderMap[currentRowStart+4] += leftBorder + emptyRowFilling + rightBorder
renderMap[currentRowStart+5] += leftBottomCorner + bottomRowFilling + rightBottomCorner
}
currentRowStart = currentRowStart + height
}
for i := 0; i < len(renderMap); i ++ {
fmt.Println(renderMap[i])
}
}