aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortyropro <[email protected]>2024-02-07 22:15:36 +0000
committerGitHub <[email protected]>2024-02-07 22:15:36 +0000
commit718cb676321ae1fee95b744179ff6a2663191f1f (patch)
treebb6836d25978b5808c19f34a669818ba402af465
parent32edf17c901f35d9e5e9ae15906342c3853ec841 (diff)
used let if and match to define the number of players and the "movement object"
-rw-r--r--src/main.rs20
1 files changed, 7 insertions, 13 deletions
diff --git a/src/main.rs b/src/main.rs
index 98cde7d..20a4ad9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -100,13 +100,11 @@ fn check_movement(mut space: u8) -> u8 {
let space_index: usize = (space - 1) as usize;
if BOARD[space_index] != 0 {
- let movement_object: &str;
-
- if BOARD[space_index] > space {
- movement_object = "ladder";
+ let movement_object: &str = if BOARD[space_index] > space {
+ "ladder"
} else {
- movement_object = "snake";
- }
+ "snake"
+ };
space = BOARD[space_index]; // sets space to the end of the object (snake or ladder)
@@ -132,17 +130,13 @@ fn main() {
let raw_no_players: Result<u8, _> = str_no_players.trim().parse();
- let no_players: u8;
-
- match raw_no_players {
- Ok(parsed_num) => {
- no_players = parsed_num;
- },
+ let no_players: u8 = match raw_no_players {
+ Ok(parsed_num) => parsed_num,
Err(_) => {
println!("Please enter a valid unsigned integer");
return;
},
- }
+ };
for i in 0..no_players {
// creates new players