2012-05-12 12 views
0

私はArena-ishコンソールゲームに取り組んでいます。毎回モンスターと戦うのではなく、あなたが特定のモンスターと戦うための空を持てるようにしたい。ここに私のコード:ボイドが読み込まれていません

#include <iostream> 
#include <conio.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <time.h> 
#include <fstream> 

using namespace std; 


char select; 
int randnum; 
int level=1; 
int maxhp=10; 
int hp=maxhp; 
int mhp; 
int exp; 
int dmg; 
int m_maxhp; 
int req_exp=10; 
int day; 
char boot; 
int a; 

ifstream leveli; 
ofstream levelo; 

ifstream playerhpi; 
ofstream playerhpo; 

ifstream expi; 
ofstream expo; 

ifstream maxhpi; 
ofstream maxhpo; 

ifstream req_expi; 
ofstream req_expo; 

ifstream dayi; 
ofstream dayo; 

void wait(time_t delay) 
{ 
time_t timer0, timer1; 
time(&timer0); 
do { 
time(&timer1); 
} while ((timer1 - timer0) < delay); 
} 


// This is the void that's not being called 
void bat() 
{ 

    m_maxhp=10; 
    mhp=m_maxhp; 
    do{ 
    dmg= rand() % 4 + 1; 
    cout << "Batt attacks you for " << dmg; 
    hp=hp-dmg; 
    cout << ", leaving you with [" << hp << "/" << maxhp << "]" << endl; 
    wait(1); 

    if(hp<=0) 
    { 
     cout << "You've lose. Try harder next time."; 
     exp=exp/2; 
     day=day+1; 

     dayo.open("daynumber.dat"); 
     dayo << day; 
     dayo.close(); 
    } 

    else if(mhp<=0) 
    { 
     cout << "You have killed the Bat. You gain 6 EXP." << endl; 
     exp=exp+6; 
     day=day+1; 

     dayo.open("daynumber.dat"); 
     dayo << day; 
     dayo.close(); 

     expo.open("experience.dat"); 
     expo << exp; 
     expo.close(); 
    } 





     }while(mhp>0); 
    } 



int main() 
{ 

leveli.open("level.dat"); 
leveli >> level; 
leveli.close(); 

playerhpi.open("health.dat"); 
playerhpi >> hp; 
playerhpi.close(); 

expi.open("experience.dat"); 
expi >> exp; 
expi.close(); 

maxhpi.open("maxhealth.dat"); 
maxhpi >> maxhp; 
maxhpi.close(); 

req_expi.open("req_exp.dat"); 
req_expi >> req_exp; 
req_expi.close(); 


cout << "Data successfully loaded. Start the game now? y/n" << endl; 
boot=_getch(); 

if(boot=='n') 
{ 

    cout << "Exiting..." << endl; 
    wait(3); 
    exit(0); 
} 

else if(boot=='y'){ 
do{ 
if (exp==req_exp) 
{ 
    level=level+1; 
    cout << "Level Up! You are now level " << level << "!" << endl; 

    exp=0; 
    req_exp=req_exp*1.5; 

    req_expo.open("req_exp.dat"); 
    req_expo << req_exp; 
    req_expo.close(); 

    levelo.open("level.dat"); 
    levelo << level; 
    levelo.close(); 
} 


else{ 
cout << endl << "Day " << day << " in The Arena." << endl << "1. Fight" << endl << "2. Stats" << endl << "3. Full Heal" << endl << "4. Half Heal" << endl; 
select=_getch(); 


    if(select=='1') 
    { 
      srand((unsigned)time(0)); 
      randnum = rand() % 500 + 1; 

     // cout << "*DEBUG* " << randnum << endl; 

      // This part doesn't work 
      if(randnum<300 && level<4) 
      { 
       cout << "You've been chosen to fight a Bat!" << endl; 
       wait(1.5); 
       void bat(); 

} 
      else 
      { 

      } 
    } 


    else if(select=='2') 
    { 
     cout << endl << "Health: [" << hp << "/" << maxhp << "]" << endl << "Level: [" << level << "]" << endl << "Experience: " << "[" << exp << "/" << req_exp << "]" << endl; 
     wait(0.5); 
    } 

    else 
    { 
     cout << "Invalid Command"; 
    } 

} 

}while (boot=='y'); 



} 

return 0; 
} 

私はボイドを間違って使っていますか?もしそうなら、誰かが私が何を変えなければならないかを指摘できますか?

+0

と書く必要があります。「空白」はありません。 'void'は型です。私はあなたが「機能」について話していると思います。 –

+0

なぜCプログラマであることがわかっているのですが、C++でプログラミングするふりをしていますか?それは何も悪いことではない! –

答えて

0

この関数を呼び出すと、戻り値の型は省略されます。あなたのコード:

 // This part doesn't work 
     if(randnum<300 && level<4) 
     { 
      cout << "You've been chosen to fight a Bat!" << endl; 
      wait(1.5); 
      void bat(); 

...

は次のようになります。

 // This part doesn't work 
     if(randnum<300 && level<4) 
     { 
      cout << "You've been chosen to fight a Bat!" << endl; 
      wait(1.5); 
      bat(); 

を...

+0

ありがとうございました!私はそれをキャッチしていない恥ずかしいです! – Rocmalone

2
if(randnum<300 && level<4) 
{ 
    cout << "You've been chosen to fight a Bat!" << endl; 
    wait(1.5); 
    void bat(); // ? 
} 

をここで予想される動作ですか? void bat();は関数宣言です。これはちょうど名前batを導入し、それ以外は何もしません。 batという名前の関数は呼び出されません。 batに電話する必要がある場合は、

bat(); // a call to "bat" 
関連する問題