Deck to waste and waste to deck working-ish

This commit is contained in:
2025-03-07 23:49:51 +00:00
parent 5106f6c53c
commit f3ecdb69a4
2 changed files with 21 additions and 14 deletions

View File

@@ -204,18 +204,26 @@ pub struct Klondike {
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,
num_cards_turned: u8,
}
impl Klondike {
pub fn draw(self: &mut Self) {
// completely temporary
let c1 = self.deck.pop().unwrap();
let c2 = self.deck.pop().unwrap();
let c3 = self.deck.pop().unwrap();
self.waste.push(c1);
self.waste.push(c2);
self.waste.push(c3);
pub fn deck_to_waste(self: &mut Self) {
for _ in 0..self.num_cards_turned {
let card = self.deck.pop();
match card {
None => (),
Some(c) => self.waste.push(c),
}
}
}
pub fn waste_to_deck(self: &mut Self) {
if self.deck.len() != 0 {
// no!
} else {
self.deck = self.waste.clone();
self.waste = vec![];
}
}
}
@@ -240,7 +248,7 @@ impl Default for Klondike {
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,
_num_cards_turned: 3,
num_cards_turned: 3,
}
}
}

View File

@@ -25,18 +25,16 @@ const CARD_HEIGHT: u16 = 11;
const CARD_WIDTH: u16 = 15;
fn draw_waste(cards_in_waste: &Vec<card_stuffs::Card>, area: Rect, frame: &mut Frame) {
let horizontal = Layout::horizontal([
Constraint::Length(3),
Constraint::Length(3),
Constraint::Length(CARD_WIDTH),
]);
let [w1, w2, top_waste] = horizontal.areas(area);
// There must be a better way to do this
// There must be a better way to do this
if cards_in_waste.len() == 0 {
frame.render_widget(
// TODO too tall for some reason
empty_pile(),
top_waste
);
@@ -332,7 +330,8 @@ impl App {
fn handle_key_event(&mut self, key_event: KeyEvent) {
match key_event.code {
KeyCode::Char('q') => self.exit(),
KeyCode::Char('d') => self.cards.draw(),
KeyCode::Char('d') => self.cards.deck_to_waste(),
KeyCode::Char('w') => self.cards.waste_to_deck(),
_ => {}
}
}