diff options
author | Guillaume Pasquet <guillaume.pasquet@eggplant.io> | 2019-11-12 10:47:03 +0100 |
---|---|---|
committer | Guillaume Pasquet <guillaume.pasquet@eggplant.io> | 2019-11-12 10:47:03 +0100 |
commit | dbb1f294d59211df1ecdece2e2d1ac61f49c144a (patch) | |
tree | f54203786a965eefa375459315a1e9c3cae338e5 /src | |
parent | 9f95c253433e84bff929e5f001a919cb84110003 (diff) | |
parent | 3794736d4bd1149247b8c4d39dc946466b550463 (diff) |
Merge branch 'master' of github.com:Etenil/roguerust
Diffstat (limited to 'src')
-rw-r--r-- | src/character.rs | 40 | ||||
-rw-r--r-- | src/main.rs | 20 | ||||
-rw-r--r-- | src/world.rs | 9 |
3 files changed, 59 insertions, 10 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);
}
diff --git a/src/main.rs b/src/main.rs index 776e224..022315c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,7 @@ mod computer; mod world; use character::Player; +use character::Character; use computer::Enemy; use pancurses::{Window, initscr, endwin}; use world::{Dungeon, Level, Generable, TileType}; @@ -39,7 +40,7 @@ fn render_level(window: &Window, level: &Level) { } } -fn debug_level(level: &Level) { +fn debug_level(level: Level) { let grid = level.to_tilegrid().unwrap(); for line in grid.raw_data().iter() { @@ -55,9 +56,20 @@ fn main() { let mut dungeon = Dungeon::new(80, 24, 5); dungeon.generate(); - for l in dungeon.levels { - debug_level(&l); - } + let start_location = dungeon.levels[0].get_start_point(); + + let mut character: Character = Character::new( + "Kshar".to_string(), + "Warror".to_string(), + 30, + 10, + 10, + 20, + start_location + ); + character.place(start_location); + + dungeon.levels.into_iter().map(debug_level); // let window = initscr(); diff --git a/src/world.rs b/src/world.rs index f2f3470..23bed8a 100644 --- a/src/world.rs +++ b/src/world.rs @@ -1,6 +1,6 @@ use rand::Rng;
-type Point = (usize, usize);
+pub type Point = (usize, usize);
#[derive(Clone)]
pub enum TileType {
@@ -264,6 +264,13 @@ impl Level { Ok(grid)
}
+ pub fn get_start_point(&self) -> Point {
+ if self.rooms.len() > 0 {
+ return self.rooms[0].center;
+ }
+ return (0,0)
+ }
+
fn overlaps(&self, start: Point, width: usize, height: usize, padding: usize) -> bool {
for room in &self.rooms {
if room.start.0 < start.0 + width + padding &&
|