diff options
author | Zach Latta <zach@zachlatta.com> | 2016-03-08 18:49:04 -0800 |
---|---|---|
committer | Zach Latta <zach@zachlatta.com> | 2016-03-08 18:49:04 -0800 |
commit | 2455e7db5c8bd1f8b923c192c438ad1d2aa20a85 (patch) | |
tree | 9010a66f95a726b22aea7ab34608ebd747738cc5 | |
parent | fedb576870bdb152708a999fb9bf81cd7b303355 (diff) | |
parent | 4f460ef4a040ae0f144660ef2aceb469de196510 (diff) | |
download | sshtron-2455e7db5c8bd1f8b923c192c438ad1d2aa20a85.tar.gz |
Merge pull request #6 from jaredfolkins/master
Fix HandleRight and prevent player from immediately reversing
-rw-r--r-- | game.go | 20 |
1 files changed, 17 insertions, 3 deletions
@@ -4,13 +4,14 @@ import ( "bufio" "bytes" "fmt" - "github.com/dustinkirkland/golang-petname" - "github.com/fatih/color" - "golang.org/x/crypto/ssh" "io" "math/rand" "sort" "time" + + "github.com/dustinkirkland/golang-petname" + "github.com/fatih/color" + "golang.org/x/crypto/ssh" ) type Hub struct { @@ -177,26 +178,39 @@ func (p *Player) calculateScore(delta float64, playerCount int) float64 { } func (p *Player) HandleUp() { + if p.Direction == PlayerDown { + return + } p.Direction = PlayerUp p.Marker = playerUpRune p.s.didAction() } func (p *Player) HandleLeft() { + if p.Direction == PlayerRight { + return + } p.Direction = PlayerLeft p.Marker = playerLeftRune p.s.didAction() } func (p *Player) HandleDown() { + if p.Direction == PlayerUp { + return + } p.Direction = PlayerDown p.Marker = playerDownRune p.s.didAction() } func (p *Player) HandleRight() { + if p.Direction == PlayerLeft { + return + } p.Direction = PlayerRight p.Marker = playerRightRune + p.s.didAction() } func (p *Player) Score() int { |