point limit parametrized
This commit is contained in:
+6
-6
@@ -1,9 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
v "bitbucket.org/hackerbots/vector"
|
||||
"code.google.com/p/go.net/websocket"
|
||||
"log"
|
||||
)
|
||||
|
||||
// < the name of the game we want to join
|
||||
@@ -45,7 +46,7 @@ type ClientConfig struct {
|
||||
Stats map[string]StatsRequest `json:"stats"`
|
||||
}
|
||||
|
||||
func (config ClientConfig) Valid() bool {
|
||||
func (config ClientConfig) Valid(max int) bool {
|
||||
total := 0
|
||||
for _, s := range config.Stats {
|
||||
total += (s.Speed +
|
||||
@@ -58,9 +59,7 @@ func (config ClientConfig) Valid() bool {
|
||||
s.WeaponDamage +
|
||||
s.WeaponSpeed)
|
||||
}
|
||||
|
||||
// allowing for 50 pts in every category
|
||||
if total > 500 {
|
||||
if total > max {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@@ -167,6 +166,7 @@ func addPlayer(ws *websocket.Conn) {
|
||||
float32(conf.Height),
|
||||
conf.Obstacles,
|
||||
conf.Tick,
|
||||
conf.MaxPoints,
|
||||
)
|
||||
go game.run()
|
||||
games.add(game)
|
||||
@@ -219,7 +219,7 @@ func addPlayer(ws *websocket.Conn) {
|
||||
}
|
||||
|
||||
// TODO: verify conf's type
|
||||
if conf.Valid() {
|
||||
if conf.Valid(game.maxPoints) {
|
||||
log.Printf("Config is Valid, continuing")
|
||||
_ = websocket.JSON.Send(ws, NewHandshake(player_id, true))
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user