Skip to content

Commit

Permalink
Merge pull request #11 from jako4295/Incoorporated-settings-into-the-…
Browse files Browse the repository at this point in the history
…game

Settings into the game
  • Loading branch information
jako4295 authored Jul 12, 2024
2 parents 9992ab5 + dfb0120 commit ac010a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/game/game_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ pub struct GameLogic {
pub score: u32,
pub play: bool,
pub current_char: Option<char>,
pub hist_amount: i8,
pub future_amount: i8,
pub hist_amount: u8,
pub future_amount: u8,
pub char_hist: Vec<char>,
pub char_future: Vec<char>,
pub correct: bool,
Expand All @@ -54,11 +54,11 @@ 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 loaded_settings = settings_struct::Settings::read_config().unwrap();
let mut h_vec = vec![];
let mut f_vec = vec![];
let h_amount: i8 = 3;
let f_amount: i8 = 5;
let h_amount: u8 = loaded_settings.history_length;
let f_amount: u8 = loaded_settings.future_length;
for _ in 0..h_amount {
Vec::push(&mut h_vec, ' ');
}
Expand All @@ -79,7 +79,7 @@ impl Default for GameLogic {
char_hist: h_vec,
char_future: f_vec,
correct: true,
settings: Result::expect(loaded_settings, "Did not find settings"),
settings: loaded_settings,
}
}
}
Expand All @@ -106,6 +106,9 @@ impl GameLogic {
self.play = true;
self.reset_char_vec();
}
pub fn update_settings(&mut self) {
self.settings = settings_struct::Settings::read_config().unwrap();
}
pub fn compare_pressed_char(&mut self, character: char) {
self.char_hist.remove(0);
self.char_hist.push(character);
Expand Down
2 changes: 2 additions & 0 deletions src/tui/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ impl<'a> App<'a> {
}
KeyCode::Char('b') => {
self.state = "game";
self.gamestruct = game_page::GameLogic::default();
self.gamestruct.reset();
}
_ => {}
}
Expand Down

0 comments on commit ac010a3

Please sign in to comment.