So I'm working on a personal project with the goal of developing a sort of survival simulator. I've been taking the minuscule step of creating its first form as a text game. A big concern for me at the moment though is establishing good programming habits so I can carry them on in the rest of the project and throughout different "reincarnations" of the game. So far with my current game I've added early versions of some of the main interfaces, but I'd like some reviews from some experienced programmers before I continue under my current methods.
To help give an idea of my situation, My background in coding consists of merely an introductory class I took in high school. I still have a lot to learn (and re-learn), particularly when it comes to good coding habits. I plan to open my project for collaboration so having proper coding that reduces errors and miscommunication is a must for me. More specifically, I've been led to sticking to two major priorities so far:
1) Having clean and efficient code that doesn't bog down the system or make room for bugs
2) Making clear, unambiguous notes in the code that describe what isn't already explicit from the code itself
I'd also prefer to use code that encourages multi-platform support, so things like
#include <windows.h>
should probably be avoided unless absolutely necessary.
BTW, I did some cursory research and made a decision on what would be the best indent format for my project:
* Indent Style: Allman (mostly because it seems to be the most common, only slightly more than K&D)
* Indent Length: 4 (using spaces to minimize copy-paste formatting issues)
Before I continue I'd like to say that I am grateful for using this website since it has, to me, some of the most understandable free C++ tutorials there is online. It felt like this would be a natural place to post this.
Now on with the code. I omitted some characteristic features of the game without altering the overall structure of the code. It compiles and runs perfectly. A few things I'd like to point out is that so far I managed to learn the habit of excluding
using namespace std;
and I got rid of all my
goto
's and replaced them with
for(;;)
loops, but
cin
was having an issue so I replaced my
std::cin >> input;
's with
getline (std::cin, input)
's. I understand that it is known as bad practice to universally declare variables but I could find no better alternative for applying my input variable.
Please provide some feedback on the structure of my code. Should I change the indents? Should I use more functions? Do the notes explain enough? Should I rearrange anything? Are there code alternatives that run faster? Bear in mind that I want this to be as clear and logically-sound as possible. Also, if you're going to recommend a new method, if possible, please provide a fundamental reason why it would be better, e.g.: this article by Timo Geusch (
http://www.lonecpluspluscoder.com/2012/09/22/i-dont-want-to-see-another-using-namespace-xxx-in-a-header-file-ever-again/) goes into detail about the problems with global namespaces and provides some alternatives, and there are many who explain the value of structured programming over using gotos and its notorious risk of creating spaghetti code.
I'm currently coding using Codelite on Ubuntu 16.04. I plan on ordering Windows 10 soon. I have the code posted below.