扫雷群规则资讯

抢红包群Ic语言经典游戏代码

发布人:微信群自动抢红包软件 来源:微信抢红包群,支付宝红包群,红包群,红包扫雷群发布时间:2022-08-20 21:03:13 热度:

C语言精品游戏主角和怪物源码

//C语言多线程-主角和怪物

include

include

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

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

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

int i=1;//i值为真

HANDLE hMutex;

//1.坐标

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

{

COORD pos;//点的结构体

pos.X=x;//横坐标

pos.Y=y;//纵坐标

SetConsoleCursorPosition(g_hout,pos);

//设置控制平台光标位置

}

DWORD WINAPI Func(LPVOID lpParamter)//多线程的功能函数6.线程是画怪物

{

HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);//7.拿到这张纸

WaitForSingleObject(hMutex, INFINITE);//13.自己进来,自己用洗手间

GamePosition(hout,x,y),printf("●");//8.在纸上画怪物

ReleaseMutex(hMutex);//14.放弃使用权

while(1)//9.怪物在横坐标为从0-10依次循环移动想要一起学习C++的可以加群248894430,群内有各种资料满足大家

{

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

{

printf(" ");

GamePosition(hout,++x,y);

printf("●");

Sleep(1000);

if(x==10)

i=0;//i为假

}

else if(x<=10&&i==0)

{

printf(" ");

GamePosition(hout,--x,y);

printf("●");

Sleep(1000);

if(x==0)

i=1;

}

}

return 0;

}

int main()

{

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

hMutex = CreateMutexA(NULL, FALSE, "123");//创建互斥锁(量)//10.关上洗手间

HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);//2.拿到这张纸

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

GamePosition(hout,a,b),printf("☆");//3.在纸上画主角

ReleaseMutex(hMutex);//12.同事出来了,放弃了洗手间的使用权

while(1)

{

if(kbhit())

switch(getch())//控制左右 4.主角上下左右移动

{

case w:

case W:

if(b>3)GamePosition(hout,a,b),printf(" "),GamePosition(hout,a,--b),printf("☆");

break;

case s:

case S:

if(b<20)GamePosition(hout,a,b),printf(" "),GamePosition(hout,a,++b),printf("☆");

break;

case a:

case A:

if(a>0)printf(" "),GamePosition(hout,--a,b),printf("☆");

break;

case d:

case D:

if(a<20)printf(" "),GamePosition(hout,++a,b),printf("☆");

break;

}

}

CloseHandle(hThread);

system("pause");

return 0;

}

扫雷游戏代码源码

想要一起学习C++的可以加群248894430,群内有各种资料满足大家

include

include

include

int main (){

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

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

char map[10][10] = {0};

char show[10][10] = {0};

srand(time(0));

for(row = 0;row <= 9;row++){

for(col = 0;col <= 9;col++){

map[row][col] = 0;

}

}

do{

row = rand() % 10;

col = rand() % 10;

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

map[row][col] = x;

num++;

}

}while(num < 10);

for (row = 0;row <= 9;row++){

for (col = 0;col <= 9;col++){

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

int cnt = 0;

for (num = 0;num <= 7;num++){

if(row + delta[num][0] < 0){

continue;

}

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

continue;

}

if(col + delta[num][1] < 0){

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 < 10;row++){

for(col = 0;col < 10;col ++){

printf("* ");

}

printf("\n");

}

num = 0;

int x,y;

do{

printf("please enter the coordinate of array:");

scanf("%d%d",&x,&y);

show[x-1][y-1] = 1;

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

for (num = 0;num <= 7;num++){

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

continue;

}

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

continue;

}

if(y -1+ delta[num][1] < 0){

continue;

}

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

continue;

}

show[x-1+delta[num][0]][y-1+delta[num][1]] = 1;

}

}

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

for (num = 0;num <= 7;num++){

int cnt = 0;

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

continue;

}

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

continue;

}

if(y-1 + delta[num][1] < 0){

continue;

}

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

continue;

}

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

show[x-1 + delta[num][0]][y -1+ delta[num][1]] = 1 ;

}

}

}

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

printf("game over!\n");

for (row = 0;row < 10;row++){

for(col = 0;col < 10;col ++){

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

}

printf("\n");

}

return 0;

}

system("cls");

printf("mine sweeping:\n");

for (row = 0;row < 10;row++){

for(col = 0;col < 10;col ++){

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

{

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

}

else

{

printf("* ");

}

}

printf("\n");

}

num = 0;

for (row = 0;row < 10;row++){

for(col = 0;col < 10;col ++){

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

{

num++;

}

}

}

printf("num:%d\n",num);

}while(num < 90);

printf("you win!");

return 0;

}

想要一起学习C++的可以加群248894430,群内有各种资料满足大家

... 
上一篇 : 微信红包群IC语言游戏编程到底怎么学之(扫雷源码)
下一篇 : QQ红包群I利用Python实现自动扫雷脚本,最高难度也难不
猜你喜欢的微信抢红包群,支付宝红包群,红包群,红包扫雷群