diff --git a/Cargo.toml b/Cargo.toml index f3822a8..cbc70a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,6 @@ name = "minesweeper" version = "0.1.0" authors = ["Alexander Kuvaev "] -license-file = "LICENSE" description = "Simple minesweeper in Rust" repository = "https://github.com/Vinatorul/minesweeper-rs.git" readme = "README.md" diff --git a/src/game.rs b/src/game.rs index 577ac03..1de1b5e 100644 --- a/src/game.rs +++ b/src/game.rs @@ -22,14 +22,14 @@ impl Game { self.draw_field(window); } - fn get_field_size(&self, window: &PistonWindow) -> [u32; 2] { - [window.size().width, window.size().height] + fn get_max_field_size(&self, window: &PistonWindow) -> [u32; 2] { + [2*window.size().width/3, window.size().height] } fn draw_field(&mut self, window: &PistonWindow) { - let field_size = self.get_field_size(window); - let cell_w = (field_size[0] / self.field.get_width()) as f64; - let cell_h = (field_size[1] / self.field.get_height()) as f64; + let max_field_size = self.get_max_field_size(window); + let cell_w = (max_field_size[0] / self.field.get_width()) as f64; + let cell_h = (max_field_size[1] / self.field.get_height()) as f64; window.draw_2d(|c, g| { clear([0.0, 0.0, 0.0, 1.0], g); for i in 0..self.field.get_width() { @@ -61,6 +61,17 @@ impl Game { } } } + let field_size = [cell_w*(self.field.get_width() as f64), cell_h*(self.field.get_height() as f64)]; + for i in 0..self.field.get_width()+1 { + line::Line::new([0.5, 0.5, 0.5, 1.0], 1.0) + .draw([(i as f64)*cell_w, 0.0, (i as f64)*cell_w, field_size[1]], + &c.draw_state, + c.transform, g); + line::Line::new([0.5, 0.5, 0.5, 1.0], 1.0) + .draw([0.0, (i as f64)*cell_h, field_size[0], (i as f64)*cell_h], + &c.draw_state, + c.transform, g); + } }); } @@ -75,9 +86,13 @@ impl Game { Button::Mouse(btn) => { match btn { MouseButton::Left => { - let field_size = self.get_field_size(window); - let cell_w = field_size[0] / self.field.get_width(); - let cell_h = field_size[1] / self.field.get_height(); + let max_field_size = self.get_max_field_size(window); + let cell_w = max_field_size[0] / self.field.get_width(); + let cell_h = max_field_size[1] / self.field.get_height(); + if (self.mouse_x > (cell_w*self.field.get_width()) as f64) || + (self.mouse_y > (cell_h*self.field.get_height()) as f64) { + return; + } let x = (self.mouse_x.floor() as u32)/cell_w; let y = (self.mouse_y.floor() as u32)/cell_h; let w = self.field.get_width(); diff --git a/src/main.rs b/src/main.rs index 2208754..cdba903 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,7 @@ fn main() { .arg(Arg::from_usage("--height [height] 'window height'")) .get_matches(); - let mut width = 800; + let mut width = 1024; let mut height = 600; if let Some(w) = matches.value_of("width") { width = w.parse().unwrap_or(width);