Skip to content
Snippets Groups Projects
Commit ae2d4cd9 authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Merge branch '22-allow-move-to-last-current-cell' into 'master'

Resolve "Allow move to last current cell"

Closes #22

See merge request !23
parents e351f1af 83c2ffe6
No related branches found
No related tags found
1 merge request!23Resolve "Allow move to last current cell"
Pipeline #7026 passed
Fix collision detection.
Correction sur détection de collision.
import 'dart:math';
import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; import 'package:flutter_custom_toolbox/flutter_toolbox.dart';
import 'package:snake/models/activity/board.dart'; import 'package:snake/models/activity/board.dart';
...@@ -158,8 +160,11 @@ class Activity { ...@@ -158,8 +160,11 @@ class Activity {
return false; return false;
} }
// first snake cell to check (end of tail), after next move
final int start = max(1, snake.cells.length - snake.size);
// check head is not looped on snake body // check head is not looped on snake body
for (int i = 0; i < snake.cells.length - 1; i++) { for (int i = start; i < snake.cells.length - 1; i++) {
if (head.col == snake.cells[i].col && head.row == snake.cells[i].row) { if (head.col == snake.cells[i].col && head.row == snake.cells[i].row) {
return false; return false;
} }
......
...@@ -3,7 +3,7 @@ description: snake game ...@@ -3,7 +3,7 @@ description: snake game
publish_to: "none" publish_to: "none"
version: 0.5.3+23 version: 0.5.4+24
environment: environment:
sdk: "^3.0.0" sdk: "^3.0.0"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment