| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1241 人关注过本帖
标题:扫雷小游戏,NUM判断游戏的胜负时有时少加,有时又多加了,出了什么问题..
只看楼主 加入收藏
小白报道
Rank: 2
等 级:论坛游民
帖 子:42
专家分:10
注 册:2019-9-17
结帖率:62.5%
收藏
 问题点数:0 回复次数:0 
扫雷小游戏,NUM判断游戏的胜负时有时少加,有时又多加了,出了什么问题..
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<graphics.h>
#include<windows.h>
#define hang 10
#define lie 10
#define lei 10
#define size 50
int  NUM = 0;
int arr[hang+2][lie+2];
IMAGE graph[12];
void fun4(int m, int n);
void fun1()
{
    int i, j,m,n,sum=0;
    for (i = 0; i < hang+2; i++)
    {
        for (j = 0; j < lie+2 ; j++)
        {
            arr[i][j] = 0;
        }
    }
    srand((unsigned int)time(NULL));
    while (lei > sum)
    {
        m = 1 + rand() % (hang);
        n = 1 + rand() % (lie);
        if (arr[m][n] == 0)
        {
            arr[m][n] = -1;
            sum++;
        }
    }
    for (i = 1; i <= hang; i++)
    {
        for (j = 1; j <=lie; j++)
        {
            if (arr[i][j] == 0)
            {
                for (m = i - 1; m <= i + 1; m++)
                {
                    for (n = j - 1; n <=j + 1;n++)
                    {
                        if (arr[m][n] == -1)
                            arr[i][j]++;
                    }
                }
            }
        }
    }
    for (i = 1; i <= hang; i++)
    {
        for (j = 0; j <= lie; j++)
        {
            arr[i][j] += 20;
        }
    }
}
int  fun2()
{
    int  m, n;
    MOUSEMSG msg = {0};
    while (1)
    {
        msg = GetMouseMsg();
        switch (msg.uMsg)
        {
        case WM_LBUTTONDOWN:
            m = msg.x / size + 1;
            n = msg.y / size + 1;
            if (arr[m][n] >= 19 && arr[m][n] <= 28)
            {
                if (arr[m][n] == 20)
                {
                    fun4(m, n);
                }
                else
                {
                    arr[m][n] -= 20;
                    NUM++;
                }
                return arr[m][n];
            }
                break;
        case WM_RBUTTONDOWN:
            m = msg.x / size + 1;
            n = msg.y / size + 1;
            if (arr[m][n] >= 19 && arr[m][n] <= 28)
            {
                arr[m][n] += 30;
            }
            else if (arr[m][n] > 30)
                arr[m][n] -= 30;
            return arr[m][n];
            break;
        }
    }
}
void fun3()
{
    int i, j;
    for (i = 1; i <= hang; i++)
    {
        for (j = 1; j <= lie; j++)
        {
            if (arr[i][j] == -1)
                putimage((i - 1)*size, (j - 1)*size, &graph[9]);
            else if (arr[i][j] >= 0 && arr[i][j] <= 8)
                putimage((i - 1)*size, (j - 1)*size, &graph[arr[i][j]]);
            else if (arr[i][j] >= 19 && arr[i][j] < 28)
                putimage((i - 1)*size, (j - 1)*size, &graph[11]);
            else if (arr[i][j]>30)
                putimage((i - 1)*size, (j - 1)*size, &graph[10]);
        }
    }
}
void fun4(int m,int n)
{
    arr[m][n] -= 20;
    NUM++;
    int i, j;
    for (i = m-1; i <= m+1; i++)
    {
        for (j = n-1; j <= n+1; j++)
        {
            if (m >= 1 && m <= hang&&n >= 1 && n <= lie)
            {
                if (arr[i][j] >= 19 && arr[i][j] <= 28)
                {
                    if (arr[i][j] != 20)
                    {
                        arr[i][j] -= 20;
                        NUM++;
                    }
                    else
                    {
                        fun4(i, j);
                    }
                }
            }
        }
    }
}
int main()
{
    HWND hand=   initgraph(size*hang, size*lie);
    loadimage(&graph[0], L"0.jpg", size, size);
    loadimage(&graph[1], L"1.jpg", size, size);
    loadimage(&graph[2], L"2.jpg", size, size);
    loadimage(&graph[3], L"3.jpg", size, size);
    loadimage(&graph[4], L"4.jpg", size, size);
    loadimage(&graph[5], L"5.jpg", size, size);
    loadimage(&graph[6], L"6.jpg", size, size);
    loadimage(&graph[7], L"7.jpg", size, size);
    loadimage(&graph[8], L"8.jpg", size, size);
    loadimage(&graph[9], L"bomb0.jpg", size, size);
    loadimage(&graph[10], L"flag.jpg", size, size);
    loadimage(&graph[11], L"s.jpg", size, size);
     fun1();
     int i, j;
     for (i = 1; i <= hang; i++)
     {
         for (j = 1; j <= lie; j++)
         {
             printf("%2d", arr[i][j]);
         }
         printf("\n");
     }
     while (1)
     {
         fun3();
         if (fun2() == -1)
         {
             fun3();
             MessageBox(hand, L"low", L"", MB_OK);
             break;
         }
         if (hang*lie - NUM == lei)
         {
             fun3();
             MessageBox(hand, L"win", L"", MB_OK);
             break;
         }

     }
    system("pause");
    return 0;
}
搜索更多相关主题的帖子: size int jpg graph for 
2019-10-09 21:20
快速回复:扫雷小游戏,NUM判断游戏的胜负时有时少加,有时又多加了,出了什么问 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033226 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved