中北大学吧 关注:362,664贴子:20,034,173
  • 6回复贴,共1

自制力差,怎么办?

只看楼主收藏回复

说过这学期,不编程了,还是编了,怎么办?自制力太差。


1楼2012-05-28 04:55回复
    几天重写了贪吃蛇代码,没成功,怎么比以前还不如,以前还能写出来。
    谁能改就改一下。
    自制力差
    #include <windows.h>
    #include <stdio.h>
    #include <string.h>
    #include <time.h>
    #include <malloc.h>
    #define RED RGB(255,0,0)
    #define GREEN RGB(0,255,0)
    #define BLUE RGB(0,0,255)
    #define ROWS 50   //行
    #define COLUMS 50   //列
    int table[ROWS][COLUMS] = {0,0};//桌面
    //得分
    int SCORE = 0;
    clock_t start = 0;
    clock_t finish = 0;
    HWND CLIENTHWND;   //客户区句柄
    RECT CLIENTRECT;   //客户区
    HDC CLIENTRECTHDC;
    HBITMAP CLIENTRECTBMP;
    HBITMAP HDCBMP;
    LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam , LPARAM lParam);
    void clearSnake();
    bool Is_Touch_Self(int x,int y);
    bool Is_out_table(int x,int y);
    void MOUVE(int x, int y);
    void EATE_FOOD(int x, int y);
    void CREATE_FOOD();
    void PRESS_DOWN(WPARAM wParam);
    void PRESS_CHAR(WPARAM wParam);
    void NEW_GAME();
    void RUN_GAME();
    void DRAW_TABLE();
    //蛇的身体
    typedef struct snake_body
    {
       int x;     //横坐标
       int y;      //纵坐标
       struct snake_body* next;
    }SNAKE;
    //游戏状态
    enum GAME_STA
    {
    GAME_OVER,
    GAME_RUN,
    GAME_PAUSE,
    GAME_START
    }STATE = GAME_START;
    //蛇移动的方向
    typedef enum _direction
    {LEFT=0,
         UP,
    DOWN,
    RIGHT
    }DIR;
    SNAKE* head = NULL;
    DIR direction;
    //清除贪吃蛇链表
    void clearSnake()
    {
    SNAKE* p;
    p = head;
    while(p != NULL)
    {
          p=p->next;
          free(head);
          head = p;
    }
    }
    //判断蛇是否碰到自己的身体
    bool Is_Touch_Self(int x, int y)
    {
    int nX, nY;
    nX = head->x;
    nY = head->y;
    if(x == nX && y == nY)
    {
       return true;
    }
    return false;
    }
    //判断蛇头是否出界
    bool Is_out_table(int x, int y)
    {
    if(x<0 ||y<0 ||x>=ROWS ||y>=COLUMS)
    {
       return true;
    }
    return false;
    }
    //蛇没有碰到食物,向前移动
    void MOUVE(int x, int y)
    {
          int nx, ny;
       SNAKE* p;
       p = head;
       while(p!=NULL)
       {
        nx = p->x;
        ny = p->y;
        p->x = x;
        p->y = y;
        x = nx;
        y = ny;
        p = p->next;
       }
    }
    //蛇碰到食物
    void EATE_FOOD(int x, int y)
    {
          SCORE += table[x][y] ;
       SNAKE* p;
       p = head;
       head = (SNAKE*)malloc(sizeof(SNAKE));
       head->x = x;
       head->y = y;
       head->next = p;
       CREATE_FOOD();
    }
    //创建食物
    


    2楼2012-05-28 04:55
    回复
          {
           int x = p->x*danwei;
           int y = p->y*danwei;
           Rectangle(CLIENTRECTHDC,x,y,x+danwei,y+danwei);
           p = p->next;
          }
          SelectObject(CLIENTRECTHDC,OLDBRUSH);
          //画食物
           int j;
           HBRUSH FOODBRUSH = CreateHatchBrush(HS_DIAGCROSS,RGB(0,0,255));
           HBRUSH OLDFOOD;
           for(i=0;i<50;i++)
           {
            for(j=0;j<50;++j)
            if(table[i][j])
            {
             OLDFOOD = (HBRUSH)SelectObject(CLIENTRECTHDC,FOODBRUSH);
             Rectangle(CLIENTRECTHDC,i*danwei,j*danwei,i*danwei+danwei,j*danwei+danwei);
             SelectObject(CLIENTRECTHDC,OLDFOOD);
            }
           }
         //画右边矩形框
         HPEN gight = CreatePen(PS_SOLID,1,RGB(122,122,122));
         HPEN oldright;
         oldright = (HPEN)SelectObject(CLIENTRECTHDC,gight);
         MoveToEx(CLIENTRECTHDC,CLIENTRECT.left+danwei*50,0,NULL);
         LineTo(CLIENTRECTHDC,CLIENTRECT.left+50*danwei,CLIENTRECT.top);
         LineTo(CLIENTRECTHDC,CLIENTRECT.right,CLIENTRECT.top);
         LineTo(CLIENTRECTHDC,CLIENTRECT.right,CLIENTRECT.bottom);
         LineTo(CLIENTRECTHDC,CLIENTRECT.left+danwei*50,CLIENTRECT.bottom);
        
         SelectObject(CLIENTRECTHDC,oldright);  
         //画得分
         TCHAR str[20];
         sprintf(str,"得分:%d",SCORE);
            SetTextColor(CLIENTRECTHDC,RGB(100,100,100));
            TextOut(CLIENTRECTHDC,CLIENTRECT.left+50*danwei+danwei,CLIENTRECT.top+25*danwei,str,sizeof(str)/sizeof(TCHAR));
           
      }
      else if(GAME_START == STATE)
      {
         LOGFONT it;
         it.lfHeight = danwei*5;
         it.lfWeight = danwei*5;
         it.lfItalic = 1;
         //HPEN pen;
         HPEN OLDPEN;
         HFONT pen;
         pen = CreateFontIndirect(&it);
         OLDPEN = (HPEN)SelectObject(CLIENTRECTHDC,pen);
         TextOut(CLIENTRECTHDC,(CLIENTRECT.right-CLIENTRECT.left)/2,
         (CLIENTRECT.bottom-CLIENTRECT.top)/2,"SNAKE GAME",sizeof("SNAKE GAME")/sizeof(TCHAR));
        
         SelectObject(CLIENTRECTHDC,OLDPEN);
      }
      else
      {
        
         LOGFONT it;
         it.lfHeight = danwei*5;
         it.lfWeight = danwei*5;
         it.lfItalic = 1;
         //HPEN pen;
         HPEN OLDPEN;
         HFONT pen;
         pen = CreateFontIndirect(&it);
      


      5楼2012-05-28 04:55
      回复
           OLDPEN = (HPEN)SelectObject(CLIENTRECTHDC,pen);
           TextOut(CLIENTRECTHDC,(CLIENTRECT.right-CLIENTRECT.left)/2,
           (CLIENTRECT.bottom-CLIENTRECT.top)/2,"GAME OVER",sizeof("GAME OVER")/sizeof(TCHAR));
          
           SelectObject(CLIENTRECTHDC,OLDPEN);
        }
        }
        //全局变量
        TCHAR szWindowClass[] = "演示程序";
        TCHAR szWindowTitle[] = "主窗口标题";
        //窗口过程函数
        LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam , LPARAM lParam)
        {
        switch(msg)
        {
           case WM_CREATE:
           {
          
               return 0;
           }
           case WM_PAINT:
           {
            PAINTSTRUCT ps;
            HDC hdc;
            hdc = BeginPaint(CLIENTHWND,&ps);
            BitBlt(hdc,CLIENTRECT.left,CLIENTRECT.top,CLIENTRECT.right,
            CLIENTRECT.bottom,CLIENTRECTHDC,0,0,SRCCOPY);
            EndPaint(CLIENTHWND,&ps);
            return 0;
           }
           //WM_DESTROY消息响应
        case WM_DESTROY:
           {
            PostQuitMessage(0);
            return 0;
           }
           //不关心的消息使用缺省处理
        default:
           return DefWindowProc(hWnd, msg, wParam, lParam);
        }
        }
        int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE, LPTSTR lpCmdLine, int nCmdShow)
        {
        //填充窗口类
        WNDCLASSEX wcex;
        wcex.cbSize    = sizeof(WNDCLASSEX);
        wcex.style    = CS_HREDRAW | CS_VREDRAW;
        wcex.lpfnWndProc = (WNDPROC)WndProc;
        wcex.cbClsExtra   = 0;
        wcex.cbWndExtra   = 0;
        wcex.hInstance   = hInstance;
        wcex.hIcon    = NULL;
        wcex.hCursor   = LoadCursor(NULL,IDC_ARROW);
        wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW +1);
        wcex.lpszMenuName = NULL;
        wcex.lpszClassName = szWindowClass;
        wcex.hIconSm   = NULL;
        //注册窗口类
        RegisterClassEx(&wcex);
        //创建窗口
        HWND hWnd = CreateWindowEx(
           0,
           szWindowClass,
           szWindowTitle,
           WS_OVERLAPPEDWINDOW,
           128,
           96,
           680,
           480,
           HWND_DESKTOP,
           NULL,
           hInstance,
           NULL);
        //创建窗口失败
        if(!hWnd)
           return 0;
                  HDC hdc;
            PAINTSTRUCT ps;
            hdc = GetDC(CLIENTHWND);
            GetClientRect(CLIENTHWND,&CLIENTRECT);/*窗口大小*/
            CLIENTRECTHDC = CreateCompatibleDC(hdc);
            CLIENTRECTBMP = CreateCompatibleBitmap(
            hdc,CLIENTRECT.right,CLIENTRECT.bottom);
            HDCBMP = (HBITMAP)SelectObject(CLIENTRECTHDC,HDCBMP);
            ReleaseDC(CLIENTHWND,hdc);
            EndPaint(CLIENTHWND,&ps);
        //显示并更新窗口
        ShowWindow(hWnd,nCmdShow);
        UpdateWindow(hWnd);
           NEW_GAME();
        //设置消息循环
        MSG msg;
        for(;;){
           if(STATE == GAME_RUN)
           RUN_GAME();
           if(PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
           {
        if(GetMessage(&msg, NULL, 0, 0))
        {
           TranslateMessage(&msg);
           DispatchMessage(&msg);
        }
        else break;
           }
        }
             DeleteObject(CLIENTRECTBMP);
             DeleteObject(HDCBMP);
             DeleteDC(CLIENTRECTHDC);
        return 1;
        }
        这学期,不编程了,复习去,要是在编程,我从主楼跳下去,对自己狠一点


        6楼2012-05-28 04:55
        回复
          犀利啊,我还不会么


          8楼2012-05-28 04:55
          回复
            没事不成仁就成鬼呀


            9楼2012-05-28 04:55
            回复