summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2024-01-19 23:47:43 -0800
committerRose Hogenson <rosehogenson@posteo.net>2024-01-19 23:47:43 -0800
commit257f624e1587744a5665970b905f74dc999fded1 (patch)
tree10cf6ac1b802b35f8a5d05e675e307b82b63362a /src/main.rs
parentRead directly in the main game loop. (diff)
downloadsnake-257f624e1587744a5665970b905f74dc999fded1.tar.zst
Use i8 for position instead of u16.
The only reason I picked u16 is because it's what ioctl returns for the window size. But we're actually just hard-coding the window size, so I don't need to use u16. I prefer to use a signed type.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs
index 3b36b2e..c98c0ca 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -9,11 +9,11 @@ fn rand(max: i32) -> i32 {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
struct Pos {
- row: u16,
- col: u16,
+ row: i8,
+ col: i8,
}
-fn pos(row: u16, col: u16) -> Pos {
+fn pos(row: i8, col: i8) -> Pos {
Pos { row, col }
}
@@ -52,8 +52,8 @@ struct Screen {
}
impl Screen {
- const ROWS: u16 = 25;
- const COLS: u16 = 50;
+ const ROWS: i8 = 25;
+ const COLS: i8 = 50;
fn init() -> Result<Screen, Box<dyn Error>> {
// Get current terminal attrs.
@@ -239,8 +239,8 @@ impl Fruit {
}
fn new_pos(&mut self) {
- self.pos.row = rand(i32::from(Screen::ROWS) - 4) as u16 + 2;
- self.pos.col = rand(i32::from(Screen::COLS) - 4) as u16 + 2;
+ self.pos.row = rand(i32::from(Screen::ROWS) - 4) as i8 + 2;
+ self.pos.col = rand(i32::from(Screen::COLS) - 4) as i8 + 2;
}
}