Hey guys, so i have this project due on the 13th of Dec. I have been trying to work on it but im at a roadblock pretty early on and im just at a loss as to what to do, so i would appreciate a ton if you guys an provide some help :)

I am to make a program that is a game and is a pirate ship game. The ships are to start randomly in a 10x10 playing board (made with an array) and are to have four attributes [Movement (how many spaces a hip can move in one turn),Armor (how much damage it can take before being killed), Weapon (how strong the weapon is), and Range (how far can it shoot)].

What i need help on now is i think moving (before i get the attributes done), i would like to make it so the user enters where he wants to move (W for up, D for right, and A for left, NOT DOWN. Eventually this would be affected by the movement attribute so the user only has a certain amount of moves per turn.

But yeah, im at a loss guys and my teacher is very bad at helping me because he is way too vague and my classmates are all having trouble too. This project is a huge chunk of my grade so im pretty stressed out about it :(

Here's what i have so far:

#include <cstdlib>
#include <iostream>
#include <iomanip>


using namespace std;

const int ROW = 10;
const int COL = 10;
int player;
int computer;

void printBoard (int[][COL]);

int main(int argc, char *argv[])
{
    int gameboard[ROW][COL];
    
    srand(time(0));
    player = rand()%99+1;
    computer = rand()%99+1;
    printBoard(gameboard);
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

void printBoard (int [] [COL])
{
    for (int rows = 0; rows < ROW; rows++)
    {
        for (int collumns = 0; collumns < COL; collumns++)
        {
			if ((player / 10) == rows && (player % 10) == collumns)
			{
				cout << " P";
			}
			if ((computer / 10) == rows && (computer % 10) == collumns)
			{
				cout << " C";
			}
			//else if statement here to check computer
			else 
			{
				cout << " *";
			}
        }
        cout << endl; 
    }
}

Here are my teachers instructions:

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.

P.S. Oh also, sorry about earlier, i think i posted two threads by accident, sorry bout that.

happygeek commented: just asking a question once, in one thread, will mean you get more help - seriously!!!! -2

Recommended Answers

All 9 Replies

Have a look at classes. Make a class for your frigate/each type of ship. Then it should have functions such as one for movement, firing etc. You'll need to be careful about what variables you need and passing them backwards and forwards between your main program and the classes.
http://www.cplusplus.com/doc/tutorial/classes/

The movement idea of your program should be considerable maths-based (ie. calculating whether a move is legal, how far should they move etc.). It appears that the logic is not too difficult, but there is a lot of it.

Good luck :)

Have a look at classes. Make a class for your frigate/each type of ship. Then it should have functions such as one for movement, firing etc. You'll need to be careful about what variables you need and passing them backwards and forwards between your main program and the classes.
http://www.cplusplus.com/doc/tutorial/classes/

The movement idea of your program should be considerable maths-based (ie. calculating whether a move is legal, how far should they move etc.). It appears that the logic is not too difficult, but there is a lot of it.

Good luck :)

Oh man, i forgot to mention that, but we are not to use classes since we haven't learnt that yet :(

So classes are banned? Awwwww shucks...if it wasn't banned you could sure learn that easily...
I guess you'll just have to use lots of functions and variables then. Go through the logic of your program, get a piece of paper, and work out what variables and functions you need. Organize the basic structure, then start to code in the finer details.

Tell your tutor that they should have taught you classes before getting you to make a game.

So classes are banned? Awwwww shucks...if it wasn't banned you could sure learn that easily...
I guess you'll just have to use lots of functions and variables then. Go through the logic of your program, get a piece of paper, and work out what variables and functions you need. Organize the basic structure, then start to code in the finer details.

Tell your tutor that they should have taught you classes before getting you to make a game.

yeah i know, the whole classes thing seems to be absurd for him to expect us to do that without teaching us classes. In any case, the thing is that im stuck with the coding of it, i just have no clue on how to do the movement of the ships. He specified that there ate "LOTS" of functions but he did not go into much more detail than that.

Eeeeek...sounds nasty. I think education globally is going to waste. I keep hearing on this site of people who are stuck on homework, not because they can't do it, but because they have a poor tutor, or the tutor is too vague or whatever. The fact that there are lots of functions doesn't really help.

My brain is trying to figure out a way of doing it without classes. For movement, I would suggest that you in your 10x10 grid, you have blank spaces as '0' and ships as 's'. Then, when you come to print, you would find all the ships in the array, get their direction, and print, say, [^] [>] [v] [<] to show the direction.

With regards to armour and range and the like, I would have an array called, eg., ArmourStats of length 'n=ships'. Therefore, ArmourStats[0] would be the value of the armour of ship one, ArmourStats[1] of ship two and so forth. Repeat for the other mass-variable storage mabobs.

You could reduce the amount of functions quite easily. Have ONE function for move, which takes a variable of where the ship you want to move is, and where to. Then you can just recycle this. Obviously, repeat with the other functions. The more of this you do, the more your tutor will/should be impressed.

Good luck again :)

Ok so this is what i have so far, the problem here is that i want it so that when i press "w" it should go up but here its going to the right. Im guessing because it is going up in the sense that it is facing to the right?
Any help on this would be appreciate it. i would like help to get to move the player ship up left or right with W, A,and D respectively. While the computer ship is moving randomly about the board.

Please explain how you would like your movement:
1. W ALWAYS moves the ship up
2. W moves in the direction facing

It looks kinda like you want the first one. Let's say you have a ship at [5, 5] and you want to move it up one space. Though the ship is facing up, you press W to go up. The ship's position is now [5, 4]. You just take one off the y value. Obviously, you have to update your board, but that up there is a simple explanation. Then repeat for A and D.

Please explain how you would like your movement:
1. W ALWAYS moves the ship up
2. W moves in the direction facing

It looks kinda like you want the first one. Let's say you have a ship at [5, 5] and you want to move it up one space. Though the ship is facing up, you press W to go up. The ship's position is now [5, 4]. You just take one off the y value. Obviously, you have to update your board, but that up there is a simple explanation. Then repeat for A and D.

I want the ships to move in respect to the way they are facing. so if its facing up.. W would make it move up one space, if its facing right.. W would make it turn 90 degrees to the left.

Well you would need a lot of "if" statements. Have a variable for each ship (use array) called "Direction". This could be an int array or string array (eg. 1 or "N" is north). When the user presses a key, use if statements to check which way they are facing and move accordingly.
EDIT:
I see you are running two threads. Please keep all your problems in this thread. Thanks.
I must go to school now (damn thing doesn't shut unless there's 1209109238 feet of snow :@

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.