Hey there guys, I'll post my code below.
I've currently finished being taught the bare basics of C++ for on of my Uni modules. However, I thought that C++ would be a useful skill to have, if not for my future line of work then just to amuse myself, So I decided to make a game.
I want to split the main game up from the introductory menu and stuff, so I read up about using header files. I think I set everything up ok, and I'm not getting any error, but for some reason, the procedure void GameStart() isn't showing up at all, despite no error and an exit code of 0x0.
Am I doing something fundamentally wrong?
EDIT - THE GAME RUNS FINE, Until it tried to call GameStart(), then it just exits. No errors no nothing.
HEADER.h File
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#ifndef HEADER_H
#define HEADER_H
#endif
#include <iostream>
#include <sstream>
#include <fstream>
#include <cstring>
#include <string>
// #define _WIN32_WINNT 0x0500
#include <windows.h>
#include <stdio.h>
#include <limits>
#include <stdexcept>
using namespace std;
class maingame
{
public:
static inline void GameStart();
};
class main
{
public:
int mercantile; //Merchant Skill points, give discounts on goods
int cunning; // Cunning Skill points, allows you to bypass some enemies
int persuasion; // How persuasive you are, can convince NPC's and such... Maybe.
int credits; //Characte Credits
//SHIP STATS
std::string shipname;
std::string shiptype;
int shipattack;
int shiphull;
int shipsheild;
int shipcargo;
int shipfuel;
private:
};
|
Game_File_1.cpp THE ONE I WANT TO BE ABLE TO SHOW ON THE CONSOLE.
1 2 3 4 5 6 7 8 9 10 11 12 13
|
#include "HEADER.h"
void GameStart()
{
system("cls");
cout << "OMG THIS ACTUALLY WORKS!!!";
system("pause");
}
|
and my Mars_Trinity_Main.cpp
A LOT OF CODE HAS BEEN OMMITED, BUT I THINK THE ERROR IS AROUND LINE 61 WHEN GameStart is called.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#include "HEADER.h"
int main()
{
Sleep(5000); // Sleep for 5 seconds
cout << " ENTER 'S' TO START THE GAME: ";
char StartGameChar;
cin >> StartGameChar;
while(StartGameChar != 'S'&& StartGameChar != 's'){
cout << "Please enter a valid character: ";
cin >> StartGameChar;
cout << endl;
}
char personalitymenu();
void mainmenu(char&);
char menuoption;
int creationcounter = 1;
mainmenu:
mainmenu(menuoption);
char CharacterRace();
std::string CharacterName();
while(menuoption != 'C' && menuoption != 'Q' && menuoption != 'I' && menuoption != 'S'){
cout << "No Valid Option selected. ";
goto mainmenu;
}
switch(menuoption)
{
// THIS CASE STARTS THE MAIN GAME
case 'S':
{
while(creationcounter == 1)
{
system("cls");
cout << "\nYou can't start the game if you havn't made a character.\nTaking you back to menu...";
Sleep(1500);
goto mainmenu;
}
cout << " Are you sure you want to start the game? Type Start to continue: ";
string StartWord;
cin >> StartWord;
while(StartWord != "start" && StartWord != "Start" && StartWord != "START")
{
cout << "\n\n Invalid Input, PLEASE ENTER START TO START GAME :";
cin >> StartWord;
}
cout << " Thanks, the game will start in 5 seconds...\n";
Sleep(1000);
cout << " 4 \n";
Sleep(1000);
cout << " 3 \n";
Sleep(1000);
cout << " 2 \n";
Sleep(1000);
cout << " 1 \n";
Sleep(1000);
cout << " Starting ";
Sleep(500);
system("cls");
maingame::GameStart;
break;
}
default:
{
cout << "Please enter a valid option, Going back to main menu.";
Sleep(2000);
goto mainmenu;
}
}
system("pause"); // To Pause the screen
return(0);
}
}
|