aboutsummaryrefslogtreecommitdiff
path: root/src/character.rs
diff options
context:
space:
mode:
authorLuis Ferro <luis.ferro@eggplant.io>2019-11-11 20:02:55 +0100
committerLuis Ferro <luis.ferro@eggplant.io>2019-11-11 20:02:55 +0100
commit0db41de73fb65bdbe2e412f79704cff1874c7312 (patch)
tree083059e57ef9fd6e7c39d37009f9388385f6f232 /src/character.rs
parent5f6768b6a7c954d47ef97809f688df83664e85bc (diff)
Add char generation and positioning in first room of the dungeon
Diffstat (limited to 'src/character.rs')
-rw-r--r--src/character.rs41
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);
}