Add Mine Cell

This commit is contained in:
daleclack 2024-02-20 14:06:47 +08:00
parent c18e22a667
commit 3ebf6aaea1
4 changed files with 65 additions and 1 deletions

View File

@ -26,7 +26,7 @@ link_directories (${GTK4_LIBRARY_DIRS})
# set(PO_DIR ${CMAKE_BINARY_DIR}/po/zh_CN/LC_MESSAGES)
#Source files
set(SOURCE_FILE src/main.cpp src/MineSweeper.cpp)
set(SOURCE_FILE src/main.cpp src/MineSweeper.cpp src/MineCell.cpp)
#Compile Resource

View File

@ -0,0 +1,50 @@
#include "MineCell.h"
struct _MineCell
{
GtkButton parent_instance;
gboolean has_mine = FALSE;
gboolean cleared = FALSE;
int mines_around;
int x, y;
};
G_DEFINE_TYPE(MineCell, mine_cell, GTK_TYPE_BUTTON)
static void mine_cell_init(MineCell *self)
{
gtk_button_set_icon_name(GTK_BUTTON(self), "");
gtk_button_set_has_frame(GTK_BUTTON(self), FALSE);
gtk_widget_set_size_request(GTK_WIDGET(self), 40, 40);
self->mines_around = 0;
self->has_mine = FALSE;
}
static void mine_cell_class_init(MineCellClass *klass)
{
}
void mine_cell_get_configs(MineCell *cell, gboolean &cell_has_mine, gboolean &cell_cleared,
int &cell_mines_around, int &cell_x, int &cell_y)
{
cell_has_mine = cell->has_mine;
cell_cleared = cell->cleared;
cell_mines_around = cell->mines_around;
cell_x = cell->x;
cell_y = cell->y;
}
void mine_cell_set_configs(MineCell *cell, gboolean cell_has_mine, gboolean cell_cleared,
int cell_mines_around, int cell_x, int cell_y)
{
cell->has_mine = cell_has_mine;
cell->cleared = cell_cleared;
cell->mines_around = cell_mines_around;
cell->x = cell_x;
cell->y = cell->y;
}
MineCell *mine_cell_new()
{
return Mine_Cell(g_object_new(mine_cell_get_type(), NULL));
}

View File

@ -0,0 +1,13 @@
#pragma once
#include <gtk/gtk.h>
G_DECLARE_FINAL_TYPE(MineCell, mine_cell, Mine, Cell, GtkButton)
MineCell *mine_cell_new();
void mine_cell_get_configs(MineCell *cell, gboolean &cell_has_mine, gboolean &cell_cleared,
int &cell_mines_around, int &cell_x, int &cell_y);
void mine_cell_set_configs(MineCell *cell, gboolean cell_has_mine, gboolean cell_cleared,
int cell_mines_around, int cell_x, int cell_y);

View File

@ -1,4 +1,5 @@
#include "MineSweeper.h"
#include "MineCell.h"
struct _MineSweeper
{