Created
June 28, 2013 21:11
-
-
Save MarkJr94/5888147 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// mummy.rs | |
use pc::PC; | |
use common::{Character}; | |
#[deriving(ToStr)] | |
pub struct Mummy { | |
hp: uint, | |
attack: uint, | |
x: int, | |
y: int | |
} | |
impl Character for Mummy { | |
pub fn x(&self) -> int { | |
self.x | |
} | |
pub fn y(&self) -> int { | |
self.y | |
} | |
pub fn set_x(&mut self, new_x: int) { | |
self.x = new_x; | |
} | |
pub fn set_y(&mut self, new_y:int) { | |
self.y = new_y; | |
} | |
pub fn translate(&mut self, dx: int, dy: int) { | |
self.x += dx; | |
self.y += dy; | |
} | |
pub fn new(x: int, y: int) -> Mummy { | |
Mummy {hp: 5u, attack: 3u, x: x, y: y } | |
} | |
pub fn attack(&mut self, player: &mut Character) -> uint { | |
let op_hp = player.hp_mut(); | |
*op_hp -= self.attack; | |
self.attack | |
} | |
pub fn name(&self) -> ~str { | |
~"Mummy" | |
} | |
pub fn rest(&mut self) { } | |
pub fn as_str(&self) -> ~str { | |
self.to_str() | |
} | |
pub fn hp(&self) -> uint { | |
self.hp | |
} | |
pub fn hp_mut<'r>(&'r mut self) -> &'r mut uint { | |
&'r mut self.hp | |
} | |
pub fn stamina(&self) -> uint { | |
100 | |
} | |
} | |
// Compiler error | |
monster/mummy.rs:39:21: 39:27 error: cannot borrow immutable argument as mutable | |
monster/mummy.rs:39 let op_hp = player.hp_mut(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment