C++ Link multiple Classes together. Create an Array of objects to access sequentially -


directly bellow partially completed function should when completed allow me place each of 5 battleships down on board. issue i'm having i want access shipname stored in ship.cpp , want associate shipname player. example can have player1 , player2 each have 5 ships associated them , run placement loop each of them.i believe that's called instantiating object. admit i'll have have read on that!

secondly have have sort of array stores each of ships , loops through each time? first pass cruiser, second pass destroyer etc. more string array have pointer reference, player.shipname pointer array or that?

i've included game.h, player.h , ships.h @ bottom reference.

thanks in advance , help!

void game::manualplaceship() {    // start loop  int currentshipsdeployed = 0; int z = 0; int = 0;  while (currentshipsdeployed  < 5){ cout << "please enter co-ordinates place your" << /**player.shipname**/ "shipname"<<  /**player.shipname**/ "shipsize" <<  "on battlefield:"; cout << "\nenter row co-ordinates between number 1-10:"; cin >> row; cout << "\nenter row co-ordinates between number 1-10:"; cin >> column; cout << "\nchoose direction place ship\n1.left-1\n2.right-r\n3.up-u\n4.down-d\n"; cin >> direction; /** if (direction == '1' {     while (z < shipsize){      gameboard[row][column] = shipid // ddestroyer = 2, cruiser =3, submarine = 4, battleship =5 , carrier = 6     row = row --;      } }  else if(direction == '2') {     while (z < shipsize){      gameboard[row][column] = shipid // destroyer = 2, cruiser =3, submarine = 4, battleship =5 , carrier = 6     row = row ++;      }  }  else if(direction == 'u')  {     while (z < shipsize){      gameboard[row][column] = shipid // destroyer = 2, cruiser =3, submarine = 4, battleship =5 , carrier = 6     row = column ++;      }  }  else if(direction == 'd') {     while (z < shipsize){      gameboard[row][column] = shipid // destroyer = 2, cruiser =3, submarine = 4, battleship =5 , carrier = 6     row = column --;      }  }  else { cout << "sorry invalid input please try again" }  **/ currentshipsdeployed ++; }  } 

game.h

#ifndef game_h #define game_h  #include "player.h" #include "ships.h" #include <vector>  class game { public:     game();     ~game();     //void addplayer(player newplayer);     void displayboard();     void displayattackboard();     void setboard();     void randomplaceships();     void setattackboard();     void manualplaceship();     bool attacksequence();     //void addship(ships newship); private:      int gameboard[10][10];      int attackboard[10][10];      int x;      int y;      int pos1;      int pos2;      int row;      int column;      char direction;  };  #endif  

player.h

#ifndef player_h #define player_h   #include <iostream> #include <vector> #include <string> #include <sstream> #include <ctime> #include <cstdlib> using namespace std;  class player {  public:     player(string n/**, playertype t**/);     ~player();     string displayplayer();  private:     string playername;     //playertype ptype;     int score;     bool victory; };  #endif 

ships.h

#ifndef ships_h #define ships_h  #include <string> using namespace std;  class ships{    public:     ships ();     ships(string shipname,  int shipsize, int shiphitpoints, int shipid);      int getshipsize();     int getshiphitpoints();     string getshipname();     ~ships();   private:     string shipname;     int shipsize;     int shiphitpoints;     int shipid;     int maxships;  };   #endif 


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -