add another player

This commit is contained in:
Daniel Løvbrøtte Olsen 2019-05-09 01:16:43 +02:00
parent d2cbb431a7
commit d3d47b0cb3
3 changed files with 20 additions and 9 deletions

View File

@ -1,4 +1,4 @@
mod player;
pub mod player;
mod star;
mod carrier;
@ -14,9 +14,8 @@ pub struct Game {
}
impl Game {
pub fn addPlayer(&mut self, name: String) {
let mut player: Player = Player::default();
player.name = name;
pub fn addPlayer(&mut self, name: String, color: Option<(u8,u8,u8)>, race: Option<player::Race>) {
let player = Player::new(name, color, race);
self.players.push(player);
}
}

View File

@ -1,5 +1,5 @@
#[derive(Debug)]
enum Race {
pub enum Race {
Griffin,
Catte
}
@ -36,7 +36,7 @@ struct Research {
#[derive(Debug)]
pub struct Player {
pub name: String,
name: String,
color: (u8, u8, u8),
race: Race,
research: Research
@ -51,4 +51,15 @@ impl Default for Player {
research: Research::default()
}
}
}
impl Player {
pub fn new(name: String, color: Option<(u8, u8, u8)>, race: Option<Race>) -> Player {
Player {
name: name,
color: color.unwrap_or(Player::default().color),
race: race.unwrap_or(Player::default().race),
research: Research::default()
}
}
}

View File

@ -24,7 +24,8 @@ fn world() -> &'static str {
fn test() -> String {
let mut game: Game = Game::default();
game.addPlayer("Daniel".to_string());
format!("{:?}", game)
game.addPlayer("Daniel".to_string(), Option::Some((255, 0, 0)), Option::Some(game::player::Race::Catte));
game.addPlayer("Torpus".to_string(), Option::Some((0, 255, 0)), Option::Some(game::player::Race::Griffin));
format!("{:#?}", game)
}