aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZach Latta <zach@zachlatta.com>2016-03-06 06:18:23 -0500
committerZach Latta <zach@zachlatta.com>2016-03-06 06:18:23 -0500
commitd4d7652ba38745c00f592ad26681d30e6af54177 (patch)
tree6d895b023315da56acff72b57ba5cacea08c664f
parent127d885494fb2f9da76f5043dee54b6c0ac1e427 (diff)
downloadsshtron-d4d7652ba38745c00f592ad26681d30e6af54177.tar.gz
Add names to games and draw them
-rw-r--r--game.go19
1 files changed, 15 insertions, 4 deletions
diff --git a/game.go b/game.go
index 6c804ad..39bd8b5 100644
--- a/game.go
+++ b/game.go
@@ -2,6 +2,7 @@ package main
import (
"fmt"
+ "github.com/dustinkirkland/golang-petname"
"github.com/fatih/color"
"golang.org/x/crypto/ssh"
"math/rand"
@@ -284,20 +285,22 @@ type Tile struct {
Type TileType
}
-type Game struct {
- hub Hub
+type Game struct {
+ Name string
Redraw chan struct{}
HighScore int
// Top left is 0,0
level [][]Tile
+ hub Hub
}
func NewGame(worldWidth, worldHeight int) *Game {
g := &Game{
- hub: NewHub(),
+ Name: petname.Generate(1, ""),
Redraw: make(chan struct{}),
+ hub: NewHub(),
}
g.initalizeLevel(worldWidth, worldHeight)
@@ -436,12 +439,20 @@ func (g *Game) worldString(s *Session) string {
strWorld[startX][len(strWorld[0])-1] = " "
} else {
warning :=
- " Warning: Other Players Must be Online for You to Score. Get a friend! "
+ " Warning: Other Players Must be Online for You to Score! "
for i, r := range warning {
strWorld[3+i][len(strWorld[0])-1] = borderColorizer(string(r))
}
}
+ // Draw the game's name
+ nameStr := fmt.Sprintf(" %s ", g.Name)
+ for i, r := range nameStr {
+ charsRemaining := len(nameStr) - i
+ strWorld[len(strWorld)-3-charsRemaining][len(strWorld[0])-1] =
+ borderColorizer(string(r))
+ }
+
// Load the level into the string slice
for x := 0; x < worldWidth; x++ {
for y := 0; y < worldHeight; y++ {
Un proyecto texto-plano.xyz