/
main.go
116 lines (93 loc) · 1.5 KB
/
main.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
105
106
107
108
109
110
111
112
113
114
115
package main
import (
"fmt"
termbox "github.com/nsf/termbox-go"
"time"
"os"
)
func log(s string) {
fmt.Print(s)
}
type Pos struct {
x, y int
}
func (p Pos) X() int {
return p.x
}
func (p *Pos) SetX(x int) {
p.x = x
}
func (p Pos) Y() int {
return p.y
}
func (p *Pos) SetY(y int) {
p.y = y
}
func (p *Pos) SetPos(x, y int) {
p.x = x
p.y = y
}
type Object struct {
Pos
cell termbox.Cell
}
func (o *Object) SetCell(c termbox.Cell) {
o.cell = c
}
func (o Object) Cell() termbox.Cell {
return o.cell
}
type Creature struct {
Object
health, mana int
attribute [4]int
}
// Attribute enum:
type Attribute int
const (
STR Attribute = iota
DEX
VIT
MAG
)
func (c *Creature) SetHealth(h int) {
c.health = h
}
func (c *Creature) SetMana(m int) {
c.mana = m
}
func (c *Creature) SetAttribute(a Attribute, val int) {
c.attribute[a] = val
}
func (c Creature) Mana() int {
return c.mana
}
func (c Creature) Health() int {
return c.health
}
type Player struct {
Creature
}
func NewPlayer() *Player {
p := Player{}
p.SetPos(32, 32)
p.SetCell(termbox.Cell{'@',termbox.ColorWhite, termbox.ColorBlack})
// p.SetHealth(10)
// p.SetMana(10)
p.SetAttribute(STR, 10)
return &p
}
func (o Object) Draw() {
termbox.SetCell(o.x, o.y, o.cell.Ch, o.cell.Fg, o.cell.Bg)
}
func main() {
termbox.Init()
termbox.HideCursor()
var p Player
p = *NewPlayer()
p.Draw()
termbox.Flush()
<-time.After(2000 * time.Millisecond)
termbox.Close()
os.Exit(0)
}