aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorcurly <curlybryce@protonmail.com>2022-08-15 15:49:56 -0600
committercurly <curlybryce@protonmail.com>2022-08-15 15:49:56 -0600
commit462c1f8bf195a1e30b6c05be7a0ec60ee89d230c (patch)
tree6965d94cfaabecef461597cf8de4b30cc225cfdc /src/lib.rs
parent008c2b23c78f8969c9741e537326c13b98c27b58 (diff)
downloadtetris-462c1f8bf195a1e30b6c05be7a0ec60ee89d230c.tar.gz
tetris-462c1f8bf195a1e30b6c05be7a0ec60ee89d230c.tar.bz2
tetris-462c1f8bf195a1e30b6c05be7a0ec60ee89d230c.zip
half working
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs42
1 files changed, 34 insertions, 8 deletions
diff --git a/src/lib.rs b/src/lib.rs
index ce1d7ad..99a347e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,6 +1,9 @@
pub mod input;
mod tetris;
+mod display;
+use crate::tetris::piece;
+use std::io::stdin;
use crate::input::Input;
pub struct Game {
@@ -16,14 +19,37 @@ impl Game {
}
// The actual game loop
- pub fn game_loop(&self, input: &Input) {}
-}
+ pub fn game_loop(&self, input: &Input) {
+ let mut tetris = tetris::Tetris::new();
+ let mut piece = piece::Piece::random();
+ loop {
+ piece.r#move(piece::Dir::Down, &tetris);
-#[cfg(test)]
-mod tests {
- #[test]
- fn it_works() {
- let result = 2 + 2;
- assert_eq!(result, 4);
+ // Check if piece is dead
+ if piece.is_alive() == false {
+ piece.apply_to_grid(&mut tetris);
+ // piece = piece::Piece::random();
+ piece = piece::Piece::new(piece::Pieces::Cube);
+ }
+
+ let grid = tetris.return_grid();
+ display::display(&grid, &piece);
+
+ let mut input = String::new();
+
+ stdin().read_line(&mut input).expect("Could not read line");
+ let input = input.get(0..1).expect("Nothing to get");
+ match input {
+ "a" => piece.r#move(piece::Dir::Left, &tetris),
+ "d" => piece.r#move(piece::Dir::Right, &tetris),
+ "e" => piece.rotate(piece::Rotate::Right),
+ "q" => piece.rotate(piece::Rotate::Right),
+ " " => break,
+ _ => (),
+ }
+ }
}
}
+
+#[cfg(test)]
+mod tests {}