HiveBrain v1.2.0
Get Started
← Back to all entries
patterncppMinor

Small "Pyramid Escape" text-based game

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
textpyramidgamesmallbasedescape

Problem

I'm extremely amateur when it comes to C++ in general, but I wanted to make a little "Pyramid Escape" text based game. I'm not done whatsoever but before I continue I want to see what I could possible do differently.

//
//  main.cpp
//  TextFiles
//
//  Created by Neal Carico on 3/12/15.
//  Copyright (c) 2015 Nedev. All rights reserved.
//

#include 
#include 

using namespace std;

int main(int argc, const char * argv[]) {

string start;
string restart;
string dead;
int turn1;
int turn2;
int turn3;
int turn4;
string decision1;
string decision2;
string decision3;
string decision4;
string decision5;
int random1;
int random2;
int random3;

while(restart != "dontrestart" || dead != "false"){
cout > start;

///The Start
if (start == "start"){

///The main part of the game.

    cout > turn1;
    if(turn1 == 2){
        cout > decision1;

    if(decision1 == "y"){
        cout > turn2;
    if (turn2 == random1) {
        cout > decision2;
    if(decision2 == "continue"){
        cout > restart;
    if (restart !="restart"){
        exit(1);
    }

}
return 0;

}

Solution

First, don't use using namespace std;, or any other namespace, for that matter. This can cause you have load functions with the same name, which can cause problems. This is discussed in more detail here.

Second, you have a ton of variables you never use, including:

int turn3;
int turn4;
string decision3;
string decision4;
string decision5;
int random2;
int random3;


Third, you should use move functions. One candidate for a function is asking whether to restart the game.

Fourth, I would use bools for dead and restart. You will need to convert the input for restart, but it better represents what is happening.

Fifth, you should consistently indent your code at 4 spaces per level. You do this for the most part, but you do not do this in main().

Code Snippets

int turn3;
int turn4;
string decision3;
string decision4;
string decision5;
int random2;
int random3;

Context

StackExchange Code Review Q#86184, answer score: 2

Revisions (0)

No revisions yet.