rustsweeper proper win conditions
This commit is contained in:
parent
10d452ec33
commit
a754491f68
@ -1,7 +1,6 @@
|
|||||||
use std::io::{stdin,stdout,Write};
|
use std::io::{stdin,stdout,Write};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use colored::*;
|
use colored::*;
|
||||||
use colored::Color::TrueColor;
|
|
||||||
use console::Term;
|
use console::Term;
|
||||||
|
|
||||||
fn output_board(board: &Vec<Vec<i64>>, state: &Vec<Vec<char>>, x_hovered: i64, y_hovered: i64) {
|
fn output_board(board: &Vec<Vec<i64>>, state: &Vec<Vec<char>>, x_hovered: i64, y_hovered: i64) {
|
||||||
@ -218,6 +217,21 @@ fn uncover(board: &Vec<Vec<i64>>, state: &mut Vec<Vec<char>>, x_hovered: usize,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn detect_win(state: &Vec<Vec<char>>, number_of_nails: i64) {
|
||||||
|
let mut number_of_covered_cells: i64 = 0;
|
||||||
|
for y in 0..state.len() {
|
||||||
|
for x in 0..state[y].len() {
|
||||||
|
if state[y][x] != 'u' {
|
||||||
|
number_of_covered_cells = number_of_covered_cells + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if number_of_covered_cells == number_of_nails {
|
||||||
|
println!("Congratulations, you won!!!");
|
||||||
|
std::process::exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let stdout = Term::buffered_stdout();
|
let stdout = Term::buffered_stdout();
|
||||||
|
|
||||||
@ -276,6 +290,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
if alive {
|
if alive {
|
||||||
output_board(&board, &state, x_hovered, y_hovered);
|
output_board(&board, &state, x_hovered, y_hovered);
|
||||||
|
detect_win(&state, number_of_nails);
|
||||||
}
|
}
|
||||||
else if alive == false {
|
else if alive == false {
|
||||||
println!("GAME OVER!\nYou got Tetanus!");
|
println!("GAME OVER!\nYou got Tetanus!");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user