extract has_position trait

This commit is contained in:
2023-12-25 13:47:15 +01:00
parent bb8a24aa91
commit c0d51f501f
7 changed files with 34 additions and 18 deletions

View File

@@ -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 {