Update gtk140
This commit is contained in:
parent
90cdf40c30
commit
89a0f11feb
|
@ -2,6 +2,7 @@
|
|||
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
|
||||
"files.associations": {
|
||||
"iostream": "cpp",
|
||||
"ostream": "cpp"
|
||||
"ostream": "cpp",
|
||||
"fstream": "cpp"
|
||||
}
|
||||
}
|
|
@ -1,19 +1,32 @@
|
|||
#include <fstream>
|
||||
#include "InputBox.hh"
|
||||
#include "jsonfile.hh"
|
||||
|
||||
InputBox::InputBox(){
|
||||
main_label.set_label("Input your name");
|
||||
}
|
||||
|
||||
void InputBox::read_json_file(){
|
||||
// Try to read json data firstly
|
||||
std::fstream json_file;
|
||||
json_file.open("scores.json", std::ios_base::in);
|
||||
if(json_file.is_open()){
|
||||
json data = json::parse(json_file);
|
||||
scores_map = data["scores"];
|
||||
}
|
||||
json_file.close();
|
||||
}
|
||||
|
||||
void InputBox::on_response(int response_id){
|
||||
// Read the original json file
|
||||
std::fstream json_file;
|
||||
json_file.open("score.json");
|
||||
// Append data to the json file
|
||||
if(json_file.is_open()){
|
||||
|
||||
}else{
|
||||
// Put the data to a map container
|
||||
std::map<std::string, times_map> outdata;
|
||||
outdata["scores"] = scores_map;
|
||||
|
||||
// Output data to json file
|
||||
std::fstream outfile;
|
||||
outfile.open("scores.json");
|
||||
json data = json::parse(outdata);
|
||||
if(outfile.is_open()){
|
||||
outfile << data;
|
||||
}
|
||||
outfile.close();
|
||||
}
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
#include <gtkmm.h>
|
||||
#include "jsonfile.hh"
|
||||
|
||||
class InputBox : public Gtk::Dialog
|
||||
{
|
||||
public:
|
||||
InputBox();
|
||||
void read_json_file();
|
||||
times_map scores_map;
|
||||
|
||||
protected:
|
||||
void on_response(int response_id);
|
||||
|
||||
private:
|
||||
Gtk::Entry entry_name;
|
||||
Gtk::Label main_label;
|
||||
};
|
|
@ -85,6 +85,9 @@ void MineSweeper::reset_game()
|
|||
winned = true;
|
||||
status_label.set_label(" ");
|
||||
calc_mines();
|
||||
|
||||
// Read scores
|
||||
win_input.read_json_file();
|
||||
}
|
||||
|
||||
void MineSweeper::calc_mines()
|
||||
|
@ -179,10 +182,14 @@ void MineSweeper::cell_clicked(MineCell *cell)
|
|||
// If all the mines has cleared, you has winned
|
||||
if (mines_clear == 40)
|
||||
{
|
||||
// Stop the game
|
||||
status_label.set_label("You winned!");
|
||||
winned = true;
|
||||
game_ended = true;
|
||||
mytimer.disconnect();
|
||||
|
||||
// Save the time of game
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue