Skip to content

Commit

Permalink
nba(jump ball): cadence
Browse files Browse the repository at this point in the history
* Fix win logic.
  • Loading branch information
chumeston committed Dec 11, 2024
1 parent 86eefa3 commit dc01c07
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions contracts/JumpBall.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,23 @@ access(all) contract JumpBall {

let winner: Address
if creatorTotal > opponentTotal {
winner = game.creator
// Creator wins
emit WinnerDetermined(gameID: gameID, winner: game.creator)
game.transferAllToWinner(winner: game.creator, winnerCap: winnerCap)
} else if opponentTotal > creatorTotal {
winner = game.opponent
// Opponent wins
emit WinnerDetermined(gameID: gameID, winner: game.opponent)
game.transferAllToWinner(winner: game.opponent, winnerCap: winnerCap)
} else {
// Tie: Return NFTs to their original owners.
emit WinnerDetermined(gameID: gameID, winner: Address(0))
emit WinnerDetermined(gameID: gameID, winner: Address.zero)
let keys = game.nfts.keys
for key in keys {
let originalOwner = game.ownership[key] ?? panic("Original owner not found for NFT.")
let depositCap = JumpBall.getDepositCapForAddress(owner: originalOwner)
game.returnNFT(nftID: key, owner: depositCap)
}
}

emit WinnerDetermined(gameID: gameID, winner: winner)

// Award NFTs to the winner
game.transferAllToWinner(winner: winner, winnerCap: winnerCap)
}
}

Expand Down

0 comments on commit dc01c07

Please sign in to comment.