/
level.go
57 lines (49 loc) · 937 Bytes
/
level.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
package roguelike
import (
"fmt"
termbox "github.com/nsf/termbox-go"
)
type Level interface {
Tiles() [][]Tile
IsBlocked(x, y int) bool
Render()
}
type level struct {
w int
h int
tiles [][]Tile
}
func (l *level) Tiles() [][]Tile {
return l.tiles
}
func (l *level) IsBlocked(x, y int) bool {
return l.tiles[x][y].IsBlocked()
}
func (l *level) Render() {
for y := 0; y < l.h; y++ {
for x := 0; x < l.w; x++ {
t := l.tiles[x][y]
if t.IsBlocked() {
termbox.SetCell(x, y, ' ', termbox.ColorDefault, colorBrown)
} else {
termbox.SetCell(x, y, ' ', termbox.ColorDefault, colorGreen)
}
}
}
}
func NewLevel(w, h int) Level {
fmt.Printf("A")
tiles := make([][]Tile, 0)
for x := 0; x < w; x++ {
column := []Tile{}
for y := 0; y < h; y++ {
column = append(column, NewTile(false, false))
}
tiles = append(tiles, column)
}
return &level{
w: w,
h: h,
tiles: tiles,
}
}