Hi, I'm making a tictactoe game, and i created a player class with a function "PlayersTurn", the problem is I need to call some functions in the tictactoe class
I tried friendship, then putting in my class member function TicTacToe.showTTTboard();
and i get the following error
expected unqualified-d before '.' token
edit i just realized friendship is used to access private members, meh so friendship is useless, can anyone lead me in the right direction?
#include <iostream>
#include "Player.h"
#include "TicTacToe.h"
void Player::PlayersTurn()
{
/* i want to be able to call TicTacToe.h's function member to set a letter in the board array and to show the current pieces on the board */
}
void startTTT(Player*,Player*,TicTacToe*,int *);
int winCheckTTT(TicTacToe*);
int main()
{
char again;
char letterChoice;
int *winner = newint;
*winner = 0;
Player *player1 = new Player;
Player *player2 = new Player;
TicTacToe *TTTgame = new TicTacToe;
do
{
std::cout<<"\t\tHiimnew Games"<<std::endl;
std::cout<<"\tDefault will be TicTacToe for now."<<std::endl;
do
{
std::cout<<"Player 1 Please choose your letter (X/O) ";
std::cin>>letterChoice;
if (letterChoice == 'x' || letterChoice == 'X')
{
letterChoice = 'X';
player1->assignLetter(letterChoice);
player2->assignLetter('O');
}
elseif ((letterChoice == 'o') ^ (letterChoice == 'O'))
{
letterChoice = 'O';
player1->assignLetter(letterChoice);
player2->assignLetter('X');
}
else
std::cout<<"\nBad letter choice, please try again!\n\n";
} while ((letterChoice != 'X') && (letterChoice != 'O'));
std::cout<<"Player 1 has been assigned "<<player1->getLetter()<<" and Player 2 has been assigned "<<player2->getLetter()<<"!"<<std::endl;
startTTT(player1,player2,TTTgame,winner);
if (*winner == 45) //player 1 wins
{
std::cout<<"Player 1 Wins!"<<std::endl;
player1->addPoint();
}
elseif (*winner == 67) //player 2 wins
{
std::cout<<"Player 2 Wins!"<<std::endl;
player2->addPoint();
}
elseif (*winner == 90) //tie
{
std::cout<<"Tie!"<<std::endl;
}
else
{
std::cout<<"Error!"<<std::endl;
}
std::cout<<"Play again? (y/n) ";
std::cin>>again;
} while ((again == 'y') ^ (again == 'Y'));
return 0;
}
void startTTT(Player *player1,Player *player2, TicTacToe *TTTgame, int *winner)
{
//Determines who goes first based on who has more points default is player 1 goes first
if (player1->getScore() == 0 && player2->getScore() == 0)
{
//playersturn member function calls for player 1 and 2 here
}
elseif (player1->getScore() < player2->getScore())
{
//playersturn member function calls for player 1 and 2 here
}
elseif (player1->getScore() > player2->getScore())
{
//playersturn member function calls for player 1 and 2 here
}
else
{
std::cout<<"ERROR @ line 57"<<std::endl;
}
do
{
//playersturn member function calls for player 1 here
*winner = winCheckTTT(TTTgame);
//playersturn member function calls for player 2 here
*winner = winCheckTTT(TTTgame);
} while (*winner == 0);
}
int winCheckTTT(TicTacToe *TTTgame)
{
return 0;
//under construction, uses and algorithm to check to see if anyone wins or if its a tie,
//then returns 1 of 4 values Player1 won, player 2 won, tie, & default to continue the game
}
/*compare 3 letters 123
456
789
123 456 789 159 357 147 258 369*/