extract has_position trait
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use std::cmp::{max, min};
|
||||
|
||||
use crate::position::Position;
|
||||
use crate::position::{HasPosition, Position};
|
||||
|
||||
pub struct Player {
|
||||
name: String,
|
||||
@@ -34,12 +34,6 @@ impl Player {
|
||||
pub fn get_max_life(&self) -> i16 {
|
||||
self.max_life
|
||||
}
|
||||
pub fn get_position(&mut self) -> &mut Position {
|
||||
&mut self.position
|
||||
}
|
||||
pub fn get_immutable_position(&self) -> &Position {
|
||||
&self.position
|
||||
}
|
||||
|
||||
/// add the given amount to the players gold stash
|
||||
pub fn retrieve_gold(&mut self, amount: usize) { self.gold += amount }
|
||||
@@ -52,6 +46,15 @@ impl Player {
|
||||
pub fn get_experience(&self) -> usize { self.experience }
|
||||
}
|
||||
|
||||
impl HasPosition for Player {
|
||||
fn get_position(&mut self) -> &mut Position {
|
||||
&mut self.position
|
||||
}
|
||||
fn get_immutable_position(&self) -> &Position {
|
||||
&self.position
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_name() {
|
||||
let p = Player {
|
||||
|
||||
Reference in New Issue
Block a user