2013-10-22 2 views
-3
#include <iostream> 
#include <cstdlib> 
#include <ctime> 
#include <string> 

using namespace std; 

void divider(); 

int main() 
{ 
    int cstats, choice; 
    int rhp, hp, i, init, atk, def, matk, mdef, dmg, mdmg, agi, magi; 
    divider(); 
    cout << "Kill the Zombie! (Text-Based Game)\n"; 
    divider(); 
    cout << "Please choose your specialty: "; 
    cout << "[1] Offense [2] Magic [3] Defense [4] Speed\n"; 
    do{cin >> cstats; } 
    while(cstats > 4 || cstats < 1); 
    { 
    switch(cstats) 
    { 
    case 1: 
     atk = 15; 
     def = 8; 
     agi = 6; 
     matk = 5; 
     mdef = 5; 
     magi = 5; 
     break; 
    case 2: 
     atk = 5; 
     def = 5; 
     agi = 5; 
     matk = 15; 
     mdef = 7; 
     magi = 10; 
     break; 
    case 3: 
     atk = 7; 
     def = 15; 
     agi = 5; 
     matk = 1; 
     mdef = 14; 
     magi = 3; 
     break; 
    case 4: 
     atk = 7; 
     def = 4; 
     agi = 15; 
     matk = 3; 
     mdef = 4; 
     magi = 14; 
     break; 
    } 
    if(cstats == 1) 
    { 
    cout << "You have chosen Offense\n"; 
    } 
    if(cstats == 2) 
    { 
    cout << "You have chosen Magic\n"; 
    } 
    if(cstats == 3) 
    { 
    cout << "You have chosen Defense\n"; 
    } 
    if(cstats == 4) 
    { 
    cout << "You have chosen Speed\n"; 
    } 
    } 
    srand((unsigned)time(0)); 
    rhp = rand()%50 + 60; 
    hp = rand()%20 + 80; 
    while(hp >0 || rhp > 0) 
    { 
    cout << "What do you want to do? [1] Normal Attack [2] Magic Attack [3] Defend [4] Dodge\n"; 
    do{cin >> choice; } 
    while(choice > 4 || choice < 1); 
    { 
    switch(choice) 
    { 
     case 1: 
      atk = rand()%20+10; 
      def = rand()%10+10; 
      agi = rand()%5; 
      break; 
     case 2: 
      matk = rand()%20+10; 
      mdef = rand()%10+10; 
      magi = rand()%15; 
      break; 
     case 3: 
      def = rand()%10+15; 
      mdef = rand()%10+15; 
      magi = rand()%10+15; 
      break; 
     case 4: 
      agi = rand()%5; 
      magi = rand()%10+10; 
      mdef = rand()%10+5; 
      break; 
    } 

    mdmg = (atk - magi) - (mdef/atk); 
    if(mdmg = 0) 
    { 
     mdmg = 0; 
    } 
    rhp = rhp - mdmg; 
    cout << "You did " << mdmg << "damage to the zombie!\n"; 
    cin.get(); 
    if(rhp <1) 
    { 
     cout << "You killed the Zombie! Congratulations, You won with " << hp << "hp left.\n"; 
     cin.get(); 
     system("pause>0"); 
     return 0; 
    } 
    cout << "The Zombie now has " << rhp << "hp left.\n"; 
    dmg = (matk - agi) - (def/matk); 
    if(dmg < 0) 
    { 
     dmg = 0; 
    } 
    hp = hp - dmg; 
    cout << "The Zombie hit you for " << dmg << " damage.\n"; 
    if(hp < 1) 
    { 
     cout << "You dided. The Zombie still has " << rhp << "hp left.\n"; 
     cin.get(); 
     system("pause>0"); 
     return 0; 
    } 
    cout << "You now have " << hp << " hp left.\n"; 
} 
} 
} 
void divider() 
{ 
    cout << "*************************************\n"; 
} 

그래, 네. 이것은 제가 만든 게임입니다. 모든 것은 작동하지만 피해는 작동하지 않습니다. 내가 뭔가 잘못했는지 나는 모른다. 나는 여기서 무엇이 잘못되었는지를 발견 할 수 없다. 내 눈은 이제 잠잘 준비가되었습니다. O.O 나는 3 일 동안 품위없는 잠을 지금 가지지 않고 있었다. 미리 감사드립니다.내가 만든 텍스트 기반 좀비 게임. (HELP!)

+4

손상된 부분이 어떤 식으로 작동하지 않습니까? 손상이 올바르게 작동하는지 테스트하기 위해 어떤 종류의 디버깅을 했습니까? – admdrew

+0

나는 내 전문 분야를 이미 선택했고 어떤 공격을 할 것인가?하지만 내 피해는 항상 0입니다. 좀비의 피해는 훌륭하지만 사용자 피해는 효과가 없습니다. – Supremo

+3

'if (mdmg = 0) mdmg = 0' 부분과 관련이 있다고 확신합니다. – JJJ

답변

4

if(mdmg = 0)은 부울 if(mdmg == 0)이어야합니다. 0인지 확인하지 않고 0이되도록 지정합니다.