implement model for adrenaline
This commit is contained in:
parent
9395b2192e
commit
93716a7f0f
25
game/game.go
25
game/game.go
@ -36,6 +36,9 @@ type Match struct {
|
|||||||
// reveal indicates whether the current player has revealed the shell that
|
// reveal indicates whether the current player has revealed the shell that
|
||||||
// will fire next.
|
// will fire next.
|
||||||
reveal bool
|
reveal bool
|
||||||
|
// adrenaline indicates whether the current player has adrenaline in
|
||||||
|
// effect, requiring them to use an opponent's item.
|
||||||
|
adrenaline bool
|
||||||
// prev is a pointer to the element of shellArray which was fired last this
|
// prev is a pointer to the element of shellArray which was fired last this
|
||||||
// game, or nil if none has been.
|
// game, or nil if none has been.
|
||||||
prev *bool
|
prev *bool
|
||||||
@ -117,17 +120,22 @@ func (g *Match) Opponent() *playerState {
|
|||||||
// Apply uses an item by index for the current player.
|
// Apply uses an item by index for the current player.
|
||||||
// If this causes the current game to end (a beer discharges the last shell),
|
// If this causes the current game to end (a beer discharges the last shell),
|
||||||
// returns ErrGameEnded but does not start the next game.
|
// returns ErrGameEnded but does not start the next game.
|
||||||
// Returns ErrWrongTurn if id does not correspond to the current player.
|
// Returns ErrWrongTurn if id does not correspond to the current player
|
||||||
|
// (with appropriate exception for adrenaline).
|
||||||
func (g *Match) Apply(id player.ID, item int) error {
|
func (g *Match) Apply(id player.ID, item int) error {
|
||||||
cur := g.CurrentPlayer()
|
p := g.CurrentPlayer()
|
||||||
if cur.id != id {
|
if g.adrenaline {
|
||||||
|
p = g.Opponent()
|
||||||
|
}
|
||||||
|
if p.id != id {
|
||||||
return ErrWrongTurn
|
return ErrWrongTurn
|
||||||
}
|
}
|
||||||
if item < 0 || item >= len(cur.items) {
|
if item < 0 || item >= len(p.items) {
|
||||||
return errors.New("item index out of bounds")
|
return errors.New("item index out of bounds")
|
||||||
}
|
}
|
||||||
if cur.items[item].apply(g) {
|
if p.items[item].apply(g) {
|
||||||
cur.items[item] = itemNone
|
p.items[item] = itemNone
|
||||||
|
g.adrenaline = false
|
||||||
}
|
}
|
||||||
if g.Empty() {
|
if g.Empty() {
|
||||||
return ErrGameEnded
|
return ErrGameEnded
|
||||||
@ -183,10 +191,11 @@ func (g *Match) MatchWinner() *playerState {
|
|||||||
// player if self is true. Advances the turn if appropriate.
|
// player if self is true. Advances the turn if appropriate.
|
||||||
// Returns ErrRoundEnded if this causes the round to end.
|
// Returns ErrRoundEnded if this causes the round to end.
|
||||||
// Returns ErrGameEnded if this causes the game but not the round to end.
|
// Returns ErrGameEnded if this causes the game but not the round to end.
|
||||||
// Returns ErrWrongTurn if id does not correspond to the current player.
|
// Returns ErrWrongTurn if id does not correspond to the current player
|
||||||
|
// or if adrenaline is in effect.
|
||||||
func (g *Match) Shoot(id player.ID, self bool) error {
|
func (g *Match) Shoot(id player.ID, self bool) error {
|
||||||
cur := g.CurrentPlayer()
|
cur := g.CurrentPlayer()
|
||||||
if cur.id != id {
|
if cur.id != id || g.adrenaline {
|
||||||
return ErrWrongTurn
|
return ErrWrongTurn
|
||||||
}
|
}
|
||||||
target := g.Opponent()
|
target := g.Opponent()
|
||||||
|
@ -62,8 +62,12 @@ func (i item) apply(g *Match) bool {
|
|||||||
g.damage = 2
|
g.damage = 2
|
||||||
return true
|
return true
|
||||||
case itemAdrenaline:
|
case itemAdrenaline:
|
||||||
|
if g.adrenaline {
|
||||||
|
// Adrenaline forbids using adrenaline.
|
||||||
|
return false
|
||||||
|
}
|
||||||
g.action = actAdrenaline
|
g.action = actAdrenaline
|
||||||
// TODO(zeph): implement
|
g.adrenaline = true
|
||||||
return true
|
return true
|
||||||
case itemPhone:
|
case itemPhone:
|
||||||
g.action = actPhone
|
g.action = actPhone
|
||||||
|
Loading…
Reference in New Issue
Block a user