Skip to content

Commit

Permalink
fix: interaction bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Emyr298 committed Jun 13, 2024
1 parent 8d750de commit d5eef93
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
17 changes: 9 additions & 8 deletions src/matches/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,23 @@ func (session *Session) isPointOpen(pos Point) bool {
}

func (session *Session) checkWinner() string {
cnt := 0
cntDead := 0
for _, hero := range session.player1.HeroList {
if hero.Health == 0 {
cnt++
cntDead++
}
}
if cnt == len(session.player1.HeroList) {
return session.player1.Id
if cntDead == len(session.player1.HeroList) {
return session.player2.Id
}
cnt = 0
cntDead = 0
for _, hero := range session.player2.HeroList {
if hero.Health == 0 {
cnt++
cntDead++
}
}
if cnt == len(session.player2.HeroList) {
return session.player2.Id
if cntDead == len(session.player2.HeroList) {
return session.player1.Id
}
return ""
}
Expand All @@ -110,6 +110,7 @@ func (session *Session) processEndResult() {
}

body := map[string]interface{}{
"matchId": session.id,
"username1": session.player1.Id,
"username2": session.player2.Id,
"isUser1Win": (winner == session.player1.Id),
Expand Down
5 changes: 3 additions & 2 deletions src/matches/states.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (state *Player2TurnState) executeAction(action IAction) error {
return nil
}

hasAction := state.session.player1.hasAvailableAction()
hasAction := state.session.player2.hasAvailableAction()
if !hasAction {
state.session.changeState(&Player1TurnState{
session: state.session,
Expand Down Expand Up @@ -322,6 +322,7 @@ func (state *EndState) startBattle() error {

func (state *EndState) getData() map[string]interface{} {
return map[string]interface{}{
"name": "END",
"name": "END",
"winnerId": state.winnerId,
}
}
2 changes: 1 addition & 1 deletion src/messaging/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func newPublisher() *Publisher {
true,
false,
amqp.Publishing{
ContentType: "text/plain",
ContentType: "application/json",
Body: []byte(msg.Body),
},
)
Expand Down

0 comments on commit d5eef93

Please sign in to comment.