Exemple #1
0
// DeactivatePlayer gets the received player and marks it as inactive
// because the player has left the game. All player's
// assets are returned to its respective origin sets. If the deactivated player was in
// his/her turn, turn passes to the next player.
func (g *Game) DeactivatePlayer(pl interfaces.Player) {
	pl.Deactivate()
	pl.RemoveCash(pl.Cash())
	g.tileset.Add(pl.Tiles())
	for _, corp := range g.Corporations() {
		if pl.Shares(corp) > 0 {
			corp.AddStock(pl.Shares(corp))
			pl.RemoveShares(corp, pl.Shares(corp))
		}
	}
	if len(g.activePlayers()) < 3 {
		g.stateMachine.ToInsufficientPlayers()
		return
	}
	for i := range g.players {
		if g.players[i] == pl && g.currentPlayerNumber == i {
			g.endTurn()
			return
		}
	}
}
Exemple #2
0
// Initialises player hand of tiles
func (g *Game) giveInitialHand(plyr interfaces.Player) {
	for i := 0; i < 6; i++ {
		tile, _ := g.tileset.Draw()
		plyr.PickTile(tile)
	}
}
Exemple #3
0
// Receive a free stock share from a recently founded corporation, if it has
// remaining shares available
// TODO this should trigger an event warning that no founder stock share will be given
// of the founded corporation has no stock shares left
func (g *Game) getFounderStockShare(pl interfaces.Player, corp interfaces.Corporation) {
	if corp.Stock() > 0 {
		corp.RemoveStock(1)
		pl.AddShares(corp, 1)
	}
}
Exemple #4
0
// Sells owned shares of a defunct corporation, returning them to the
// corporation's stock
func (g *Game) sell(pl interfaces.Player, corp interfaces.Corporation, amount int) {
	corp.AddStock(amount)
	pl.RemoveShares(corp, amount).
		AddCash(corp.StockPrice() * amount)
}