aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZach Latta <zach@zachlatta.com>2016-03-06 05:51:53 -0500
committerZach Latta <zach@zachlatta.com>2016-03-06 05:51:53 -0500
commit127d885494fb2f9da76f5043dee54b6c0ac1e427 (patch)
treec31d341c938387515f020514d4b68f046fdd9ab6
parent753d276b82a12b84fe7b3c0a6ea14fd8381978c4 (diff)
downloadsshtron-127d885494fb2f9da76f5043dee54b6c0ac1e427.tar.gz
Don't let people share colors
-rw-r--r--game.go26
-rw-r--r--main.go3
2 files changed, 26 insertions, 3 deletions
diff --git a/game.go b/game.go
index da63f9c..6c804ad 100644
--- a/game.go
+++ b/game.go
@@ -493,6 +493,26 @@ func (g *Game) WorldHeight() int {
return len(g.level[0])
}
+func (g *Game) AvailableColors() []color.Attribute {
+ usedColors := map[color.Attribute]bool{}
+ for _, color := range playerColors {
+ usedColors[color] = false
+ }
+
+ for player := range g.players() {
+ usedColors[player.Color] = true
+ }
+
+ availableColors := []color.Attribute{}
+ for color, used := range usedColors {
+ if !used {
+ availableColors = append(availableColors, color)
+ }
+ }
+
+ return availableColors
+}
+
func (g *Game) Run() {
// Proxy g.Redraw's channel to g.hub.Redraw
go func() {
@@ -589,9 +609,11 @@ type Session struct {
Player *Player
}
-func NewSession(c ssh.Channel, worldWidth, worldHeight int) *Session {
+func NewSession(c ssh.Channel, worldWidth, worldHeight int,
+ color color.Attribute) *Session {
+
s := Session{c: c}
- s.newGame(worldWidth, worldHeight, -1)
+ s.newGame(worldWidth, worldHeight, color)
return &s
}
diff --git a/main.go b/main.go
index da5b794..bc8215b 100644
--- a/main.go
+++ b/main.go
@@ -59,7 +59,8 @@ func handler(conn net.Conn, game *Game, config *ssh.ServerConfig) {
fmt.Println("Received new connection")
- session := NewSession(channel, game.WorldWidth(), game.WorldHeight())
+ session := NewSession(channel, game.WorldWidth(), game.WorldHeight(),
+ game.AvailableColors()[0])
game.AddSession(session)
reader := bufio.NewReader(channel)
Un proyecto texto-plano.xyz