华哥和高鑫告诉我。要多写一下博客。记录下自己的学习问题及感想。这样就能更好的向大家学习交流。自己也能从中找到更大的学习乐趣和广泛的知识。
昨天。醒哥说我学了那么久自己也可以试一下先写些简单的小程序练习一下。这样就能从实践中学习和发现一些从课本上找不到的问题。以便向大家请教。是的,自己在一个自闭的角落是学习。真的进步很慢。所以。我会以后自己多写博客。多问问题。希望大家能多多的指教。谢谢大家。
昨天就先试写了一个贪吃蛇。因为自己早在两个星期前就看过高鑫的源码。所以对于它的思路也非常清楚了。但还是从写的过程中发现了很多细节的问题。先附上代码
//贪吃蛇
#include <windows.h>
#include <stdlib.h>
#include <time.h>
int NUM=5;
#define ID_TIMER 1
int i ,BTN = 4 ;
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
struct Snake
{
int left;
int top;
int right;
int button;
}s[500];
struct food
{
int x;
int y;
}f;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("Retro Snaker " ) ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ( "This program requires Windows NT!" ),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, // window class name