更名FINDBOOM为MineSweepe
正式初步完成了MineSweepe
@ -1,36 +1,37 @@
|
|||||||
cmake_minimum_required(VERSION 3.31)
|
cmake_minimum_required(VERSION 3.30.1)
|
||||||
project(
|
project(
|
||||||
saolei
|
MineSweeper
|
||||||
VERSION 0.1.0
|
VERSION 0.1.0
|
||||||
LANGUAGES C
|
LANGUAGES C
|
||||||
)
|
)
|
||||||
|
|
||||||
set(CMAKE_C_STANDARD 11)
|
set(CMAKE_C_STANDARD 11)
|
||||||
|
|
||||||
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static")
|
||||||
|
|
||||||
set(CMAKE_PREFIX_PATH ./lib/SDL/cmake)
|
set(CMAKE_PREFIX_PATH ./lib/SDL/cmake)
|
||||||
find_package(SDL2 REQUIRED)
|
find_package(SDL2 REQUIRED)
|
||||||
find_package(SDL2_image REQUIRED)
|
find_package(SDL2_image REQUIRED)
|
||||||
find_package(SDL2_mixer REQUIRED)
|
|
||||||
find_package(SDL2_ttf REQUIRED)
|
find_package(SDL2_ttf REQUIRED)
|
||||||
|
|
||||||
file(GLOB res res/**)
|
file(GLOB res res/**)
|
||||||
file(COPY ${res} DESTINATION ${CMAKE_BINARY_DIR}/res)
|
file(COPY ${res} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/res)
|
||||||
|
|
||||||
add_executable(saolei
|
file(GLOB lib lib/SDL/x86_64-w64-mingw32/bin/**)
|
||||||
|
file(COPY ${lib} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||||
|
|
||||||
|
add_executable(MineSweeper
|
||||||
src/main.c
|
src/main.c
|
||||||
src/game.c
|
src/game.c
|
||||||
include/game.h
|
|
||||||
src/data.c
|
src/data.c
|
||||||
include/data.h
|
|
||||||
src/img.c
|
src/img.c
|
||||||
include/img.h
|
src/over.c
|
||||||
|
src/resource/logo.rc
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(saolei
|
target_link_libraries(MineSweeper
|
||||||
${SDL2_LIBRARIES}
|
${SDL2_LIBRARIES}
|
||||||
SDL2_mixer::SDL2_mixer
|
|
||||||
SDL2_ttf::SDL2_ttf
|
SDL2_ttf::SDL2_ttf
|
||||||
SDL2_image::SDL2_image
|
SDL2_image::SDL2_image
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_options(saolei PRIVATE -Wl,-subsystem,console)
|
|
||||||
13
README.md
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# MineSweeper
|
||||||
|
|
||||||
|
这一个初学者对c语言的初次探索,在mingw的环境下基于SDL2实现的一个有着可视化窗口的扫雷小游戏。
|
||||||
|
|
||||||
|
## 使用Cmkae构建
|
||||||
|
|
||||||
|
```shell
|
||||||
|
cmake -B build -G "MingGW Makefiles"
|
||||||
|
```
|
||||||
|
|
||||||
|
```shell
|
||||||
|
cmake --build build --config Release -j18
|
||||||
|
```
|
||||||
@ -1,14 +0,0 @@
|
|||||||
#ifndef GLOBAL_H
|
|
||||||
#define GLOBAL_H
|
|
||||||
|
|
||||||
#include "def.h"
|
|
||||||
#include "context.h"
|
|
||||||
#include "window.h"
|
|
||||||
|
|
||||||
typedef struct Global {
|
|
||||||
Context context;
|
|
||||||
Window window;
|
|
||||||
} Global;
|
|
||||||
|
|
||||||
extern Global global;
|
|
||||||
#endif //GLOBAL_H
|
|
||||||
@ -1,17 +0,0 @@
|
|||||||
#ifndef INIT_H
|
|
||||||
#define INIT_H
|
|
||||||
#include "def.h"
|
|
||||||
#include <SDL.h>
|
|
||||||
|
|
||||||
typedef struct Context {
|
|
||||||
int map[ROW][COL];
|
|
||||||
int mapcopy[ROW][COL];
|
|
||||||
SDL_Texture * imgs[10];
|
|
||||||
} Context;
|
|
||||||
|
|
||||||
void contextInit();
|
|
||||||
void imgInit();
|
|
||||||
|
|
||||||
#endif //INIT_H
|
|
||||||
|
|
||||||
|
|
||||||
@ -9,7 +9,5 @@ typedef struct Data {
|
|||||||
|
|
||||||
void initData(Data *data, int x, int y ,int boom);
|
void initData(Data *data, int x, int y ,int boom);
|
||||||
void getData(Data *data, int x, int y);
|
void getData(Data *data, int x, int y);
|
||||||
|
int checkData(Data *data);
|
||||||
void showData(Data *data);
|
|
||||||
|
|
||||||
#endif //DATA_H
|
#endif //DATA_H
|
||||||
|
|||||||
@ -1,24 +0,0 @@
|
|||||||
#ifndef DEF_H
|
|
||||||
#define DEF_Hs
|
|
||||||
|
|
||||||
// 行列数
|
|
||||||
#define ROW 10
|
|
||||||
#define COL 10
|
|
||||||
|
|
||||||
// 地雷个数
|
|
||||||
#define BOOM 15
|
|
||||||
|
|
||||||
// 窗口大小
|
|
||||||
#define WinWidth 400
|
|
||||||
#define WinHeight 400
|
|
||||||
|
|
||||||
// 矩形大小
|
|
||||||
#define rectWidth 40
|
|
||||||
#define rectHeight 40
|
|
||||||
|
|
||||||
// 颜色
|
|
||||||
#define OVER (Color){0X4E,0X4E,0X4E,255}
|
|
||||||
#define BACKGROUND (Color){0XE1,0XE2,0XE3,0XFF}
|
|
||||||
#define FLOW (Color){175,175,175,0}
|
|
||||||
|
|
||||||
#endif //DEF_H
|
|
||||||
@ -18,12 +18,14 @@ typedef struct Color {
|
|||||||
int r,g,b,a;
|
int r,g,b,a;
|
||||||
} Color;
|
} Color;
|
||||||
|
|
||||||
#define RED (Color){150,40,40,255}
|
#define SQUARE (Color){0xC0,0XC0,0XC0,255}
|
||||||
#define GREEN (Color){40,150,40,255}
|
#define BACKGROUND (Color){0x24,0x49,0X5E,255}
|
||||||
#define BLUE (Color){40,40,150,255}
|
#define BUTTON (Color){0X2c,0X3E,0X50,255}
|
||||||
|
#define FLOW (Color){0xD9,0xD9,0xD9}
|
||||||
|
|
||||||
void initGame(const char* name, int width, int height);
|
void initGame(const char* name, int width, int height);
|
||||||
void gameLoop();
|
void gameLoop();
|
||||||
|
void setColor(Color color);
|
||||||
void windowClose();
|
void windowClose();
|
||||||
|
|
||||||
#endif //RUNNING_H
|
#endif //RUNNING_H
|
||||||
|
|||||||
22
include/over.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#ifndef WIN_H
|
||||||
|
#define WIN_H
|
||||||
|
#include "game.h"
|
||||||
|
#include <SDL_ttf.h>
|
||||||
|
|
||||||
|
typedef struct Font {
|
||||||
|
TTF_Font * fontKind;
|
||||||
|
SDL_Texture* texture;
|
||||||
|
int w, h;
|
||||||
|
} Font;
|
||||||
|
|
||||||
|
typedef struct Button {
|
||||||
|
int x,y,w,h;
|
||||||
|
} Button;
|
||||||
|
typedef struct Over {
|
||||||
|
int nameH,buttonH,w;
|
||||||
|
Button botton;
|
||||||
|
} Over;
|
||||||
|
|
||||||
|
void initOver(Game * game, Over * over);
|
||||||
|
void drawOver(int fontSizeName, int fontSizeButton,Font * font, const char * nameText, Color buttonColor, SDL_Renderer * renderer , Over* over);
|
||||||
|
#endif //WIN_H
|
||||||
@ -1,25 +0,0 @@
|
|||||||
#ifndef WINDOW_H
|
|
||||||
#define WINDOW_H
|
|
||||||
#include <SDL_events.h>
|
|
||||||
#include <SDL_render.h>
|
|
||||||
|
|
||||||
// 颜色
|
|
||||||
typedef struct Color {
|
|
||||||
int r;
|
|
||||||
int g;
|
|
||||||
int b;
|
|
||||||
int a;
|
|
||||||
} Color;
|
|
||||||
|
|
||||||
// 窗口
|
|
||||||
typedef struct Window{
|
|
||||||
SDL_Window *Window;
|
|
||||||
SDL_Renderer *Renderer;
|
|
||||||
SDL_Event Event;
|
|
||||||
} Window;
|
|
||||||
|
|
||||||
void windowInit();
|
|
||||||
void windowLoop();
|
|
||||||
void windowShutdown();
|
|
||||||
|
|
||||||
#endif //WINDOW_H
|
|
||||||
@ -1,65 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# Get the canonical path of the folder containing this script
|
|
||||||
bindir=`cd -P -- "\`dirname -- "$0"\`" && printf '%s\n' "\`pwd -P\`"`
|
|
||||||
|
|
||||||
# Calculate the canonical path of the prefix, relative to the folder of this script
|
|
||||||
prefix=`cd -P -- "$bindir/.." && printf '%s\n' "\`pwd -P\`"`
|
|
||||||
exec_prefix=${prefix}/bin
|
|
||||||
exec_prefix_set=no
|
|
||||||
libdir=${prefix}/lib
|
|
||||||
|
|
||||||
#usage="\
|
|
||||||
#Usage: $0 [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs]"
|
|
||||||
usage="\
|
|
||||||
Usage: $0 [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs] [--static-libs]"
|
|
||||||
|
|
||||||
if test $# -eq 0; then
|
|
||||||
echo "${usage}" 1>&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
while test $# -gt 0; do
|
|
||||||
case "$1" in
|
|
||||||
-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
|
|
||||||
*) optarg= ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
case $1 in
|
|
||||||
--prefix=*)
|
|
||||||
prefix=$optarg
|
|
||||||
if test $exec_prefix_set = no ; then
|
|
||||||
exec_prefix=$optarg
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
--prefix)
|
|
||||||
echo $prefix
|
|
||||||
;;
|
|
||||||
--exec-prefix=*)
|
|
||||||
exec_prefix=$optarg
|
|
||||||
exec_prefix_set=yes
|
|
||||||
;;
|
|
||||||
--exec-prefix)
|
|
||||||
echo $exec_prefix
|
|
||||||
;;
|
|
||||||
--version)
|
|
||||||
echo 2.32.8
|
|
||||||
;;
|
|
||||||
--cflags)
|
|
||||||
echo -I${prefix}/include/SDL2 -Dmain=SDL_main
|
|
||||||
;;
|
|
||||||
--libs)
|
|
||||||
echo -L${prefix}/lib -lmingw32 -lSDL2main -lSDL2 -mwindows
|
|
||||||
;;
|
|
||||||
--static-libs)
|
|
||||||
# --libs|--static-libs)
|
|
||||||
sdl_static_libs=$(echo "-lmingw32 -lSDL2main -lSDL2 -mwindows -Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lsetupapi -lversion -luuid" | sed -E "s#-lSDL2[ $]#$libdir/libSDL2.a #g")
|
|
||||||
echo -L${prefix}/lib $sdl_static_libs
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "${usage}" 1>&2
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
BIN
res/4.png
|
Before Width: | Height: | Size: 659 B After Width: | Height: | Size: 680 B |
BIN
res/5.png
|
Before Width: | Height: | Size: 606 B After Width: | Height: | Size: 719 B |
BIN
res/6.png
|
Before Width: | Height: | Size: 710 B After Width: | Height: | Size: 830 B |
BIN
res/7.png
|
Before Width: | Height: | Size: 528 B After Width: | Height: | Size: 603 B |
BIN
res/8.png
|
Before Width: | Height: | Size: 804 B After Width: | Height: | Size: 880 B |
BIN
res/Minecraft.ttf
Normal file
BIN
res/boom.png
|
Before Width: | Height: | Size: 578 B After Width: | Height: | Size: 629 B |
BIN
res/flag.png
|
Before Width: | Height: | Size: 221 B After Width: | Height: | Size: 224 B |
@ -1,3 +0,0 @@
|
|||||||
#include "../include/Global.h"
|
|
||||||
|
|
||||||
Global global = { 0 } ;
|
|
||||||
@ -1,57 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <rend.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <SDL_image.h>
|
|
||||||
|
|
||||||
#include "../include/Global.h"
|
|
||||||
|
|
||||||
char * img_paths[10] = {
|
|
||||||
"./res/1.png",
|
|
||||||
"./res/2.png",
|
|
||||||
"./res/3.png",
|
|
||||||
"./res/4.png",
|
|
||||||
"./res/5.png",
|
|
||||||
"./res/6.png",
|
|
||||||
"./res/7.png",
|
|
||||||
"./res/8.png",
|
|
||||||
"./res/boom.png",
|
|
||||||
"./res/flag.png"
|
|
||||||
};
|
|
||||||
|
|
||||||
// 初始化数据
|
|
||||||
void contextInit() {
|
|
||||||
// 设置随机位置为-1
|
|
||||||
srand((unsigned)time(NULL));
|
|
||||||
for (int i = 0; i < BOOM;) {
|
|
||||||
char k, l;
|
|
||||||
k = rand() % ROW;
|
|
||||||
l = rand() % COL;
|
|
||||||
if (!global.context.map[k][l]) {
|
|
||||||
global.context.map[k][l] = -1;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 把以 -1 为中心的九宫格数据都+1,-1除外
|
|
||||||
for (int i = 0; i < ROW; i++) {
|
|
||||||
for (int j = 0; j < COL; j++) {
|
|
||||||
if (global.context.map[i][j] == -1) {
|
|
||||||
for (int k = i-1; k <= i+1; k++) {
|
|
||||||
for (int l = j-1; l <= j+1; l++) {
|
|
||||||
if ((k >= 0 && k < ROW && l >= 0 && l < COL ) && global.context.map[k][l] != -1) {
|
|
||||||
global.context.map[k][l]++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void imgInit () {
|
|
||||||
for (int i = 0; i < sizeof(global.context.imgs)/sizeof(global.context.imgs[0]); i++) {
|
|
||||||
SDL_Surface * surface = IMG_Load(img_paths[i]);
|
|
||||||
global.context.imgs[i] = SDL_CreateTextureFromSurface(global.window.Renderer,surface);
|
|
||||||
SDL_FreeSurface(surface);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
37
src/data.c
@ -3,22 +3,28 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <rend.h>
|
#include <rend.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "../include/over.h"
|
||||||
|
static int isArrInint = 1;
|
||||||
void initData(Data *data ,int x, int y, int boom) {
|
void initData(Data *data ,int x, int y, int boom) {
|
||||||
|
|
||||||
data->x = x;
|
data->x = x;
|
||||||
data->y = y;
|
data->y = y;
|
||||||
data->arr = (int **)malloc( x * sizeof(int*));
|
if (isArrInint) {
|
||||||
for (int i = 0; i < x; i++) {
|
data->arrcopy = (int **)malloc( x * sizeof(int*));
|
||||||
data->arr[i] = (int *)malloc( y * sizeof(int));
|
data->arr = (int **)malloc( x * sizeof(int*));
|
||||||
memset(data->arr[i], 0, y * sizeof(int));
|
for (int i = 0; i < x; i++) {
|
||||||
|
data->arr[i] = (int *)malloc( y * sizeof(int));
|
||||||
|
data->arrcopy[i] = (int *)malloc( y * sizeof(int));
|
||||||
|
}
|
||||||
|
isArrInint = 0;
|
||||||
}
|
}
|
||||||
data->arrcopy = (int **)malloc( x * sizeof(int*));
|
|
||||||
for (int i = 0; i < x; i++) {
|
for (int i = 0; i < x; i++) {
|
||||||
data->arrcopy[i] = (int *)malloc( y * sizeof(int));
|
memset(data->arr[i], 0, y * sizeof(int));
|
||||||
memset(data->arrcopy[i], 0, y * sizeof(int));
|
memset(data->arrcopy[i], 0, y * sizeof(int));
|
||||||
}
|
}
|
||||||
|
|
||||||
data->boom = boom;
|
data->boom = boom;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,7 +34,7 @@ void getData(Data *data, int x, int y) {
|
|||||||
char i,j;
|
char i,j;
|
||||||
i = rand() % data->x;
|
i = rand() % data->x;
|
||||||
j = rand() % data->y;
|
j = rand() % data->y;
|
||||||
if (i != x && j != y && data->arr[i][j] != -1) {
|
if ((i != x || j != y) && data->arr[i][j] != -1) {
|
||||||
data->arr[i][j] = -1;
|
data->arr[i][j] = -1;
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
@ -49,11 +55,18 @@ void getData(Data *data, int x, int y) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void showData(Data *data){
|
int checkData(Data *data) {
|
||||||
|
int num = 1;
|
||||||
for (int i = 0; i < data->x; i++) {
|
for (int i = 0; i < data->x; i++) {
|
||||||
for (int j = 0; j < data->y; j++ ) {
|
for (int j = 0; j < data->y; j++) {
|
||||||
printf("%3d", data->arrcopy[i][j]);
|
if ( data->arr[i][j] == -1 && data->arrcopy[i][j] == -1 ) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (data->arr[i][j] != -1 && data->arrcopy[i][j] >= 0 && num) {
|
||||||
|
num =0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
printf("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return num;
|
||||||
}
|
}
|
||||||
|
|||||||
201
src/game.c
@ -1,17 +1,25 @@
|
|||||||
#include "../include/game.h"
|
#include "../include/game.h"
|
||||||
#include "../include/data.h"
|
#include "../include/data.h"
|
||||||
#include "../include/img.h"
|
#include "../include/img.h"
|
||||||
|
#include "../include/over.h"
|
||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
#include <SDL_ttf.h>
|
||||||
#include <SDL_image.h>
|
#include <SDL_image.h>
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
Game game;
|
Game game;
|
||||||
Data data;
|
Data data;
|
||||||
Img img;
|
Img img;
|
||||||
|
Over over;
|
||||||
|
Font font;
|
||||||
|
|
||||||
static int running = 1;
|
static int running = 1;
|
||||||
static int isfirst = 1;
|
static int isfirst = 1;
|
||||||
const char * imgArr[] = {
|
static int flag = 0;
|
||||||
|
static int isInit = 1;
|
||||||
|
static int isOverInit = 0;
|
||||||
|
|
||||||
|
const char *imgArr[] = {
|
||||||
"./res/boom.png",
|
"./res/boom.png",
|
||||||
"./res/1.png",
|
"./res/1.png",
|
||||||
"./res/2.png",
|
"./res/2.png",
|
||||||
@ -22,72 +30,76 @@ const char * imgArr[] = {
|
|||||||
"./res/7.png",
|
"./res/7.png",
|
||||||
"./res/8.png",
|
"./res/8.png",
|
||||||
"./res/flag.png"
|
"./res/flag.png"
|
||||||
|
|
||||||
};
|
};
|
||||||
|
const char *winTitle = "WC NB";
|
||||||
|
const char *failureTitle = "G G";
|
||||||
|
|
||||||
void initGame(const char* name,int width,int height) {
|
TTF_Font *fontKind = NULL;
|
||||||
|
|
||||||
|
void initGame(const char *name, int width, int height) {
|
||||||
SDL_Init(SDL_INIT_EVERYTHING);
|
SDL_Init(SDL_INIT_EVERYTHING);
|
||||||
IMG_Init(IMG_INIT_PNG);
|
IMG_Init(IMG_INIT_PNG );
|
||||||
|
TTF_Init();
|
||||||
|
|
||||||
game.title = name;
|
game.title = name;
|
||||||
game.window.width = width;
|
game.window.width = width;
|
||||||
game.window.height = height;
|
game.window.height = height;
|
||||||
game.window.window = SDL_CreateWindow(name,SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,width,height,SDL_WINDOW_SHOWN);
|
game.window.window = SDL_CreateWindow(name,SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED, width, height,
|
||||||
game.window.renderer = SDL_CreateRenderer(game.window.window,-1,SDL_RENDERER_ACCELERATED);
|
SDL_WINDOW_SHOWN);
|
||||||
initImg(&img,imgArr,10,game.window.renderer);
|
game.window.renderer = SDL_CreateRenderer(game.window.window, -1, SDL_RENDERER_ACCELERATED);
|
||||||
|
initImg(&img, imgArr, 10, game.window.renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void windowClose() {
|
void windowClose() {
|
||||||
SDL_DestroyRenderer(game.window.renderer);
|
SDL_DestroyRenderer(game.window.renderer);
|
||||||
SDL_DestroyWindow(game.window.window);
|
SDL_DestroyWindow(game.window.window);
|
||||||
|
IMG_Quit();
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void normalization (int* x, int* y) {
|
void normalization(int *x, int *y) {
|
||||||
*x = *x / (game.window.width / data.x);
|
*x = *x / (game.window.width / data.y);
|
||||||
*y = *y / (game.window.height / data.y);
|
*y = *y / (game.window.height / data.x);
|
||||||
|
|
||||||
*x = *x ^ *y;
|
*x = *x ^ *y;
|
||||||
*y = *y ^ *x;
|
*y = *y ^ *x;
|
||||||
*x = *x ^ *y;
|
*x = *x ^ *y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void extend(int i,int j) {
|
void extend(int i, int j) {
|
||||||
if (i>=0 && i< data.x && j>=0 && j< data.y && data.arr[i][j] == 0 && data.arrcopy[i][j] != -1) {
|
if (i >= 0 && i < data.x && j >= 0 && j < data.y && data.arr[i][j] == 0 && data.arrcopy[i][j] != -1) {
|
||||||
data.arrcopy[i][j] = -1;
|
data.arrcopy[i][j] = -1;
|
||||||
extend(i - 1 ,j);
|
extend(i - 1, j);
|
||||||
extend(i ,j - 1);
|
extend(i, j - 1);
|
||||||
extend(i ,j + 1);
|
extend(i, j + 1);
|
||||||
extend(i + 1, j);
|
extend(i + 1, j);
|
||||||
} else if ( i>=0 && i< data.x && j>=0 && j< data.y && data.arr[i][j] > 0 ) {
|
} else if (i >= 0 && i < data.x && j >= 0 && j < data.y && data.arr[i][j] > 0) {
|
||||||
data.arrcopy[i][j] = -1;
|
data.arrcopy[i][j] = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void eventProcess(SDL_Event event) {
|
void runningEventProcess(SDL_Event event) {
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
running = 0;
|
running = 0;
|
||||||
break;
|
break;
|
||||||
case SDL_MOUSEBUTTONUP:
|
case SDL_MOUSEBUTTONUP:
|
||||||
int x,y;
|
int x, y;
|
||||||
SDL_GetMouseState(&x,&y);
|
SDL_GetMouseState(&x, &y);
|
||||||
|
normalization(&x, &y);
|
||||||
normalization(&x,&y);
|
|
||||||
|
|
||||||
if (event.button.button == SDL_BUTTON_LEFT) {
|
if (event.button.button == SDL_BUTTON_LEFT) {
|
||||||
if (isfirst == 1 && data.arrcopy[x][y] == 0 ) {
|
if (isfirst == 1 && data.arrcopy[x][y] == 0) {
|
||||||
getData(&data, x, y);
|
getData(&data, x, y);
|
||||||
isfirst = 0;
|
isfirst = 0;
|
||||||
}
|
}
|
||||||
if (data.arr[x][y] == 0 && data.arrcopy[x][y] == 0) {
|
if (data.arr[x][y] == 0 && data.arrcopy[x][y] == 0) {
|
||||||
extend(x ,y );
|
extend(x, y);
|
||||||
}
|
}
|
||||||
if (data.arrcopy[x][y] == 0) {
|
if (data.arrcopy[x][y] == 0) {
|
||||||
data.arrcopy[x][y] = -1;
|
data.arrcopy[x][y] = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.button.button == SDL_BUTTON_RIGHT) {
|
if (event.button.button == SDL_BUTTON_RIGHT) {
|
||||||
if (data.arrcopy[x][y] == 0) {
|
if (data.arrcopy[x][y] == 0) {
|
||||||
data.arrcopy[x][y] = 1;
|
data.arrcopy[x][y] = 1;
|
||||||
@ -101,70 +113,137 @@ void eventProcess(SDL_Event event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setColor(Color color) {
|
void setColor(Color color) {
|
||||||
SDL_SetRenderDrawColor(game.window.renderer,color.r,color.g,color.b,color.a);
|
SDL_SetRenderDrawColor(game.window.renderer, color.r, color.g, color.b, color.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Rect creatRect(int x,int y,Game* game,Data* data) {
|
SDL_Rect creatRect(int x, int y, Game *game, Data *data) {
|
||||||
|
|
||||||
SDL_Rect rect = {
|
SDL_Rect rect = {
|
||||||
x * game->window.width / data->x + 4,
|
x * game->window.width / data->y + 4,
|
||||||
y * game->window.width / data->y+ 4 ,
|
y * game->window.height / data->x + 4,
|
||||||
game->window.width / data->x - 8,
|
game->window.width / data->y - 8,
|
||||||
game->window.height / data->y - 8
|
game->window.height / data->x - 8
|
||||||
};
|
};
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawRect(int x,int y, int kind,int isCilck) {
|
void drawRect(int x, int y, int kind, int isCilck) {
|
||||||
if (isCilck == 0) {
|
if (isCilck == 0) {
|
||||||
setColor(RED);
|
setColor(SQUARE);
|
||||||
SDL_Rect rect = creatRect(y,x,&game,&data);
|
SDL_Rect rect = creatRect(x, y, &game, &data);
|
||||||
SDL_RenderFillRect(game.window.renderer,&rect);
|
SDL_RenderFillRect(game.window.renderer, &rect);
|
||||||
} else if (isCilck == 1) {
|
} else if (isCilck == 1) {
|
||||||
SDL_Rect rect = creatRect(y,x,&game,&data);
|
SDL_Rect rect = creatRect(x, y, &game, &data);
|
||||||
SDL_RenderCopy(game.window.renderer,img.texture[9],NULL,&rect);
|
SDL_RenderCopy(game.window.renderer, img.texture[9],NULL, &rect);
|
||||||
} else if (isCilck == -1) {
|
} else if (isCilck == -1) {
|
||||||
SDL_Rect rect = creatRect(y,x,&game,&data);
|
SDL_Rect rect = creatRect(x, y, &game, &data);
|
||||||
if (kind > 0) {
|
if (kind > 0) {
|
||||||
SDL_RenderCopy(game.window.renderer,img.texture[kind],NULL,&rect);
|
SDL_RenderCopy(game.window.renderer, img.texture[kind],NULL, &rect);
|
||||||
} else if (kind == -1) {
|
} else if (kind == -1) {
|
||||||
SDL_RenderCopy(game.window.renderer,img.texture[0],NULL,&rect);
|
SDL_RenderCopy(game.window.renderer, img.texture[0],NULL, &rect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawMap(Data data) {
|
void drawMap(Data data) {
|
||||||
setColor(BLUE);
|
setColor(BACKGROUND);
|
||||||
SDL_RenderClear(game.window.renderer);
|
SDL_RenderClear(game.window.renderer);
|
||||||
for(int i = 0; i < data.x; i++) {
|
for (int i = 0; i < data.x; i++) {
|
||||||
for(int j = 0; j < data.y; j++) {
|
for (int j = 0; j < data.y; j++) {
|
||||||
drawRect(i, j,data.arr[i][j],data.arrcopy[i][j]);
|
drawRect(j, i, data.arr[i][j], data.arrcopy[i][j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void moveMouse() {
|
void moveMouse() {
|
||||||
int x,y;
|
int x, y;
|
||||||
SDL_GetMouseState(&x,&y);
|
SDL_GetMouseState(&x, &y);
|
||||||
normalization(&x,&y);
|
normalization(&x, &y);
|
||||||
if (data.arrcopy[x][y] == 0 && x > 0 && y > 0 && x < data.x && y < data.y) {
|
if (data.arrcopy[x][y] == 0 && x >= 0 && y >= 0 && x < data.x && y < data.y) {
|
||||||
setColor(GREEN);
|
setColor(FLOW);
|
||||||
SDL_Rect rect = creatRect(y,x,&game,&data);
|
SDL_Rect rect = creatRect(y, x, &game, &data);
|
||||||
SDL_RenderDrawRect(game.window.renderer,&rect);
|
SDL_RenderFillRect(game.window.renderer, &rect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void showAll(Data *data) {
|
||||||
|
for (int i = 0; i < data->x; i++) {
|
||||||
|
memset(data->arrcopy[i], -1, data->y * sizeof(int));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void overEventProcess(SDL_Event event) {
|
||||||
|
while (SDL_PollEvent(&event)) {
|
||||||
|
switch (event.type) {
|
||||||
|
case SDL_QUIT:
|
||||||
|
running = 0;
|
||||||
|
break;
|
||||||
|
case SDL_MOUSEBUTTONUP:
|
||||||
|
int x, y;
|
||||||
|
SDL_GetMouseState(&x, &y);
|
||||||
|
if (event.button.button == SDL_BUTTON_LEFT && x > over.botton.x && y > over.botton.y && x < (
|
||||||
|
over.botton.x + over.botton.w) && y < (over.botton.y + over.botton.h)) {
|
||||||
|
setColor(BACKGROUND);
|
||||||
|
SDL_RenderClear(game.window.renderer);
|
||||||
|
flag = 0;
|
||||||
|
isInit = 1;
|
||||||
|
isfirst = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void gameLoop() {
|
void gameLoop() {
|
||||||
initData(&data,10,10,15);
|
int time = 0;
|
||||||
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (running) {
|
while (running) {
|
||||||
drawMap(data);
|
switch (flag) {
|
||||||
|
case 0:
|
||||||
eventProcess(event);
|
if (isInit) {
|
||||||
|
initData(&data, 20, 20, 88);
|
||||||
moveMouse();
|
isInit = 0;
|
||||||
|
}
|
||||||
|
runningEventProcess(event);
|
||||||
|
drawMap(data);
|
||||||
|
moveMouse();
|
||||||
|
flag = checkData(&data);
|
||||||
|
if (flag != 0) {
|
||||||
|
isOverInit = 1;
|
||||||
|
time = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
if (time < 1000) {
|
||||||
|
time += 6;
|
||||||
|
if (isOverInit) {
|
||||||
|
initOver(&game, &over);
|
||||||
|
isOverInit = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setColor(BACKGROUND);
|
||||||
|
SDL_RenderClear(game.window.renderer);
|
||||||
|
drawOver(102,22 ,&font, winTitle, SQUARE, game.window.renderer, &over);
|
||||||
|
overEventProcess(event);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case -1:
|
||||||
|
if (time < 1000) {
|
||||||
|
time += 6;
|
||||||
|
showAll(&data);
|
||||||
|
drawMap(data);
|
||||||
|
if (isOverInit) {
|
||||||
|
initOver(&game, &over);
|
||||||
|
isOverInit = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setColor(BACKGROUND);
|
||||||
|
SDL_RenderClear(game.window.renderer);
|
||||||
|
drawOver(102, 22, &font,failureTitle, SQUARE, game.window.renderer, &over);
|
||||||
|
overEventProcess(event);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
SDL_RenderPresent(game.window.renderer);
|
SDL_RenderPresent(game.window.renderer);
|
||||||
SDL_Delay(6);
|
SDL_Delay(6);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,8 @@
|
|||||||
#include "../include/game.h"
|
#include "../include/game.h"
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "../include/data.h"
|
|
||||||
|
|
||||||
int main(int, char**) {
|
int main(int, char**) {
|
||||||
initGame("扫雷", 400, 400);
|
initGame("MineSweeper", 800, 800);
|
||||||
|
|
||||||
gameLoop();
|
gameLoop();
|
||||||
|
|
||||||
|
|||||||
56
src/over.c
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#include "../include/over.h"
|
||||||
|
#include "../include/game.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
const char *ttf_path = "../res/Minecraft.ttf";
|
||||||
|
const char *buttonText = "PLAY GAME AGAIN";
|
||||||
|
static SDL_Color fontColor = {0xE7, 0X4C, 0X3C, 255};
|
||||||
|
|
||||||
|
static SDL_Color buttonFontColor = { 0x3C, 0X4E, 0X60 };
|
||||||
|
|
||||||
|
void initOver(Game * game, Over * over) {
|
||||||
|
over->nameH = game->window.height * 7 / 10;
|
||||||
|
over->buttonH = game->window.height - over->nameH;
|
||||||
|
over->w = game->window.width;
|
||||||
|
|
||||||
|
over->botton.h = over->buttonH * 1 / 4;
|
||||||
|
over->botton.w = over->w * 3 / 5;
|
||||||
|
over->botton.x= ( over->w - over->botton.w ) / 2;
|
||||||
|
over->botton.y = ( over->buttonH - over->botton.h ) / 2 + over->nameH;
|
||||||
|
}
|
||||||
|
|
||||||
|
void initFont(int fontSize,Font * font, const char * text, SDL_Color color, SDL_Renderer * renderer) {
|
||||||
|
font->fontKind = TTF_OpenFont(ttf_path, fontSize);
|
||||||
|
SDL_Surface* Surface = TTF_RenderText_Blended(font->fontKind, text, color);
|
||||||
|
font->texture = SDL_CreateTextureFromSurface(renderer, Surface);
|
||||||
|
SDL_FreeSurface(Surface);
|
||||||
|
|
||||||
|
int width, height;
|
||||||
|
SDL_QueryTexture(font->texture, NULL, NULL, &width, &height);
|
||||||
|
font->w = width;
|
||||||
|
font->h = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawFont(Font * font, int x, int y, int width, int height, SDL_Renderer * renderer) {
|
||||||
|
SDL_Rect rect = { (width - font->w) / 2 + x, (height - font->h) / 2 + y, font->w, font->h };
|
||||||
|
SDL_RenderCopy(renderer, font->texture, NULL, &rect);
|
||||||
|
SDL_DestroyTexture(font->texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawButton(Font * font ,Over * over, SDL_Renderer * renderer ,Color color) {
|
||||||
|
setColor(color);
|
||||||
|
SDL_Rect rect = { over->botton.x, over->botton.y, over->botton.w, over->botton.h };
|
||||||
|
SDL_RenderFillRect(renderer, &rect);
|
||||||
|
drawFont(font, rect.x, rect.y, rect.w, rect.h, renderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawOver(int fontSizeName, int fontSizeButton, Font * font,const char * nameText, Color buttonColor, SDL_Renderer * renderer , Over* over) {
|
||||||
|
|
||||||
|
initFont(fontSizeName, font, nameText, fontColor, renderer);
|
||||||
|
drawFont(font, 0,0,over->w,over->nameH, renderer);
|
||||||
|
|
||||||
|
drawButton(font,over,renderer, buttonColor);
|
||||||
|
initFont(fontSizeButton, font, buttonText , buttonFontColor, renderer);
|
||||||
|
drawFont(font,over->botton.x,over->botton.y, over->botton.w, over->botton.h, renderer);
|
||||||
|
}
|
||||||
1
src/resource/logo.rc
Normal file
@ -0,0 +1 @@
|
|||||||
|
id ICON "logo.ico"
|
||||||
167
src/window.c
@ -1,167 +0,0 @@
|
|||||||
#include <SDL_image.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "../include/Global.h"
|
|
||||||
|
|
||||||
static int flag = 0;
|
|
||||||
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD>Ⱦ<EFBFBD><C8BE>
|
|
||||||
void windowInit(int width,int height) {
|
|
||||||
SDL_Init(SDL_INIT_EVERYTHING);
|
|
||||||
IMG_Init(IMG_INIT_PNG);
|
|
||||||
global.window.Window = SDL_CreateWindow("ɨ<EFBFBD><EFBFBD>",SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_SHOWN);
|
|
||||||
global.window.Renderer = SDL_CreateRenderer(global.window.Window, -1, SDL_RENDERER_ACCELERATED);
|
|
||||||
}
|
|
||||||
|
|
||||||
// <20><><EFBFBD>ղ<EFBFBD><D5B2>ر<EFBFBD><D8B1><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD>Ⱦ<EFBFBD><C8BE>
|
|
||||||
void windowShutdown() {
|
|
||||||
SDL_DestroyRenderer(global.window.Renderer);
|
|
||||||
SDL_DestroyWindow(global.window.Window);
|
|
||||||
IMG_Quit();
|
|
||||||
SDL_Quit();
|
|
||||||
}
|
|
||||||
|
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|
||||||
void setColor(Color color) {
|
|
||||||
SDL_SetRenderDrawColor(global.window.Renderer, color.r, color.g, color.b, color.a);
|
|
||||||
}
|
|
||||||
|
|
||||||
// <20><>һ<EFBFBD><D2BB>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ɫ<EFBFBD>Ŀ<EFBFBD><C4BF>ľ<EFBFBD><C4BE><EFBFBD>
|
|
||||||
void drawRect(SDL_Rect* rect,Color color) {
|
|
||||||
setColor(color);
|
|
||||||
SDL_RenderFillRect(global.window.Renderer, rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
// <20><>ʾͼƬ
|
|
||||||
void drawImg( int i,int j,SDL_Rect * rect) {
|
|
||||||
if (global.context.map[i][j] == -1 ) {
|
|
||||||
SDL_RenderCopy(global.window.Renderer,global.context.imgs[8],NULL,rect);
|
|
||||||
} else if (global.context.map[i][j] > 0) {
|
|
||||||
SDL_RenderCopy(global.window.Renderer,global.context.imgs[global.context.map[i][j] - 1 ],NULL,rect);
|
|
||||||
} else if (global.context.map[i][j] == 0) {
|
|
||||||
setColor(BACKGROUND);
|
|
||||||
SDL_RenderFillRect(global.window.Renderer,rect);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
||||||
void drawMap() {
|
|
||||||
// <20><><EFBFBD><EFBFBD>
|
|
||||||
setColor(BACKGROUND);
|
|
||||||
SDL_RenderClear(global.window.Renderer);
|
|
||||||
|
|
||||||
for (int i = 0; i < ROW; i++) {
|
|
||||||
for (int j = 0; j < COL; j++) {
|
|
||||||
SDL_Rect rect = {j * rectWidth + 1,i * rectHeight + 1,rectWidth - 2,rectHeight - 2};
|
|
||||||
if (global.context.mapcopy[i][j] == 0) {
|
|
||||||
drawRect(&rect,OVER);
|
|
||||||
} else if (global.context.mapcopy[i][j] == -1) {
|
|
||||||
drawImg(i,j,&rect);
|
|
||||||
} else if (global.context.mapcopy[i][j] == 1) {
|
|
||||||
SDL_RenderCopy(global.window.Renderer,global.context.imgs[ 9 ],NULL,&rect);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
||||||
void mouseMove() {
|
|
||||||
int x,y;
|
|
||||||
SDL_GetMouseState(&x,&y);
|
|
||||||
SDL_Rect rect = {x / 40 * 40 + 1,y / 40 * 40 + 1,40 - 2,40 - 2};
|
|
||||||
if (global.context.mapcopy[y/40][x/40] == 0) {
|
|
||||||
drawRect(&rect,FLOW);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// <20><>ˮ<EFBFBD><CBAE><EFBFBD><EFBFBD><EFBFBD>㷨
|
|
||||||
void extend(int i, int j) {
|
|
||||||
if (i>=0 && j>=0 && i<ROW && j<COL && global.context.map[i][j] == 0 && global.context.mapcopy[i][j] != -1) {
|
|
||||||
global.context.mapcopy[i][j] = -1;
|
|
||||||
extend(i - 1,j);
|
|
||||||
extend(i,j - 1);
|
|
||||||
extend(i + 1,j);
|
|
||||||
extend(i,j + 1);
|
|
||||||
} else if ( i>=0 && j>=0 && i<ROW && j<COL && global.context.map[i][j] > 0) {
|
|
||||||
global.context.mapcopy[i][j] = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// <20>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>
|
|
||||||
void eventsProcess() {
|
|
||||||
while (SDL_PollEvent(&global.window.Event)) {
|
|
||||||
switch (global.window.Event.type) {
|
|
||||||
case SDL_QUIT:
|
|
||||||
windowShutdown();
|
|
||||||
case SDL_MOUSEBUTTONUP:
|
|
||||||
int x,y;
|
|
||||||
SDL_GetMouseState(&x,&y);
|
|
||||||
if (global.window.Event.button.button == SDL_BUTTON_LEFT) {
|
|
||||||
if ( global.context.map[y/40][x/40] == 0 && global.context.mapcopy[y/40][x/40] == 0) {
|
|
||||||
extend(y/40,x/40);
|
|
||||||
}
|
|
||||||
if ( global.context.mapcopy[y/40][x/40] == 0) {
|
|
||||||
global.context.mapcopy[y/40][x/40] = -1;
|
|
||||||
}
|
|
||||||
} else if (global.window.Event.button.button == SDL_BUTTON_RIGHT) {
|
|
||||||
if (global.context.mapcopy[y/40][x/40] == 1) {
|
|
||||||
global.context.mapcopy[y/40][x/40] = 0;
|
|
||||||
} else if (global.context.mapcopy[y/40][x/40] == 0) {
|
|
||||||
global.context.mapcopy[y/40][x/40] = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// <20><><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD>
|
|
||||||
void check() {
|
|
||||||
int num = BOOM;
|
|
||||||
for (int i = 0; i < ROW; i++) {
|
|
||||||
for (int j = 0; j < COL; j++) {
|
|
||||||
if (global.context.mapcopy[i][j] == -1 && global.context.map[i][j] == -1) {
|
|
||||||
flag = -1;
|
|
||||||
return;
|
|
||||||
} else if (global.context.mapcopy[i][j] == 1 && global.context.map[i][j] == -1) {
|
|
||||||
num -= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (num == 0) {
|
|
||||||
flag = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ʧ<><CAA7>
|
|
||||||
void defend() {
|
|
||||||
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
||||||
|
|
||||||
while (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// <20><>ʤ
|
|
||||||
void win() {
|
|
||||||
|
|
||||||
printf("<EFBFBD><EFBFBD>Ӯ<EFBFBD><EFBFBD>");
|
|
||||||
while (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void windowLoop() {
|
|
||||||
flag = 0;
|
|
||||||
|
|
||||||
while ( 1 ) {
|
|
||||||
if (flag == -1) {
|
|
||||||
defend();
|
|
||||||
break;
|
|
||||||
} else if (flag == 1) {
|
|
||||||
win();
|
|
||||||
break;
|
|
||||||
} else if (flag == 0) {
|
|
||||||
drawMap();
|
|
||||||
mouseMove();
|
|
||||||
SDL_RenderPresent(global.window.Renderer);
|
|
||||||
eventsProcess();
|
|
||||||
check();
|
|
||||||
}
|
|
||||||
SDL_Delay(6);
|
|
||||||
}
|
|
||||||
}
|
|
||||||