代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
CSharp
】
打靶游戏
作者:
pan_yz
/ 发布于
2015/3/23
/
891
#define GDIPVER 0x0110 #define WIN32_LEAN_AND_MEAN #include <windows.h> #include <ObjIdl.h> #include <GdiPlus.h> #include <windowsx.h> #include <tchar.h> #include <mmsystem.h> #include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> #include "resource.h" #include <mmsystem.h> #pragma comment(lib, "winmm.lib") #pragma comment(lib,"GdiPlus.lib") using namespace Gdiplus; #define WINDOW_WIDTH 800 #define WINDOW_HEIGHT 600 static int cxball,cyball; VOID OnPaint(HDC hDC,int x,int y) { Graphics _g(hDC); //构造画笔 Pen _p( Color::Red, //颜色 2.0F); //笔宽(默认:1.0F) _g.DrawEllipse(&_p,x, y, 50, 50); //设置笔宽与颜色 _p.SetColor(Color(255,111,222,55)); //设置颜色 _p.SetWidth(3.0F);//设置笔宽 //获得笔宽与颜色 Color _c;_p.GetColor(&_c);//获取颜色 REAL _r = _p.GetWidth();//获取笔宽 } LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wparam, LPARAM lparam) { static PMSG pmsg; switch(msg) { PAINTSTRUCT ps ; HDC hDC; static int cxClient, cyClient ; static int cxcreat,cycreat; static int times,score; TCHAR szText[256]; case WM_CREATE: { hDC = GetDC(hWnd); PlaySound(MAKEINTRESOURCE(IDR_WAVE1), hinstance_app, SND_RESOURCE | SND_ASYNC); times = 9; score = 0; ReleaseDC(hWnd,hDC); return(0); } break; case WM_SIZE: { cxClient = LOWORD (lparam) ; cyClient = HIWORD (lparam) ; return 0 ; } break; case WM_LBUTTONDOWN : { switch (wparam) { case MK_LBUTTON: hDC = GetDC(hWnd); sprintf(szText,"得分为 %d",score); TextOut(hDC,900,240,szText,10); times--; sprintf(szText,"次数为 %d",times); TextOut(hDC,900,280,szText,8); cxcreat = (int)LOWORD( lparam ) ; //获取鼠标位置x坐标信息 cycreat = (int)HIWORD( lparam ) ; //获取鼠标位置y坐标信息 SetBkMode(hDC, OPAQUE); if(cxcreat>cxball-50&&cxcreat<cxball+50) { if(cycreat>cyball-50&&cycreat<cyball+50) { score+=100; } } if(times <= 0) { score = 0; times = 0; MessageBox(hWnd,TEXT("次数超过了"),TEXT("错误"),MB_ICONERROR); } ReleaseDC(hWnd,hDC); break; } return 0; } break; case WM_PAINT: { hDC = BeginPaint(hWnd,&ps); MoveToEx(hDC,800,0,NULL); LineTo(hDC,800,600); MoveToEx(hDC,0,600,NULL); LineTo(hDC,800,600); EndPaint(hWnd,&ps); return(0); } break; case WM_DESTROY: { PlaySound(NULL, hinstance_app, SND_PURGE); PostQuitMessage(0); return(0); } break; default:break; } return (DefWindowProc(hWnd, msg, wparam, lparam)); } INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, INT) { HWND hwnd; ULONG_PTR GdiplusToken; GdiplusStartupInput GdiplusStartupInput; Status sResult = GdiplusStartup(&GdiplusToken, &GdiplusStartupInput, NULL); if(sResult != Ok)return 0; WNDCLASSEX WndClassEx = { sizeof(WNDCLASSEX), CS_HREDRAW | CS_VREDRAW, WinProc, 0L, 0L, GetModuleHandle(NULL), LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1)), LoadCursor(hInst, MAKEINTRESOURCE(IDC_CURSOR1)), (HBRUSH)GetStockObject(WHITE_BRUSH), NULL, _T("SimpleWindowClass"), LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1)) }; RegisterClassEx(&WndClassEx); hwnd = CreateWindow( _T("SimpleWindowClass"), _T("pan's game ~~"), WS_OVERLAPPEDWINDOW| WS_VSCROLL, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, GetDesktopWindow(), NULL, WndClassEx.hInstance, NULL); ShowWindow(hwnd, SW_SHOWDEFAULT); UpdateWindow(hwnd); HDC hdc; hdc = GetDC(hwnd); srand(GetTickCount()); cxball = WINDOW_WIDTH/2; cyball = WINDOW_HEIGHT/2; RECT rect; rect.left=0; rect.bottom=600; rect.right=800; rect.top=0; int xv = -4+rand()%8; int yv = -4+rand()%8; MSG Msg; do { GetMessage(&Msg, NULL, 0U, 0U); TranslateMessage(&Msg); DispatchMessage(&Msg); OnPaint(hdc,cxball,cyball); cxball += xv; cyball += yv; if (cxball < 0 || cxball > WINDOW_WIDTH - 50) { xv=-xv; cxball += xv; } else if (cyball < 0 || cyball > WINDOW_HEIGHT - 50) { yv=-yv; cyball += yv; } OnPaint(hdc,cxball,cyball); Sleep(10); InvalidateRect(hwnd,&rect,TRUE); }while(Msg.message != WM_QUIT); ReleaseDC(hwnd,hdc); UnregisterClass( _T("SimpleWindowClass"), WndClassEx.hInstance); GdiplusShutdown(GdiplusToken); return 0; }
试试其它关键字
打靶游戏
同语言下
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
pan_yz
贡献的其它代码
(
5
)
.
文件上传 plupload
.
模拟post请求
.
实现文件上传
.
每日检查SQL Server 2012数据库SSIS运行状态
.
打靶游戏
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3