Skip to content

Commit

Permalink
clippy changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasAlban committed Jun 9, 2023
1 parent cc67063 commit 1b4bac6
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 148 deletions.
3 changes: 0 additions & 3 deletions src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ impl Minesweeper {
self.get_tile_mut(coord).state = TileState::Open;
if self.get_tile(coord).mines == TileMines::Mine {
self.state = GameState::Lost;
return;
} else if self.get_tile(coord).mines == TileMines::NoMine(0) {
// if the tile has no mines around it, open all the tiles around it recursively
for neighbour in self.iter_neighbours(coord) {
Expand All @@ -191,11 +190,9 @@ impl Minesweeper {
}
}
}
return;
}
TileState::Flagged => {
self.get_tile_mut(coord).state = TileState::Closed;
return;
}
TileState::Open => {
if let TileMines::NoMine(n) = self.get_tile(coord).mines {
Expand Down
4 changes: 2 additions & 2 deletions src/rects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ pub fn mouse_intersects_rect(mouse_pos: [f64; 2], rect: [f64; 4]) -> bool {

pub fn get_window_size(game: &Minesweeper) -> [f64; 2] {
[
game.dimensions.x as f64 * TILE_SIZE as f64 + BORDER_SIZE * 2.,
game.dimensions.y as f64 * TILE_SIZE as f64
game.dimensions.x as f64 * TILE_SIZE + BORDER_SIZE * 2.,
game.dimensions.y as f64 * TILE_SIZE
+ BORDER_MIDDLE_POS
+ BORDER_SIZE
+ BORDER_SIZE * BORDER_WIDE_SCALE_FACTOR,
Expand Down
192 changes: 95 additions & 97 deletions src/sprites.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ pub fn tile_sprites<'a>(
// show all flags that aren't mines as wrong
texture = &textures.tile.mine_wrong;
}
} else if game.state == GameState::Won {
if game.get_tile(coord).mines == TileMines::Mine {
// if we have won, show all mines as flagged
texture = &textures.tile.flagged;
}
} else if game.state == GameState::Won && game.get_tile(coord).mines == TileMines::Mine
{
// if we have won, show all mines as flagged
texture = &textures.tile.flagged;
}
sprites.push((image, texture));
}
Expand All @@ -57,95 +56,94 @@ pub fn border_sprites<'a>(
window_size: &Size,
textures: &'a GameTextures,
) -> impl Iterator<Item = (Image, &'a Texture<gfx_device_gl::Resources>)> {
let mut sprites = Vec::new();

// top
sprites.push((
Image::new().rect([0., 0., window_size.width, BORDER_SIZE]),
&textures.border.horizontal,
));
// bottom
sprites.push((
Image::new().rect([
0.,
window_size.height - BORDER_SIZE * BORDER_WIDE_SCALE_FACTOR,
window_size.width,
BORDER_SIZE * BORDER_WIDE_SCALE_FACTOR,
]),
&textures.border.horizontal_wide,
));
// left
sprites.push((
Image::new().rect([0., 0., BORDER_SIZE, window_size.height]),
&textures.border.vertical,
));
// right
sprites.push((
Image::new().rect([
window_size.width - BORDER_SIZE,
0.,
BORDER_SIZE,
window_size.height,
]),
&textures.border.vertical,
));
// middle
sprites.push((
Image::new().rect([0., BORDER_MIDDLE_POS, window_size.width, BORDER_SIZE]),
&textures.border.horizontal,
));
// top left
sprites.push((
Image::new().rect([0., 0., BORDER_SIZE, BORDER_SIZE]),
&textures.border.top_left,
));
// top right
sprites.push((
Image::new().rect([
window_size.width - BORDER_SIZE,
0.,
BORDER_SIZE,
BORDER_SIZE,
]),
&textures.border.top_right,
));
// bottom left
sprites.push((
Image::new().rect([
0.,
window_size.height - BORDER_SIZE * BORDER_WIDE_SCALE_FACTOR,
BORDER_SIZE,
BORDER_SIZE * BORDER_WIDE_SCALE_FACTOR,
]),
&textures.border.bottom_left_wide,
));
// bottom right
sprites.push((
Image::new().rect([
window_size.width - BORDER_SIZE,
window_size.height - BORDER_SIZE * BORDER_WIDE_SCALE_FACTOR,
BORDER_SIZE,
BORDER_SIZE * BORDER_WIDE_SCALE_FACTOR,
]),
&textures.border.bottom_right_wide,
));
// middle left
sprites.push((
Image::new().rect([0., BORDER_MIDDLE_POS, BORDER_SIZE, BORDER_SIZE]),
&textures.border.middle_left,
));
// middle right
sprites.push((
Image::new().rect([
window_size.width - BORDER_SIZE,
BORDER_MIDDLE_POS,
BORDER_SIZE,
BORDER_SIZE,
]),
&textures.border.middle_right,
));

sprites.into_iter()
vec![
// top
(
Image::new().rect([0., 0., window_size.width, BORDER_SIZE]),
&textures.border.horizontal,
),
// bottom
(
Image::new().rect([
0.,
window_size.height - BORDER_SIZE * BORDER_WIDE_SCALE_FACTOR,
window_size.width,
BORDER_SIZE * BORDER_WIDE_SCALE_FACTOR,
]),
&textures.border.horizontal_wide,
),
// left
(
Image::new().rect([0., 0., BORDER_SIZE, window_size.height]),
&textures.border.vertical,
),
// right
(
Image::new().rect([
window_size.width - BORDER_SIZE,
0.,
BORDER_SIZE,
window_size.height,
]),
&textures.border.vertical,
),
// middle
(
Image::new().rect([0., BORDER_MIDDLE_POS, window_size.width, BORDER_SIZE]),
&textures.border.horizontal,
),
// top left
(
Image::new().rect([0., 0., BORDER_SIZE, BORDER_SIZE]),
&textures.border.top_left,
),
// top right
(
Image::new().rect([
window_size.width - BORDER_SIZE,
0.,
BORDER_SIZE,
BORDER_SIZE,
]),
&textures.border.top_right,
),
// bottom left
(
Image::new().rect([
0.,
window_size.height - BORDER_SIZE * BORDER_WIDE_SCALE_FACTOR,
BORDER_SIZE,
BORDER_SIZE * BORDER_WIDE_SCALE_FACTOR,
]),
&textures.border.bottom_left_wide,
),
// bottom right
(
Image::new().rect([
window_size.width - BORDER_SIZE,
window_size.height - BORDER_SIZE * BORDER_WIDE_SCALE_FACTOR,
BORDER_SIZE,
BORDER_SIZE * BORDER_WIDE_SCALE_FACTOR,
]),
&textures.border.bottom_right_wide,
),
// middle left
(
Image::new().rect([0., BORDER_MIDDLE_POS, BORDER_SIZE, BORDER_SIZE]),
&textures.border.middle_left,
),
// middle right
(
Image::new().rect([
window_size.width - BORDER_SIZE,
BORDER_MIDDLE_POS,
BORDER_SIZE,
BORDER_SIZE,
]),
&textures.border.middle_right,
),
]
.into_iter()
}

pub fn face_button_sprite<'a>(
Expand Down Expand Up @@ -187,11 +185,11 @@ pub fn difficulty_buttons_sprites<'a>(
sprites.into_iter()
}

fn num_display_sprites<'a>(
textures: &'a GameTextures,
fn num_display_sprites(
textures: &GameTextures,
num_display_rect: [f64; 4],
num: i32,
) -> impl Iterator<Item = (Image, &'a Texture<gfx_device_gl::Resources>)> {
) -> impl Iterator<Item = (Image, &Texture<gfx_device_gl::Resources>)> {
let mut sprites = Vec::new();
let num = if num < 0 { 0 } else { num };
// the background
Expand Down
94 changes: 48 additions & 46 deletions src/textures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ impl GameTextures {
let mut exe_folder = std::env::current_exe().unwrap();
// remove the executable's name, leaving the path to the containing folder
exe_folder.pop();
// find the assets folder starting from the executable's folder
let assets = find_folder::Search::ParentsThenKids(3, 3)
// find the resources folder starting from the executable's folder
let mut assets = find_folder::Search::ParentsThenKids(3, 3)
.of(exe_folder)
.for_folder("assets")
.for_folder("Resources")
.unwrap();
assets.push("assets");

// return the struct containing all the textures
GameTextures {
tile: TileTextures::new(window, &assets),
Expand Down Expand Up @@ -61,23 +63,23 @@ pub struct TileTextures {
impl MinesweeperTexture for TileTextures {
fn new(window: &mut PistonWindow, assets: &PathBuf) -> Self {
TileTextures {
closed: Self::load_texture(window, &assets, "tiles/tile_closed.png"),
flagged: Self::load_texture(window, &assets, "tiles/tile_flagged.png"),
closed: Self::load_texture(window, assets, "tiles/tile_closed.png"),
flagged: Self::load_texture(window, assets, "tiles/tile_flagged.png"),

mine: Self::load_texture(window, &assets, "tiles/tile_mine.png"),
mine_hit: Self::load_texture(window, &assets, "tiles/tile_mine_hit.png"),
mine_wrong: Self::load_texture(window, &assets, "tiles/tile_mine_wrong.png"),
mine: Self::load_texture(window, assets, "tiles/tile_mine.png"),
mine_hit: Self::load_texture(window, assets, "tiles/tile_mine_hit.png"),
mine_wrong: Self::load_texture(window, assets, "tiles/tile_mine_wrong.png"),

number: [
Self::load_texture(window, &assets, "tiles/tile_0.png"),
Self::load_texture(window, &assets, "tiles/tile_1.png"),
Self::load_texture(window, &assets, "tiles/tile_2.png"),
Self::load_texture(window, &assets, "tiles/tile_3.png"),
Self::load_texture(window, &assets, "tiles/tile_4.png"),
Self::load_texture(window, &assets, "tiles/tile_5.png"),
Self::load_texture(window, &assets, "tiles/tile_6.png"),
Self::load_texture(window, &assets, "tiles/tile_7.png"),
Self::load_texture(window, &assets, "tiles/tile_8.png"),
Self::load_texture(window, assets, "tiles/tile_0.png"),
Self::load_texture(window, assets, "tiles/tile_1.png"),
Self::load_texture(window, assets, "tiles/tile_2.png"),
Self::load_texture(window, assets, "tiles/tile_3.png"),
Self::load_texture(window, assets, "tiles/tile_4.png"),
Self::load_texture(window, assets, "tiles/tile_5.png"),
Self::load_texture(window, assets, "tiles/tile_6.png"),
Self::load_texture(window, assets, "tiles/tile_7.png"),
Self::load_texture(window, assets, "tiles/tile_8.png"),
],
}
}
Expand All @@ -102,19 +104,19 @@ pub struct BorderTextures {
impl MinesweeperTexture for BorderTextures {
fn new(window: &mut PistonWindow, assets: &PathBuf) -> Self {
BorderTextures {
top_left: Self::load_texture(window, &assets, "border/top_left.png"),
top_right: Self::load_texture(window, &assets, "border/top_right.png"),
top_left: Self::load_texture(window, assets, "border/top_left.png"),
top_right: Self::load_texture(window, assets, "border/top_right.png"),

middle_left: Self::load_texture(window, &assets, "border/middle_left.png"),
middle_right: Self::load_texture(window, &assets, "border/middle_right.png"),
middle_left: Self::load_texture(window, assets, "border/middle_left.png"),
middle_right: Self::load_texture(window, assets, "border/middle_right.png"),

bottom_left_wide: Self::load_texture(window, &assets, "border/bottom_left_wide.png"),
bottom_right_wide: Self::load_texture(window, &assets, "border/bottom_right_wide.png"),
bottom_left_wide: Self::load_texture(window, assets, "border/bottom_left_wide.png"),
bottom_right_wide: Self::load_texture(window, assets, "border/bottom_right_wide.png"),

horizontal: Self::load_texture(window, &assets, "border/horizontal.png"),
horizontal_wide: Self::load_texture(window, &assets, "border/horizontal_wide.png"),
horizontal: Self::load_texture(window, assets, "border/horizontal.png"),
horizontal_wide: Self::load_texture(window, assets, "border/horizontal_wide.png"),

vertical: Self::load_texture(window, &assets, "border/vertical.png"),
vertical: Self::load_texture(window, assets, "border/vertical.png"),
}
}
}
Expand All @@ -128,9 +130,9 @@ pub struct FaceButtonTextures {
impl MinesweeperTexture for FaceButtonTextures {
fn new(window: &mut PistonWindow, assets: &PathBuf) -> Self {
FaceButtonTextures {
normal: Self::load_texture(window, &assets, "buttons/face_normal.jpg"),
won: Self::load_texture(window, &assets, "buttons/face_won.jpg"),
lost: Self::load_texture(window, &assets, "buttons/face_lost.jpg"),
normal: Self::load_texture(window, assets, "buttons/face_normal.jpg"),
won: Self::load_texture(window, assets, "buttons/face_won.jpg"),
lost: Self::load_texture(window, assets, "buttons/face_lost.jpg"),
}
}
}
Expand All @@ -149,14 +151,14 @@ pub struct DifficultyButtonTextures {
impl MinesweeperTexture for DifficultyButtonTextures {
fn new(window: &mut PistonWindow, assets: &PathBuf) -> Self {
DifficultyButtonTextures {
easy: Self::load_texture(window, &assets, "buttons/easy.jpg"),
easy_pressed: Self::load_texture(window, &assets, "buttons/easy_pressed.jpg"),
easy: Self::load_texture(window, assets, "buttons/easy.jpg"),
easy_pressed: Self::load_texture(window, assets, "buttons/easy_pressed.jpg"),

medium: Self::load_texture(window, &assets, "buttons/medium.jpg"),
medium_pressed: Self::load_texture(window, &assets, "buttons/medium_pressed.jpg"),
medium: Self::load_texture(window, assets, "buttons/medium.jpg"),
medium_pressed: Self::load_texture(window, assets, "buttons/medium_pressed.jpg"),

hard: Self::load_texture(window, &assets, "buttons/hard.jpg"),
hard_pressed: Self::load_texture(window, &assets, "buttons/hard_pressed.jpg"),
hard: Self::load_texture(window, assets, "buttons/hard.jpg"),
hard_pressed: Self::load_texture(window, assets, "buttons/hard_pressed.jpg"),
}
}
}
Expand All @@ -169,18 +171,18 @@ pub struct NumberDisplayTextures {
impl MinesweeperTexture for NumberDisplayTextures {
fn new(window: &mut PistonWindow, assets: &PathBuf) -> Self {
NumberDisplayTextures {
background: Self::load_texture(window, &assets, "number_display/background.jpg"),
background: Self::load_texture(window, assets, "number_display/background.jpg"),
numbers: [
Self::load_texture(window, &assets, "number_display/0.jpg"),
Self::load_texture(window, &assets, "number_display/1.jpg"),
Self::load_texture(window, &assets, "number_display/2.jpg"),
Self::load_texture(window, &assets, "number_display/3.jpg"),
Self::load_texture(window, &assets, "number_display/4.jpg"),
Self::load_texture(window, &assets, "number_display/5.jpg"),
Self::load_texture(window, &assets, "number_display/6.jpg"),
Self::load_texture(window, &assets, "number_display/7.jpg"),
Self::load_texture(window, &assets, "number_display/8.jpg"),
Self::load_texture(window, &assets, "number_display/9.jpg"),
Self::load_texture(window, assets, "number_display/0.jpg"),
Self::load_texture(window, assets, "number_display/1.jpg"),
Self::load_texture(window, assets, "number_display/2.jpg"),
Self::load_texture(window, assets, "number_display/3.jpg"),
Self::load_texture(window, assets, "number_display/4.jpg"),
Self::load_texture(window, assets, "number_display/5.jpg"),
Self::load_texture(window, assets, "number_display/6.jpg"),
Self::load_texture(window, assets, "number_display/7.jpg"),
Self::load_texture(window, assets, "number_display/8.jpg"),
Self::load_texture(window, assets, "number_display/9.jpg"),
],
}
}
Expand Down

0 comments on commit 1b4bac6

Please sign in to comment.