diff options
author | Guillaume <g@bitimplosion.com> | 2019-11-12 09:50:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-12 09:50:07 +0100 |
commit | 3794736d4bd1149247b8c4d39dc946466b550463 (patch) | |
tree | 9735bd620d04ee24668c3e933ff9436f55658b82 /src/character.rs | |
parent | 5f6768b6a7c954d47ef97809f688df83664e85bc (diff) | |
parent | 5216caa5e64b8be05ff859ba85f90f7a8fa1e6c1 (diff) |
Merge pull request #1 from lferro9000/character_generation
Add char generation and positioning in first room of the dungeon
Diffstat (limited to 'src/character.rs')
-rw-r--r-- | src/character.rs | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/src/character.rs b/src/character.rs index 04b31a8..3e6c4a7 100644 --- a/src/character.rs +++ b/src/character.rs @@ -1,5 +1,7 @@ use std::cmp;
+use crate::world::Point;
+
pub struct Character {
pub name: String,
pub class: String,
@@ -8,7 +10,8 @@ pub struct Character { attack: i32,
dodge: i32,
luck: i32,
- xp: i32
+ xp: i32,
+ location: Point
}
pub trait Player {
@@ -18,9 +21,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 +40,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 +58,8 @@ impl Player for Character { health: i32,
attack: i32,
dodge: i32,
- luck: i32
+ luck: i32,
+ location: Point
) -> Character {
Character {
name: name,
@@ -55,9 +70,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 +85,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 +139,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);
}
|