mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
examples/2048: Refactoring: Don't animate when all tiles are not to move
This commit is contained in:
parent
3153720e9a
commit
b59649336a
@ -61,11 +61,6 @@ func (b *Board) Update(input *Input) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
for t := range b.tiles {
|
||||
if t.IsAnimating() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if dir, ok := input.Dir(); ok {
|
||||
if err := b.Move(dir); err != nil {
|
||||
return err
|
||||
|
@ -167,6 +167,12 @@ func MoveTiles(tiles map[*Tile]struct{}, size int, dir Dir) bool {
|
||||
t.animationCount = maxAnimationCount
|
||||
}
|
||||
}
|
||||
if !moved {
|
||||
for t := range tiles {
|
||||
t.next = TileData{}
|
||||
t.animationCount = 0
|
||||
}
|
||||
}
|
||||
return moved
|
||||
}
|
||||
|
||||
|
@ -227,8 +227,11 @@ func TestMoveTiles(t *testing.T) {
|
||||
for _, test := range testCases {
|
||||
want, _ := tilesToCells(cellsToTiles(test.Want, size), size)
|
||||
tiles := cellsToTiles(test.Input, size)
|
||||
MoveTiles(tiles, size, test.Dir)
|
||||
_, got := tilesToCells(tiles, size)
|
||||
moved := MoveTiles(tiles, size, test.Dir)
|
||||
input, got := tilesToCells(tiles, size)
|
||||
if !moved {
|
||||
got = input
|
||||
}
|
||||
if fmt.Sprint(got) != fmt.Sprint(want) {
|
||||
t.Errorf("dir: %s, input: %v, got %v; want %v", test.Dir.String(), test.Input, got, want)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user