c语言编一个简单的c编写剪刀石头布程序游戏?

石头剪刀布游戏课程设计_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
石头剪刀布游戏课程设计
&&C语言石头剪刀布游戏课程设计
阅读已结束,下载文档到电脑
想免费下载本文?
定制HR最喜欢的简历
下载文档到电脑,方便使用
还剩11页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢 上传我的文档
 下载
 收藏
该文档贡献者很忙,什么也没留下。
 下载此文档
C++课程设计石头剪刀布游戏 最终
下载积分:1000
内容提示:C++课程设计石头剪刀布游戏 最终
文档格式:DOC|
浏览次数:153|
上传日期: 00:19:00|
文档星级:
全文阅读已结束,如果下载本文需要使用
 1000 积分
下载此文档
该用户还上传了这些文档
C++课程设计石头剪刀布游戏 最终
官方公共微信欢迎加入我们,一同切磋技术。 &
用户名: &&&
密 码: &
共有 3962 人关注过本帖
标题:写了一个简单的打字游戏
等 级:黑侠
帖 子:218
专家分:556
结帖率:100%
&&问题点数:0&&回复次数:18&&&
写了一个简单的打字游戏
程序代码:#include &windows.h&
#include &stdlib.h&
#include &string.h&
#include &stdio.h&
#include &time.h&
#define&&& X_LEN&&&&&&&&&&&&500
#define Y_LEN&&&&&&&&&&&&150
#define TIM1&&&&&&&&&&&&1
typedef struct Pos
&&& int&&&&&&&&&&&&x;
&&& int&&&&&&&&&&&&y;
LRESULT CALLBACK&&& WndProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
&&& HDC&&&&&&&&&&&&&&&
&&& PAINTSTRUCT&&&&&&&&
&&& RECT&&&&&&&&&&&&
&&& static&&int&&&&&
&&& static&&& POS&&&&&&&&
&&& static&&TCHAR&&& ch = 'a';
&&& static&&int&&&&&&&&
&&& static&&int&&&&&
&&& static&&TCHAR&&& score[<font color=#];
&&& switch (message)
&&& case WM_CREATE:
&&&&&&&&&&&&hdc = GetDC (hwnd);
&&&&&&&&&&&&GetClientRect (hwnd, &rect);
&&&&&&&&&&&&ReleaseDC (hwnd, hdc);
&&&&&&&&&&&&srand ((unsigned) time (NULL));
&&&&&&&&&&&&ran = rand () % rect.right -<font color=#;
&&&&&&&&&&&&count = <font color=#;
&&&&&&&&&&&&speed = <font color=#;
&&&&&&&&&&&&sprintf (score, &SCORE:%d&, count);
&&&&&&&&&&&
&&&&&&&&&&&&SetTimer (hwnd,&&& TIM1, speed, NULL);
&&&&&&&&&&&&pos.x = ran + <font color=#;
&&&&&&&&&&&&pos.y = rect.left + <font color=#;
&&&&&&&&break;
&&& case WM_PAINT:
&&&&&&&&&&&&GetClientRect (hwnd, &rect);
&&&&&&&&&&&&hdc = BeginPaint (hwnd, &ps);
&&&&&&&&&&&&SetBkColor (hdc, TRANSPARENT); //TRANSPARENT文本字体背景为透明
&&&&&&&&&&&&SetTextColor (hdc, RGB (<font color=#, <font color=#, <font color=#));
&&&&&&&&&&&&TextOut (hdc, pos.x, pos.y, &ch, <font color=#);
&&&&&&&&&&&&SetTextColor (hdc, RGB (<font color=#, <font color=#, <font color=#));
&&&&&&&&&&&&TextOut (hdc, <font color=#, <font color=#, score, strlen (score));
&&&&&&&&&&&&EndPaint (hwnd, &ps);
&&&&&&&&break;
&&& case WM_CHAR:
&&&&&&&&&&&&TCHAR&&&
&&&&&&&&&&&&TCHAR&&&
&&&&&&&&&&&&sprintf (&shu, &%c&, wParam);
&&&&&&&&&&&&sprintf (&cha, &%c&, ch);
&&&&&&&&&&&&hdc = GetDC (hwnd);
&&&&&&&&&&&&GetClientRect (hwnd, &rect);
&&&&&&&&&&&&ReleaseDC (hwnd, hdc);
&&&&&&&&&&&&ran = rand () % rect.right -<font color=#;
&&&&&&&&&&&&if (shu == cha)
&&&&&&&&&&&&{
&&&&&&&&&&&&&&& speed = <font color=# + rand () % <font color=#;
&&&&&&&&&&&&&&& count++;
&&&&&&&&&&&&&&& sprintf (score, &SCORE:%d&, count);
&&&&&&&&&&&&&&& ran = rand () % rect.right -<font color=#;
&&&&&&&&&&&&&&& pos.x =
&&&&&&&&&&&&&&& pos.y = <font color=#;
&&&&&&&&&&&
&&&&&&&&&&&&&&& ran = rand () % rect.right -<font color=#;
&&&&&&&&&&&&&&& ch = 'a' + rand () % <font color=#;
&&&&&&&&&&&&&&& if (speed &= <font color=#)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&speed -= <font color=#;
&&&&&&&&&&&&&&&&&&&&KillTimer (hwnd, TIM1);
&&&&&&&&&&&&&&&&&&&&SetTimer (hwnd, TIM1, speed, NULL);
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& InvalidateRect (hwnd, NULL, TRUE);
&&&&&&&&&&&&}
&&&&&&&&break;
&&& case WM_TIMER:
&&&&&&&&&&&&hdc = GetDC (hwnd);
&&&&&&&&&&&&GetClientRect (hwnd, &rect);
&&&&&&&&&&&&ReleaseDC (hwnd, hdc);
&&&&&&&&&&&&pos.y += <font color=#;
&&&&&&&&&&&&if (pos.y & rect.bottom)
&&&&&&&&&&&&{
&&&&&&&&&&&&&&& count--;
&&&&&&&&&&&&&&& if (count & -<font color=#)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&KillTimer (hwnd, TIM1);
&&&&&&&&&&&&&&&&&&&&MessageBox (hwnd, TEXT (&你输了&), TEXT (&哈哈&), MB_OK | MB_ICONINFORMATION);
&&&&&&&&&&&&&&&&&&&&DestroyWindow (hwnd);
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& sprintf (score, &SCORE:%d&, count);
&&&&&&&&&&&&&&& pos.y = rect.top + <font color=#;
&&&&&&&&&&&&&&& pos.x =
&&&&&&&&&&&&&&& if (pos.x & rect.right)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&pos.x = rect.left + <font color=#;
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& ch += <font color=#;
&&&&&&&&&&&&&&& if (ch & 'a' + <font color=#)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&ch = 'a';
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&}
&&&&&&&&&&&&InvalidateRect (hwnd, NULL, TRUE);
&&&&&&&&break;
&&& case WM_CLOSE:
&&&&&&&&&&&&DestroyWindow (hwnd);
&&&&&&&&break;
&&& case WM_DESTROY:
&&&&&&&&&&&&PostQuitMessage (<font color=#);
&&&&&&&&break;
&&& default:
&&&&&&&&return DefWindowProc (hwnd, message, wParam, lParam);
&&& return <font color=#;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
&&& WNDCLASS&&&&&&&&
&&& HWND&&&&&&&&&&&&
&&& MSG&&&&&&&&&&&&&&&
&&& TCHAR&&&&&&&&&&&&Title[<font color=#] = &打字练习by瓦药墙&;
&&& TCHAR&&&&&&&&&&&&ClsName[<font color=#] = &ClsName&;
&&& wc.cbClsExtra&&&&&&&&&&&&=&&& <font color=#;
&&& wc.cbWndExtra&&&&&&&&&&&&=&&& <font color=#;
&&& wc.hbrBackground&&&&&&&&=&&& (HBRUSH) GetStockObject (BLACK_BRUSH);
&&& wc.hCursor&&&&&&&&&&&&&&& =&&& LoadCursor (NULL, IDC_ARROW);
&&& wc.hIcon&&&&&&&&&&&&&&& =&&& LoadIcon (NULL, IDI_APPLICATION);
&&& wc.hInstance&&&&&&&&&&&&=&&& hI
&&& wc.lpfnWndProc&&&&&&&&&&&&=&&& WndP
&&& wc.lpszClassName&&&&&&&&=&&& ClsN
&&& wc.lpszMenuName&&&&&&&&&&&&=&&& NULL;
&&& wc.style&&&&&&&&&&&&&&& =&&& CS_HREDRAW | CS_VREDRAW;
&&& if ( !RegisterClass (&wc) )
&&&&&&&&MessageBox (NULL, &RegisterClass Error&, &Error&, MB_OK | MB_ICONERROR);
&&&&&&&&return -<font color=#;
&&& hwnd = CreateWindow (ClsName, Title, WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, X_LEN, Y_LEN, NULL, NULL, hInstance, NULL);
&&& ShowWindow (hwnd, SW_SHOW);
&&& UpdateWindow (hwnd);
&&& ShowCursor (FALSE);
&&& while ( GetMessage (&msg, NULL, <font color=#, <font color=#) & <font color=# )
&&&&&&&&TranslateMessage (&msg);
&&&&&&&&DispatchMessage (&msg);
&&& return msg.wP
//-----------------------------------------------------
//算法与数据结构q群: 欢迎志同道和的朋友一起讨论进步
搜索更多相关主题的帖子:
来 自:农村一小伙
等 级:贵宾
威 望:12
帖 子:1132
专家分:2671
先顶一下~,看到最后一句发现楼主貌似醉翁之意不在酒哦~
等 级:黑侠
帖 子:218
专家分:556
哎,米办法
等 级:贵宾
威 望:18
帖 子:2296
专家分:6418
以下是引用遮天云在 11:49:43的发言:
先顶一下~,看到最后一句发现楼主貌似醉翁之意不在酒哦~那在什么? 美女?
到底是“出来混迟早要还”还是“杀人放火金腰带”?
等 级:论坛游民
帖 子:77
专家分:52
你的代码行不通
来 自:农村一小伙
等 级:贵宾
威 望:12
帖 子:1132
专家分:2671
回复 4楼 vandychan
说不定有美女加入哦
等 级:贵宾
威 望:10
帖 子:988
专家分:1627
上个效果图看看?
等 级:论坛游民
帖 子:26
专家分:14
就是应该给个效果图看看
等 级:黑侠
帖 子:218
专家分:556
附件: 您没有浏览附件的权限,请
等 级:版主
威 望:14
帖 子:1178
专家分:3032
看来楼主对C语言的图形模式掌握的很好
欢迎来到我的博客:.cn/noisunyuhong
版权所有,并保留所有权利。
Powered by , Processed in 0.080135 second(s), 7 queries.
Copyright&, BCCN.NET, All Rights ReservedC语言实现石头剪刀布的结构化程序设计小游戏
以下是用C语言实现的结构化程序的小游戏:石头剪刀布,其中1代表石头&
2代表剪刀& 3代表布& 4代表退出
中间用到了系统的随机函数。
#include &stdio.h&
#include &conio.h&
#include &stdlib.h&
#include &time.h&
void printMenu(void)
&&printf("\t\t
-------------------------------------------\n");
&&printf("\t\t|&&&&&&&&&&&&&&
石头剪刀布游戏&&&&&&&&&&&&&
&&printf("\t\t|&&&&&&&
----------------------------&&&&&&
printf("\t\t|&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
& printf("\t\t|
说明:&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
printf("\t\t|&&&&&
此小游戏是用C语言实现的结构化程序&&&
printf("\t\t|&&&&&
设计,能够实现用户和电脑相互对玩的&&&
printf("\t\t|&&&&&
过程,其中用户的出拳在下面有说明&&&&
printf("\t\t|&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
& printf("\t\t|
用户操作:&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
printf("\t\t|&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
printf("\t\t|&&&&&&
1-石头& 2-剪刀& 3-布&
4-退出&&&&&&&
printf("\t\t
-------------------------------------------\n\n\n");
int main(void)
int win=0,lose=0,he=0; //分别统计赢、输、平手的次数
srand(time(NULL));//用系统时间来初始化随机数发生器
printMenu();
printf("\t\t您的选择(1、2、3):");
&&&&&&&&&&&&&&
ch = getch();
&&&&&&&&&&&&&&
if(ch=='1'||ch=='2'||ch=='3'||ch=='4')
&&&&&&&&&&&&&&
{ //这里对输入做了限制,只能输入1到4之间的整数
&&&&&&&&&&&&&&&&&&&
printf("%c\t",ch);
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&
if(ch=='4') //如果按了4,则退出游戏。
&&&&&&&&&&&&&&
switch(ch)
{ //显示玩家选择的手型
&&&&&&&&&&&&&&
case '1': printf("石头 VS ");
&&&&&&&&&&&&&&
case '2': printf("剪刀 VS ");
&&&&&&&&&&&&&&
case '3': printf("布 VS ");
Computer = rand()%3+1+48;
//电脑随机产生1到3之间的整数,后面加上48的目的是将整数转换成字符
switch(Computer)
//显示电脑随机产生的手型
&&&&&&&&&&&&&&
&&&&&&printf("石头");
&&&&&&&&&&&&&&
&&&&&&printf("剪刀");
&&&&&&&&&&&&&&
&&&&&&printf("布");
switch(ch-Computer)
//这里是比较输赢,通过计算0表示平手,-1和2表示胜利,1和-2表示输了。
&&&&&&&&&&&&&&
printf("\t平手!\n");
&&&&&&he++;
&&&&&&&&&&&&&&
case -1: case 2:
&&&&&&printf("\t你赢了!\n");
&&&&&&win++;
&&&&&&&&&&&&&&
case 1: case -2:
&&&&&&printf("\t你输了!\n");
&&&&&&lose++;
//如果游戏退出,则打印统计的结果
& printf("\n\n\n");
& printf("\t\t
-------------------TOTAL-------------------\n");
&&printf("\t\t|&&&&&&&&&&&&&&&&
您一共玩了%d次&&&&&&&&&&&
|\n",win+lose+he);
& printf("\t\t
---------------------|-------------------- \n");
&&printf("\t\t|&&&&&&&
胜利&&&&&&&&
|\n",win);
& printf("\t\t
---------------------|-------------------- \n");
&&printf("\t\t|&&&&&&&
失败&&&&&&&&
|\n",lose);
& printf("\t\t
---------------------|-------------------- \n");
&&printf("\t\t|&&&&&&&
平手&&&&&&&&
& printf("\t\t
---------------------|-------------------- \n");
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

我要回帖

更多关于 c语言简单编程实例 的文章

 

随机推荐