Did some little adjustments and started to work on the turns.
This commit is contained in:
parent
9769934c81
commit
73c66acd09
|
@ -89,14 +89,34 @@ version = "1.0.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
|
||||
|
||||
[[package]]
|
||||
name = "console"
|
||||
version = "0.15.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb"
|
||||
dependencies = [
|
||||
"encode_unicode",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"unicode-width",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "durak"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"console",
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encode_unicode"
|
||||
version = "0.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.12"
|
||||
|
@ -108,6 +128,12 @@ dependencies = [
|
|||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.153"
|
||||
|
@ -156,6 +182,12 @@ version = "0.11.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
|
||||
|
||||
[[package]]
|
||||
name = "utf8parse"
|
||||
version = "0.2.1"
|
||||
|
|
|
@ -8,3 +8,4 @@ edition = "2021"
|
|||
[dependencies]
|
||||
rand = "0.8.5"
|
||||
clap = "4.5.4"
|
||||
console = "0.15.8"
|
||||
|
|
|
@ -48,6 +48,16 @@ pub struct Player {
|
|||
pub outcome: PlayerOutcome,
|
||||
}
|
||||
|
||||
impl Player {
|
||||
pub fn print_hand(&self) {
|
||||
println!("{:?}'s hand: {:?}", self.name, self.hand);
|
||||
}
|
||||
|
||||
pub fn check_hand_empty(&self) -> bool {
|
||||
self.hand.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct GameState {
|
||||
pub players: Vec<Player>,
|
||||
|
@ -61,4 +71,11 @@ impl GameState {
|
|||
self.players.shuffle(&mut rng);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn shuffle_deck(&mut self) -> Self {
|
||||
let mut rng = thread_rng();
|
||||
|
||||
self.deck.shuffle(&mut rng);
|
||||
self.to_owned()
|
||||
}
|
||||
}
|
||||
|
|
54
src/game.rs
54
src/game.rs
|
@ -1,12 +1,60 @@
|
|||
use std::io;
|
||||
|
||||
use crate::definitions::*;
|
||||
use console::Term;
|
||||
use rand::{thread_rng, Rng};
|
||||
|
||||
fn play_card(hand: &[Card]) -> u8 {
|
||||
|
||||
let choice = loop {
|
||||
println!("Pick a card to play!!! (number from 1 to {})", hand.len());
|
||||
|
||||
fn hand_check(player: Player) -> bool {
|
||||
player.hand.is_empty()
|
||||
let mut card_input = String::new();
|
||||
io::stdin().read_line(&mut card_input).expect("gay");
|
||||
card_input
|
||||
.trim_end()
|
||||
.parse::<u8>()
|
||||
.expect("I need a number you fool!!!");
|
||||
|
||||
println!(
|
||||
"Are you sure of your choice? [y/n]\nSelected: {}",
|
||||
&card_input
|
||||
);
|
||||
|
||||
let mut sure_check = String::new();
|
||||
io::stdin().read_line(&mut sure_check).expect("ultra-gay");
|
||||
println!("{}", sure_check);
|
||||
|
||||
if sure_check.trim_end() == "y" {
|
||||
break card_input.trim_end().parse();
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
};
|
||||
choice.expect("Number needed!")
|
||||
}
|
||||
|
||||
fn turn(attacker: Player, defender: Player) -> Player {
|
||||
//let term = Term::stdout();
|
||||
//term.clear_screen().unwrap();
|
||||
|
||||
attacker.print_hand();
|
||||
defender.print_hand();
|
||||
play_card(&attacker.hand);
|
||||
defender
|
||||
}
|
||||
|
||||
pub fn game_play(game: GameState) {
|
||||
todo!()
|
||||
let mut x = 0;
|
||||
|
||||
let mut attacker = game.players.get(x).unwrap().to_owned();
|
||||
attacker.status = Status::Atk;
|
||||
|
||||
let mut defender = game.players.get(x + 1).unwrap().to_owned();
|
||||
defender.status = Status::Def;
|
||||
|
||||
println!("The fricking attacker man: {:?}", attacker);
|
||||
println!("The fricking defender man: {:?}", defender);
|
||||
|
||||
turn(attacker, defender);
|
||||
}
|
||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -2,14 +2,24 @@ mod start;
|
|||
mod game;
|
||||
mod definitions;
|
||||
|
||||
use console::Term;
|
||||
|
||||
use start::*;
|
||||
|
||||
use crate::game::game_play;
|
||||
|
||||
fn main() {
|
||||
|
||||
let term = Term::stdout();
|
||||
|
||||
term.set_title("Durak");
|
||||
term.clear_screen().unwrap();
|
||||
|
||||
let game = game_setup();
|
||||
|
||||
println!("{:?}", &game.deck);
|
||||
println!("Deck: {:?}", &game.deck);
|
||||
println!("Shuffled rotation: {:?}", &game.players);
|
||||
|
||||
// game::game_play(game);
|
||||
game_play(game);
|
||||
|
||||
}
|
||||
|
|
18
src/start.rs
18
src/start.rs
|
@ -1,12 +1,4 @@
|
|||
use std::usize;
|
||||
use rand::{thread_rng, Rng};
|
||||
|
||||
use crate::{definitions::*, game};
|
||||
|
||||
fn random_card(deck: &[Card]) -> usize {
|
||||
let mut rng = thread_rng();
|
||||
rng.gen_range(0..deck.len())
|
||||
}
|
||||
use crate::definitions::*;
|
||||
|
||||
fn generate_deck() -> Vec<Card> {
|
||||
|
||||
|
@ -32,17 +24,19 @@ fn generate_deck() -> Vec<Card> {
|
|||
fn generate_hand(game: &mut GameState) -> Vec<Card> {
|
||||
let mut x = 0;
|
||||
let mut hand = Vec::new();
|
||||
|
||||
game.shuffle_deck();
|
||||
|
||||
let mut new_deck = game.deck.clone();
|
||||
|
||||
|
||||
while x < 6 {
|
||||
x += 1;
|
||||
|
||||
let random_card_index = random_card(&new_deck);
|
||||
let card_hand = new_deck[random_card_index];
|
||||
let card_hand = game.deck[x];
|
||||
|
||||
hand.push(card_hand);
|
||||
new_deck.remove(random_card_index);
|
||||
new_deck.remove(x);
|
||||
|
||||
}
|
||||
game.deck = new_deck;
|
||||
|
|
Loading…
Reference in New Issue