Game Development Reference
In-Depth Information
Listing 7-6. Player.h
#pragma once
#include <string>
struct Player
{
std::string m_name;
};
This file is very simple. All we have here is the definition of the Player struct. This might seem like a
waste, but I can assure you that this struct will grow in size as we build out our game.
Listing 7-7 shows the code contained in GameLoop.h .
Listing 7-7. GameLoop.h
#pragma once
#include "Player.h"
#include "PlayerOptions.h"
namespace GameLoop
{
void WelcomePlayer(Player& player);
void GivePlayerOptions();
void GetPlayerInput(std::string& playerInput);
PlayerOptions EvaluateInput(std::string& playerInput);
bool RunGame();
}
We have created a namespace called GameLoop to contain our functions. This will prevent any
name clashes that might occur with functions in other files in the future. You might notice that the
header only contains the declarations for our functions. This is an important feature, as it provides
an optimization for the compiler and also makes the code easier to read for other programmers.
The compiler can build source files that call functions from this header file faster when it does not
need to read and compile the entire function declarations. Programmers can use the functions
faster by simply looking at the parameters the function takes and the types that they return. Other
programmers do not necessarily need to know exactly how the function operates internally.
The actual function definitions are contained in the GameLoop.cpp file shown in Listing 7-8.
Listing 7-8. GameLoop.cpp
#include "GameLoop.h"
#include <iostream>
using namespace std;
 
Search WWH ::




Custom Search