Work in progress proof of concept: an R package with a system for saving high scores persistently.
You can install from GitHub.
install.packages("remotes") # if not yet installed
remotes::install_github("matt-dray/hiscore")
The simplest possible game is included for demonstration purposes. Try to guess as many coinflips in a row as possible.
play_coinflip()
[H]eads or [T]ails? Answer: H
Correct! Current score: 1
[H]eads or [T]ails? Answer: H
Incorrect! Final score: 1
New high score!
New high score saved.
You can then retrieve your current high score, which is saved to your machine at the location given by tools::R_user_dir()
. The data persists even if you restart your session.
hiscore::get_save_data()
game high_score
1 coinflip 1
You can retry to try and beat your score.
play_coinflip()
Welcome. Your current high score is 1
[H]eads or [T]ails? Answer: h
Correct! Current score: 1
[H]eads or [T]ails? Answer: t
Correct! Current score: 2
[H]eads or [T]ails? Answer: h
Incorrect! Final score: 2
New high score!
New high score saved.
And let's check that high score again.
hiscore::get_save_data()
game high_score
1 coinflip 2
You can delete the saved game data.
hiscore::delete_save_data()
Really delete? [Y]es/[N]o: Y
High score data deleted.`