Skip to content

fixed compiler warnings in snake-game #597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions microbit/src/11-snake-game/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ optional = true
[dependencies]
cortex-m = "0.7.3"
cortex-m-rt = "0.7.0"
rtt-target = { version = "0.3.1", features = ["cortex-m"] }
panic-rtt-target = { version = "0.1.2", features = ["cortex-m"] }
lsm303agr = "0.2.2"
nb = "1.0.0"
libm = "0.2.1"
heapless = "0.8.0"
tiny-led-matrix = "1.0.1"
rtt-target = "0.6.1"
panic-rtt-target = "0.2.0"

[features]
v2 = ["microbit-v2"]
Expand Down
14 changes: 7 additions & 7 deletions microbit/src/11-snake-game/src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ pub enum GameStatus {
/// The outcome of a single move/step.
enum StepOutcome {
/// Grid full (player wins)
Full(Coords),
Full,
/// Snake has collided with itself (player loses)
Collision(Coords),
Collision,
/// Snake has eaten some food
Eat(Coords),
/// Snake has moved (and nothing else has happened)
Expand Down Expand Up @@ -248,13 +248,13 @@ impl Game {
// won't actually be any collision (as the tail will have moved by the time the head
// moves onto the tile)
if next_move != *self.snake.tail.peek().unwrap() {
StepOutcome::Collision(next_move)
StepOutcome::Collision
} else {
StepOutcome::Move(next_move)
}
} else if next_move == self.food_coords {
if self.snake.tail.len() == 23 {
StepOutcome::Full(next_move)
StepOutcome::Full
} else {
StepOutcome::Eat(next_move)
}
Expand All @@ -266,8 +266,8 @@ impl Game {
/// Handle the outcome of a step, updating the game's internal state.
fn handle_step_outcome(&mut self, outcome: StepOutcome) {
self.status = match outcome {
StepOutcome::Collision(_) => GameStatus::Lost,
StepOutcome::Full(_) => GameStatus::Won,
StepOutcome::Collision => GameStatus::Lost,
StepOutcome::Full => GameStatus::Won,
StepOutcome::Eat(c) => {
self.snake.move_snake(c, true);
self.place_food();
Expand Down Expand Up @@ -333,4 +333,4 @@ impl Game {
}
values
}
}
}
2 changes: 1 addition & 1 deletion microbit/src/11-snake-game/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::game::{Game, GameStatus};
#[entry]
fn main() -> ! {
rtt_init_print!();
let mut board = Board::take().unwrap();
let board = Board::take().unwrap();
let mut timer = Timer::new(board.TIMER0).into_periodic();
let mut rng = Rng::new(board.RNG);
let mut game = Game::new(rng.random_u32());
Expand Down
Loading