Ok, so the 'gameboard' class part of my program works. It draws the board, shows the board, allows you to move on the board, and spawns the player and enemys at random locations.
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <conio.h>
#include "gameboard.h"
usingnamespace std;
gameboard::gameboard() : xCo(0), yCo(0){}
gameboard::gameboard(int x, int y) : xCo(x), yCo(y){}
void gameboard::draw(){
for (int i=0; i < ROW; i++){
for (int j=0; j < COL; j++){
this->board[i][j] = 176;
}
}
spawn();
}
void gameboard::show(){
cout << endl;
for (int i=0; i < ROW; i++){
for (int j=0; j < COL; j++){
cout << this->board[i][j];
}
cout << endl;
}
}
void gameboard::move(){
char dir = 'x';
cout << "Type Enter to quit\n";
while (dir != '\r'){
cout << "\nYour location is x" << xCo <<",y" << yCo;
cout << "\nPress direction key(n,s,e,w):";
dir = getche();
int tempx = xCo;
int tempy = yCo;
bool error = 0;
switch(dir){
case'e':
if (yCo >= 9){
yCo = 9;
cout << "\n\n********************" << endl;
cout << "\nYou\'re running into a wall.\n\n";
cout << "********************\n" << endl;
error = 1;
}
else
yCo++;
break;
case'w':
if (yCo <= 0){
yCo = 0;
cout << "\n\n********************" << endl;
cout << "\nYou\'re running into a wall.\n\n";
cout << "********************\n" << endl;
error = 1;
}
else
yCo--;
break;
case's':
if (xCo >= 9){
xCo = 9;
cout << "\n\n********************" << endl;
cout << "\nYou\'re running into a wall.\n\n";
cout << "********************\n" << endl;
error = 1;
}
else
xCo++;
break;
case'n':
if (xCo <= 0){
xCo = 0;
cout << "\n\n********************" << endl;
cout << "\nYou\'re running into a wall.\n\n";
cout << "********************\n" << endl;
error = 1;
}
else
xCo--;
break;
case'\r':
cout << "\n\n********************" << endl;
cout << "\nHope you enjoy\'d playing, come again!\n\n";
cout << "********************\n" << endl;
break;
default:
cout << "\n\n********************" << endl;
cout << "\nYou didn't follow instructions.\n\n";
cout << "********************\n" << endl;
error = 1;
}
if (!error){
this->board[xCo][yCo] = 233;
this->board[tempx][tempy] = 176;
show();
}
}
}
void gameboard::spawn(){
srand(time(NULL));
for (int j=0; j < 3; j++){
int rX = rand() % 9;
int rY = rand() % 9;
while (rX == xCo && rY == yCo)
{
rX = rand() % 9;
rY = rand() % 9;
}
this->board[xCo][yCo] = 233;
this->board[rX][rY] = 157;
}
}
void gameboard::areaOfAttack(){
}
but now in my player class, I am wondering how I am going to connect the movement in the gameboard to the player, and when they get to an enemy cords, the enemy and player class will fight. I am just not sure how to go about connecting theses dots.
The player and enemy class will basically be derived from the same base player class since they both will have hp and attack power, just need help connecting the dots.
This is all I have for the player class
1 2 3 4 5 6 7 8 9 10 11 12 13
#ifndef PLAYER_H
#define PLAYER_H
class person
{
private:
int hp, attackPwr, xCo, yCo;
public:
};
#endif // PLAYER_H
I think your issue is that the gameboard has too much control.
Perhaps you could change it so the person/player class has the function to get the input, and that will query the gameboard as to whether or not the player can move there.
Thanks, that's what I was starting to think as well.. I did give more control with person with the move command, but I was getting a big buy when trying to make the gameboard and player classes play nice with each other.