Add play again button for rematch after game ends
When a game finishes (win or draw), players see a "Play again" button. Clicking it creates a new game and the opponent sees a "Join Rematch" link to join the same game.
This commit is contained in:
28
main.go
28
main.go
@@ -281,6 +281,16 @@ func main() {
|
||||
c.Sync()
|
||||
})
|
||||
|
||||
createRematch := c.Action(func() {
|
||||
if gi == nil {
|
||||
return
|
||||
}
|
||||
newGI := gi.CreateRematch(store)
|
||||
if newGI != nil {
|
||||
c.Redirectf("/game/%s", newGI.ID())
|
||||
}
|
||||
})
|
||||
|
||||
// If nickname exists in session and game exists, join immediately
|
||||
if gameExists && sessionNickname != "" && gi.GetPlayerColor(playerID) == 0 {
|
||||
player := &game.Player{
|
||||
@@ -325,7 +335,7 @@ func main() {
|
||||
content = append(content,
|
||||
h.H1(h.Text("Connect 4")),
|
||||
ui.PlayerInfo(g, myColor),
|
||||
ui.StatusBanner(g, myColor),
|
||||
ui.StatusBanner(g, myColor, createRematch.OnClick()),
|
||||
ui.BoardComponent(g, columnClick, myColor),
|
||||
)
|
||||
|
||||
@@ -444,6 +454,22 @@ const gameCSS = `
|
||||
color: white;
|
||||
}
|
||||
|
||||
.play-again-btn, .rematch-link {
|
||||
margin-left: 1rem;
|
||||
padding: 0.25rem 0.75rem;
|
||||
font-size: 0.875rem;
|
||||
background: white;
|
||||
color: #333;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.play-again-btn:hover, .rematch-link:hover {
|
||||
background: #eee;
|
||||
}
|
||||
|
||||
.player-info {
|
||||
display: flex;
|
||||
gap: 2rem;
|
||||
|
||||
Reference in New Issue
Block a user