Help with ship project please

This is a discussion on Help with ship project please within the C++ Programming forums, part of the General Programming Boards category; Ok i seem to be getting the same kind of consensus with my program so far. Im to do a ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    1

    Help with ship project please

    Ok i seem to be getting the same kind of consensus with my program so far. Im to do a game where there are two ships (the player's ship and the computers ship) on a 10x10 playing grid, they are to have 4 different attributes (movement to give the ships a number of moves per turn, armor to see how much damage a ship can take before its game over, weapon how strong the weapon of a ship is, range how far a ship can shoot).

    Here are the instructions from my proffessor:

    Each Frigate can move left, right, straight or not at all. It can't move diagonally or backwards. It can only move in the direction it is facing (N, S, E, W). Each frigate can fire only to the right or to the left of the direction it is facing. (E.g. if facing North, the ship can shoot east or west only)

    Each turn the user gets to put in a sequence of actions equal to the number of actions their ship has available. All the actions are entered one after another for the user, and then the computer calculates its turn (up to the number of actions it has). Each ship then takes an action starting at the top of its list of actions, one action at a time. Order (or who goes first each for each segment of the turn) is determined randomly. When a ship fires, it can hit the other ship if the number of squares (starting with the square in front of the ship) counting to the square the opponents ship is in, is less than or equal to the range of their weapon. It does damage to the opposing ships armor equal to the count of the range of the weapon. If during any turn, any ship’s armor is equal to or less than zero, it is disabled and can no longer move forward, it may only turn in place.

    Now my problem is that i am displaying my ships incorrectly, in a way that is hard to manipulate them the way i would need to for this assignment. Can you guys give me alternatives as to how to display the ships on the playing grid so that they are easy to manipulate in other functions? They are to start in random places at the beginning of the game and they are the size of only one element, this is not long ships like in battleship.

    Also, i am to use no classes or anything other than: different variables, decisions, loops, arrays, and functions.

    Here is my code:
    Code:
    #include <cstdlib>
    #include <iostream>
    #include <iomanip>
    
    
    using namespace std;
    
    const int ROW = 10;
    const int COL = 10;
    
    void printBoard (int[][COL], int&, int&);
    void movement (int [][COL], int & , int & );
    
    int main(int argc, char *argv[])
    {
        int player;
        int computer;
        int gameboard[ROW][COL];
        
        srand(time(0));
        player = rand()%99+1;
        computer = rand()%99+1;
        printBoard(gameboard, player, computer);
        movement (gameboard, player, computer);
        printBoard(gameboard, player, computer);
        
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    
    void printBoard (int [] [COL], int & player, int & computer )
    {
        for (int rows = 0; rows < ROW; rows++)
        {
            for (int collumns = 0; collumns < COL; collumns++)
            {
    			if ((player / 10) == rows && (player % 10) == collumns)
    			{
    				cout << " P";
    			}
    			else if ((computer / 10) == rows && (computer % 10) == collumns)
    			{
    				cout << " C";
    			}
    			//else if statement here to check computer
    			else 
    			{
    				cout << " *";
    			}
            }
            cout << endl; 
        }
    }
    
    
    void movement (int [][COL], int & player, int & computer)
    {
        char move;
        
        cout << "Please enter your moves: ";
        cin >> move;
        
        if (move = 'w')
        {
            player += 1;
        }
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,849
    if (move = 'w')
    Try == rather than =

    > Ok i seem to be getting the same kind of consensus with my program so far
    Consensus, as in opinions from a lot of people?
    Lemme guess, you've been posting on lots of boards?
    I might be back later....
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,849
    Displaying Two Ships On A Playing Grid - C And C++ | Dream.In.Code
    Welcome to the new "shooting fish in a barrel" game.
    Otherwise known as finding cross-posted questions on internet forums.
    How To Ask Questions The Smart Way
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble with two two dimensional arrays
    By scmurphy64 in forum C Programming
    Replies: 5
    Last Post: 12-06-2009, 06:57 PM
  2. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 10:05 AM
  3. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 08:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21