Compare commits
3 commits
1e276e61ff
...
fc49a2add1
Author | SHA1 | Date | |
---|---|---|---|
|
fc49a2add1 | ||
|
d35a92ed23 | ||
|
e8b6170797 |
3 changed files with 2528 additions and 7 deletions
|
@ -1,10 +1,16 @@
|
||||||
#[repr(u8)]
|
#[derive(PartialEq, Eq)]
|
||||||
pub enum Play {
|
pub enum Play {
|
||||||
Rock,
|
Rock,
|
||||||
Paper,
|
Paper,
|
||||||
Scissors,
|
Scissors,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum ResultPlay {
|
||||||
|
Win,
|
||||||
|
Draw,
|
||||||
|
Loss,
|
||||||
|
}
|
||||||
|
|
||||||
impl Into<char> for Play {
|
impl Into<char> for Play {
|
||||||
fn into(self) -> char {
|
fn into(self) -> char {
|
||||||
match self {
|
match self {
|
||||||
|
@ -25,12 +31,27 @@ impl Into<i32> for Play {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn translate(letter: char) -> Option<Play> {
|
impl From<char> for Play {
|
||||||
|
fn from(letter: char) -> Self {
|
||||||
match letter {
|
match letter {
|
||||||
'A' => Some(Play::Rock),
|
'A' => Play::Rock,
|
||||||
'B' => Some(Play::Paper),
|
'B' => Play::Paper,
|
||||||
'C' => Some(Play::Scissors),
|
'C' => Play::Scissors,
|
||||||
_ => None,
|
'X' => Play::Rock,
|
||||||
|
'Y' => Play::Paper,
|
||||||
|
'Z' => Play::Scissors,
|
||||||
|
_ => panic!("Only A, B, C, X, Y or Z letters are available."),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Into<i32> for ResultPlay {
|
||||||
|
fn into(self) -> i32 {
|
||||||
|
match self {
|
||||||
|
ResultPlay::Win => 6,
|
||||||
|
ResultPlay::Draw => 3,
|
||||||
|
ResultPlay::Loss => 0,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue