blob: 58e223257e9f76ff03708844823cffce75475c0d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
package game
import "fmt"
func (ctx *Context) RollDice() {
ctx.EventPop()
// Roll Dice
diceRoll1 := ctx.Random.Int32N(6) + 1
diceRoll2 := ctx.Random.Int32N(6) + 1
total := diceRoll1 + diceRoll2
ctx.Turn.Log = append(ctx.Turn.Log, fmt.Sprintf(LogRolled, total))
ctx.Turn.NumDiceRolled++
ctx.Turn.DiceRollsRemaining--
if diceRoll1 == diceRoll2 {
ctx.Turn.RolledDoubles = true
ctx.Turn.DiceRollsRemaining++
ctx.RemovePlayerFromJail(ctx.Turn.Current)
ctx.Turn.EventStack = append(ctx.Turn.EventStack, EventRollDice)
}
if ctx.Turn.NumDiceRolled >= 3 {
ctx.PutPlayerInJail(ctx.Turn.Current)
}
ctx.Turn.MoveQueue = append(ctx.Turn.MoveQueue, total)
}
func (ctx *Context) Buy() {
ctx.EventPop()
playerID := ctx.Turn.Current
player := ctx.Players.Alive[playerID.Index()]
prop := ColorProperties[BoardSpaces[player.CurrentSpaceID.Index()].SubIndexID]
for i, p := range ctx.Properties.Owners {
if p.SpaceID == player.CurrentSpaceID {
ctx.Properties.Owners[i].OwnerID = playerID
}
}
ctx.AdjustPlayerMoney(playerID, -prop.Price)
}
func (ctx *Context) EndTurn() {
ctx.EventPop()
nextTurnPlayerID := PlayerID{ID: (ctx.Turn.Current.ID + 1) % int32(len(ctx.Players.Alive))}
ctx.Turn = initTurn(nextTurnPlayerID, !ctx.PlayerCanMove(nextTurnPlayerID))
// TODO: send options list to the next player
}
|