2012-09-25 17:22:28 -05:00
|
|
|
#[legacy_exports];
|
|
|
|
|
2012-09-05 14:32:05 -05:00
|
|
|
use to_str::*;
|
|
|
|
use to_str::ToStr;
|
2012-04-26 14:15:46 -05:00
|
|
|
|
|
|
|
mod kitty {
|
2012-09-21 20:10:45 -05:00
|
|
|
#[legacy_exports];
|
2012-04-26 14:15:46 -05:00
|
|
|
|
2012-09-07 21:04:40 -05:00
|
|
|
struct cat {
|
2012-09-10 20:56:07 -05:00
|
|
|
priv mut meows : uint,
|
2012-09-06 21:40:15 -05:00
|
|
|
mut how_hungry : int,
|
|
|
|
name : ~str,
|
2012-09-07 21:04:40 -05:00
|
|
|
}
|
2012-04-26 14:15:46 -05:00
|
|
|
|
2012-09-07 21:04:40 -05:00
|
|
|
impl cat : ToStr {
|
2012-10-11 16:12:50 -05:00
|
|
|
pure fn to_str() -> ~str { self.name }
|
2012-04-26 14:15:46 -05:00
|
|
|
}
|
|
|
|
|
2012-09-07 21:04:40 -05:00
|
|
|
priv impl cat {
|
|
|
|
fn meow() {
|
|
|
|
error!("Meow");
|
|
|
|
self.meows += 1u;
|
|
|
|
if self.meows % 5u == 0u {
|
|
|
|
self.how_hungry += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2012-09-05 17:58:43 -05:00
|
|
|
|
2012-09-07 21:04:40 -05:00
|
|
|
impl cat {
|
|
|
|
fn speak() { self.meow(); }
|
|
|
|
|
|
|
|
fn eat() -> bool {
|
|
|
|
if self.how_hungry > 0 {
|
|
|
|
error!("OM NOM NOM");
|
|
|
|
self.how_hungry -= 2;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
error!("Not hungry!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-09-05 17:58:43 -05:00
|
|
|
fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
|
|
|
|
cat {
|
|
|
|
meows: in_x,
|
|
|
|
how_hungry: in_y,
|
|
|
|
name: in_name
|
|
|
|
}
|
2012-04-26 14:15:46 -05:00
|
|
|
}
|
2012-09-05 17:58:43 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|