players order gets shuffled to generate players rotation
This commit is contained in:
parent
8168c6c5ec
commit
9769934c81
|
@ -7,4 +7,4 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
rand = "0.8.5"
|
||||
clap = "4.5.3"
|
||||
clap = "4.5.4"
|
||||
|
|
|
@ -22,6 +22,8 @@ be finished.
|
|||
- [x] player's hand creation
|
||||
- [x] player's creation
|
||||
- [x] removing card from deck when players are generated
|
||||
- [ ] making it responsive to user input
|
||||
- [ ] game logic
|
||||
~~- [x] random first-player draft~~
|
||||
- [x] players order gets shuffled to generate players rotation
|
||||
- [ ] turn logic
|
||||
- [ ] everything else
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use std::fmt;
|
||||
use rand::{seq::SliceRandom, thread_rng};
|
||||
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
|
@ -52,3 +53,12 @@ pub struct GameState {
|
|||
pub players: Vec<Player>,
|
||||
pub deck: Vec<Card>,
|
||||
}
|
||||
|
||||
impl GameState {
|
||||
pub fn generate_rotation(mut self) -> Self {
|
||||
let mut rng = thread_rng();
|
||||
|
||||
self.players.shuffle(&mut rng);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
12
src/game.rs
12
src/game.rs
|
@ -1,18 +1,12 @@
|
|||
use crate::definitions::*;
|
||||
use rand::{thread_rng, Rng};
|
||||
|
||||
fn choose_first_player(game: &GameState) -> &Player {
|
||||
|
||||
let mut rng = thread_rng();
|
||||
|
||||
game.players.get(rng.gen_range(0..game.players.len())).unwrap()
|
||||
|
||||
fn hand_check(player: Player) -> bool {
|
||||
player.hand.is_empty()
|
||||
}
|
||||
|
||||
pub fn game_play(game: GameState) {
|
||||
|
||||
let first_player = choose_first_player(&game);
|
||||
|
||||
println!("The first player is: {:?}", &first_player.name);
|
||||
|
||||
todo!()
|
||||
}
|
||||
|
|
|
@ -4,14 +4,12 @@ mod definitions;
|
|||
|
||||
use start::*;
|
||||
|
||||
use crate::game::game_play;
|
||||
|
||||
fn main() {
|
||||
let game = game_setup();
|
||||
|
||||
println!("{:?}", &game.deck);
|
||||
println!("{:?}", &game.players);
|
||||
println!("Shuffled rotation: {:?}", &game.players);
|
||||
|
||||
game_play(game);
|
||||
// game::game_play(game);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::usize;
|
||||
use rand::{thread_rng, Rng};
|
||||
|
||||
use crate::definitions::*;
|
||||
use crate::{definitions::*, game};
|
||||
|
||||
fn random_card(deck: &[Card]) -> usize {
|
||||
let mut rng = thread_rng();
|
||||
|
@ -81,6 +81,11 @@ pub fn game_setup() -> GameState {
|
|||
|
||||
game.players = generate_players(names, &mut game);
|
||||
|
||||
println!("Unshuffled rotation: {:?}", &game.players);
|
||||
|
||||
game = game.generate_rotation();
|
||||
|
||||
game
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue