Skip to content

Instantly share code, notes, and snippets.

@jmcnevin
Created January 19, 2015 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmcnevin/8b2840ea76c2698eaf1e to your computer and use it in GitHub Desktop.
Save jmcnevin/8b2840ea76c2698eaf1e to your computer and use it in GitHub Desktop.
use actors::Race::*;
pub enum Race {
Human,
Robot,
Dog,
Wolf,
Bear
}
impl Race {
pub fn max_health(&self) -> usize {
match *self {
Human => 10,
Robot => 30,
Dog => 5,
Wolf => 8,
Bear => 15
}
}
pub fn damage(&self) -> usize {
match *self {
Human => 3,
Robot => 5,
Dog => 1,
Wolf => 2,
Bear => 3
}
}
pub fn greeting(&self) -> &str {
match *self {
Human => "Hey",
Robot => "Beep",
Dog => "Woof",
Wolf => "Growl",
Bear => "ROAR"
}
}
}
pub struct Monster {
pub race: Race,
pub health: usize
}
impl Monster {
pub fn new(race: Race) -> Monster {
Monster {
race: race,
health: race.max_health()
}
}
pub fn say_hello(&self) -> &str {
self.race.greeting()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment