0

当我使用它创建以下类的实例时,Game newGame;会引发 c1001 错误,指出存在编译器错误。

游戏.h:

#pragma once

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <conio.h>
#include "cls.h"
#include "explode.h"

using namespace std;

class Game
{
private:
    explode EXP;
    CLS cls;
    string _SaveGame, _DIRECTORY;
    int _GAMEDATA[500];
    string _DATATITLES[500] = { "Ticks", "Dwarves", "Grain Mills", "Lumber Mills", "Mines", "Grain Workers", "Lumber Workers", "Mine Workers", "Grain Mill Experts", "Lumber Mill Experts", "Mine Experts" };

public:

    void CS() 
    { 
        cls.clear(); 
    }

    void SetSaveName(string SaveName)
    {
        _SaveGame = SaveName;
    }

    void init(string directory)
    {
        _DIRECTORY = directory;
        cout << "Init Game" << endl;
        CS();

        ofstream gameSave;
        gameSave.open(_DIRECTORY + _SaveGame + ".save", ofstream::out | ofstream::app);
        cout << "Game Saved As: " << _DIRECTORY + _SaveGame + ".save";
        if (!gameSave.good())
        {
            // Write New Data To File
            cout << "Game Saved As: " << _DIRECTORY + _SaveGame + ".save";
            gameSave.flush();
            gameSave << "0\n"; // TICKS
            gameSave.flush();
            gameSave << "7\n"; // Dwarves
            gameSave.flush();
            gameSave << "1\n"; // Grain Mills
            gameSave.flush();
            gameSave << "1\n"; // Lumber Mill
            gameSave.flush();
            gameSave << "1\n"; // Mine
            gameSave.flush();
            gameSave << "2\n"; // Grain Mill Workers
            gameSave.flush();
            gameSave << "2\n"; // Lumber Mill Workers
            gameSave.flush();
            gameSave << "3\n"; // Mine Workers
            gameSave.flush();
            gameSave << "1\n"; // Grain Mill Experts
            gameSave.flush();
            gameSave << "1\n"; // Lumber Mill Experts
            gameSave.flush();
            gameSave << "1\n"; // Mine Experts
            gameSave.flush();

            gameSave << "ENDFILE";
            gameSave.flush();

        }
        else
        {
            // Read Data From File
            loadGame(_SaveGame);
        }

        bool GameLoop = true;
        while (GameLoop)
        {
            // Begin Game Loop Instance
            printData();
            string in;
            bool parseDataLoop = 1;
            while (parseDataLoop)
            {
                in = getData();
                int parseDataInt = parseData(in);
                if (parseDataInt == 1) {
                    GameLoop = 0;
                    saveGame();
                    exit(0);
                }
                else if (parseDataInt == 2) {
                    _getch();
                }
                else
                {
                    parseDataLoop = 0;
                }
            }
            saveGame();
        }

    }

    void GameTick()
    {
        _GAMEDATA[0] += 1; // Number Of Game Ticks

    }

    void printData()
    {
        CS();
        for (int i = 0; i < 500; i++) {
            if (_GAMEDATA[i] != NULL) {
                cout << _DATATITLES[i] << " : " << _GAMEDATA[i];
            }
        }
    }

    string getData()
    {
        string DATA;

        cin >> DATA;

        return DATA;
    }

    int parseData(string input)
    {

        int quit = 0;
        if (input == "help")
        {
            // Print List Of Commands And Descriptions: 
            cout << "List Of All Available Commands:" << endl;
            cout << "help : Shows A List Of All Available Commands" << endl;
            cout << "tick : Makes Game Progress One Tick" << endl;
            cout << "tick.NUM : Makes Game Progress NUM Tick(s)" << endl;
            cout << "quit : Saves Game And Terminates Program" << endl;
            quit = 2;
        }
        else if (input == "quit")
        {
            quit = 1;
        }
        else if (input == "tick")
        {
            // Skip One Tick

            GameTick();
        }
        else if (find(input, '.')) {
            vector<string> output;
            output = EXP.explodeStuff(input, '.');

            if (output[0] == "tick") {
                if (isInterger(output[1]))
                {
                    for (int i = 0; i < stoi(output[1]); i++) {
                        GameTick();
                    }
                }
                else
                {
                    cout << "ERROR: tick." << output[1] << ", is not vaid please use numbers not letters." << endl;
                    quit = 2;
                }
            }
        }
        else
        {
            cout << "ERROR: Invalid Command Please type \"help\" To See A List Of Available Commands." << endl;
            quit = 2;
        }

        return quit;
    }

    void loadGame(string saveGame)
    {
        ifstream inData;
        string temp;
        inData.open(_DIRECTORY + saveGame + ".cod");
        if (inData.good())
        {
            for (int i = 0; i < 500; i++) {
                getline(inData, temp);
                if (temp == "ENDFILE") { break; }
                if (temp != "")
                {
                    _GAMEDATA[i] = stoi(temp);
                }
            }
            inData.close();
        }
    }

    void saveGame()
    {
        // Update Data in file

        ofstream gameSave(_DIRECTORY + _SaveGame + ".save");
        gameSave.clear();
        for (int i = 0; i < 500; i++) {
            if (_GAMEDATA[i] != NULL) {
                gameSave << _GAMEDATA[i];
            }
        }
        gameSave << "\nENDFILE";
    }

    bool find(string input, char find)
    {
        bool RETURN = 0;

        for each (char CHAR in input)
        {
            if (CHAR == find) {
                RETURN = 1;
                break;
            }
        }

        return RETURN;

    }

    inline bool isInterger(const std::string & s)
    {
        if (s.empty() || ((!isdigit(s[0])) && (s[0] != '-') && (s[0] != '+'))) return false;
        char* p;
        strtol(s.c_str(), &p, 10);
        return (*p == 0);
    }

};

主.cpp:

#include <iostream>
#include <fstream>
#include <string>
#include <vector>

#include "game.h"
#include "programSettings.h" 
#include "cls.h"
#include "explode.h" // Adds explode(string input, char delimeter), and explodePrint(vector<string> input)

using namespace std;

string _DIRECTORY = (string)getenv("APPDATA") + "/cityOfDwarves/";
vector<int> _SETTINGS; // Array To Hold All Settings In The SETTINGS.cod File
int SettingsConfigured;
explode EXP;
CLS cls;

int main()
{

    SetConsoleTitle("CityOfDwarves");

    programSettings pSet(_DIRECTORY);

    _SETTINGS = pSet.readSettings();
    if (_SETTINGS.size() > 0) {
        SettingsConfigured = _SETTINGS[0];
    }
    else
    {
        SettingsConfigured = 0;
    }

    if (!SettingsConfigured) {
        pSet.setSettings();
    }

    cout << "Settings Configured" << endl;
    cls.clear();

    cout << "Please Enter a Save Name:" << endl;
    string SaveName;
    cin >> SaveName;
    cout << "Using: " << SaveName << ", As The Current Save File." << endl;

    // Begin Game Loop
    Game mainGame;
    mainGame.SetSaveName(SaveName);
    mainGame.init(_DIRECTORY);

    char i;
    cin >> i;

    return 0;
}

完整错误代码:
严重性代码 描述 项目文件行错误 C1001 编译器发生内部错误。CityOfDwarves C:\Users\Daniel\Documents\Visual Studio 2015\Projects\CityOfDwarves\CityOfDwarves\main.cpp 1

4

0 回答 0