Skip to content

Commit

Permalink
Merge branch 'update-timer-display' into game_logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakob Olsen committed Jul 12, 2024
2 parents b1167c2 + 5fdee95 commit 3cf5530
Show file tree
Hide file tree
Showing 7 changed files with 550 additions and 38 deletions.
171 changes: 171 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ color-eyre = "0.6.3"
crossterm = "0.27.0"
ratatui = "0.26.3"
chrono = "0.4.38"
confy = "0.6.1"
serde_derive = "1.0.203"
serde = "1.0.203"
50 changes: 34 additions & 16 deletions src/game/game_page.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::char_lib::load_chars;
use crate::settings::settings_struct;
use chrono::{DateTime, Duration, Local};
use dict::{Dict, DictIface};

Expand All @@ -17,6 +18,20 @@ pub fn get_dict() -> Dict<bool> {
dict
}

//pub fn load_settings() -> settings_struct::Settings {
// // Load settings from .config/crabtype

// settings_struct::Settings::default()
//}

fn _history() -> Vec<char> {
todo!();
}

fn _future() -> Vec<char> {
todo!();
}

#[derive(Debug)]
pub struct GameLogic{
pub time: Duration,
Expand All @@ -38,6 +53,7 @@ impl Default for GameLogic {
let dict: Dict<bool> = get_dict();
let start_t = Local::now();
let load_char: Vec<char> = load_chars::load_files_to_vec(dict);
let loaded_settings = settings_struct::Settings::read_config();
let mut h_vec = vec![];
let mut f_vec = vec![];
let h_amount: i8 = 3;
Expand All @@ -62,6 +78,7 @@ impl Default for GameLogic {
char_hist: h_vec,
char_future: f_vec,
correct: true,
settings: Result::expect(loaded_settings, "Did not find settings"),
}
}
}
Expand Down Expand Up @@ -92,7 +109,7 @@ impl GameLogic {
self.char_hist.remove(0);
self.char_hist.push(character);

if self.time >= Duration::seconds(30) {
if self.time >= Duration::seconds(self.settings.total_time_sec.into()) {
self.play = false
}
if self.random_char == character {
Expand All @@ -109,22 +126,21 @@ impl GameLogic {

pub fn render(&self, area: Rect, buf: &mut Buffer) {
let title = Title::from(" CrabType ".bold());
// let instructions = Title::from(Line::from(vec![
// " Decrement ".into(),
// "<Left>".blue().bold(),
// " Increment ".into(),
// "<Right>".blue().bold(),
// " Quit ".into(),
// "<Q> ".blue().bold(),
// ]));
let instructions = Title::from(Line::from(vec![
" Exit ".into(),
" <Esc> ".yellow().bold(),
" Restart ".into(),
" <Space> ".yellow().bold(),
]));
let block = Block::default()
.title(title.alignment(Alignment::Center))
// .title(
// instructions
// .alignment(Alignment::Center)
// .position(Position::Bottom),
// )
.title(
instructions
.alignment(Alignment::Center)
.position(Position::Bottom),
)
.borders(Borders::ALL)
.style(Style::default().fg(Color::Yellow).bg(Color::Black))
.border_set(border::THICK);

let mut letter_line = vec![];
Expand All @@ -145,7 +161,9 @@ impl GameLogic {
text::Line::from(vec![
Span::from("Timer: "),
Span::from(self.time.num_seconds().to_string()),
Span::from("sec / 30 sec"),
Span::from("sec / "),
Span::from(self.settings.total_time_sec.to_string()),
Span::from(" sec"),
]),
text::Line::from(" "),
text::Line::from(vec![
Expand Down Expand Up @@ -178,6 +196,7 @@ impl GameLogic {
Paragraph::new(text)
.centered()
.block(block)
.fg(Color::White)
.render(area, buf);
} else {
Paragraph::new(text2)
Expand All @@ -186,4 +205,3 @@ impl GameLogic {
.render(area, buf);
}
}
}
1 change: 1 addition & 0 deletions src/settings/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod settings_page;
pub mod settings_struct;
Loading

0 comments on commit 3cf5530

Please sign in to comment.