diff --git a/card_stuffs/src/lib.rs b/card_stuffs/src/lib.rs index 1786130..35451f5 100644 --- a/card_stuffs/src/lib.rs +++ b/card_stuffs/src/lib.rs @@ -204,18 +204,26 @@ pub struct Klondike { pub foundation: [Vec; 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, } } } diff --git a/card_stuffs/src/main.rs b/card_stuffs/src/main.rs index abe5ff1..8b8e0d8 100644 --- a/card_stuffs/src/main.rs +++ b/card_stuffs/src/main.rs @@ -25,18 +25,16 @@ const CARD_HEIGHT: u16 = 11; const CARD_WIDTH: u16 = 15; fn draw_waste(cards_in_waste: &Vec, 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(), _ => {} } }