File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -34,7 +34,9 @@ func NewGame() *Game {
3434
3535// Update updates a game by one tick.
3636func (g * Game ) Update () error {
37- g .state .Tick ++
37+ if ! g .state .Paused {
38+ g .state .Tick ++
39+ }
3840
3941 switch g .state .Screen {
4042 case domain .ScreenControlSelection :
Original file line number Diff line number Diff line change 1+ package game
2+
3+ import (
4+ "testing"
5+
6+ "github.com/morozov/river-raid-ebiten/pkg/domain"
7+ )
8+
9+ // TestTickFrozenWhenPaused verifies that GameState.Tick does not advance while
10+ // the game is paused, matching the original where the main loop is blocked by the
11+ // interrupt handler during pause and state_tick never increments.
12+ func TestTickFrozenWhenPaused (t * testing.T ) {
13+ g := NewGame ()
14+ g .state .Screen = domain .ScreenGameplay
15+ g .state .Paused = true
16+ before := g .state .Tick
17+
18+ if err := g .Update (); err != nil {
19+ t .Fatalf ("Update returned error: %v" , err )
20+ }
21+
22+ if g .state .Tick != before {
23+ t .Errorf ("Tick advanced during pause: got %d, want %d" , g .state .Tick , before )
24+ }
25+ }
26+
27+ // TestTickAdvancesWhenNotPaused verifies that GameState.Tick increments by one
28+ // per Update call during normal (non-paused) operation.
29+ func TestTickAdvancesWhenNotPaused (t * testing.T ) {
30+ g := NewGame ()
31+ g .state .Screen = domain .ScreenControlSelection
32+ before := g .state .Tick
33+
34+ if err := g .Update (); err != nil {
35+ t .Fatalf ("Update returned error: %v" , err )
36+ }
37+
38+ if g .state .Tick != before + 1 {
39+ t .Errorf ("Tick = %d, want %d" , g .state .Tick , before + 1 )
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments