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