diff options
author | Guillaume Pasquet <dev@etenil.net> | 2019-11-19 04:23:57 +0000 |
---|---|---|
committer | Guillaume Pasquet <dev@etenil.net> | 2019-11-19 04:23:57 +0000 |
commit | 649e209c64a86e951bf24805e369143888f33c9a (patch) | |
tree | d7cb3e64f924392ba9683b01a69d94bae9b8f51b | |
parent | 591e0dad70e8aa9514039f9193dfcd57d6334a7f (diff) |
`get_` getters don't appear to be idiomatic rust
-rw-r--r-- | src/entities.rs | 21 | ||||
-rw-r--r-- | src/main.rs | 4 | ||||
-rw-r--r-- | src/state.rs | 15 | ||||
-rw-r--r-- | src/tiling.rs | 2 | ||||
-rw-r--r-- | src/world.rs | 12 |
5 files changed, 29 insertions, 25 deletions
diff --git a/src/entities.rs b/src/entities.rs index 4265b1d..79f482b 100644 --- a/src/entities.rs +++ b/src/entities.rs @@ -9,11 +9,11 @@ pub trait Entity { /// Initial placement of the entity
fn place(&mut self, location: Point);
/// Get the tiletype for the entity
- fn get_tiletype(&self) -> &TileType;
+ fn tiletype(&self) -> &TileType;
/// Get the entity's current location
- fn get_location(&self) -> &Point;
+ fn location(&self) -> &Point;
/// Get the entity's previous location (before it moved)
- fn get_previous_location(&self) -> &Point;
+ fn previous_location(&self) -> &Point;
/// Move the entity to another point
fn move_to(&mut self, location: Point);
/// Move the entity with a movement differential
@@ -71,15 +71,15 @@ impl Entity for Character { )
}
- fn get_tiletype(&self) -> &TileType {
+ fn tiletype(&self) -> &TileType {
&self.tile_type
}
- fn get_location(&self) -> &Point {
+ fn location(&self) -> &Point {
&self.location
}
- fn get_previous_location(&self) -> &Point {
+ fn previous_location(&self) -> &Point {
&self.previous_location
}
@@ -184,7 +184,14 @@ impl Player for Character { fn stats(&self) -> String {
format!(
"{}({}) - hp: {}/{} attack: {} dodge: {} luck: {} experience: {}",
- self.name, self.class, self.health, self.max_health, self.attack, self.dodge, self.luck, self.xp
+ self.name,
+ self.class,
+ self.health,
+ self.max_health,
+ self.attack,
+ self.dodge,
+ self.luck,
+ self.xp
)
}
}
diff --git a/src/main.rs b/src/main.rs index 81f537b..c8e3133 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,7 @@ use std::env; use std::io::{stdout, Write}; use world::{Dungeon, DOWN, LEFT, RIGHT, UP}; -fn get_player_name() -> String { +fn player_name() -> String { match env::var_os("USER") { Some(val) => val.into_string().unwrap(), None => String::from("Kshar"), @@ -29,7 +29,7 @@ fn main() { let term_size = terminal::size().unwrap(); let mut state = State::new( - Player::new(get_player_name(), String::from("Warrior"), 30, 10, 10, 20), + Player::new(player_name(), String::from("Warrior"), 30, 10, 10, 20), Dungeon::new(term_size.0 as usize, (term_size.1 - 2) as usize, 5), ); diff --git a/src/state.rs b/src/state.rs index 1a2387d..68d5250 100644 --- a/src/state.rs +++ b/src/state.rs @@ -26,7 +26,7 @@ impl State { pub fn init(&mut self) { self.dungeon.generate(); self.switch_level(0); - self.player.place(self.current_level().get_start_point()); + self.player.place(self.current_level().start_point()); } pub fn switch_level(&mut self, num_level: usize) { @@ -51,18 +51,15 @@ impl State { if !entity.is_dirty() { return; } - let dirt = entity.get_previous_location(); - let background = self.grid.as_ref().unwrap().get_block_at(dirt.0, dirt.1); + let dirt = entity.previous_location(); + let background = self.grid.as_ref().unwrap().block_at(dirt.0, dirt.1); let mut sout = stdout(); queue!( sout, MoveTo(dirt.0 as u16, dirt.1 as u16), Output(tile_to_str(background)), - MoveTo( - entity.get_location().0 as u16, - entity.get_location().1 as u16 - ), - Output(tile_to_str(entity.get_tiletype())) + MoveTo(entity.location().0 as u16, entity.location().1 as u16), + Output(tile_to_str(entity.tiletype())) ) .unwrap(); sout.flush().unwrap(); @@ -82,7 +79,7 @@ impl State { let mut sout = stdout(); queue!( sout, - MoveTo(0, (self.dungeon.get_ysize() + 1) as u16), + MoveTo(0, (self.dungeon.ysize() + 1) as u16), Output(self.player.stats()) ) .unwrap(); diff --git a/src/tiling.rs b/src/tiling.rs index fa00464..81b7be4 100644 --- a/src/tiling.rs +++ b/src/tiling.rs @@ -39,7 +39,7 @@ impl TileGrid { &self.grid } - pub fn get_block_at(&self, x: usize, y: usize) -> &TileType { + pub fn block_at(&self, x: usize, y: usize) -> &TileType { &self.grid[y + 1][x] } } diff --git a/src/world.rs b/src/world.rs index d8d44f9..20b510a 100644 --- a/src/world.rs +++ b/src/world.rs @@ -254,7 +254,7 @@ impl Dungeon { } } - pub fn get_ysize(&self) -> usize { + pub fn ysize(&self) -> usize { self.ysize } } @@ -263,13 +263,13 @@ impl Generatable for Dungeon { fn generate(&mut self) { let mut level = Level::new(self.xsize, self.ysize, 1, None); level.generate(); - let mut next_entrance = level.get_exit(); + let mut next_entrance = level.exit(); self.levels.push(level); for d in 1..self.depth { level = Level::new(self.xsize, self.ysize, d + 1, Some(next_entrance)); level.generate(); - next_entrance = level.get_exit(); + next_entrance = level.exit(); self.levels.push(level); } } @@ -312,18 +312,18 @@ impl Level { Ok(grid) } - pub fn get_start_point(&self) -> Point { + pub fn start_point(&self) -> Point { if !self.rooms.is_empty() { return self.rooms[0].center; } (0, 0) } - // pub fn get_entrance(&self) -> Point { + // pub fn entrance(&self) -> Point { // self.entrance // } - pub fn get_exit(&self) -> Point { + pub fn exit(&self) -> Point { self.exit } |