Bad deck -> waste working-ish
Display looks alright, so that's good!
This commit is contained in:
@@ -171,7 +171,7 @@ impl Default for Deck {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Seed {
|
pub enum Seed {
|
||||||
Unseeded,
|
Unseeded,
|
||||||
SeedVal(u64),
|
SeedVal(u64),
|
||||||
}
|
}
|
||||||
@@ -188,7 +188,7 @@ impl Deck {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
enum NumPassesThroughDeck {
|
enum NumPassesThroughDeck {
|
||||||
Unlimited,
|
Unlimited,
|
||||||
Limited(u64),
|
Limited(u64),
|
||||||
@@ -196,15 +196,27 @@ enum NumPassesThroughDeck {
|
|||||||
|
|
||||||
pub const NUM_PILES_KLONDIKE: usize = 7;
|
pub const NUM_PILES_KLONDIKE: usize = 7;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Klondike {
|
pub struct Klondike {
|
||||||
pub piles: [Vec<Card>; NUM_PILES_KLONDIKE],
|
pub piles: [Vec<Card>; NUM_PILES_KLONDIKE],
|
||||||
pub deck: Vec<Card>,
|
pub deck: Vec<Card>, // this term is a bit overloaded
|
||||||
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,
|
_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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Klondike {
|
impl Default for Klondike {
|
||||||
@@ -226,9 +238,9 @@ impl Default for Klondike {
|
|||||||
deck: deck.cards,
|
deck: deck.cards,
|
||||||
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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,43 +24,50 @@ pub struct App {
|
|||||||
const CARD_HEIGHT: u16 = 11;
|
const CARD_HEIGHT: u16 = 11;
|
||||||
const CARD_WIDTH: u16 = 15;
|
const CARD_WIDTH: u16 = 15;
|
||||||
|
|
||||||
fn waste_widget(cards_in_waste: &Vec<card_stuffs::Card>) -> List {
|
fn draw_waste(cards_in_waste: &Vec<card_stuffs::Card>, area: Rect, frame: &mut Frame) {
|
||||||
let mut cards_to_display = Vec::new();
|
if cards_in_waste.len() == 0 {
|
||||||
|
frame.render_widget(
|
||||||
|
// TODO something different here to show empty stack - also it's too tall for some reason
|
||||||
|
facedown_card(false),
|
||||||
|
area
|
||||||
|
);
|
||||||
|
}
|
||||||
|
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
|
||||||
if cards_in_waste.len() >= 3 {
|
if cards_in_waste.len() >= 3 {
|
||||||
cards_to_display.push(cards_in_waste.windows(3).last());
|
frame.render_widget(
|
||||||
|
partially_covered_card(&cards_in_waste[cards_in_waste.len() - 1]),
|
||||||
|
w1
|
||||||
|
);
|
||||||
|
frame.render_widget(
|
||||||
|
partially_covered_card(&cards_in_waste[cards_in_waste.len() - 2]),
|
||||||
|
w2
|
||||||
|
);
|
||||||
|
frame.render_widget(
|
||||||
|
card_widget(&cards_in_waste[cards_in_waste.len() - 3], true, false, false),
|
||||||
|
top_waste
|
||||||
|
);
|
||||||
} else if cards_in_waste.len() == 2 {
|
} else if cards_in_waste.len() == 2 {
|
||||||
cards_to_display.push(cards_in_waste.windows(2).last());
|
frame.render_widget(
|
||||||
|
partially_covered_card(&cards_in_waste[cards_in_waste.len() - 1]),
|
||||||
|
w2
|
||||||
|
);
|
||||||
|
frame.render_widget(
|
||||||
|
card_widget(&cards_in_waste[cards_in_waste.len() - 2], true, false, false),
|
||||||
|
top_waste
|
||||||
|
);
|
||||||
} else if cards_in_waste.len() == 1 {
|
} else if cards_in_waste.len() == 1 {
|
||||||
cards_to_display.push(cards_in_waste.windows(1).last());
|
frame.render_widget(
|
||||||
|
card_widget(&cards_in_waste[cards_in_waste.len() - 1], true, false, false),
|
||||||
|
top_waste
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Eeeek - we're no longer a basic "List"... I think maybe I need
|
|
||||||
// a new widget I've make myself... I probably should do that for all cards
|
|
||||||
// to be toootaly honest
|
|
||||||
|
|
||||||
|
|
||||||
// This (and the rest) probably shouldn't be ListItems
|
|
||||||
let hidden_card = [
|
|
||||||
format!("#############"),
|
|
||||||
format!("#############"),
|
|
||||||
format!("#############"),
|
|
||||||
format!("#####TODO####"),
|
|
||||||
format!("#############"),
|
|
||||||
format!("#############"),
|
|
||||||
format!("#############"),
|
|
||||||
format!("#############"),
|
|
||||||
format!("#############"),
|
|
||||||
];
|
|
||||||
|
|
||||||
let card_image: Vec<ListItem> = hidden_card.iter().map(|m| {
|
|
||||||
ListItem::new(m.to_string())
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
List::new(card_image)
|
|
||||||
.block(Block::new()
|
|
||||||
.borders(Borders::ALL)
|
|
||||||
.border_type(BorderType::Rounded))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deck_widget(cards_in_deck: &Vec<card_stuffs::Card>) -> Paragraph<'static> {
|
fn deck_widget(cards_in_deck: &Vec<card_stuffs::Card>) -> Paragraph<'static> {
|
||||||
@@ -138,6 +145,7 @@ fn partially_covered_card(card: &card_stuffs::Card) -> Paragraph {
|
|||||||
.border_type(BorderType::Rounded))
|
.border_type(BorderType::Rounded))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
struct CardWidget {
|
struct CardWidget {
|
||||||
card: card_stuffs::Card,
|
card: card_stuffs::Card,
|
||||||
// put display stuff in here?
|
// put display stuff in here?
|
||||||
@@ -149,6 +157,7 @@ impl Widget for CardWidget {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
fn facedown_card(top: bool) -> Paragraph<'static> {
|
fn facedown_card(top: bool) -> Paragraph<'static> {
|
||||||
let hidden_card = format!(
|
let hidden_card = format!(
|
||||||
@@ -218,29 +227,12 @@ impl App {
|
|||||||
let [deck_area, waste_area, fa, fb, fc, fd] = horizontal.areas(dwf_area);
|
let [deck_area, waste_area, fa, fb, fc, fd] = horizontal.areas(dwf_area);
|
||||||
let foundation_areas = [fa, fb, fc, fd];
|
let foundation_areas = [fa, fb, fc, fd];
|
||||||
|
|
||||||
let horizontal = Layout::horizontal([
|
|
||||||
Constraint::Length(3),
|
|
||||||
Constraint::Length(3),
|
|
||||||
Constraint::Length(CARD_WIDTH),
|
|
||||||
]);
|
|
||||||
let [w1, w2, waste_area] = horizontal.areas(waste_area);
|
|
||||||
|
|
||||||
frame.render_widget(
|
frame.render_widget(
|
||||||
deck_widget(&self.cards.deck),
|
deck_widget(&self.cards.deck),
|
||||||
deck_area
|
deck_area
|
||||||
);
|
);
|
||||||
frame.render_widget(
|
|
||||||
partially_covered_card(&self.cards.piles[0][0]),
|
draw_waste(&self.cards.waste, waste_area, frame);
|
||||||
w1
|
|
||||||
);
|
|
||||||
frame.render_widget(
|
|
||||||
partially_covered_card(&self.cards.piles[1][0]),
|
|
||||||
w2
|
|
||||||
);
|
|
||||||
frame.render_widget(
|
|
||||||
waste_widget(&self.cards.waste),
|
|
||||||
waste_area
|
|
||||||
);
|
|
||||||
|
|
||||||
for fa in foundation_areas {
|
for fa in foundation_areas {
|
||||||
frame.render_widget(
|
frame.render_widget(
|
||||||
@@ -318,6 +310,7 @@ 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(),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user