菜鸟学C++的首作!!!(猜拳游戏)

xniao 2002-03-19 08:46:01
下载地址:http://user1.7host.com/may8866/test.exe

源代码:

#include<iostream>
#include<fstream>
#include<string>
#include<time.h>
#include<cstdlib>
#include<conio.h>
#include<stdlib.h>


using namespace std;

void write_log(int suc_fai)
{
ofstream outfile ("log.txt",ios_base::app);
if (!outfile) ofstream outfile ("log.txt");
if (!outfile) cout <<"\n无法存储挡案记录!!!\n";
if (suc_fai==1)
outfile <<"赢\n";
if (suc_fai==2)
outfile <<"输\n";
}



void doing_game(int hand_number,int guess_number)
{
int random_number;
srand( (unsigned)time( NULL ) );
for (int x=1;x<5;++x)
random_number=int(rand())/10000;


int suc_fai=1;
cout <<"\n我出个"<<random_number<<"只手。"<<"你出了"<<hand_number<<"只手,一共有"<<(random_number+hand_number)*5<<"只手指头,所以......";
if (guess_number==hand_number*5+random_number*5)
{
suc_fai=1;
cout <<"\n恭喜,猜对了!!";
}
else
{
suc_fai=2;
cout <<"\n你猜错了!";
}
write_log(suc_fai);
}




void start_game()
{
int hand_number,guess_number;
cout <<"\n开始啦~~~~~~~~~~!!!";
while(1)
{
cout <<"\n你要伸出几个手?(0-2)";
cin >>hand_number;
if (hand_number>2||hand_number<0)
{
cout<<"faint...指定动作无法完成!\n";
continue;}
cout <<"你猜测的手指头数目(0,5,10,15,20):";
cin >>guess_number;
if (!(guess_number==0)&&!(guess_number==5)&&!(guess_number==15)&&!(guess_number==20)&&!(guess_number==10))
{
cout<<"faint......你白痴啊~~~~~!重来!!!\n";
continue;}
doing_game(hand_number,guess_number);
cout <<"\n继续玩吗?(任意键继续,ESC键退出)";
if (getch()== 27) exit(0);
else continue;

}
}

void read_log()
{
ifstream infile ("log.txt");
if (!infile)
cout <<"未发现历史记录!!!\n";
else
{
cout <<"\n历史记录:\n";
int count=1;
string name;
while (infile >> name)
{
cout <<count<<":"<<name<<" ";
if (count<10) cout<<" ";
if (count%10==0) cout <<"\n";
count++;
}
}
}


int main()
{
int choice;
cout <<"\n###############################################"
<<"\n# #"
<<"\n# 菜鸟猜拳(15/20版) #"
<<"\n# #"
<<"\n###############################################";
while(1)
{

cout <<"\n1:开始游戏 2:退出游戏 3:查看记录 选择:";
cin >>choice;
if (choice<1||choice>3) continue;
if (choice==1) start_game();
if (choice==2) return 0;
if (choice==3) read_log();
}

}

###########################################
哈哈,够幼稚吧~~~~~~~~~~:)
...全文
162 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Nizvoo 2002-03-19
  • 打赏
  • 举报
回复
呵呵
bensonlc 2002-03-19
  • 打赏
  • 举报
回复
呵呵,还行,看见了我那时候
xniao 2002-03-19
  • 打赏
  • 举报
回复
谢谢火种兄,偶也这么认为,呵呵,a joke only!
mahongxi 2002-03-19
  • 打赏
  • 举报
回复
在线吗?聊聊!
QQ:55669753
fireseed 2002-03-19
  • 打赏
  • 举报
回复
/************************感谢关注**********************/
/////////////////////////Creamdog///////////////////////

你很厉害,将来一定行!呵呵...........
xniao 2002-03-19
  • 打赏
  • 举报
回复
老兄,给点面子嘛~~~~新手呀~~:)
mahongxi 2002-03-19
  • 打赏
  • 举报
回复
不算C++

15,440

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧