when you finish the game, you won

master
kirbylife 2019-06-18 13:50:29 -05:00
parent 55b90b248f
commit 6b28b62fac
1 changed files with 18 additions and 0 deletions

View File

@ -73,6 +73,19 @@ fn reveal(pivot: [usize; 2], mut board: [[char; COLUMNS]; ROWS], game: [[i8; COL
board board
} }
fn check_revealed(board: [[char; COLUMNS]; ROWS], game: [[i8; COLUMNS]; ROWS]) -> i32 {
// Return the number of boxes already revealed
let mut count: i32 = 0;
for (i, row) in board.iter().enumerate() {
for (j, item) in row.iter().enumerate() {
if game[i][j] != -1 && item != &'#' && item != &'-' {
count += 1;
}
}
}
count
}
fn main() { fn main() {
let mut running = true; let mut running = true;
let mut board = [['-'; COLUMNS]; ROWS]; let mut board = [['-'; COLUMNS]; ROWS];
@ -86,6 +99,11 @@ fn main() {
while running == true { while running == true {
clear(); clear();
let revealed = check_revealed(board, game);
if revealed == ((COLUMNS * ROWS) as i32 - MINES) {
print!("You win");
break;
}
for (i, row) in board.iter().enumerate() { for (i, row) in board.iter().enumerate() {
for (j, item) in row.iter().enumerate() { for (j, item) in row.iter().enumerate() {
if pivot[0] == i && pivot[1] == j { if pivot[0] == i && pivot[1] == j {