start using util functions
This commit is contained in:
parent
82d2afa3fa
commit
66fb3cc777
78
game.go
78
game.go
@ -168,10 +168,7 @@ func (g *Game) PlayerStateAct(id int, cmd string) *GameView {
|
||||
g.Status = StatusPlaying
|
||||
}
|
||||
//skip draw step when 0 life
|
||||
if id == SentinalID && g.SentinalPlayer.Life <= 0 {
|
||||
g.CanDraw = false
|
||||
g.HasDrawn = true
|
||||
} else if id == ScourgeID && g.ScourgePlayer.Life <= 0 {
|
||||
if g.GetPlayer(id).Life <= 0 {
|
||||
g.CanDraw = false
|
||||
g.HasDrawn = true
|
||||
} else {
|
||||
@ -181,30 +178,18 @@ func (g *Game) PlayerStateAct(id int, cmd string) *GameView {
|
||||
if id != g.CurrentTurn {
|
||||
return nil
|
||||
}
|
||||
if id == SentinalID {
|
||||
for _, v := range g.GameBoard.Sentinal {
|
||||
for _, v := range g.GetBoard(id) {
|
||||
OracleUpkeep(v, g)
|
||||
}
|
||||
} else {
|
||||
for _, v := range g.GameBoard.Scourge {
|
||||
OracleUpkeep(v, g)
|
||||
}
|
||||
}
|
||||
case "e":
|
||||
//end turn and clean up
|
||||
if id != g.CurrentTurn {
|
||||
return nil
|
||||
}
|
||||
g.CardBuffer = DeckFromCards([]*Card{})
|
||||
if id == SentinalID {
|
||||
for _, v := range g.GameBoard.Sentinal {
|
||||
for _, v := range g.GetBoard(id) {
|
||||
OracleEndstep(v, g)
|
||||
}
|
||||
} else {
|
||||
for _, v := range g.GameBoard.Scourge {
|
||||
OracleEndstep(v, g)
|
||||
}
|
||||
}
|
||||
if g.CurrentTurn == SentinalID {
|
||||
g.CurrentTurn = ScourgeID
|
||||
} else {
|
||||
@ -221,15 +206,9 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
|
||||
var curr *Player
|
||||
var opp *Player
|
||||
var currD *Deck
|
||||
if id == g.SentinalPlayer.Id {
|
||||
curr = g.SentinalPlayer
|
||||
opp = g.ScourgePlayer
|
||||
currD = g.SentinalDeck
|
||||
} else {
|
||||
curr = g.ScourgePlayer
|
||||
opp = g.SentinalPlayer
|
||||
currD = g.ScourgeDeck
|
||||
}
|
||||
curr = g.GetPlayer(id)
|
||||
opp = g.GetOpponent(id)
|
||||
currD = g.GetDeck(id)
|
||||
cmd_s := strings.Split(cmd, " ")
|
||||
if len(cmd_s) < 1 {
|
||||
return nil
|
||||
@ -319,15 +298,10 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
|
||||
OracleAttack(g.GameBoard.GetCard(g.CurrentTurn, x_i), g)
|
||||
res := g.GameBoard.Attack(g.CurrentTurn, x_i, y_i)
|
||||
var aid, did int
|
||||
if id == SentinalID {
|
||||
aid = SentinalID
|
||||
did = ScourgeID
|
||||
} else {
|
||||
aid = ScourgeID
|
||||
did = SentinalID
|
||||
}
|
||||
attacker := g.GameBoard.GetRow(aid)[x_i]
|
||||
defender := g.GameBoard.GetRow(did)[y_i]
|
||||
aid = g.GetPlayer(id).Id
|
||||
did = g.GetOpponent(id).Id
|
||||
attacker := g.GetBoard(aid)[x_i]
|
||||
defender := g.GetBoard(did)[y_i]
|
||||
switch res {
|
||||
case 1:
|
||||
opp.Life = opp.Life - 1
|
||||
@ -396,3 +370,35 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
|
||||
func Debug(g *Game) {
|
||||
return
|
||||
}
|
||||
|
||||
func (g *Game) GetPlayer(id int) *Player {
|
||||
if id == SentinalID {
|
||||
return g.SentinalPlayer
|
||||
} else if id == ScourgeID {
|
||||
return g.ScourgePlayer
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
func (g *Game) GetOpponent(id int) *Player {
|
||||
if id == SentinalID {
|
||||
return g.ScourgePlayer
|
||||
} else if id == ScourgeID {
|
||||
return g.SentinalPlayer
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
func (g *Game) GetDeck(id int) *Deck {
|
||||
if id == SentinalID {
|
||||
return g.SentinalDeck
|
||||
} else if id == ScourgeID {
|
||||
return g.ScourgeDeck
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Game) GetBoard(id int) []*Card {
|
||||
return g.GameBoard.GetRow(id)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user