猜拳小游戏 C语言
2015-03-15 09:03
302 查看
博客搬家了,最近同时更新,没准什么时候就完全搬走了-_-
http://blog.just666.cn 这个是新博客地址,希望大家多多关照
http://blog.just666.cn 这个是新博客地址,希望大家多多关照
用C语言写的猜拳的小游戏。 源代码下载地址:http://www.oschina.net/code/snippet_2309129_45545
////////////////////////////////// //名称:猜拳游戏V1.0 //作者:耗子、 //时间:2015.1.19 ///////////////////////////////// #include <time.h> #include <iostream> #include <stdlib.h> #include <conio.h> #define SEC 1 using namespace std; //函数声明 int computer(); char player(); void putUi(); void judge(int play, int com); void theEnd(); void out(int x); void wait(int n); int win=0,lose=0,draw=0; int main() { system("title 猜拳游戏V1.0"); int play,com; while (1) { putUi(); //显示UI play = player(); //玩家选择 wait(SEC); //设置等待 com = computer(); //电脑选择 judge(play,com); //判断 theEnd(); //冻结屏幕 } return 0; } int computer() //电脑随机生成一个选项 { srand((unsigned)time(NULL)); return rand()%3+1; } char player() //等待玩家选择一个选项 { int play; cout<<"\t\t\t\t 请选择"; for (;;) { play = getch(); if (play>='1'&&play<='3') return play-'0'; } } void putUi() //UI的输出 { system ("CLS"); system ("color 0A"); cout<<"\t\t\t\t猜拳游戏V1.0\n"; cout<<"Win:"<<win<<"\nLose:"<<lose<<"\nDraw:"<<draw<<"\n"; cout<<"\t\t\t\t1、我出石头\n"; cout<<"\t\t\t\t2、我出剪刀\n"; cout<<"\t\t\t\t3、我出布\n"; } void judge(int play, int com) //判断输赢 { if (play == com) { cout<<"\n\t\t\t 你们都出了"; out(play); cout<<"所以打成平手!"; draw++; } else if (play == 1 && com == 3 || play == 2 && com == 1 || play == 3 && com == 2) { cout<<"\n\t\t\t你出了"; out(play); cout<<",电脑出了"; out(com); cout<<",你输了!\n"; lose++; } else { cout<<"\n\t\t\t你出了"; out(play); cout<<",电脑出了"; out(com); cout<<",你赢了!"; win++; } } void theEnd() //屏幕冻结 { getch(); } void out(int x) //根据数值判断出的是什么 { if (x == 1) cout<<"石头"; if (x == 2) cout<<"剪刀"; if (x == 3) cout<<"布"; } void wait(int n) //设置等待 { int i; cout<<"\n\t\t\t .....Please wait....\n"; time_t t1,t2; time(&t1); time(&t2); while((t2-t1)<n) time(&t2); }
相关文章推荐
- 自己写的一个猜拳小游戏(C语言)
- C语言猜拳小游戏,课堂设计
- C语言猜拳问题
- c语言控制台输出制作拼图小游戏
- 用C语言实现简单的三子棋小游戏
- 学习ios第八天 番外篇 《c语言小游戏 推箱子的实现》
- C语言小游戏---扫雷
- C语言实现的猜数字小游戏(主要是对于自定义函数的运用)
- 学C语言半个月了,分享个自己编写的弹球小游戏,vc编译,请高手指点
- 猜拳的银魂(Java小游戏)
- JAVA语言实现人机猜拳小游戏
- 猜拳小游戏
- c 语言 猜拳小游戏
- 用C语言实现三子棋小游戏
- 以前用C语言编写的生成随机数的猜数字小游戏
- C语言编写小游戏——骑士飞行棋
- C#猜拳小游戏
- [java小程序]-猜拳小游戏-初学
- Java猜拳小游戏
- C语言小游戏:三字棋(增强版本)