示例#1
0
// Trades two stock shares from a defunct corporation for a
// share of the acquiring one
func (g *Game) trade(corp interfaces.Corporation, amount int) {
	acquirer := g.mergeCorps["acquirer"][0]
	amountSharesAcquiringCorp := amount / 2
	corp.AddStock(amount)
	acquirer.RemoveStock(amountSharesAcquiringCorp)
	g.CurrentPlayer().
		RemoveShares(corp, amount).
		AddShares(acquirer, amountSharesAcquiringCorp)
}
示例#2
0
文件: game.go 项目: svera/acquire
// FoundCorporation founds a new corporation
func (g *Game) FoundCorporation(corp interfaces.Corporation) error {
	if g.stateMachine.CurrentStateName() != interfaces.FoundCorpStateName {
		return errors.New(ActionNotAllowed)
	}
	if corp.IsActive() {
		return errors.New(CorporationAlreadyOnBoard)
	}
	g.board.SetOwner(corp, g.newCorpTiles)
	corp.Grow(len(g.newCorpTiles))
	g.newCorpTiles = []interfaces.Tile{}
	g.getFounderStockShare(g.CurrentPlayer(), corp)
	g.stateMachine.ToBuyStock()
	return nil
}
示例#3
0
// Calculates and returns bonus amounts to be paid to owners of stock of a
// corporation
func (g *Game) payBonuses(corp interfaces.Corporation) {
	stockHolders := g.getMainStockHolders(corp)
	numberMajorityHolders := len(stockHolders["majority"])
	numberMinorityHolders := len(stockHolders["minority"])

	for _, majorityStockHolder := range stockHolders["majority"] {
		if numberMajorityHolders > 1 {
			majorityStockHolder.AddCash((corp.MajorityBonus() + corp.MinorityBonus()) / numberMajorityHolders)
		} else {
			majorityStockHolder.AddCash(corp.MajorityBonus() / numberMajorityHolders)
		}
	}
	for _, minorityStockHolder := range stockHolders["minority"] {
		minorityStockHolder.AddCash(corp.MinorityBonus() / numberMinorityHolders)
	}
}
示例#4
0
文件: game.go 项目: svera/acquire
// Makes a corporation grow with the passed tiles
func (g *Game) growCorporation(corp interfaces.Corporation, tiles []interfaces.Tile) {
	g.board.SetOwner(corp, tiles)
	corp.Grow(len(tiles))
}
示例#5
0
文件: game.go 项目: svera/acquire
// 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)
	}
}
示例#6
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)
}
示例#7
0
func (g *Game) buy(corp interfaces.Corporation, amount int) {
	corp.RemoveStock(amount)
	g.CurrentPlayer().
		AddShares(corp, amount).
		RemoveCash(corp.StockPrice() * amount)
}