Compare commits
2 Commits
5106f6c53c
...
a64031e3bc
| Author | SHA1 | Date | |
|---|---|---|---|
| a64031e3bc | |||
| f3ecdb69a4 |
@@ -203,19 +203,28 @@ pub struct Klondike {
|
|||||||
pub waste: Vec<Card>,
|
pub waste: Vec<Card>,
|
||||||
pub foundation: [Vec<Card>; 4], // 4 = len of num suits
|
pub foundation: [Vec<Card>; 4], // 4 = len of num suits
|
||||||
_max_num_passes_through_deck: NumPassesThroughDeck,
|
_max_num_passes_through_deck: NumPassesThroughDeck,
|
||||||
_current_num_passes_through_deck: u64,
|
pub current_num_passes_through_deck: u64,
|
||||||
_num_cards_turned: u8,
|
pub num_cards_turned: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Klondike {
|
impl Klondike {
|
||||||
pub fn draw(self: &mut Self) {
|
pub fn deck_to_waste(self: &mut Self) {
|
||||||
// completely temporary
|
for _ in 0..self.num_cards_turned {
|
||||||
let c1 = self.deck.pop().unwrap();
|
let card = self.deck.pop();
|
||||||
let c2 = self.deck.pop().unwrap();
|
match card {
|
||||||
let c3 = self.deck.pop().unwrap();
|
None => (),
|
||||||
self.waste.push(c1);
|
Some(c) => self.waste.push(c),
|
||||||
self.waste.push(c2);
|
}
|
||||||
self.waste.push(c3);
|
}
|
||||||
|
}
|
||||||
|
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(),
|
waste: Vec::new(),
|
||||||
foundation: [Vec::new(), Vec::new(), Vec::new(), Vec::new()], // is this really the best way?
|
foundation: [Vec::new(), Vec::new(), Vec::new(), Vec::new()], // is this really the best way?
|
||||||
_max_num_passes_through_deck: NumPassesThroughDeck::Unlimited,
|
_max_num_passes_through_deck: NumPassesThroughDeck::Unlimited,
|
||||||
_current_num_passes_through_deck: 0,
|
current_num_passes_through_deck: 0,
|
||||||
_num_cards_turned: 3,
|
num_cards_turned: 3,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,25 +25,23 @@ const CARD_HEIGHT: u16 = 11;
|
|||||||
const CARD_WIDTH: u16 = 15;
|
const CARD_WIDTH: u16 = 15;
|
||||||
|
|
||||||
fn draw_waste(cards_in_waste: &Vec<card_stuffs::Card>, area: Rect, frame: &mut Frame) {
|
fn draw_waste(cards_in_waste: &Vec<card_stuffs::Card>, area: Rect, frame: &mut Frame) {
|
||||||
|
|
||||||
let horizontal = Layout::horizontal([
|
let horizontal = Layout::horizontal([
|
||||||
Constraint::Length(3),
|
Constraint::Length(3),
|
||||||
Constraint::Length(3),
|
Constraint::Length(3),
|
||||||
Constraint::Length(CARD_WIDTH),
|
Constraint::Length(CARD_WIDTH),
|
||||||
]);
|
]);
|
||||||
let [w1, w2, top_waste] = horizontal.areas(area);
|
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 {
|
if cards_in_waste.len() == 0 {
|
||||||
frame.render_widget(
|
frame.render_widget(
|
||||||
// TODO too tall for some reason
|
|
||||||
empty_pile(),
|
empty_pile(),
|
||||||
top_waste
|
top_waste
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if cards_in_waste.len() >= 3 {
|
if cards_in_waste.len() >= 3 {
|
||||||
frame.render_widget(
|
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
|
w1
|
||||||
);
|
);
|
||||||
frame.render_widget(
|
frame.render_widget(
|
||||||
@@ -51,16 +49,16 @@ fn draw_waste(cards_in_waste: &Vec<card_stuffs::Card>, area: Rect, frame: &mut F
|
|||||||
w2
|
w2
|
||||||
);
|
);
|
||||||
frame.render_widget(
|
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
|
top_waste
|
||||||
);
|
);
|
||||||
} else if cards_in_waste.len() == 2 {
|
} else if cards_in_waste.len() == 2 {
|
||||||
frame.render_widget(
|
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
|
w2
|
||||||
);
|
);
|
||||||
frame.render_widget(
|
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
|
top_waste
|
||||||
);
|
);
|
||||||
} else if cards_in_waste.len() == 1 {
|
} else if cards_in_waste.len() == 1 {
|
||||||
@@ -220,7 +218,7 @@ impl App {
|
|||||||
Constraint::Min(0),
|
Constraint::Min(0),
|
||||||
Constraint::Length(1),
|
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(
|
frame.render_widget(
|
||||||
Block::new()
|
Block::new()
|
||||||
@@ -230,9 +228,15 @@ impl App {
|
|||||||
title_bar
|
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([
|
let vertical = Layout::vertical([
|
||||||
Constraint::Length(CARD_HEIGHT),
|
Constraint::Length(CARD_HEIGHT),
|
||||||
Constraint::Min(0)
|
Constraint::Min(0),
|
||||||
]);
|
]);
|
||||||
let [dwf_area, piles_area] = vertical.areas(main_area);
|
let [dwf_area, piles_area] = vertical.areas(main_area);
|
||||||
|
|
||||||
@@ -332,7 +336,10 @@ impl App {
|
|||||||
fn handle_key_event(&mut self, key_event: KeyEvent) {
|
fn handle_key_event(&mut self, key_event: KeyEvent) {
|
||||||
match key_event.code {
|
match key_event.code {
|
||||||
KeyCode::Char('q') => self.exit(),
|
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