add another player
This commit is contained in:
		
							parent
							
								
									d2cbb431a7
								
							
						
					
					
						commit
						d3d47b0cb3
					
				@ -1,4 +1,4 @@
 | 
				
			|||||||
mod player;
 | 
					pub mod player;
 | 
				
			||||||
mod star;
 | 
					mod star;
 | 
				
			||||||
mod carrier;
 | 
					mod carrier;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -14,9 +14,8 @@ pub struct Game {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl Game {
 | 
					impl Game {
 | 
				
			||||||
    pub fn addPlayer(&mut self, name: String) {
 | 
					    pub fn addPlayer(&mut self, name: String, color: Option<(u8,u8,u8)>, race: Option<player::Race>) {
 | 
				
			||||||
        let mut player: Player = Player::default();
 | 
					        let player = Player::new(name, color, race);
 | 
				
			||||||
        player.name = name;
 | 
					 | 
				
			||||||
        self.players.push(player);
 | 
					        self.players.push(player);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
#[derive(Debug)]
 | 
					#[derive(Debug)]
 | 
				
			||||||
enum Race {
 | 
					pub enum Race {
 | 
				
			||||||
    Griffin,
 | 
					    Griffin,
 | 
				
			||||||
    Catte
 | 
					    Catte
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -36,7 +36,7 @@ struct Research {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#[derive(Debug)]
 | 
					#[derive(Debug)]
 | 
				
			||||||
pub struct Player {
 | 
					pub struct Player {
 | 
				
			||||||
    pub name: String,
 | 
					    name: String,
 | 
				
			||||||
    color: (u8, u8, u8),
 | 
					    color: (u8, u8, u8),
 | 
				
			||||||
    race: Race,
 | 
					    race: Race,
 | 
				
			||||||
    research: Research
 | 
					    research: Research
 | 
				
			||||||
@ -52,3 +52,14 @@ impl Default for Player {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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()
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										5
									
								
								main.rs
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								main.rs
									
									
									
									
									
								
							@ -24,7 +24,8 @@ fn world() -> &'static str {
 | 
				
			|||||||
fn test() -> String {
 | 
					fn test() -> String {
 | 
				
			||||||
    let mut game: Game =  Game::default();
 | 
					    let mut game: Game =  Game::default();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    game.addPlayer("Daniel".to_string());
 | 
					    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)
 | 
					    format!("{:#?}", game)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user