| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 836 人关注过本帖, 1 人收藏
标题:用win32编的打飞机,不知道哪里错了,大家帮忙看看
只看楼主 加入收藏
hbytwq
Rank: 1
等 级:新手上路
帖 子:4
专家分:2
注 册:2013-10-19
结帖率:0
收藏(1)
已结贴  问题点数:20 回复次数:9 
用win32编的打飞机,不知道哪里错了,大家帮忙看看
大神们帮忙看看我下面这个代码有什么问题,老师让写一个模拟微信里打飞机的游戏的程序 ,用VC 2005里面 win32写的我现在写到飞机能动 空格键发射子弹能发,敌人飞机能下来,就差最后一步:子弹碰到敌人飞机,子弹和敌人同时消失,应该就是最后一个函数的问题,游戏一运行到子弹碰到敌机就崩溃,我是在是想不出来怎么改……麻烦大家帮忙看下,谢谢了!!! 主要是最后一个函数


#include<windows.h>

#define FEIJI_TIME 1001
#define ZIDAN_TIME 1002
#define DIREN_TIME 1003
typedef struct Node
{
    int x;
    int y;
    struct Node *pNext;
}PLANE,ZIDAN,DIREN;
PLANE *pHead = NULL;
ZIDAN *pZidan = NULL;
DIREN *pDiren = NULL;
LRESULT CALLBACK pp(HWND a, UINT b, WPARAM c, LPARAM d);
void zaoPLANE(int x,int y);
void showPLANE(int x,int y,HWND hWnd);
void showZIDAN(PLANE *pHead,HWND hWnd);
void moveZIDAN(PLANE *pHead);
void zaoZIDAN();
void moveDIREN(DIREN *pDiren);
void showDIREN(DIREN *pDiren,HWND hWnd);
void zaoDIREN();
void blast(ZIDAN *pZidan,DIREN *pDiren);
int __stdcall WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR pszCmdLine,int nShowCmd)
{
    WNDCLASSEX wc;
    HWND hWnd;
    MSG msg;
    wc.cbClsExtra = 0;
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.cbWndExtra = 0;
    wc.hbrBackground = (HBRUSH)5;
    wc.hCursor = NULL;
    wc.hIcon = NULL;
    wc.hIconSm = NULL;
    wc.hInstance = hInstance;
    wc.lpfnWndProc = pp;
    wc.lpszClassName = "hahaha";
    wc.lpszMenuName = NULL;
    wc.style = CS_HREDRAW | CS_VREDRAW;

    RegisterClassEx(&wc);

    hWnd = CreateWindow("hahaha","hehe",WS_OVERLAPPEDWINDOW,0,0,1370,745,NULL,NULL,hInstance,NULL);
    ShowWindow(hWnd,nShowCmd);

    while(GetMessage(&msg,NULL,0,0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return 0;
}

LRESULT CALLBACK pp(HWND hWnd, UINT msg, WPARAM wParam, LPARAM d)
{
    static int x = 600;
    static int y = 600;
    HDC hdc;
    switch(msg)
    {
    case WM_KEYDOWN:
        switch(wParam)
        {
            case VK_DOWN:
                y+=10;
                break;
            case VK_UP:
                y-=10;   
                break;
            case VK_LEFT:
                x-=30;
                break;
            case VK_RIGHT:
                x+=30;
                break;
            case VK_SPACE:
                zaoPLANE(x,y);
                zaoZIDAN();
        }
        break;
    case WM_CREATE:
        SetTimer(hWnd,FEIJI_TIME,3,NULL);
        SetTimer(hWnd,ZIDAN_TIME,40,NULL);
        SetTimer(hWnd,DIREN_TIME,400,NULL);
        break;
    case WM_TIMER:
        blast(pZidan,pDiren);
        hdc = GetDC(hWnd);
        Rectangle(hdc,0,0,10000,10000);
        ReleaseDC(hWnd,hdc);
        
        switch(wParam)
        {
        case FEIJI_TIME:
            
            break;
        case ZIDAN_TIME:
            
            moveZIDAN(pZidan);
            break;
        case DIREN_TIME:
            zaoDIREN();
            moveDIREN(pDiren);
            break;
        }
        break;
    case WM_CLOSE:
        PostQuitMessage(0);
        break;
    }
   
    showPLANE(x,y,hWnd);
    showZIDAN(pZidan,hWnd);
    showDIREN(pDiren,hWnd);
   
    return DefWindowProc(hWnd,msg,wParam,d);
}

void zaoPLANE(int x,int y)
{
   
    PLANE *temp;
    temp = (PLANE*)malloc(sizeof(PLANE));
    temp->x = x;
    temp->y = y;
    temp->pNext = NULL;
    if(NULL == pHead)
    {
        pHead = temp;
    }
    else
    {
        temp->pNext = pHead;
        pHead = temp;
    }
   
}

void showPLANE(int x,int y,HWND hWnd)
{
    HDC hdc;
    hdc = GetDC(hWnd);
    Rectangle(hdc,x,y,x+30,y+30);
    ReleaseDC(hWnd,hdc);

}
  //造飞机,显示飞机
void zaoZIDAN()
{
    ZIDAN *temp = (ZIDAN*)malloc(sizeof(ZIDAN));
    temp->x = pHead->x;
    temp->y = pHead->y;
    temp->pNext = NULL;
    if(NULL == pZidan)
    {
        pZidan = temp;
    }
    else
    {
        temp->pNext = pZidan;
        pZidan = temp;
    }
}
void showZIDAN(PLANE *pHead,HWND hWnd)
{   
    HDC hdc;
    hdc = GetDC(hWnd);
    while(pHead != NULL)
    {
        Rectangle(hdc,pHead->x+9,pHead->y,pHead->x+10+9,pHead->y+10);
        pHead = pHead->pNext;
    }
    ReleaseDC(hWnd,hdc);
}

void moveZIDAN(PLANE *pHead)
{
    while(pHead != NULL)
    {
        pHead->y-=10;
        pHead = pHead->pNext;
    }
}


void zaoDIREN()
{
    DIREN *temp = (DIREN*)malloc(sizeof(DIREN));
    temp->x = rand()%1200;
    temp->y = -60;
    temp->pNext = NULL;
    if(NULL == pDiren)
    {
        pDiren = temp;
    }
    else
    {
        temp->pNext = pDiren;
        pDiren = temp;
    }
}

void showDIREN(DIREN *pDiren,HWND hWnd)
{
    HDC hdc = GetDC(hWnd);
    while(pDiren)
    {
        Ellipse(hdc,pDiren->x,pDiren->y,pDiren->x+30,pDiren->y+30);
        pDiren = pDiren->pNext;
    }
    ReleaseDC(hWnd,hdc);
}

void moveDIREN(DIREN *pDiren)
{
    while(pDiren)
    {
        pDiren->y+=30;
        pDiren = pDiren->pNext;
    }
}

void blast(ZIDAN *pZidan,DIREN *pDiren)
{
    ZIDAN *ji_pZidan = pZidan;
    DIREN *ji_pDiren = pDiren;
    DIREN *ji_pDiren_2 = pDiren;
    ZIDAN *a = NULL;
    DIREN *b = NULL;
    while(pZidan)
    {
        while(pDiren)
        {
            if( (pZidan->x >= pDiren->x && pZidan->x <= pDiren->x+30) &&  (pZidan->y >= pDiren->y && pZidan->y <= pDiren->y+30))
            {
                //MessageBox(NULL,"asa","asa",MB_OK);   
                //break;
                a = pZidan;
                b = pDiren;
                /*ji_pDiren->pNext = pDiren->pNext;
                ji_pZidan->pNext = pZidan->pNext;*/
                free(a);
                free(b);
                break;
            }
            ji_pDiren = pDiren;
            pDiren = pDiren->pNext;
        }
        pDiren = ji_pDiren_2;
        ji_pZidan = pZidan;
        pZidan = pZidan->pNext;
    }
}
搜索更多相关主题的帖子: 游戏 include 
2013-10-19 18:28
qunxingw
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:贵宾
威 望:24
帖 子:1676
专家分:7295
注 册:2011-6-30
收藏
得分:4 
先收藏学习一下!
是否是当孑弹和飞机位置相同时刪除这两个结点的思路?

www.qunxingw.wang
2013-10-19 20:30
tlliqi
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:204
帖 子:15453
专家分:65956
注 册:2006-4-27
收藏
得分:4 
楼主很不错嘛
2013-10-19 20:36
hbytwq
Rank: 1
等 级:新手上路
帖 子:4
专家分:2
注 册:2013-10-19
收藏
得分:0 
回复 2楼 qunxingw
是的,总崩溃 我都要崩溃了……
2013-10-19 20:39
hbytwq
Rank: 1
等 级:新手上路
帖 子:4
专家分:2
注 册:2013-10-19
收藏
得分:0 
回复 3楼 tlliqi
额……
2013-10-19 20:39
LD199
Rank: 2
来 自:中国
等 级:论坛游民
帖 子:18
专家分:46
注 册:2013-10-12
收藏
得分:4 
有点牛。不知这个程序在哪里运行?
2013-10-20 23:01
C_printf
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:102
专家分:122
注 册:2010-1-26
收藏
得分:4 
整个程序中,链表的增删改查都错了。
看一个星期链表再来吧
2013-10-21 11:08
龙之心
Rank: 1
等 级:新手上路
帖 子:1
专家分:4
注 册:2013-10-21
收藏
得分:4 
先顶一下,楼主是我等小白的榜样啊
2013-10-21 12:59
冬2509102
Rank: 2
等 级:论坛游民
帖 子:32
专家分:33
注 册:2013-9-14
收藏
得分:4 
请问一下,你这是属于C++程序吗

[ 本帖最后由 冬2509102 于 2013-10-21 18:20 编辑 ]
2013-10-21 18:18
风清云起
Rank: 1
等 级:新手上路
帖 子:11
专家分:4
注 册:2015-6-27
收藏
得分:0 
就是注释太少
2015-07-05 10:36
快速回复:用win32编的打飞机,不知道哪里错了,大家帮忙看看
数据加载中...
 
   



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

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