在C ++中打开的文本游戏打开两次

时间:2015-01-28 03:23:05

标签: c++

所以,我正在制作一个文字游戏。它打开并正常工作,然后突然关闭,没有明显的触发器,并打开自己的新实例。在它执行此操作后,它不会再次执行此操作。如果我愚蠢地做其他事情,我也想知道这一点。抬头说这是很多代码,因为我不知道问题出在哪里。我试图删除非重要位。还想知道如何读取exe文件所在的另一个目录中的写文件。我正在使用Code :: Blocks进行编译。如果头文件很重要,我可以包含它们。

//#libraries

#include <iostream>
#include <cstdlib>
#include <fstream>
#include <string>
#include "windows.h"
#include "math.h"
#include "time.h"
#include "Dungeon.h"

using namespace std;
//functions
int roomLogic();
void stats();
void options();
void devConsole();
void tutorial();
//Choose Class functions
void chooseClass();
void choosePaladin();
void chooseWarlock();
void chooseRanger();
void chooseWarrior();
void chooseRogue();
//global variables
int textSpeed;
int turns = 0;
bool debug = false;
//Player Stats
//Name and Such
int kills = 0;
int killScore = 0;
int damageDelt = 0;
int damageTaken = 0;
int score = 0;
string name;
string Class;
string race;
//Items
int keys = 0;
int money = 10;
int moneySpent = 0;
//Combat
int att = 10;
int def = 10;
int speed = 10;
int sneak = 10;
int eva = 10;
int perc = 10;
int accuracy = 10;
int health = 100;
int maxHealth = 150;
int mp = 50;
int magicPower = 10;

int main()
{
  cout << "WHOLE BUNCH OF INTRO TEXT THAT YOU DO NOT NEED TO READ BECAUSE  
  THERE IS A LOT" << endl;
  Sleep(1000);
  //Text Speed Definition
  cout << "How do you like your text speed? 'Slow', or 'Fast'?" << endl;
  cout << "Type your answer and press ENTER to send" << endl;
  string textSpeedInput;
  cin >> textSpeedInput;
  bool success = false;
  //a while statement to get them to say yes no and set a text speed, not   
  important


  cout << "If you have never played the game before and would like a   
  tutorial, type \n'tutorial' if not type 'no'" << endl;
  string tutor;
  cin >> tutor;
  bool tut = false;
  //another while statement thing that I cut out the function literally just     
  couts
  chooseClass();
  stats();
  roomLogic();
  system("PAUSE");
  exit(0);
  return 0;
}

void chooseClass()
{
  cout << "Choice is fun, but randomness can be too, Would you like to 
  choose your class   and race(Yes) or get a random class and race(No)" <<  
  endl;
  string willChoose;
  cin >> willChoose;
  if(willChoose == "Yes" || willChoose == "yes")
  {
    cout << "Would you like to be a:\n" << endl;
    cout << "Paladin (+3 Defense, -1 Speed)," << endl;
    cout << "Warlock (+3 Magic Power, -1 Defense)," << endl;
    cout << "Ranger (+2 Accuracy, +1 Perception, +1 Speed, -2 Defense)," << 
    endl;
    cout << "Warrior (+2 Attack, +1 Defense, -1 Magic Power), or" << endl;
    cout << "Rogue (+2 Stealth, +1 Attack, +1 Evasion, +1 Speed, -3 
    Defense)?" << endl;
    bool hasChoosen = false;
    cin >> willChoose;
    //another cut out while statement 

代码已经破了这一点。我不知道为什么。请帮忙,这是我需要在我的主要内容中增加的内容吗? 这是一个我只是使用的读写示例,你知道:

 ifstream x_file (".filenamehere.txt"); x_file >> variable to change; 
 x_file.close();

写下:

 ofstream y_file (".filename.txt"); y_file << thing to write; y_file.close();

0 个答案:

没有答案