コード例 #1
0
ファイル: stabbey.go プロジェクト: Garoth/StAbbey
/* Keep the player's websocket alive and continue reading from it forever */
func PlayerKeepReading(p interfaces.Player, ws *websocket.Conn) {
	for {
		var message string
		playerOrder := struct {
			CommandCode int
			TickNum     int
			Queue       []string
		}{}

		if e := websocket.Message.Receive(ws, &message); e != nil {
			break
		} else {
			log.Println("Received message on websocket:", message)
			err := json.Unmarshal([]byte(message), &playerOrder)
			if err != nil {
				log.Fatalln("Error Decoding Order: ", string(message))
				break
			}

			o := order.NewOrder(playerOrder.CommandCode, playerOrder.TickNum,
				playerOrder.Queue, p, GAME)
			RUNTIME.AddOrder(o)
		}
	}
	log.Printf("Closing socket for %v", p.GetPlayerId())
	ws.Close()
}
コード例 #2
0
ファイル: player.go プロジェクト: Garoth/StAbbey
func NewPlayer(p interfaces.Player) *Player {
	me := &Player{}

	me.Id = p.GetPlayerId()
	me.EntityId = p.GetEntityId()

	actions := p.GetAvailableActions()
	for k := 0; k < len(actions); k++ {
		me.AvailableActions = append(me.AvailableActions, NewAction(actions[k]))
	}

	return me
}
コード例 #3
0
ファイル: game.go プロジェクト: Garoth/StAbbey
func (g *Game) AddPlayer(player interfaces.Player, entity interfaces.Entity) {
	g.Players[player.GetPlayerId()] = player
	g.AddEntity(entity)
	g.PlayersToEntities[player] = entity
}