From 0db41de73fb65bdbe2e412f79704cff1874c7312 Mon Sep 17 00:00:00 2001 From: Luis Ferro Date: Mon, 11 Nov 2019 20:02:55 +0100 Subject: Add char generation and positioning in first room of the dungeon --- src/character.rs | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) (limited to 'src/character.rs') 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); } -- cgit v1.2.3 From 5216caa5e64b8be05ff859ba85f90f7a8fa1e6c1 Mon Sep 17 00:00:00 2001 From: Luis Ferro Date: Tue, 12 Nov 2019 09:44:34 +0100 Subject: Fix diff and remove default macro --- src/character.rs | 1 - src/world.rs | 4 ---- 2 files changed, 5 deletions(-) (limited to 'src/character.rs') diff --git a/src/character.rs b/src/character.rs index 76f4414..3e6c4a7 100644 --- a/src/character.rs +++ b/src/character.rs @@ -2,7 +2,6 @@ use std::cmp; use crate::world::Point; -#[derive(Default)] pub struct Character { pub name: String, pub class: String, diff --git a/src/world.rs b/src/world.rs index d55a9e5..05b82ed 100644 --- a/src/world.rs +++ b/src/world.rs @@ -193,13 +193,9 @@ pub trait GameWorld { fn generate(&mut self); -<<<<<<< Updated upstream fn to_tilegrid(&self) -> Result; -======= - fn to_tilegrid(&self) -> TileGrid; fn get_start_location(&self) -> Point; ->>>>>>> Stashed changes } fn hor_dist(point1: Point, point2: Point) -> f32 { -- cgit v1.2.3