C语言卓绝游戏代码

#include <stdio.h>

图片 1

void printMap(char map[][10]);

C语言精品游戏主演和魔鬼源码

void shoveBox(char map[][10]);

//C语言二十八线程-主演和魔鬼

int main(int argc, const char * argv[])

#include

{

#include

char map[][10] = {

#define bool int //定义int变量为bool变量,bool不是真正是假

{‘#’, ‘#’, ‘#’, ‘#’, ‘#’, ‘#’, ‘#’, ‘#’, ‘#’, ‘#’},

int a=0,b=20;//主演的坐标

{‘#’, ‘ ‘, ‘#’, ‘#’, ‘#’, ‘#’, ‘#’, ‘#’, ‘#’, ‘#’},

int x=1,y=0;//怪物的坐标

{‘#’, ‘ ‘, ‘ ‘, ‘#’, ‘ ‘, ‘#’, ‘#’, ‘#’, ‘#’, ‘#’},

int i=1;//i值为真

{‘#’, ‘#’, ‘ ‘, ‘ ‘, ‘ ‘, ‘#’, ‘#’, ‘#’, ‘#’, ‘#’},

HANDLE hMutex;

{‘#’, ‘#’, ‘ ‘, ‘ ‘, ‘ ‘, ‘ ‘, ‘ ‘, ‘ ‘, ‘#’, ‘#’},

//1.坐标

{‘#’, ‘#’, ‘ ‘, ‘0’, ‘ ‘, ‘ ‘, ‘ ‘, ‘ ‘, ‘#’, ‘#’},

void GamePosition(HANDLE g_hout,int x,int y)

{‘#’, ‘#’, ‘ ‘, ‘x’, ‘ ‘, ‘ ‘, ‘ ‘, ‘ ‘, ‘#’, ‘#’},

{

{‘#’, ‘#’, ‘ ‘, ‘ ‘, ‘ ‘, ‘ ‘, ‘ ‘, ‘ ‘, ‘#’, ‘#’},

CEO卡宴D pos;//点的结构体

{‘#’, ‘#’, ‘ ‘, ‘ ‘, ‘ ‘, ‘ ‘, ‘ ‘, ‘#’, ‘#’, ‘#’},

pos.X=x;//横坐标

{‘#’, ‘#’, ‘#’, ‘#’, ‘#’, ‘#’, ‘ ‘, ‘#’, ‘#’, ‘#’}

pos.Y=y;//纵坐标

};

SetConsoleCursorPosition(g_hout,pos);

printMap(map);

//设置调节平台光标地点

shoveBox(map);

}

return 0;

DWOQashqaiD WINAPI Func(LPVOID lpParamter)//10二线程的功用函数陆.线程是画怪物

}

{

void shoveBox(char map[][10])

HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);//柒.获得那张纸

{

WaitForSingleObject(hMutex, INFINITE);//1三.温馨进入,自身用厕所

int pX = 6;

GamePosition,printf;//八.在纸上画怪物

int pY = 三; //人物的坐标

ReleaseMutex;//1四.抛弃使用权

int bX = 5;

while//九.怪物在横坐标为从0-十一一轮回移动

int bY = 3; //箱子坐标

{

char key = ‘ ‘;

if(x>=0&&i==1)

printf(“X代表人,0代表箱子,w,s,a,d调整方向\n”);

{

while (map[bX][bY] != map[9][6]) {
//循环,假设箱子不在出口一贯循环

printf;

scanf(“%c”,&key); //输入方向键调节人物

GamePosition(hout,++x,y);

getchar();

printf;

switch (key) {

Sleep;

case ‘w’: //往上

if

if (map[pX-1][pY] == ‘0’ && map[bX-1][bY] == ‘ ‘) {
//人物前边若是有箱子,并且箱子在上,箱子前面是空

i=0;//i为假

map[pX][pY] = ‘ ‘;

}

map[bX][bY] = ‘x’;

else if(x

map[bX-1][bY] = ‘0’;

{

–pX;

printf;

–bX;

GamePosition(hout,–x,y);

}else if (map[pX-1][pY] == ‘ ‘){ //人物后面固然是空

printf;

map[pX][pY] = ‘ ‘;

Sleep;

map[pX-1][pY] = ‘x’;

if

–pX;

i=1;

}

}

break;

}

case ‘s’: // 往下

return 0;

if (map[pX+1][pY] == ‘0’ && map[bX+1][bY] == ‘ ‘) {
//人物前面要是有箱子

}

map[pX][pY] = ‘ ‘;

int main()

map[bX][bY] = ‘x’;

{

map[bX+1][bY] = ‘0’;

HANDLE hThread = CreateThread(NULL, 0, Func, NULL, 0, NULL);//伍.创造线程

++pX;

hMutex = CreateMutexA(NULL, FALSE, “12三”);//创造互斥锁//拾.关上厕所

++bX;

HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);//二.得到那张纸

}else if (map[pX+1][pY] == ‘ ‘){ //人物前边如若是空

WaitForSingleObject(hMutex, INFINITE);//11.等待你的同事出去 一伍步接着

map[pX][pY] = ‘ ‘;

GamePosition,printf;//三.在纸上画主演

map[pX+1][pY] = ‘x’;

ReleaseMutex;//1二.同事出去了,吐弃了洗手间的使用权

++pX;

while

}

{

break;

if

case ‘a’: // 往左

switch//调整左右 四.支柱上下左右活动

if (map[pX][pY-1] == ‘0’ && map[bX][bY-1] == ‘ ‘) {
//人物前边借使有箱子

{

map[pX][pY] = ‘ ‘;

case ‘w’:

map[bX][bY] = ‘x’;

case ‘W’:

map[bX][bY-1] = ‘0’;

ifGamePosition,printf,GamePosition(hout,a,–b),printf;

–pY;

break;

–bY;

case ‘s’:

}else if (map[pX][pY-1] == ‘ ‘){ //人物后面借使是空

case ‘S’:

map[pX][pY] = ‘ ‘;

if(b

map[pX][pY-1] = ‘x’;

break;

–pY;

case ‘a’:

}

case ‘A’:

break;

ifprintf,GamePosition(hout,–a,b),printf;

case ‘d’: // 往右

break;

if (map[pX][pY+1] == ‘0’ && map[bX][bY+1] == ‘ ‘) {
//人物前面假诺有箱子

case ‘d’:

map[pX][pY] = ‘ ‘;

case ‘D’:

map[bX][bY] = ‘x’;

if(a

map[bX][bY+1] = ‘0’;

break;

++pY;

}

++bY;

}

}else if (map[pX][pY+1] == ‘ ‘){ //人物后面即便是空

CloseHandle;

map[pX][pY] = ‘ ‘;

system;

map[pX][pY+1] = ‘x’;

return 0;

++pY;

}

}

扫雷游戏代码源码

break;

#include

}

#include

printMap(map);

#include

}

int main (){

}

int delta[8][2] = {{-1,-1},{-1,0},{-1,1},,,,,};

/**

int row =0,col = 0,num = 0;

* 打字与印刷地图

char map[10][10] = ;

*

char show[10][10] = ;

* @param map 地图

srand;

*/

for(row = 0;row

void printMap(char map[][10])

for(col = 0;col

{

map[row][col] = ‘0’;

for (int x = 0; x <= 10 -1 ; x++) {

}

for (int j = 0 ; j <= 10 – 1; j++) {

}

printf(“%c”, map[x][j]);

do{

}

row = rand() % 10;

printf(“\n”);

col = rand() % 10;

}

if(map[row][col] == ‘0’){

if (map[9][6] == ‘0’) {

map[row][col] = ‘x’;

printf(“成功!\n”);

num++;

}

}

}

}while(num

for (row = 0;row

for (col = 0;col

if(map[row][col] != ‘x’){

int cnt = 0;

for (num = 0;num

if(row + delta[num][0]

continue;

}

if(row + delta[num][0] > 9){

continue;

}

if(col + delta[num][1]

continue;

}

if(col + delta[num][1] > 9){

continue;

}

if(map[row + delta[num][0]][col + delta[num][1]]== ‘x’){

cnt++;

}

}

map[row][col] = ‘0’ + cnt;

}

}

}

for (row = 0;row

for(col = 0;col

printf;

}

printf;

}

num = 0;

int x,y;

do{

printf(“please enter the coordinate of array:”);

scanf(“%d%d”,&x,&y);

if(map[x-1][y-1] == ‘0’){

for (num = 0;num

if(x-1 + delta[num][0]

continue;

}

if(x-1 + delta[num][0] > 9){

continue;

}

if(y -1+ delta[num][1]

continue;

}

if(y-1 + delta[num][1] > 9){

continue;

}

}

}

if (map[x-1][y-1]!= ‘x’&&map[x-1][y-1] != ‘0’){

for (num = 0;num

int cnt = 0;

if(x-1 + delta[num][0]

continue;

}

if(x-1 + delta[num][0] > 9){

continue;

}

if(y-1 + delta[num][1]

continue;

}

if(y-1 + delta[num][1] > 9){

continue;

}

if( map[x -1 + delta[num][0]][y -1+ delta[num][1]] != ‘x’){

}

}

}

if(map[x-1][y-1] == ‘x’) {

printf(“game over!\n”);

for (row = 0;row

for(col = 0;col

printf(“%c “,map[row][col]);

}

printf;

}

return 0;

}

system;

printf(“mine sweeping:\n”);

for (row = 0;row

for(col = 0;col

if (show[row][col] == 1)

{

printf(“%c “, map[row][col]);

}

else

{

printf;

}

}

printf;

}

num = 0;

for (row = 0;row

for(col = 0;col

if (show[row][col] == 1 )

{

num++;

}

}

}

printf(“num:%d\n”,num);

}while(num

printf(“you win!”);

return 0;

}

图片 2图片 3