Fixed waste display issue and added cards per draw

This commit is contained in:
2025-03-07 23:58:52 +00:00
parent f3ecdb69a4
commit a64031e3bc
2 changed files with 18 additions and 9 deletions

View File

@@ -203,8 +203,8 @@ pub struct Klondike {
pub waste: Vec<Card>,
pub foundation: [Vec<Card>; 4], // 4 = len of num suits
_max_num_passes_through_deck: NumPassesThroughDeck,
_current_num_passes_through_deck: u64,
num_cards_turned: u8,
pub current_num_passes_through_deck: u64,
pub num_cards_turned: u8,
}
impl Klondike {
@@ -223,6 +223,7 @@ impl Klondike {
} else {
self.deck = self.waste.clone();
self.waste = vec![];
self.current_num_passes_through_deck += 1;
}
}
}
@@ -247,7 +248,7 @@ impl Default for Klondike {
waste: Vec::new(),
foundation: [Vec::new(), Vec::new(), Vec::new(), Vec::new()], // is this really the best way?
_max_num_passes_through_deck: NumPassesThroughDeck::Unlimited,
_current_num_passes_through_deck: 0,
current_num_passes_through_deck: 0,
num_cards_turned: 3,
}
}

View File

@@ -41,7 +41,7 @@ fn draw_waste(cards_in_waste: &Vec<card_stuffs::Card>, area: Rect, frame: &mut F
}
if cards_in_waste.len() >= 3 {
frame.render_widget(
partially_covered_card(&cards_in_waste[cards_in_waste.len() - 1]),
partially_covered_card(&cards_in_waste[cards_in_waste.len() - 3]),
w1
);
frame.render_widget(
@@ -49,16 +49,16 @@ fn draw_waste(cards_in_waste: &Vec<card_stuffs::Card>, area: Rect, frame: &mut F
w2
);
frame.render_widget(
card_widget(&cards_in_waste[cards_in_waste.len() - 3], true, false, false),
card_widget(&cards_in_waste[cards_in_waste.len() - 1], true, false, false),
top_waste
);
} else if cards_in_waste.len() == 2 {
frame.render_widget(
partially_covered_card(&cards_in_waste[cards_in_waste.len() - 1]),
partially_covered_card(&cards_in_waste[cards_in_waste.len() - 2]),
w2
);
frame.render_widget(
card_widget(&cards_in_waste[cards_in_waste.len() - 2], true, false, false),
card_widget(&cards_in_waste[cards_in_waste.len() - 1], true, false, false),
top_waste
);
} else if cards_in_waste.len() == 1 {
@@ -218,7 +218,7 @@ impl App {
Constraint::Min(0),
Constraint::Length(1),
]);
let [title_bar, main_area, _status_bar] = vertical.areas(frame.area());
let [title_bar, main_area, status_bar] = vertical.areas(frame.area());
frame.render_widget(
Block::new()
@@ -228,9 +228,15 @@ impl App {
title_bar
);
let status_bar_info = format!("Cards Per-Draw: {} ---- Times Through Deck: {} ", self.cards.num_cards_turned, self.cards.current_num_passes_through_deck);
frame.render_widget(
Block::new().borders(Borders::TOP).title(status_bar_info),
status_bar
);
let vertical = Layout::vertical([
Constraint::Length(CARD_HEIGHT),
Constraint::Min(0)
Constraint::Min(0),
]);
let [dwf_area, piles_area] = vertical.areas(main_area);
@@ -332,6 +338,8 @@ impl App {
KeyCode::Char('q') => self.exit(),
KeyCode::Char('d') => self.cards.deck_to_waste(),
KeyCode::Char('w') => self.cards.waste_to_deck(),
KeyCode::Char('1') => self.cards.num_cards_turned = 1,
KeyCode::Char('3') => self.cards.num_cards_turned = 3,
_ => {}
}
}