aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZach Latta <zach@zachlatta.com>2016-03-08 18:49:04 -0800
committerZach Latta <zach@zachlatta.com>2016-03-08 18:49:04 -0800
commit2455e7db5c8bd1f8b923c192c438ad1d2aa20a85 (patch)
tree9010a66f95a726b22aea7ab34608ebd747738cc5
parentfedb576870bdb152708a999fb9bf81cd7b303355 (diff)
parent4f460ef4a040ae0f144660ef2aceb469de196510 (diff)
downloadsshtron-2455e7db5c8bd1f8b923c192c438ad1d2aa20a85.tar.gz
Merge pull request #6 from jaredfolkins/master
Fix HandleRight and prevent player from immediately reversing
-rw-r--r--game.go20
1 files changed, 17 insertions, 3 deletions
diff --git a/game.go b/game.go
index 18c10fd..f51b726 100644
--- a/game.go
+++ b/game.go
@@ -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 {
Un proyecto texto-plano.xyz