首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++文字游戏,麻烦高手看一下

2012-06-07 
C++文字游戏,求助啊,麻烦高手看一下// game4.cpp : 定义控制台应用程序的入口点。//#include stdafx.h#in

C++文字游戏,求助啊,麻烦高手看一下
// game4.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include"ctime"
#include <iostream>
using namespace std;

class Role{
public:
  virtual void CreatRole()
{
 x=0;y=0;
 hp=0;attack=0;
}
  int x,y,hp,attack;
};

class Boss:public Role
{
public:
void CreatBoss()
{
b_x=4;b_y=7;b_hp=500;b_attack=80;
}
int b_x,b_y,b_hp,b_attack;
};////////////////

class Gameapp{
public:
  void Init()
{
enterbattle=0;
Boss *q1;
Boss w1;
q1=&w1;
q1->CreatBoss();//
Monster *q2;
Monster w2;
q2=&w2;
q2->CreatMonster();//
Player *q3;
Player w3;
q3=&w3;
q3->CreatPlayer();
Prop *q4;
Prop w4;
q4=&w4;
q4->CreatProp();
}
  void Run(){
Gameapp *Pl,*M;
Gameapp pl,m;
Pl=&pl;
M=&m;
  while (std::cin.get(ch)) {
  cout<<"qing cao zuo w shang yi,s xia yi,a zuo yi,d you yi.i shu xing"<<endl;
  switch (ch) {
  case 'w':
  p_x--;
  cout<<"ren wu xin xi geng xin wei"<<p_x<<p_y<<endl;
if((p_x==m_x1&&p_y==m_y1)||(p_x=m_x2&&p_y=m_y2)){
cout<<"kan dao yi tou ye zhu,shi fou zhan dou"<<"y/n?"<<endl;
if(cin.get=='y'||'Y')
Pl->Battle();
 if(cin.get=='n'||'N')
break;
else
continue;}
else if(p_x==p_x1&&p_y==p_y1)
{
Pl->Getprop();
getprop=1;
cout<<"kan dao yi wan hong shao rou,ren wu chi hou bian qiang le"<<"hp:"<<p_hp<<"attack:"<<p_attack<<endl;
}
else if(p_x==b_x1&&p_y=b_y1)
{
  cout<<"yu dao boss,qiang zhi zhan dou"<<endl;
Pl->BossBattle();
}
  if(key==1&&p_x==0&&p_y==0)
cout<<"you xi tong guan"<<endl;
  break; //////////////////////////w  
  case 's':
  p_ x++;
cout<<"ren wu xin xi geng xin wei"<<p_x<<p_y<<endl;
if((p_x==m_x1&&p_y==m_y1)||(p_x=m_x2&&p_y=m_y2)){
cout<<"kan dao yi tou ye zhu,shi fou zhan dou"<<"y/n?"<<endl;
if(cin.get=='y'||'Y')
Pl->Battle();
 if(cin.get=='n'||'N')
break;
else
continue;}
else if(p_x==p_x1&&p_y==p_y1)
{
Pl->Getprop();
getprop=1;
cout<<"kan dao yi wan hong shao rou,ren wu chi hou bian qiang le"<<"hp:"<<p_hp<<"attack:"<<p_attack<<endl;
}
else if(p_x==b_x1&&p_y=b_y1)
{
  cout<<"yu dao boss,qiang zhi zhan dou"<<endl;
Pl->BossBattle();
}
  if(key==1&&p_x==0&&p_y==0)
cout<<"you xi tong guan"<<endl;
  break; ////////////////s

  case 'a':
  p_y--;
  cout<<"ren wu xin xi geng xin wei"<<p_x<<p_y<<endl;
if((p_x==m_x1&&p_y==m_y1)||(p_x=m_x2&&p_y=m_y2)){
cout<<"kan dao yi tou ye zhu,shi fou zhan dou"<<"y/n?"<<endl;
if(cin.get=='y'||'Y')
Pl->Battle();


 if(cin.get=='n'||'N')
break;
else
continue;}
else if(p_x==p_x1&&p_y==p_y1)
{
Pl->Getprop();
getprop=1;
cout<<"kan dao yi wan hong shao rou,ren wu chi hou bian qiang le"<<"hp:"<<p_hp<<"attack:"<<p_attack<<endl;
}
else if(p_x==b_x1&&p_y=b_y1)
{
  cout<<"yu dao boss,qiang zhi zhan dou"<<endl;
Pl->BossBattle();
}
  if(key==1&&p_x==0&&p_y==0)
cout<<"you xi tong guan"<<endl;
  break; ///////////////////a
  case 'd':
  p_y++;
cout<<"ren wu xin xi geng xin wei"<<p_x<<p_y<<endl;
if((p_x==m_x1&&p_y==m_y1)||(p_x=m_x2&&p_y=m_y2)){
cout<<"kan dao yi tou ye zhu,shi fou zhan dou"<<"y/n?"<<endl;
if(cin.get=='y'||'Y')
Pl->Battle();
 if(cin.get=='n'||'N')
break;
else
continue;}
else if(p_x==p_x1&&p_y==p_y1)
{
Pl->Getprop();
getprop=1;
cout<<"kan dao yi wan hong shao rou,ren wu chi hou bian qiang le"<<"hp:"<<p_hp<<"attack:"<<p_attack<<endl;
}
else if(p_x==b_x1&&p_y=b_y1)
{
  cout<<"yu dao boss,qiang zhi zhan dou"<<endl;
Pl->BossBattle();
}
  if(key==1&&p_x==0&&p_y==0)
cout<<"you xi tong guan"<<endl;
  break; ////////d
  case 'i':
  cout<<"cha kan re wu shu xing:"<<"hp="<<p_hp<<"attack="<<p_attack<<"zuo biao<<"("<<"p_x<<p_y<<")"<<endl;
  break;
   
  default:
  cout<<"shu ru cuo wu"<<endl;
  break;
  }
  }
void Battle(){
cout<<"zhun bei zhan dou"<<endl;

for(;m_hp>0&&p_hp>0;m_hp=m_hp-30,p_hp=p_hp-20;)
{
cout<<"guai wu de sheng yu xue liang wei:"<<m_hp<<endl;
cout<<"ying xiong de sheng yu xue liang wei:"<<p_hp<<endl;
}

if(m_hp<=0&&p_hp>0)
cout<<"zhan dou sheng li!"<<endl;
if(hp<=0)
cout<<"game over"<<endl;
}

void BossBattle(){
int key;
cout<<"zhun bei zhan dou"<<endl;
for(;m_hp>0&&hp>0;m_hp=m_hp-100,p_hp=p_hp-50;)
{
cout<<"guai wu de sheng yu xue liang wei:"<<m_hp<<endl;
cout<<"ying xiong de sheng yu xue liang wei:"<<p_hp<<endl;
}
if(m_hp<=0&&p_hp>0){
cout<<"zhan dou sheng li!"<<endl;
cout<<"get a key"<<endl;
key=1;
}
if(p_hp<=0)
cout<<"game over"<<endl;
}

void Getprop(){ int getprop;
if((x==pr_x1&&y=pr_y1)||(x==pr_x2&&y=pr_y2))
p_hp=p_hp+500;
p_attack=p_attack+70;
getprop=1;
}
void Gameapp::Battle()
{
cout<<"zhun bei zhan dou"<<endl;

for(;m_hp>0&&p_hp>0;m_hp=m_hp-30,p_hp=p_hp-20;)
{
cout<<"guai wu de sheng yu xue liang wei:"<<m_hp<<endl;
cout<<"ying xiong de sheng yu xue liang wei:"<<p_hp<<endl;


}

if(m_hp<=0&&p_hp>0)
cout<<"zhan dou sheng li!"<<endl;
if(hp<=0)
cout<<"game over"<<endl;
}
  int hp,attack,x,y;
  int *monster1point,*monster2point;
  int *random1,*random2;
  int *prop1point,*prop2point;
};///////////

class Monster:public Role{
public:
void CreatMonster()
{
  random1=new int[2];
  random2=new int[2];
  monster1point=new int[2];
  monster2point=new int[2];
  srand((unsigned)time(0));
  for(int i=0;i<2;i++)
  {
  random1[i]=rand()%4;
  random2[i]=rand()%5;
  }
monster1point[0]=random1[0];
monster1point[1]=random1[1];
m_x1=monster1point[0];
m_y1=monster1point[1];
  cout<<"guai wu1 de zuo biao"<<endl;
for(int i=0;i<2;i++)
  cout<<*(monster1point+i)<<" ";
  cout<<endl;
  monster2point[0]=random2[0];
monster2point[1]=random2[1];
m_x2=monster2point[0];
m_y2=monster2point[1];
  cout<<"guai wu2 de zuobiao"<<endl;
for(int i=0;i<2;i++)
  cout<<*(monster2point+i)<<" ";
  cout<<endl;
m_hp=100;
m_attack=20;
}
int m_x1,m_y1,m_x2,m_y2,m_hp,m_attack;
}; ///////////
class Player:public Role{
public:
  int CreatPlayer()
{
  p_x=4;
  p_y=1;
  p_hp=100;
  p_attack=30;
  return 0;
}
  int p_x,p_y,p_hp,p_attack;
};//////////
class Prop:public Role{
public:
void CreatProp()
{
  random1=new int[2];
  random2=new int[2];
 prop1point=new int[2];
  prop2point=new int[2];
  srand((unsigned)time(0));
  for(int i=0;i<2;i++)
  {
  random1[i]=rand()%4;
  random2[i]=rand()%5;//  

  }
prop1point[0]=random1[0]+4;
prop1point[1]=random1[1];
p_x1=prop1point[0];
p_y1=prop1point[1];
  cout<<"dao ju 1 de zuobiao"<<endl;
for(int i=0;i<2;i++)
  cout<<*(prop1point+i)<<" ";
  cout<<endl;
  prop2point[0]=random2[0]+4;
prop2point[1]=random2[1];
p_x2=prop2point[0];
p_y2=prop2point[1];
  cout<<"daoju 2 de zuo biao"<<endl;
for(int i=0;i<2;i++)
  cout<<*(prop2point+i)<<" ";
  cout<<endl;
}
int pr_x1,pr_y1,pr_x2,pr_y2,pr_hp,pr_attack;
}; /////////////




int _tmain(int argc, _TCHAR* argv[])
{
Gameapp *g;
Gameapp m;
g=&m;
g->Init();
g->run();
return 0;
}/////////////////////

提示错误:
 左 圆括号“(”(在“d:\我的文档\visual studio 2005\projects\game4\game4\game4.cpp(166)”中找到)未能正确匹配,
fatal error C1075: 与左侧的 大括号“{”(位于“d:\我的文档\visual studio 2005\projects\game4\game4\game4.cpp(29)”)匹配之前遇到文件结束

[解决办法]
void Battle()这个函数上面少了个}把

热点排行