make7libre  0.8.6
game.h
Go to the documentation of this file.
1 /*
2  * Make7Libre, free (as in freedom) implementation of the
3  * unfamous game 'Make 7 Hexa Puzzle'
4  * Copyright 2016-2017 (C) Felicien PILLOT <felicien.pillot@member.fsf.org>
5  *
6  * This file is part of Make7Libre.
7  *
8  * Make7Libre is free software: you can redistribute it and/or modify
9  * under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * Make7Libre is distributed in the hope that it will be useful,
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * with Make7Libre. If not, see <http://www.gnu.org/licenses/>.
20  */
21 /***********
22  * game.h *
23  * ~~~~~~~ *
24  ***********/
25 
26 #ifndef MAKE7LIBRE_GAME_H__
27 #define MAKE7LIBRE_GAME_H__
28 
29 #if HAVE_CONFIG_H
30 # include <config.h>
31 #endif /* HAVE_CONFIG_H */
32 #if HAVE_UNISTD_H
33 # include <unistd.h>
34 #endif /* HAVE_UNISTD_H */
35 
36 #include <iostream>
37 #include <gtkmm.h>
38 #include "gettext.h"
39 
44 class Game
45 {
46 public:
47  /* Public functions */
48  Game ();
49  void connect_every_button ();
50  void display (Glib::RefPtr<Gtk::Application> app);
51  void import_every_widget ();
52  void launch_game ();
54 private:
55  /* Private functions */
56  void big_badaboom (std::list<int> hexas);
57  void check_end ();
58  void display_error (int i);
59  void define_hexa (int ref, Glib::ustring valref);
60  void erase_hexa (int ref);
61  std::map<int, Glib::ustring> get_board_snapshot ();
62  void game_button_selected (int ref);
63  Glib::ustring get_config_file ();
64  bool get_confirmation ();
65  Glib::ustring get_main_hexa ();
66  int get_neighbour (int rel, int givenRef);
67  int get_pos2 ();
68  void get_random_hexas ();
69  void get_scores ();
70  Glib::ustring get_second_hexa ();
71  void merge_hexas (int newHexa, std::list<int> oldHexas);
73  void on_close_scores_activate ();
75  void on_display_help_activate ();
77  void on_entry_editing_done ();
78  bool on_make7window_hide (_GdkEventAny* event);
79  void on_new_game_activate ();
80  void on_next_hexa_activate ();
81  void on_quit_game_activate ();
82  int refresh_score ();
83  void refresh_selection_area ();
84  void reset_board ();
85  void reset_selection_area ();
86  void reset_snapshot ();
87  void rotate_hexas_left ();
88  bool rotate_hexas_right (GdkEventButton* event);
89  bool scan_neighbours (int ref, std::list<int> &oldRefs);
90  void set_main_hexa (Glib::ustring Snum);
91  void set_pos2 (int givenPos2);
92  void set_second_hexa (Glib::ustring Snum);
93  void store_oldvalhexas ();
94  bool triggers (int ref);
95  void update_hexa_color (int hexa);
96  void write_scores ();
98  /* Windows*/
99  Gtk::Window *make7window, *make7scores;
101  Gtk::AboutDialog *make7credits;
102 
103  /* Main window titlebar and menu actions */
104  Gtk::HeaderBar *headerbar;
105  Gtk::Menu *appmenu;
106  Gtk::MenuItem *newgame, *scores, *credits, *quit;
107 
108  /* Buttons pointers */
109  // For the interface
113  Gtk::ToggleButton *button_erase;
114  // For the Game Board
115  Gtk::Button *nnw, *nn, *nne, *nww, *nw, *ne, *nee, *ww,
116  *w, *m, *e, *ee, *sww,*sw, *se, *see, *ssw, *ss, *sse,
117  // For the Game Selection Area
118  *mainNw, *mainNe, *mainW, *mainM, *mainE, *mainSw, *mainSe;
119 
120  /* Game score and box */
121  Gtk::Label *current_score;
122  Gtk::Box *box_score;
123  Gtk::Entry *user_entry;
124 
125  /* Some shared global variables */
126  std::map<int,Gtk::Button*> Board, SelectionArea;
127  std::map<int,Glib::ustring> BoardSnapshotMap, Colors;
130  Glib::ustring oldValHexa1, oldValHexa2;
131  Glib::RefPtr<Gtk::CssProvider> CssProvider;
132 };
133 
134 #endif // MAKE7LIBRE_GAME_H__
void big_badaboom(std::list< int > hexas)
Erase all hexas around three (or more) matching "7" hexas.
Definition: game.cc:262
int get_pos2()
Returns pos2 (not very useful)
Definition: game.cc:498
int get_neighbour(int rel, int givenRef)
Calculates the position of a neighbor button.
Definition: game.cc:472
Gtk::Window * make7window
Definition: game.h:99
Gtk::AboutDialog * make7credits
Definition: game.h:101
Gtk::Box * box_score
Definition: game.h:122
Gtk::Button * button_quit
Definition: game.h:110
Gtk::Button * mainM
Definition: game.h:115
Gtk::Button * w
Definition: game.h:115
Gtk::Button * e
Definition: game.h:115
Glib::ustring get_config_file()
Create config file if it doesn&#39;t exist, then return its path.
Definition: game.cc:423
Gtk::MessageDialog * make7message
Definition: game.h:100
Gtk::Button * button_credits
Definition: game.h:110
Gtk::Button * se
Definition: game.h:115
void on_display_help_activate()
Signal function activated by button_help.
Definition: game.cc:612
void set_main_hexa(Glib::ustring Snum)
Put the string to the label of the main hexa in SelectionArea.
Definition: game.cc:809
bool triggers(int ref)
Deal with a new hexa on the board.
Definition: game.cc:850
void import_every_widget()
Function containing a lot of lines too.
Definition: game.cc:165
Gtk::Button * mainNw
Definition: game.h:115
std::map< int, Glib::ustring > Colors
Definition: game.h:127
std::map< int, Gtk::Button * > Board
Definition: game.h:126
Gtk::MenuItem * scores
Definition: game.h:106
Gtk::Button * nn
Definition: game.h:115
std::map< int, Glib::ustring > BoardSnapshotMap
Definition: game.h:127
void on_close_scores_activate()
Signal function activated by button_close_scores.
Definition: game.cc:599
void reset_board()
Erase values and colors of all hexas on the Board.
Definition: game.cc:690
void get_random_hexas()
Generate random numbers and fill valHexa1 and valHexa2 with them.
Definition: game.cc:504
int valHexa2
Definition: game.h:129
void game_button_selected(int ref)
Called when any Board button is clicked.
Definition: game.cc:376
std::list< int > SelectionAreaKeys
Definition: game.h:128
Gtk::HeaderBar * headerbar
Definition: game.h:104
Gtk::MessageDialog * make7confirm
Definition: game.h:100
Gtk::Button * nnw
Definition: game.h:115
int refresh_score()
Update the amount of points in the score label.
Definition: game.cc:666
Gtk::Button * button_rotate
Definition: game.h:110
void refresh_selection_area()
Re-display the content of the SelectionArea.
Definition: game.cc:682
std::map< int, Gtk::Button * > SelectionArea
Definition: game.h:126
Gtk::MessageDialog * make7askname
Definition: game.h:100
Gtk::Button * ee
Definition: game.h:115
Glib::ustring get_main_hexa()
Returns the value of the main hexa button label.
Definition: game.cc:463
Gtk::ToggleButton * button_erase
Definition: game.h:113
void on_quit_game_activate()
Signal function activated by button_quit.
Definition: game.cc:660
void store_oldvalhexas()
Definition: game.cc:840
Glib::ustring oldValHexa2
Definition: game.h:130
Gtk::Menu * appmenu
Definition: game.h:105
void display_error(int i)
Spawns a Gtk::MessageDialog containing an appropriated message.
Definition: game.cc:318
void connect_every_button()
Function containing a lot of lines.
Definition: game.cc:83
Gtk::Label * current_score
Definition: game.h:121
void erase_hexa(int ref)
Erase value and color of the given hexa.
Definition: game.cc:347
void get_scores()
Read users scores from saved file.
Definition: game.cc:521
std::list< int > BoardKeys
Definition: game.h:128
Gtk::Button * ww
Definition: game.h:115
Gtk::Button * button_save
Definition: game.h:110
Gtk::Button * button_scores
Definition: game.h:110
Gtk::MenuItem * quit
Definition: game.h:106
Gtk::Button * nee
Definition: game.h:115
bool get_confirmation()
Ask user to confirm the quitting.
Definition: game.cc:448
Gtk::Button * mainE
Definition: game.h:115
std::list< int > ColorsKeys
Definition: game.h:128
void merge_hexas(int newHexa, std::list< int > oldHexas)
Erase values and colors of matching neighbors.
Definition: game.cc:559
Glib::ustring get_second_hexa()
Same as get_main_hexa () but with the second.
Definition: game.cc:551
bool rotate_hexas_right(GdkEventButton *event)
Signal function activated when user right-clicks on main hexa.
Definition: game.cc:753
Gtk::Button * sse
Definition: game.h:115
Main class contains the graphical interface (set by Glade and imported with Gtk::Builder) and the mai...
Definition: game.h:44
Gtk::Button * mainNe
Definition: game.h:115
void set_second_hexa(Glib::ustring Snum)
Same as set_main_hexa (), but with the second.
Definition: game.cc:826
void reset_snapshot()
Re-display an old configuration of Board and SelectionArea, using the std::map created by get_snapsho...
Definition: game.cc:714
Gtk::Button * ne
Definition: game.h:115
void rotate_hexas_left()
Signal function activated when user left-clicks on main hexa.
Definition: game.cc:733
int score
Definition: game.h:129
Game()
Constructor.
Definition: game.cc:41
Gtk::Window * make7scores
Definition: game.h:99
int nMatch
Definition: game.h:129
Glib::RefPtr< Gtk::CssProvider > CssProvider
Definition: game.h:131
void set_pos2(int givenPos2)
Set pos2 to the given value (not very useful)
Definition: game.cc:820
void on_cancel_action_activate()
Signal function activated by button_cancel.
Definition: game.cc:591
void write_scores()
Save the score in a file.
Definition: game.cc:905
Gtk::Button * mainSe
Definition: game.h:115
int valHexa1
Definition: game.h:129
void launch_game()
All initializations needed at the beginning of a new game.
Definition: game.cc:239
Gtk::Button * button_cancel
Definition: game.h:110
void reset_selection_area()
Erase values and colors of all hexas on the SelectionArea.
Definition: game.cc:700
bool on_make7window_hide(_GdkEventAny *event)
Signal function activated when user wants to quit.
Definition: game.cc:633
void define_hexa(int ref, Glib::ustring valref)
Define the new hexa then check neighbors while there are.
Definition: game.cc:336
Gtk::Button * button_help
Definition: game.h:110
Gtk::Button * sw
Definition: game.h:115
Gtk::Button * button_next
Definition: game.h:110
Gtk::Button * ss
Definition: game.h:115
bool scan_neighbours(int ref, std::list< int > &oldRefs)
Check if the neighbors of a given hexa have the same value as it.
Definition: game.cc:777
void on_new_game_activate()
Signal function activated by button_new.
Definition: game.cc:642
Gtk::Button * nww
Definition: game.h:115
void on_entry_editing_done()
Activates button_apply_save when user hits &#39;Enter&#39;.
Definition: game.cc:626
Gtk::Button * button_new
Definition: game.h:110
void update_hexa_color(int hexa)
Change the color of a given hexa.
Definition: game.cc:873
void display(Glib::RefPtr< Gtk::Application > app)
Here is actually displayed the window.
Definition: game.cc:130
Gtk::Button * button_close_scores
Definition: game.h:110
int max
Definition: game.h:129
Gtk::Button * sww
Definition: game.h:115
Gtk::Button * ssw
Definition: game.h:115
Gtk::MenuItem * newgame
Definition: game.h:106
void on_next_hexa_activate()
Signal function activated by button_next.
Definition: game.cc:649
void on_display_credits_activate()
Signal function activated by button_credits.
Definition: game.cc:605
Gtk::Entry * user_entry
Definition: game.h:123
Gtk::MenuItem * credits
Definition: game.h:106
Gtk::Button * nne
Definition: game.h:115
Gtk::Button * mainSw
Definition: game.h:115
Gtk::Button * m
Definition: game.h:115
Gtk::Button * see
Definition: game.h:115
void on_display_scores_activate()
Signal function activated by button_scores.
Definition: game.cc:620
Gtk::Button * mainW
Definition: game.h:115
Glib::ustring oldValHexa1
Definition: game.h:130
Gtk::MessageDialog * make7error_board
Definition: game.h:100
void check_end()
Definition: game.cc:280
std::map< int, Glib::ustring > get_board_snapshot()
Backup the whole Board and SelectionArea in a std::map.
Definition: game.cc:367
int pos2
Definition: game.h:129
Gtk::Button * nw
Definition: game.h:115