Thread: Looking for constructive criticism

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    23

    Looking for constructive criticism

    This is the final assignment for my introductory c++ class. I decided to continue learning on my own, so I'm gonna start by rewritting my project. I would greatly appreciate any feedback/constructive criticism you guys can provide.

    Please, bare in mind; the course did not cover, classes, inheritance or any kind of object oriented programming. In fact, we only learned about data types, operators, basic input/output, control structures, functions, arrays and data structures.
    The little I know about any other topic, I learned it indirectly, on my own, by trying to solve the problems the project offered.

    Thank you all in advance.

    Code:
    //  Your final project is to create a game called Sub Hunter.
    //
    //  BOARD:
    //  Is a 10 x 10 grid of cells
    //   Destroyer:
    //  Represented by the @ symbol
    //  Has properties consisting of
    //  Direction facing (N,S,E,W)
    //  Depth charges - a count of remaining depth charges
    //  Strength - How much damage it can take before sinking
    //  Damage taken - how much damage it has taken from the sub
    //  Has three action points to spend each round - to be input by the player
    //  Possible Actions:
    //  Move Forward - move one square in the direction facing
    //  Turn Left - make a 90 degree turn to the left in the same square
    //  Turn Right - make a 90 degree turn to the right in the same square
    //  Ping - look for a sub. Ping allows the destroyer to "see" if the sub is within two squares of its current location. If the sub is within two squares, the destroyer only knows the direction from its position (not the distance)
    //  Depth charge - drop a depth charge
    //
    //  Sub:
    //  Represented by the ┴ symbol
    //  Has properties consisting of
    //  Direction facing (N,S,E,W)
    //  Torpedos - a count of remaining torpedos
    //  Strength - How much damage it can take before sinking
    //  Damage taken - how much damage it has taken from the destroyer
    //  Has two action points to spend each round - to be determined by the computer
    //  Possible Actions:
    //  Move Forward - move one square in the direction facing
    //  Turn Left - make a 90 degree turn to the left in the same square
    //  Turn Right - make a 90 degree turn to the right in the same square
    //  Scope- look for a destroyer. Scope allows the sub to "see" if the destroyer is within two squares of its current location. If the destroyer is within two squares, the sub knows the direction and distance from its position
    //  Torpedo - shoot a torpedo at the ship (only the direction it is facing)
    //  Game Play:
    //  The user inputs their actions as one turn (e.g. Forward, forward, ping).
    //  The computer determines the subs actions (Scope, torpedo)
    //  The program then runs the turns, sub first then destroyer based on the users actions and the computers actions and gives appropriate messages to the user based what happens.
    //  When the destroyer runs out of depth charges it is considered to be sunk by the sub
    //  If the sub runs out of torpedos, it can run away (head for the boarder of the map) if it successfully runs away the game is a draw
    //  Depth charges - When dropped they explode in the square they are in causing full damage to that square and half damage to all the squares around it.
    //  Torpedos - run straight in the direction the sub is facing for 2 squares. They hit for full damage if the sub is on that line within two square of the launch point - otherwise they miss.
    //  You should determine damage - limits for the ships and amount caused by the weapons, that make the game playable.
    //
    //  Extra Credit ideas - implement more!
    //  Levels to the game (Easy, Hard etc)
    //  Directional pings - only work in one direction but give exact information
    //  Launchable depth charges can go X squares away before exploding
    //  Homing torpedos
    //  Smarter sub tactics (run quiet ie. harder to find)
    //  Depth to the grid (3d array, meaning you also need depth for the charges to explode, minimum depth for scoping etc etc)
    //  Sound and more. Be creative.
    
    //////////////////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////////////////
    
    
    // Title: Sub Hunter
    // Name:  *********
    // Class: COP1320
    // Due:   06/21
    // -------------------------------------------------------------------------------------------
    
    
    
    #include <cstdlib>
    #include <iostream>
    #include <ctime>
    
    using namespace std;
    
    struct vessel
    {   short ammo;
        short wepDamage;
        short hullIntegrity;
        short movePoints;
        short position[2];
        short heading;
        short *destination;
        bool  visibility;
        char  shape;
    } sub, destroyer;
    
    struct board
    {   static const short COLUMN = 10;
        static const short ROW = 10;
        short patrolPoint [4][2];
    } map;
    
    enum orientation {NORTH, EAST, SOUTH, WEST};
    enum patrolP {A, B, C, D};
    enum coordinates {X, Y};
    
    // Function prototypes;
    // -------------------------------;
    void    initialize();
    void    drawMap();
    void    attack(vessel);
    void    aI_turn();
    void    humanTurn();
    void    checkStatus();
    bool    moveSub(std::string action);
    short   ping(vessel vType, bool verbose = false);
    short   message(std::string code, bool drawBoard = true);
    
    bool gameOver = false;      // modified only in the 'message' function.
    
    // FUNCTION DEFINITIONS:
    //-------------------------;
    // Initialize(): This function initializes the respective struct members to default values.
    // ------------------------;
    // CALLS TO: none
    // CALLED FROM: main.
    
    void initialize ()
    {   srand(time(NULL));
        destroyer.ammo = 14;
        destroyer.wepDamage = 10;
        destroyer.hullIntegrity = 140;
        destroyer.movePoints = 3;
        destroyer.shape = '@';
        destroyer.position[X] = rand()%8 + 1;
        destroyer.position[Y] = rand()%8 + 1;
        destroyer.heading = NORTH;
        sub.ammo = 8;
        sub.wepDamage = 20;
        sub.hullIntegrity = 80;
        sub.movePoints = 2;
        sub.shape = 193;            
        sub.visibility = false;
        sub.heading = NORTH;
        sub.destination = NULL;
        sub.position[X] = rand()%10;
        sub.position[Y] = rand()%10;
    
        map.patrolPoint [A][X] = map.ROW * .25;
        map.patrolPoint [A][Y] = map.COLUMN * .25;
        map.patrolPoint [B][X] = map.ROW * .75;
        map.patrolPoint [B][Y] = map.COLUMN * .25;
        map.patrolPoint [C][X] = map.ROW * .75;
        map.patrolPoint [C][Y] = map.COLUMN * .75;
        map.patrolPoint [D][X] = map.ROW * .25;
        map.patrolPoint [D][Y] = map.COLUMN * .75;
    }
    
    // ping(): The function will calculate and return the distance between the sub and destroyer as well as tell the AI  whether the
    // ship is or not within shooting range.
    // ------------------------;
    // Parameters:
    // vType (vessel)   - the type of vessel to perform the ping on (sub or destroyer)
    // verbose (bool)   - if true, calls 'message();' to print the ping results on the screen.
    //
    // CALLS TO: message.
    // CALLED FROM: humanTurn, aI_turn.
    
    short ping (vessel vType, bool verbose)
    {   short proximity = 0, inRange =-1, subPingRange = 3, destroyerPingRange = 3;
    
        proximity = abs(sub.position[Y] - destroyer.position[Y]) + abs(sub.position[X] - destroyer.position[X]);
        if (vType.shape == sub.shape)
        {    if (proximity <= destroyerPingRange && verbose)
                sub.visibility = true;
            else if (verbose)
                message ("pingFailed");
    
            return proximity;
        }
        else if (vType.shape == destroyer.shape)
        {   if (proximity <= subPingRange)
                return inRange;
            else
                return 0;
        }
    }
    
    // message(): The function displays on the screen all the  messages to the user. Before each message the game board
    // is redrawn, by calling "drawMap()" to avoid text agglomeration on screen. If 'exit' is passed as an argument, the function will
    // ask the user whether or not to quit, and it will modify the global 'gameOver' depending on the answer.
    // ----------------------;
    // Parameters:
    // code (string)     - What message to display.
    // drawMap (bool)    - if true the gameBoard will be drawn before the pertinent message.
    // CALLS TO:        drawMap.
    // CALLED FROM: humanTurn, checkStatus, main.
    
    short message (string code, bool drawBoard)
    {   char    exit = 0;
        if (drawBoard)
            drawMap    ();
    
        if (code == "invalidKey")
            std::cout <<"Invalid key, please try again ";
        else if (code == "mapEdge")
            std::cout <<"You can't move beyond the edge of the map";
        else if (code == "subHit")
            std::cout << "You Have hit the target!!. Hull Integrity: " <<sub.hullIntegrity;
        else if (code == "shipHit")
            std::cout <<"You have been hit by the sub. Hull integrity: "<<destroyer.hullIntegrity;
        else if (code == "missed")
            std::cout <<"You missed !";
        else if (code == "noAmmo")
            std::cout <<"You have run out of charges. You lose, Game Over !" <<std::endl;
        else if (code == "ranAway")
            std::cout <<"The Submarine has escaped the waters... Game is a draw";
        else if (code == "debug")
        {   std::cout << "sub X: " <<sub.position[X] <<" sub Y: " <<sub.position[Y] <<std::endl;
            std::cout << "destroyer X: " <<destroyer.position[X] <<" destroyer Y: " <<destroyer.position[Y] <<std::endl;
            std::cout << "sub Integrity: " <<sub.hullIntegrity <<" destryer integrity: " <<destroyer.hullIntegrity <<std::endl;
            std::cout << "sub ammo: " <<sub.ammo <<" destryer ammo: " <<destroyer.ammo <<std::endl;
            std::cout << "sub move points: " <<sub.movePoints <<" destroyer movePoints: " <<destroyer.movePoints <<std::endl;
            std::cout <<"sub heading is: " <<sub.heading <<std::endl;
            std::cout << "proximity is : " <<ping(sub) <<std::endl;
        }
        else if (code == "welcome")
        {   system ("cls");
            std::cout <<"Welcome to SUB_Hunter !!" <<std::endl <<"Your Objective is to locate and destroy "
                      <<"an enemy submarine that patrols these waters. To locate the sub you must use your radar "
                      <<"to ping its location. If the sub is within a two square radious, its location will be "
                      <<"revealed. " <<"To attack the sub you must drop depth charges at it. "
                      <<"Depth charges will explode on the square you are causing full damage, and half damage to "
                      <<"adjacent squares." "\n" <<std::endl
                      <<"To fire depth charges, press 'F', to ping press 'E', to turn left press 'A', to turn "
                      <<"right press 'D',to turn back press 'S', to turn front press'Q' to move press 'W'"<<std::endl
                      <<"TO READ THIS MESSAGE AGAIN press 'H'";
        }
        else if (code == "pingFailed")
            std::cout <<"Not in range ";
        else if (code == "exit")
        {   std::cout    <<"Do you want to quit the game ?" <<"\n" <<"Yes(y) No(n)" <<std::endl;
            std::cin    >> exit;
            exit = tolower(exit);
            if (exit == 'y')
                gameOver = true;
                return 0;
        }
        else if (code == "g_over")
        {   if (sub.hullIntegrity <= 0)
                std::cout <<"VICTORY You have annihilated the enemy Submarine !!" <<std::endl;
            else
                std::cout <<"You have been destroyed by the enemy..." <<std::endl;
        }
    
        cin.ignore();
        cin.get();
    }
    
    // drawMap(): This function prints the game board, the ship and the submarine on the screen. The board is a two dimensional
    // char array of size ROW and COLUMN. The function uses a 'for' loop to iterate through each index of the array and compare
    // it to the submarine and destroyer's position. These positions are a set of coordinates, (X,Y) representing array indexes.
    // If the indexes coincide, the ship or sub characters will be stored there. Otherwise the "land" character will be stored. The
    // contents of each index is printed sequentially on each iteration.
    // ----------------------;
    // CALLS TO: none
    // CALLED FROM: main, message.
    
    void drawMap ()
    {   char gameBoard [map.ROW][map.COLUMN];
        char land = '|', pit = '_', terrain = land;     // "water" would be more corect since we are dealing with marine vessels :)
        char stern = destroyer.shape, bow = '*';
        short shpPosX = destroyer.position[X], shpPosY = destroyer.position[Y];
        system ("cls");
    
        for (short i=0; i<map.ROW; i++)
        {   for (short j=0; j<map.COLUMN; j++)
            {    if (sub.visibility == true && j == sub.position[X] && i == sub.position[Y])
                    terrain = sub.shape;
                else if (j == shpPosX && i == shpPosY )
                    terrain = stern;
                else if ((destroyer.heading == NORTH && i == shpPosY - 1 && j == shpPosX) ||
                            (destroyer.heading == SOUTH && i == shpPosY + 1 && j == shpPosX) ||
                            (destroyer.heading == EAST && i == shpPosY && j == shpPosX + 1) ||
                            (destroyer.heading == WEST && i == shpPosY && j == shpPosX - 1))
                    terrain = bow;
                else if (j != shpPosX || i != shpPosY)
                    terrain = land;
    
                gameBoard[j][i] = terrain;
                std::cout <<gameBoard[j][i] <<pit;
            }
            std::cout <<std::endl;
        }
    }
    
    // humanTurn(): The function controls the user interactions, takes and validates user inputs, deducts movement points and
    // moves the destroyer, providing feedback to the user along teh way.
    // ----------------------;
    // CALLS TO: message, atack, ping.
    // CALLED FROM: main.
    
    void humanTurn ()
    {   char  key = 0;
        short nextPosX    = destroyer.position[X], nextPosY = destroyer.position[Y];
    
        while (destroyer.hullIntegrity  && destroyer.movePoints)
        {   std::cout    <<"Your move " <<"(" <<destroyer.movePoints <<")" <<" moves left ";
            std::cout   <<destroyer.ammo <<" charges left" <<std::endl;
            std::cin    >>key;
            key = tolower(key);
            if (key == 'w' || key == 'd' || key == 's' || key == 'a' || key == 'q'|| key == 'e' || key == 'f' || key == 'b' || key =='x' || key == 'h')
                break;
            else
                message ("invalidKey");
        }
        if (key == 'q')
            destroyer.heading = NORTH;
        else if (key == 'd')
            destroyer.heading = EAST;
        else if (key == 's')
            destroyer.heading = SOUTH;
        else if (key == 'a')
            destroyer.heading = WEST;
        else if (key == 'w' )
        {   if (destroyer.heading == NORTH)
                nextPosY --;
            else if (destroyer.heading == EAST)
                nextPosX ++;
            else if (destroyer.heading == SOUTH)
                nextPosY ++;
            else if (destroyer.heading == WEST)
                nextPosX --;
        }
        else if (key == 'e')
            ping (sub,true);
        else if (key == 'f')
            attack (sub);
        else if (key == 'b')
            message ("debug");
        else if (key == 'x')
            message ("exit");
        else if (key == 'h')
        {   message ("welcome",false);
            key = 0;
        }
    
           if (nextPosX < 0 || nextPosX > map.ROW-1 || nextPosY < 0 || nextPosY > map.COLUMN-1)
               message ("mapEdge");
        else if (key)
        {   destroyer.position[X] = nextPosX;
            destroyer.position[Y] = nextPosY;
            destroyer.movePoints --;
        }
    }
    
    // attack(): This function determines if the destroyer or sub are within shooting range, if so it deducts ammo points and health
    // from whatever is specified as vessel type and It informs the user of its attack results as well as the sub's.
    // ----------------------;
    // Parameters:
    // vType (vessel)   - what vessel to attack, sub or destroyer.
    // CALLS TO: message, ping, moveSub.
    // CALLED FROM:
    
    void attack (vessel vtype)
    {   short proximity = 0;
        if (vtype.shape == sub.shape)
        {  proximity = ping(sub);
           if ( proximity < 2)
           {   sub.hullIntegrity -= (destroyer.wepDamage / (proximity + 1));
               sub.visibility = true;
               message ("subHit");
           }
           else
               message ("missed");
           destroyer.ammo --;
         }
        else if (vtype.shape == destroyer.shape)
        {   if (moveSub("chase") == true);
            {   while (sub.movePoints > 0 && sub.ammo && destroyer.hullIntegrity)
                {   sub.ammo --;
                    sub.movePoints --;
                    destroyer.hullIntegrity -= sub.wepDamage;
                    message ("shipHit");
                }
            }
        }
    }
    
    // moveSub(): The function is in charge of controlling the sub movements. Depending on the arguments passed, it will Patrol a
    // predefined area around the map, move the sub away from the destroyer, drive the sub away from the map, when the sub
    // runs out of charges, or it will position the sub at the correct firing distance and  the correct heading to discharge torpedos at
    // the destroyer.
    // ----------------------;
    // Parameters:
    // action (string)  - will tell the function what action to perform, whether to chase the destroyer, evade, run away from the map
    // or patrol the area.
    // CALLS TO: none
    // CALED FROM: attack, aI_turn.
    
    bool moveSub (string action)
    {   short distanceX = 0, distanceY = 0, absDstX = 0, absDstY = 0;
    
        // If "chase" is passed as an argument, the function will find the shortest path to the destroyer by finding the difference
        // in the X and Y positions between both vessels. It will then move the sub in that axis, towards the destroyer, by increasing
        // its position if the difference is negative and decreasing it if positive.
        // Everytime the sub position is updated, its orientation is checked, so that it moves in the direction it's heading, if it isn't its
        // heading is updated and a move point is deducted.
        // If the sub is within fire distance of the destroyer, i.e the absolute value of the difference of their array index position, is
        // less or equal to fireRange's value, the function will return true. Orientation will be checked again.
    
        if (action == "chase")
        {   short fireRange = 2;
            bool inFireRange = true;
    
            while  (sub.movePoints > 0)
            {   distanceX = sub.position[X] - destroyer.position[X];        //distance between the sub and the ship in the X axis.
                distanceY = sub.position[Y] - destroyer.position[Y];        //distance between the sub and the ship in the Y axis.
                absDstX = abs(distanceX);
                absDstY = abs(distanceY);
    
                // if the sub is within two squares on the same axis.
                if ((absDstX <= fireRange && !absDstY) || (absDstY <= fireRange && !absDstX))
                {   if (distanceX < 0 && sub.heading != EAST)
                    {   sub.heading = EAST;
                        sub.movePoints--;
                    }
                    else if (distanceX > 0 && sub.heading != WEST)
                    {   sub.heading = WEST;
                        sub.movePoints--;
                    }
                    else if (distanceY < 0 && sub.heading != SOUTH)
                    {   sub.heading = SOUTH;
                        sub.movePoints--;
                    }
                    else if (distanceY > 0 && sub.heading != NORTH)
                    {   sub.heading = NORTH;
                        sub.movePoints--;
                    }
                    return inFireRange;
                }
                else // if the path is closer on the X axis
                {   if (absDstX < absDstY && absDstX || !absDstY)
                    {   if (distanceX < 0)
                        {   sub.position[X] ++;
                            if (sub.heading != EAST)
                            {   sub.heading = EAST;
                                sub.movePoints--;
                            }
                        }
                        else
                        {   sub.position[X] --;
                            if (sub.heading != WEST)
                            {   sub.heading = WEST;
                                sub.movePoints--;
                            }
                        }
                    }
                    else
                    {   if (distanceY < 0)
                        {   sub.position[Y] ++;
                            if (sub.heading != SOUTH)
                            {   sub.heading = SOUTH;
                                sub.movePoints--;
                            }
                        }
                        else
                        {   sub.position[Y] --;
                            if (sub.heading != NORTH)
                            {   sub.heading = NORTH;
                                sub.movePoints--;
                            }
                        }
                    }
                    sub.movePoints --;
                }
            }
            return false;
        }
    
        // If "patrol" is passed as an argument, the sub will begin to move towards predefined set-points. First  the sub's position is
        // checked. if its position does not coincide with one of the patrol points then point "A" is set as the default destination.
        // Once it arrives there, point "B" is set as the next destination, and then "C".. This goes on and on until the sub moves
        // through all the points, and then begins again.
        // 'Destination' is a pointer variable that will hold the address of the patrol point the sub is heading to. The X and Y position
        // of the destination point is then extracted from 'destination' and substracted with the sub's X and Y positions. The sub
        // will then increase or decrease its position based on whether the difference is positive or negative by an amount
        // corresponding to the absolute value of that difference.
    
        else if (action == "patrol")
        {   short moveRow = 0, moveColumn = 0, posX = 0, posY = 0;
            short *destinationY = NULL;
    
            if (sub.position[X] == map.patrolPoint[A][X] && sub.position[Y] == map.patrolPoint[A][Y])
                sub.destination = &map.patrolPoint[B][X];
            else if (sub.position[X] == map.patrolPoint[B][X] && sub.position[Y] == map.patrolPoint[B][Y])
                sub.destination = &map.patrolPoint[C][X];
            else if (sub.position[X] == map.patrolPoint[C][X] && sub.position[Y] == map.patrolPoint[C][Y])
                sub.destination = &map.patrolPoint[D][X];
            else if (sub.position[X] == map.patrolPoint[D][X] && sub.position[Y] == map.patrolPoint[D][Y])
                sub.destination = &map.patrolPoint[A][X];
            else if (!sub.destination)
                sub.destination = &map.patrolPoint[A][X];
    
            posX = *sub.destination;
            distanceX = sub.position[X] - posX;
            moveRow = abs(distanceX);
            destinationY = &sub.destination[Y];
            posY = *destinationY;
            distanceY = sub.position[Y] - posY;
            moveColumn = abs(distanceY);
    
    
            for (short i = 0, j = sub.movePoints; j > 0 && i < moveRow; i++, j--)
            {   if (distanceX > 0)
                    sub.position[X]--;
                else
                    sub.position[X]++;
            }
            for (short i = 0, j = sub.movePoints; j > 0 && i < moveColumn; i++, j--)
            {   if (distanceY > 0)
                    sub.position[Y]--;
                else
                    sub.position[Y]++;
            }
            sub.movePoints = 0;
        }
    
        // if evade is passed as an argument, the sub will move backwards, in the opposite direction it's heading. This moves the sub
        // directly away from below the destroyer, where it causes more damage and saves movepoints to fire at least one shot in
        // that turn, by not having to waste points turning. "evade" is passed when "aI_turn" determines the sub is low on health.
    
        else if (action == "evade")
        {   if (sub.heading == NORTH && sub.position[Y] < map.COLUMN)
                sub.position[Y]++;
            else if (sub.heading == SOUTH && sub.position[Y] > 0)
                sub.position[Y]--;
            else if (sub.heading == EAST && sub.position[X] > 0)
                sub.position[X]--;
            else if (sub.heading == WEST && sub.position[X] < map.ROW)
                sub.position[X]++;
    
            sub.movePoints--;
        }
    
        // If "runAway" is passed as an argument, the function will move the sub out of the map, finding the fastest route by
        // dividing the size of the array in 2 and comparing the current sub position with it.
        // "aI_turn" will pass this argument if the sub runs out of torpedos. This functionality was part of the assignment but the
        // game mechanics do not allow for it to be used, since the sub will kill the destroyer before running out of charges.
        // Reducing the number of torpedos would make the destroyer not-killable so that isn't an option. The only option would be to
        // make the sub fire "test" shots every now and then, but since the torpedo range is the same as the ping range, theres not
        // any advantage to this. A more attractive option would be to make a shipwright base where the destroyer can get repairs
        // provided that the sub doesn't find it first.
    
        else if (action == "runAway")
        {   short middle = 0;
    
            distanceX = sub.position[X] - map.ROW;
            distanceY = sub.position[Y] - map.COLUMN;
            absDstX = abs(distanceX);
            absDstY = abs(distanceY);
            middle = map.ROW / 2;
            if (absDstX < absDstY)
            {   if (absDstX <= middle)
                    sub.position[X]++;
                else
                    sub.position[X]--;
            }
            else
            {   if (absDstY <= middle)
                    sub.position[Y]++;
                else
                    sub.position[Y]--;
            }
            sub.movePoints--;
        }
    }
    
    // This function controls all the AI decisions and behavior. if the sub is directly below the destroyer with low health it will pass
    // "evade" to moveSub. If the destroyer is discovered, it will call the "attack" function. Otherwise it will pass "patrol" to moveSub.
    // If the sub runs out of ammo, it will pass "runAway"(note* see "runAway" section on the moveSub function to see why this will
    // never occur.
    // ------------------------;
    // CALLS TO: moveSub, ping.
    // CALLED FROM: main.
    
    void aI_turn()
    {   if (destroyer.movePoints <= 0)
        {   sub.visibility = false;
            if (sub.ammo)
            {  if (sub.position[X] == destroyer.position[X] && sub.position[Y] == destroyer.position[Y] &&
                    sub.hullIntegrity <= destroyer.wepDamage * 3 && destroyer.hullIntegrity > sub.wepDamage * 2)
                    moveSub("evade");
                else if (ping(destroyer))
                   attack (destroyer);
                else
                    moveSub("patrol");
            }
            else
                moveSub ("runAway");
        }
    }
    
    // checkStatus (): This function will check the game looking for game ending conditions. If found, a propper message will be
    // issued to the user and the game will finish. After both sub and destroyer have played out their turns their move points are
    // restored.
    // ------------------------;
    // CALLS TO: message, initialize.
    // CALLED FROM: main.
    
    void checkStatus()
    {   if (!gameOver)
        {   bool game_over = 0;
    
            if (sub.hullIntegrity <= 0 || destroyer.hullIntegrity <= 0)
            {   message ("g_over");
                game_over = true;
            }
            else if (destroyer.ammo <= 0)
            {   message ("noAmmo");
                game_over = true;
            }
            else if (sub.ammo <= 0 && (sub.position[X] >= map.ROW || sub.position[Y] >= map.COLUMN))
            {   message ("ranAway");
                game_over = true;
            }
    
            if (game_over)
            {   message ("exit");
                initialize();
            }
            else if (!sub.movePoints  && !destroyer.movePoints)
            {   destroyer.movePoints = 3;
                sub.movePoints = 2;
            }
        }
    }
    
    
    
    int main(int argc, char *argv[])
    {
        message("welcome",false);
        initialize();
    
        while (!gameOver)
        {    drawMap();
            aI_turn();
            humanTurn();
            checkStatus();
        }
        return 0;
    }

    I hope this also can help future students, scavenging the web for answers, to get a general idea of how this can be approached, and avoid being as lost as I was when I first started. Word of caution though, the professor sends all submitted code through a code analyzer that compares your code with a database of previous submissions. Any similarity higher than 60% will raise red flags all over and you will most likely get an F. So take the concepts and implement them in your own way.
    Last edited by skyliner; 09-07-2012 at 02:48 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  2. Constructive criticism/suggestions
    By LineOFire in forum C Programming
    Replies: 11
    Last Post: 09-30-2006, 09:32 AM
  3. Constructive criticism, suggestions etc
    By BobS0327 in forum C Programming
    Replies: 3
    Last Post: 01-08-2006, 09:35 AM
  4. Constructive criticism highly appreciated!
    By muggizuggi in forum C++ Programming
    Replies: 17
    Last Post: 08-01-2005, 11:54 AM