Intro to c++ class game project

  • (2 Pages)
  • +
  • 1
  • 2

29 Replies - 4104 Views - Last Post: 07 December 2010 - 08:48 AM Rate Topic: -----

#1 halopower67  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 92
  • Joined: 16-October 10

Intro to c++ class game project

Posted 29 November 2010 - 01:20 PM

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; 
    }
}



Is This A Good Question/Topic? 1
  • +

Replies To: Intro to c++ class game project

#2 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Intro to c++ class game project

Posted 29 November 2010 - 01:57 PM

So what exactly is your question?
Was This Post Helpful? 0
  • +
  • -

#3 halopower67  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 92
  • Joined: 16-October 10

Re: Intro to c++ class game project

Posted 29 November 2010 - 02:00 PM

View PostOler1s, on 29 November 2010 - 12:57 PM, said:

So what exactly is your question?


My question is how do i achieve the movement of the ships?
Was This Post Helpful? 0
  • +
  • -

#4 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Intro to c++ class game project

Posted 29 November 2010 - 02:04 PM

If you were doing this with pen and paper, how would you achieve movement of ships?
Was This Post Helpful? 0
  • +
  • -

#5 JaKWaC  Icon User is offline

  • D.I.C Head

Reputation: 76
  • View blog
  • Posts: 234
  • Joined: 15-November 10

Re: Intro to c++ class game project

Posted 29 November 2010 - 02:13 PM

Are you asking how to get player input, or what to do when you have the player input?
Was This Post Helpful? 0
  • +
  • -

#6 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Intro to c++ class game project

Posted 29 November 2010 - 02:19 PM

Quote

what to do when you have the player input
This. If we were playing with pen and paper, and I said to you, "Forward", what would you do (to update the game)?
Was This Post Helpful? 0
  • +
  • -

#7 halopower67  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 92
  • Joined: 16-October 10

Re: Intro to c++ class game project

Posted 29 November 2010 - 02:23 PM

View PostOler1s, on 29 November 2010 - 01:19 PM, said:

Quote

what to do when you have the player input
This. If we were playing with pen and paper, and I said to you, "Forward", what would you do (to update the game)?


What i am asking is how would i go about coding so that when the user enters the move for the ship, the ship will moving the direction the user specified. So for example, since the player ship has 5 movement points every turn because the user put 5 points towards movement, the player would have to enter 5 moves every turn. So he would put for example W W W D D, which would translate into the ship moving up 3 times and right 2 times.
Was This Post Helpful? 0
  • +
  • -

#8 halopower67  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 92
  • Joined: 16-October 10

Re: Intro to c++ class game project

Posted 29 November 2010 - 02:28 PM

Here are the instructions from my teacher:

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.
Was This Post Helpful? 0
  • +
  • -

#9 halopower67  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 92
  • Joined: 16-October 10

Re: Intro to c++ class game project

Posted 29 November 2010 - 02:49 PM

If there is any more info you guys need, ask away.
Was This Post Helpful? 0
  • +
  • -

#10 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Intro to c++ class game project

Posted 29 November 2010 - 02:54 PM

I know what you are asking me. Instead of giving you a recipe of how to code this, which would be cheating, I'm trying to get you to solve it yourself.

You failed to answer my question. If you were playing with pen and paper, and I told you to move the ship forward, what would you do?
Was This Post Helpful? 0
  • +
  • -

#11 halopower67  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 92
  • Joined: 16-October 10

Re: Intro to c++ class game project

Posted 29 November 2010 - 02:57 PM

View PostOler1s, on 29 November 2010 - 01:54 PM, said:

I know what you are asking me. Instead of giving you a recipe of how to code this, which would be cheating, I'm trying to get you to solve it yourself.

You failed to answer my question. If you were playing with pen and paper, and I told you to move the ship forward, what would you do?


So if i was playing with pen and paper, i would have to redraw the board with the updated ship position. If that is what you mean.
Was This Post Helpful? 0
  • +
  • -

#12 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Intro to c++ class game project

Posted 29 November 2010 - 02:58 PM

Ok, but how would you get the updated ship position?
Was This Post Helpful? 0
  • +
  • -

#13 halopower67  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 92
  • Joined: 16-October 10

Re: Intro to c++ class game project

Posted 29 November 2010 - 02:59 PM

View PostOler1s, on 29 November 2010 - 01:58 PM, said:

Ok, but how would you get the updated ship position?


yes i would have to so i know where the ship is.
Was This Post Helpful? 0
  • +
  • -

#14 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Intro to c++ class game project

Posted 29 November 2010 - 03:10 PM

Quote

know where the ship is.
So you have a notion of ship positions. In other words, before you can update ship position, you must have the ship position noted down somewhere. How might you represent the ship position?
Was This Post Helpful? 0
  • +
  • -

#15 halopower67  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 92
  • Joined: 16-October 10

Re: Intro to c++ class game project

Posted 29 November 2010 - 03:12 PM

View PostOler1s, on 29 November 2010 - 02:10 PM, said:

Quote

know where the ship is.
So you have a notion of ship positions. In other words, before you can update ship position, you must have the ship position noted down somewhere. How might you represent the ship position?


By the "P" for the players ship or "C" for the computers ship.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2