программа завершается с кодом 3221225477

Когда я запускаю программу она работает один проход и потом завершается с вышеуказанным кодом.

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <fstream>

using namespace std;

fstream Saves;

int xp = 0;
string hweapon = "fists";
int hlvl = 0;
int count = 0;
string playerName;

class livingCreature{
    public:
        int baseHp;
        int hp;

        int xpGain;
        int neededXp;
        int lvl;
        
        bool dead;
        
        string usedWeapon;
        
        void spawn(){
            cout << "You see something in a distance." << endl;
        }
};

class weapon{
    public:
        string name;
        int damage;
};

class longsword : public weapon{
    public:
        longsword(){
            this->name = "Knight's Longsword";
            this->damage = 50;  
        };
        void spawn(){
            cout << "You've found a Knight's Longsword." << endl;
        };
};

class mace : public weapon{
    public:
        mace(){
            this->name = "Ogre's Mace";
            this->damage = 75;  
        };
        void spawn(){
            cout << "You've found an Ogre's Mace." << endl;
        };
};

class bow : public weapon{
    public:
        bow(){
            this->name = "Bow";
            this->damage = 40;
        };
        void spawn(){
            cout << "You've found a Bow." << endl;
        };
};

class fists : public weapon{
    public:
        fists(){
            this->name = "Fists";
            this->damage = 15;  
        };
};


class mainCharacter : public livingCreature{
    public: 
        mainCharacter(){
            this->baseHp = 100;
            
            this->neededXp = 100 + (20*hlvl);
            this->xpGain = 0;
            
            this->usedWeapon = "Fists";
            
            this->dead = false;
            
            this->hp = this->baseHp + (5*hlvl);
        };
};

class rat : public livingCreature{
    public:
        rat(){
            this->baseHp = 15;
            
            this->xpGain = 10;
            this->lvl = 0;
            
            this->usedWeapon = "Fists";
            
            this->dead = false;
            
            this->hp = this->baseHp + (7*hlvl);
        };
        
        void spawn(){
                cout << "You see rat in a distance.\nIt blocks the exit. You need to fight it." << endl;
        };
};

class ogre : public livingCreature{
    public:
        ogre(){
            this->baseHp = 150;
            
            this->xpGain = 50;
            this->lvl = 0;
            
            this->usedWeapon = "mace";
            
            this->dead = false;
            
            this->hp = this->baseHp + (20*hlvl - 10);
        };
        
        void spawn(){
                cout << "You see ogre in a distance.\nIt blocks the exit. You need to fight it." << endl;
        };
};

class skeleton : public livingCreature{
    public:
        skeleton(){
            this->baseHp = 100;
            
            this->xpGain = 25;
            this->lvl = 0; 
            
            this->usedWeapon = "bow";
            
            this->dead = false;
            
            this->hp = this->baseHp + (10*hlvl - 5);
        };
        
        void spawn(){
                cout << "You see skeleton in a distance.\nIt blocks the exit. You need to fight it." << endl;
        };
};

void Save(){
    Saves.open("saves.txt", ios_base::app);
    Saves << playerName << " " << count << "\n";
    Saves.close();
    exit(0);
}

string typeRoom(){
    srand(time(NULL));
    if(rand() % 3 == 0){
        return "loot";
    } else{
        return "enemy";
    }
}

void move(){
    count = count + 1;
    cout << "You're moving to the next room..." << endl;
    
}

void createLootRoom(){
    char answer;
    srand(time(NULL));
    
    mainCharacter hero;
    longsword Longsword;
    mace Mace;
    bow Bow;
    
    if(rand() % 3 == 0){
        Longsword.spawn();
        cout << "Do you want to pick it up?(Y/N)" << endl;
        cin >> answer;
    
        if(answer == 'Y' || answer == 'y'){
            hweapon = Longsword.name;
        } else{
            hweapon = hweapon;
        }
        
    } else if(rand() % 3 == 1){
        Mace.spawn();
        cout << "Do you want to pick it up?(Y/N)" << endl;
        cin >> answer;
    
        if(answer == 'Y' || answer == 'y'){
            hweapon = Mace.name;
        } else{
            hweapon = hweapon;
        }
        
    } else{
        Bow.spawn();
        cout << "Do you want to pick it up?(Y/N)" << endl;
        cin >> answer;
    
        if(answer == 'Y' || answer == 'y'){
            hweapon = Bow.name;
        } else{
            hweapon = hweapon;
        }
            
    };
    
    cout << "You're using " << hweapon << endl;
    
    
    move();
}

void createEnemyRoom(){
    char answer;
    int damage;
    srand(time(NULL));
    
    rat Rat;
    ogre Ogre;
    skeleton Skeleton;
    fists Fists;
    longsword Longsword;
    mace Mace;
    bow Bow;
    mainCharacter hero;
    
    if(hweapon == "fists"){
        damage = Fists.damage;
    } else if(hweapon == Longsword.name){
        damage = Longsword.damage; 
    } else if(hweapon == Mace.name){
        damage = Mace.damage;
    } else{
        damage = Bow.damage;
    }

    if(rand() % 10 >= 0 && rand() % 10 <= 5){
        Rat.spawn();
        
        if(hlvl >= 5) Rat.lvl = hlvl + 4;
        if(hlvl >= 15) Rat.lvl = hlvl + 6;
        
        while(Rat.dead != true || hero.dead != true){
            Rat.hp = Rat.hp - damage;
            cout << "Rat's hp: " << Rat.hp << endl;
            if(Rat.hp <= 0){
                Rat.dead = true;
                cout << "You won!" << endl;
                cout << "Xp gained: " << Rat.xpGain << "." << endl;
                xp = xp + Rat.xpGain;
                cout << "Level progress: " << xp << "/" << hero.neededXp << "." << endl;
                cout << "Level: " << hlvl << endl;
                if(xp >= hero.neededXp){
                    hlvl++;
                    xp = xp - hero.neededXp;
                }
                break;
            } else if(hero.hp <= 0){
                cout << "You've died!" << endl;
                hero.dead = true;
                Save();
            }
        
            hero.hp = hero.hp - Fists.damage; 
            cout << "Your's hp: " << hero.hp << endl;
        }

    } else if(rand() % 10 >= 6 && rand() % 10 <= 8){
        Skeleton.spawn();
        
        if(hlvl >= 5) Skeleton.lvl = hlvl + 3;
        if(hlvl >= 15) Skeleton.lvl = hlvl + 5;
        
        while(Skeleton.dead != true || hero.dead != true){
            Skeleton.hp = Skeleton.hp - damage;
            cout << "Skeleton's hp: " << Skeleton.hp << endl;
            if(Skeleton.hp <= 0){
                Skeleton.dead = true;
                cout << "You won!" << endl;
                cout << "Xp gained: " << Skeleton.xpGain << "." << endl;
                xp = xp + Skeleton.xpGain;
                cout << "Level progress: " << xp << "/" << hero.neededXp << "." << endl;
                cout << "Level: " << hlvl << endl;
                if(xp >= hero.neededXp){
                    hlvl++;
                    xp = xp - hero.neededXp;
                }
                break;
            } else if(hero.hp <= 0){
                cout << "You've died!" << endl;
                hero.dead = true;
                Save();
            }
        
            hero.hp = hero.hp - Bow.damage; 
            cout << "Your's hp: " << hero.hp << endl;
        }
    
    } else{
        Ogre.spawn();
        
        if(hlvl >= 5) Ogre.lvl = hlvl + 2;
        if(hlvl >= 15) Ogre.lvl = hlvl + 4;
        
        while(Ogre.dead != true || hero.dead != true){
            Ogre.hp = Ogre.hp - damage;
            cout << "Ogre's hp: " << Ogre.hp << endl;
            if(Ogre.hp <= 0){
                Ogre.dead = true;
                cout << "You won!" << endl;
                cout << "Xp gained: " << Ogre.xpGain << "." << endl;
                xp = xp + Ogre.xpGain;
                cout << "Level progress: " << xp << "/" << hero.neededXp << "." << endl;
                cout << "Level: " << hlvl << endl;
                if(xp >= hero.neededXp){
                    hlvl++;
                    xp = xp - hero.neededXp;
                }
                break;
            } else if(hero.hp <= 0){
                cout << "You've died!" << endl;
                hero.dead = true;
                Save();
            }
        
            hero.hp = hero.hp - Mace.damage; 
            cout << "Your's hp: " << hero.hp << endl;
        }
    }
    
    move();
}

string createRoom(){
    string type = typeRoom();
    if(type == "loot"){
        createLootRoom();
    } else{
        createEnemyRoom();
    }
}



void welcome(){
    int answer;
    
    cout << "You have a choice.\nWhat'll you do next?" << endl;
    cout << "1 - Go through exit." << endl;
    cout << "2 - Exit game." << endl;
    cin >> answer;
    
    if(answer < 1 || answer > 2){
        cout << "Invalid parameters" << endl;
    }   else if(answer == 1){
        createRoom();
    } else{
        Save(); 
    }
};

 //Àíäðåé

int main(){ 
    char answer;
    
    cout << "What's your name?" << endl;
    cin >> playerName;
    
    welcome();
    
        
    for(int i = 0; i < 100; i++){
        welcome();
        
        if(count >= 0){
            cout << "Continue?(Y/N)" << endl;
            cin >> answer;
            
            if(answer == 'n' || answer == 'N'){
                Save();
            }
        }
    }   
    
    /*do{
        
        
    }
    while(answer == 'y' || answer == 'Y');
    */

}


Ответы (0 шт):