diff options
Diffstat (limited to 'src/character.rs')
-rw-r--r-- | src/character.rs | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/src/character.rs b/src/character.rs index 04b31a8..76f4414 100644 --- a/src/character.rs +++ b/src/character.rs @@ -1,5 +1,8 @@ use std::cmp;
+use crate::world::Point;
+
+#[derive(Default)]
pub struct Character {
pub name: String,
pub class: String,
@@ -8,7 +11,8 @@ pub struct Character { attack: i32,
dodge: i32,
luck: i32,
- xp: i32
+ xp: i32,
+ location: Point
}
pub trait Player {
@@ -18,9 +22,12 @@ pub trait Player { health: i32,
attack: i32,
dodge: i32,
- luck: i32
+ luck: i32,
+ location: Point
) -> Character;
+ fn place(&mut self, location: Point);
+
fn select(&self, player_name: String, player_luck: i32) -> Self;
fn damage(&mut self, damage_amount: i32);
@@ -34,8 +41,16 @@ pub trait Player { fn info(&self) -> String;
fn stats(&self) -> String;
+
+ fn walk(&mut self, dir: Direction);
}
+pub enum Direction {
+ North,
+ South,
+ East,
+ West
+}
impl Player for Character {
fn new(
@@ -44,7 +59,8 @@ impl Player for Character { health: i32,
attack: i32,
dodge: i32,
- luck: i32
+ luck: i32,
+ location: Point
) -> Character {
Character {
name: name,
@@ -55,9 +71,14 @@ impl Player for Character { dodge: dodge,
luck: luck,
xp: 0,
+ location: location
}
}
+ fn place(&mut self, location: Point) {
+ self.location = location;
+ }
+
fn select(&self, player_name: String, player_luck: i32) -> Self {
Self::new(
player_name,
@@ -65,10 +86,20 @@ impl Player for Character { self.health,
self.attack,
self.dodge,
- self.luck + player_luck
+ self.luck + player_luck,
+ (0,0)
)
}
+ fn walk(&mut self, dir: Direction) {
+ match dir {
+ Direction::North => { (); },
+ Direction::South => { (); },
+ Direction::East => { (); },
+ Direction::West => { (); }
+ }
+ }
+
fn damage(&mut self, damage_amount: i32) {
self.health = cmp::max(0, self.health - damage_amount);
self.xp += 2;
@@ -109,7 +140,7 @@ mod tests { use super::*;
fn test_attack() {
- let player = Character::new("".to_string(), "Rogue".to_string(), 1, 4, 1, 4);
+ let player = Character::new("".to_string(), "Rogue".to_string(), 1, 4, 1, 4, (0,0));
assert_eq!(player.attack(), 6);
}
|