diff --git a/src/app.rs b/src/app.rs index cc5a343..22e183a 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,16 +1,14 @@ -use serde::{Deserialize, Serialize}; // use serde_wasm_bindgen::to_value; use wasm_bindgen::prelude::*; -use web_sys::AddEventListenerOptions; // use wasm_bindgen_futures::spawn_local; use yew::{prelude::*, html::Scope}; -use log::info; -use wasm_bindgen::JsValue; +// use log::info; +// use wasm_bindgen::JsValue; -use minesweeper_ui::components::{button::Button, board::BoardComponent}; +use minesweeper_ui::components::board::BoardComponent; -use minesweeper_ui::minesweeper::{cell::Cell, board::Board, Game}; +use minesweeper_ui::minesweeper::{cell::Cell, Game}; #[wasm_bindgen] extern "C" { @@ -20,12 +18,16 @@ extern "C" { pub enum Msg { Discover{ cell: Cell }, - Flag{ cell: Cell } + Flag{ cell: Cell }, + Reset } pub struct App { link: Scope, - game: Game + game: Game, + height: usize, + width: usize, + num_mines: usize } impl Component for App { @@ -34,32 +36,47 @@ impl Component for App { type Properties = (); fn create(ctx: &Context) -> Self { - let height = 100; - let width = 41; + let height = 30; + let width = 30; let num_mines =(height * width / 10) as usize; - let mut game = Game::new(height, width, num_mines); + let mut game = Game::new(height, width, 5); game.start_board(); Self { link: ctx.link().clone(), - game + game, + height, + width, + num_mines } } - fn view(&self, ctx: &Context) -> Html { + fn view(&self, _ctx: &Context) -> Html { let b = self.game.get_board().clone(); html!{
// Disable context menu - // - - + + +
+ +
+ +
+
+
} } - fn update(&mut self, ctx: &Context, msg: Self::Message) -> bool { + fn update(&mut self, _ctx: &Context, msg: Self::Message) -> bool { match msg { Msg::Discover {cell} => { self.game.show(cell.get_pos()); @@ -67,6 +84,10 @@ impl Component for App { Msg::Flag {cell} => { self.game.set_flag(cell.get_pos(), !self.game.get_cell(cell.get_pos()).is_flagged()); } + Msg::Reset => { + self.game = Game::new(self.height, self.width, self.num_mines); + self.game.start_board(); + } } true } diff --git a/src/components/board.rs b/src/components/board.rs index 460fa7b..df3cf55 100644 --- a/src/components/board.rs +++ b/src/components/board.rs @@ -4,8 +4,8 @@ use crate::minesweeper::{board::Board, cell::Cell}; use crate::components::button::Button; -use log::info; -use wasm_bindgen::JsValue; +// use log::info; +// use wasm_bindgen::JsValue; pub struct BoardComponent { link: Scope, @@ -62,7 +62,7 @@ impl Component for BoardComponent { } } - fn update(&mut self, ctx: &Context, msg: Self::Message) -> bool { + fn update(&mut self, _ctx: &Context, msg: Self::Message) -> bool { match msg { Msg::Discover {cell} => { self.onsignal.emit(cell); diff --git a/src/components/button.rs b/src/components/button.rs index ec1fd4f..fa365b6 100644 --- a/src/components/button.rs +++ b/src/components/button.rs @@ -1,8 +1,8 @@ use yew::{prelude::*, html::Scope}; use crate::minesweeper::cell::Cell; -use log::info; -use wasm_bindgen::JsValue; +// use log::info; +// use wasm_bindgen::JsValue; pub struct Button { link: Scope, @@ -36,7 +36,7 @@ impl Component for Button { } } - fn view(&self, ctx: &Context) -> Html { + fn view(&self, _ctx: &Context) -> Html { let mut style = String::new(); if !self.cell.is_hidden() { style = format!("background-color: #2f2f2f; color: #ffffff; transition: background-color 0.5s, color 0.5s; transition-delay: {}s, {}s;", self.cell.get_delay(), self.cell.get_delay()); @@ -46,7 +46,7 @@ impl Component for Button {