Compare commits
2 Commits
5106f6c53c
...
a64031e3bc
| Author | SHA1 | Date | |
|---|---|---|---|
| a64031e3bc | |||
| f3ecdb69a4 |
@@ -203,19 +203,28 @@ 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 {
|
||||
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![];
|
||||
self.current_num_passes_through_deck += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,8 +248,8 @@ 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,
|
||||
_num_cards_turned: 3,
|
||||
current_num_passes_through_deck: 0,
|
||||
num_cards_turned: 3,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,25 +25,23 @@ 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
|
||||
);
|
||||
}
|
||||
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(
|
||||
@@ -51,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 {
|
||||
@@ -220,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()
|
||||
@@ -230,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,7 +336,10 @@ 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(),
|
||||
KeyCode::Char('1') => self.cards.num_cards_turned = 1,
|
||||
KeyCode::Char('3') => self.cards.num_cards_turned = 3,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user