From 257f624e1587744a5665970b905f74dc999fded1 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Fri, 19 Jan 2024 23:47:43 -0800 Subject: 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. --- src/main.rs | 14 +++++++------- 1 file 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> { // 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; } } -- cgit v1.3.1