diff --git a/.gitignore b/.gitignore index 53c5bc1..bb73084 100644 --- a/.gitignore +++ b/.gitignore @@ -43,8 +43,9 @@ gschemas.compiled #backend source backend/* -#The binary +#The binary files FiveRow +24game # Prerequisites *.d diff --git a/Gtkmm3/gtk128_24game/CMakeLists.txt b/Gtkmm3/gtk128_24game/CMakeLists.txt new file mode 100644 index 0000000..5d4b831 --- /dev/null +++ b/Gtkmm3/gtk128_24game/CMakeLists.txt @@ -0,0 +1,72 @@ +set(CMAKE_CXX_STANDARD 17) +cmake_minimum_required(VERSION 3.0.0) +project(gtk128_24game VERSION 1.0.0) + +list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../GCR_CMake/macros) +include(GlibCompileResourcesSupport) + +include(CTest) +enable_testing() + +set(CPACK_PROJECT_NAME ${PROJECT_NAME}) +set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) + +include(CPack) +include_directories(.) +include_directories(..) + +#Find PkgConfig to use gtkmm3 +find_package (PkgConfig REQUIRED) +pkg_check_modules (GTKMM3 REQUIRED gtkmm-3.0) +include_directories (${GTKMM3_INCLUDE_DIRS}) +link_directories (${GTKMM3_LIBRARY_DIRS}) + +#Find Gettext +find_package (Gettext REQUIRED) +set(PO_DIR ${CMAKE_BINARY_DIR}/po/zh_CN/LC_MESSAGES) + +#Source files +set(SOURCE_FILE src/main.cc src/MyWin.cc src/Game24.cc) + +#Compile Resource + +set(RESOURCE_LIST + window.ui) + +compile_gresources(RESOURCE_FILE + XML_OUT + TYPE EMBED_C + RESOURCES ${RESOURCE_LIST} + PREFIX "/org/gtk/daleclack" + SOURCE_DIR ${PROJECT_SOURCE_DIR}/res) + +# Add a custom target to the makefile. Now make builds our resource file. +# It depends on the output RESOURCE_FILE. + +add_custom_target(resource ALL DEPENDS ${RESOURCE_FILE}) + +#For win32 platform,use rc resource and .ico icon +if(WIN32) + SET(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres) + set(app_WINRC ../icon.rc) + set_property(SOURCE ../icon.rc APPEND PROPERTY + OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/../icon.ico + ) + add_executable(${PROJECT_NAME} WIN32 ${app_WINRC} ${SOURCE_FILE} ${RESOURCE_FILE}) + add_custom_command( TARGET ${PROJECT_NAME} + COMMAND echo * > ${CMAKE_BINARY_DIR}/.gitignore + COMMAND echo **/* > ${CMAKE_BINARY_DIR}/.hgignore) +else() + add_executable(${PROJECT_NAME} ${SOURCE_FILE} ${RESOURCE_FILE}) + add_custom_command( TARGET ${PROJECT_NAME} + COMMAND echo \"*\" > ${CMAKE_BINARY_DIR}/.gitignore + COMMAND echo \"**/*\" > ${CMAKE_BINARY_DIR}/.hgignore) +endif(WIN32) + +#Add command to generate .gitignore and .mo files +# add_custom_command( TARGET ${PROJECT_NAME} +# COMMAND mkdir -p ${PO_DIR} +# COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} ${CMAKE_SOURCE_DIR}/po/zh_CN.po -o ${PO_DIR}/${PROJECT_NAME}.mo) + +SET (CMAKE_EXTRA_CXX_FLAGS ${GTKMM3_CFLAGS_OTHER}) +target_link_libraries (${PROJECT_NAME} ${GTKMM3_LIBRARIES} -lpthread) diff --git a/Gtkmm3/gtk128_24game/po/zh_CN.po b/Gtkmm3/gtk128_24game/po/zh_CN.po new file mode 100644 index 0000000..2384ba4 --- /dev/null +++ b/Gtkmm3/gtk128_24game/po/zh_CN.po @@ -0,0 +1,67 @@ +#: src/MyWin.cc:8 +msgid "Open Image" +msgstr "打开图像文件" + +#: src/MyWin.cc:11 +msgid "Position" +msgstr "位置" + +#: src/MyWin.cc:12 +msgid "rgb()/rgba() for css3" +msgstr "用于css3的rgb()/rgba()代码" + +#: src/MyWin.cc:13 +msgid "(A)RGB Code" +msgstr "(A)RGB代码" + +#: src/MyWin.cc:16 +msgid "Color Settings And Position info" +msgstr "颜色与位置信息" + +#: src/MyWin.cc:18 +msgid "Copy Css3 Code" +msgstr "复制css3代码" + +#: src/MyWin.cc:19 +msgid "Copy (A)RGB String" +msgstr "复制(A)RGB代码" + +#: src/MyWin.cc:20 +msgid "Pick Color" +msgstr "拾取颜色" + +#: src/MyWin.cc:22 +msgid "Color Picker" +msgstr "颜色拾取器" + +#: src/MyWin.cc:152 +msgid "Open a image file" +msgstr "打开图像文件" + +#: src/MyWin.cc:153 +msgid "OK" +msgstr "确定" + +#: src/MyWin.cc:153 +msgid "Cancel" +msgstr "取消" + +#: src/MyWin.cc:157 +msgid "Image Files" +msgstr "图像文件" + +#: src/MyWin.cc:172 +msgid "Any Files" +msgstr "所有文件" + +msgid "Color Panel" +msgstr "调色板" + +msgid "Color Reference" +msgstr "颜色参考" + +msgid "Color:" +msgstr "颜色:" + +msgid "Copy Color Code" +msgstr "复制颜色代码" diff --git a/Gtkmm3/gtk128_24game/res/window.ui b/Gtkmm3/gtk128_24game/res/window.ui new file mode 100644 index 0000000..89ee8c2 --- /dev/null +++ b/Gtkmm3/gtk128_24game/res/window.ui @@ -0,0 +1,385 @@ + + + + + + False + 440 + 260 + + + True + False + 5 + 5 + 5 + 5 + True + True + vertical + 10 + + + True + False + center + + + True + False + The Numbers: + + + False + True + 0 + + + + + True + False + + + False + True + 1 + + + + + False + True + 0 + + + + + True + False + True + + + True + False + Input answer: + + + False + True + 0 + + + + + True + True + True + + + False + True + 1 + + + + + False + True + 1 + + + + + + True + False + True + True + True + True + + + 7 + True + True + True + True + True + none + + + 0 + 1 + + + + + 8 + True + True + True + none + + + 1 + 1 + + + + + 9 + True + True + True + none + + + 2 + 1 + + + + + 4 + True + True + True + none + + + 0 + 2 + + + + + 5 + True + True + True + none + + + 1 + 2 + + + + + 6 + True + True + True + none + + + 2 + 2 + + + + + 1 + True + True + True + none + + + 0 + 3 + + + + + 2 + True + True + True + none + + + 1 + 3 + + + + + 3 + True + True + True + none + + + 2 + 3 + + + + + 0 + True + True + True + none + + + 1 + 4 + + + + + + + True + True + True + none + + + 3 + 1 + + + + + - + True + True + True + none + + + 3 + 2 + + + + + * + True + True + True + none + + + 3 + 3 + + + + + / + True + True + True + none + + + 3 + 4 + + + + + ( + True + True + True + none + + + 0 + 4 + + + + + ) + True + True + True + none + + + 2 + 4 + + + + + + + + + + + + + + + + + False + True + 2 + + + + + True + False + center + 10 + + + Start + True + True + True + + + False + True + 0 + + + + + Check + True + True + True + + + False + True + 1 + + + + + Exit + True + True + True + + + False + True + 2 + + + + + False + True + 3 + + + + + + diff --git a/Gtkmm3/gtk128_24game/src/Game24.cc b/Gtkmm3/gtk128_24game/src/Game24.cc new file mode 100644 index 0000000..00eb801 --- /dev/null +++ b/Gtkmm3/gtk128_24game/src/Game24.cc @@ -0,0 +1,156 @@ +// Reference code: https://www.jb51.net/article/182079.htm +#include "Game24.hh" + +// Generate a number in [begin,end] +static double randnum(int begin = 0, int end = 1) +{ + return rand() % (end - begin + 1) + begin; +} + +// The Game Class +void Game24::startgame(string user_result) +{ + bool winned = false; + + // Format result number + if (user_result[user_result.length()] != ')' || user_result[0] != '(') + { + user_result = '(' + user_result + ')'; + } + + // Check user input and the results + for (std::vector::iterator it = result_strings.begin(); it != result_strings.end(); it++) + { + if (*it == user_result) + { + std::cout << "Winned!" << std::endl; + winned = true; + break; + } + else + { + continue; + } + } + + // If lost, output information + if (!winned) + { + std::cout << "Lost" << std::endl; + } +} + +void Game24::getnumbers() +{ + srand(time(NULL)); + for (int i = 0; i < n; i++) + { + // Get Number and output + number[i] = randnum(1, 13); + std::cout << number[i] << " "; + + // Process number to string for display + switch ((int)number[i]) + { + case 10: + result[i] = "10"; + break; + case 11: + result[i] = "11"; + break; + case 12: + result[i] = "12"; + break; + case 13: + result[i] = "13"; + break; + default: + result[i] = '0' + number[i]; + } + } + std::cout << std::endl; + + // Get the algorithm that can get the result + F(n); + std::cout << "Has" << count << "Results" << std::endl; + sprintf(numbers_char, "%d %d %d %d", (int)number[0], (int)number[1], (int)number[2], (int)number[3]); +} + +void Game24::F(int n) +{ + // Calculate for three times + if (n == 1) + { + if (number[0] == 24) + { + std::cout << result[0] << std::endl; + result_strings.push_back(result[0]); + count++; + } + } + + for (int i = 0; i < n; i++) + { + for (int j = i + 1; j < n; j++) + { + double a, b; + string x, y; + + // Save number + a = number[i]; + b = number[j]; + number[j] = number[n - 1]; + + // Save Result String + x = result[i]; + y = result[j]; + result[j] = result[n - 1]; + + // Add + number[i] = a + b; + result[i] = '(' + x + '+' + y + ')'; + F(n - 1); + + // Minus + number[i] = a - b; + result[i] = '(' + x + '-' + y + ')'; + F(n - 1); + number[i] = b - a; + result[i] = '(' + y + '-' + x + ')'; + F(n - 1); + + // multiply + number[i] = a * b; + result[i] = '(' + x + '*' + y + ')'; + F(n - 1); + + // divide + if (b != 0) + { + number[i] = a / b; + result[i] = '(' + x + '/' + y + ')'; + F(n - 1); + } + + if (a != 0) + { + number[i] = b / a; + result[i] = '(' + y + '/' + x + ')'; + F(n - 1); + } + + // if the result is not 24, make the numbers back + number[i] = a; + number[j] = b; + result[i] = x; + result[j] = y; + } + } +} + +// int main(int argc, char **argv) +// { +// Game24 game1; +// game1.startgame(); +// return 0; +// } diff --git a/Gtkmm3/gtk128_24game/src/Game24.hh b/Gtkmm3/gtk128_24game/src/Game24.hh new file mode 100644 index 0000000..127155e --- /dev/null +++ b/Gtkmm3/gtk128_24game/src/Game24.hh @@ -0,0 +1,28 @@ +#pragma once + +#include +#include +#include +#include + +typedef std::string string; + +class Game24 +{ +public: + void startgame(string user_result); + void getnumbers(); + char numbers_char[20]; + +private: + const int n = 4; // Flag of third calculate + double number[4] = {0}; // Numbers + char oper[4] = {'+', '-', '*', '/'}; // operators + string result[4]; + int count = 0; + + std::vector result_strings; + + // Handlers + void F(int n); +}; diff --git a/Gtkmm3/gtk128_24game/src/MyWin.cc b/Gtkmm3/gtk128_24game/src/MyWin.cc new file mode 100644 index 0000000..7bde5be --- /dev/null +++ b/Gtkmm3/gtk128_24game/src/MyWin.cc @@ -0,0 +1,63 @@ +#include "MyWin.hh" + +MyWin::MyWin(BaseObjectType *cobject, const Glib::RefPtr &ref_Glade) + : Gtk::Window(cobject), + ref_builder(ref_Glade) +{ + // Get Widgets + ref_builder->get_widget("label_numbers",label_numbers); + ref_builder->get_widget("btnstart",btnstart); + ref_builder->get_widget("btncheck",btncheck); + ref_builder->get_widget("btnexit",btnexit); + ref_builder->get_widget("btn0",btns[0]); + ref_builder->get_widget("btn1",btns[1]); + ref_builder->get_widget("btn2",btns[2]); + ref_builder->get_widget("btn3",btns[3]); + ref_builder->get_widget("btn4",btns[4]); + ref_builder->get_widget("btn5",btns[5]); + ref_builder->get_widget("btn6",btns[6]); + ref_builder->get_widget("btn7",btns[7]); + ref_builder->get_widget("btn8",btns[8]); + ref_builder->get_widget("btn9",btns[9]); + ref_builder->get_widget("btnadd",btns[10]); + ref_builder->get_widget("btnsubb",btns[11]); + ref_builder->get_widget("btnmul",btns[12]); + ref_builder->get_widget("btndiv",btns[13]); + ref_builder->get_widget("btnleft",btns[14]); + ref_builder->get_widget("btnright",btns[15]); + + // Link Signals + btnstart->signal_clicked().connect(sigc::mem_fun(*this,&MyWin::btnstart_clicked)); + btnexit->signal_clicked().connect(sigc::mem_fun(*this,&MyWin::hide)); + btncheck->signal_clicked().connect(sigc::mem_fun(*this,&MyWin::btncheck_clicked)); + for(int i = 0 ; i < 16;i++){ + btns[i]->signal_clicked().connect(sigc::bind(sigc::mem_fun(*this,&MyWin::btns_clicked),btns[i])); + } +} + +void MyWin::btns_clicked(Gtk::Button *button){ + // Get Original text and add number from button + //Glib::ustring text = entry_ans->get_text(); + Glib::ustring label = button->get_label(); + //entry_ans->set_text(text+label); +} + +void MyWin::btnstart_clicked(){ + // Start Game + main_game.getnumbers(); + label_numbers->set_label(main_game.numbers_char); +} + +void MyWin::btncheck_clicked(){ + // Check Answer +} + +MyWin *MyWin::create() +{ + // Create a new window + MyWin * window = nullptr; + auto builder = Gtk::Builder::create_from_resource("/org/gtk/daleclack/window.ui"); + builder->get_widget_derived("window",window); + + return window; +} \ No newline at end of file diff --git a/Gtkmm3/gtk128_24game/src/MyWin.hh b/Gtkmm3/gtk128_24game/src/MyWin.hh new file mode 100644 index 0000000..1dfc40a --- /dev/null +++ b/Gtkmm3/gtk128_24game/src/MyWin.hh @@ -0,0 +1,28 @@ +#pragma once + +#include +#include "Game24.hh" + +class MyWin : public Gtk::Window +{ +public: + static MyWin *create(); + MyWin(BaseObjectType *cobject, const Glib::RefPtr &ref_Glade); + +private: + // Main GtkBuilder + Glib::RefPtr ref_builder; + + // 24-Game Class + Game24 main_game; + + // Child widgets + Gtk::Entry *entry_ans; + Gtk::Label *label_numbers; + Gtk::Button *btns[16], *btnstart, *btncheck, *btnexit; + + // Signal Handlers + void btns_clicked(Gtk::Button * button); + void btnstart_clicked(); + void btncheck_clicked(); +}; \ No newline at end of file diff --git a/Gtkmm3/gtk128_24game/src/main.cc b/Gtkmm3/gtk128_24game/src/main.cc new file mode 100644 index 0000000..d83a759 --- /dev/null +++ b/Gtkmm3/gtk128_24game/src/main.cc @@ -0,0 +1,9 @@ +#include "MyWin.hh" + +int main(int argc,char **argv){ + auto app = Gtk::Application::create(argc,argv,"org.gtk.daleclack"); + + auto window = MyWin::create(); + + return app->run(*window); +} \ No newline at end of file