Displaying ships on a game grid and other things

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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#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;
    }
}
Topic archived. No new replies allowed.