summaryrefslogtreecommitdiff
path: root/webapp/src/components/game.rs
diff options
context:
space:
mode:
Diffstat (limited to 'webapp/src/components/game.rs')
-rw-r--r--webapp/src/components/game.rs28
1 files changed, 24 insertions, 4 deletions
diff --git a/webapp/src/components/game.rs b/webapp/src/components/game.rs
index 33fb5b7..0f25fc3 100644
--- a/webapp/src/components/game.rs
+++ b/webapp/src/components/game.rs
@@ -1,11 +1,17 @@
use crate::bridge_engine::{self, Contract, Player};
use crate::card;
use crate::card::Suit;
-use crate::components::{Bidding, Hand, HandProps};
+use crate::components::{Bidding, Hand, HandProps, ShowBid};
use yew::prelude::*;
pub const SUIT_DISPLAY_ORDER: [Suit; 4] = [Suit::Diamond, Suit::Club, Suit::Heart, Suit::Spade];
+#[derive(Debug)]
+enum Phase {
+ Bidding,
+ Cardplay,
+}
+
#[function_component(Game)]
pub fn game() -> Html {
let mut rng = rand::thread_rng();
@@ -25,12 +31,19 @@ pub fn game() -> Html {
Callback::from(move |c| contract.set(Some(c)))
};
+ let phase = if contract.is_none() {
+ Phase::Bidding
+ } else {
+ Phase::Cardplay
+ };
+
let shuffle = {
let north = north.clone();
let west = west.clone();
let south = south.clone();
let east = east.clone();
let dealer = dealer.clone();
+ let contract = contract.clone();
Callback::from(move |_| {
let mut rng = rand::thread_rng();
@@ -42,19 +55,26 @@ pub fn game() -> Html {
east.set(deal.east.into_iter().collect());
dealer.set(dealer.next());
+ contract.set(None);
})
};
html! {
<>
+ <div class="nav">
+ if let Some((contract, bidding)) = &*contract {
+ <ShowBid contract={contract.clone()} bidding={bidding.clone()}/>
+ }
+ <p>{ format!("Phase: {:?}", phase) }</p>
+ <button onclick={shuffle}>{ "Shuffle" }</button>
+ </div>
<div class="center">
<p>{ format!("Dealer: {:?}", *dealer) }</p>
- if let Some((contract, bidding)) = &*contract {
- { format!("Got contract {:?}. Bidding was {:?}", contract, bidding) }
+ if let Some(_) = &*contract {
+ { "Let's play" }
} else {
<Bidding {on_contract} dealer={ *dealer } />
}
- <button onclick={shuffle}>{ "Shuffle" }</button>
</div>
<div class="hand west">
<Hand ..(*west).clone() />