Thank you for the response.
As far as I know - I have gone back and tried to change everything that you said.
it doesn't see my .h file...no matter what I try. I'm posting the code below.
I'm trying to get it to compile and run and be correct - I am very lost at the moment.
I will keep in mind the tab suggestion and the future idea of writing less and compiling more often. I cannot help but think there's some fundamental gap Im not getting...
Code:
#include "stdafx.h"
#include ".\TicTacToe.h"
#include <iostream>
#using <mscorlib.dll>
using namespace System;
using namespace std;
#define _tmain main
void getPlayersLetters(char &p1, char &p2);
int main()
{
//This is how you declare an instance of the class.
TicTacToe mainTac;
//Our player letters!
char p1, p2;
//Call our get letters function.
getPlayersLetters(p1,p2);
//This is how you call them
mainTac.InitBoard();
mainTac.PrintBoard();
for (int turn = 1; turn < 9; turn++)
{
mainTac.PlayTurn(turn);
mainTac.EnterMove();
mainTac.PrintBoard();
mainTac.CheckHoriz();
}
return 0;
}
void getPlayersLetters(char &p1, char &p2)
{
int num;
cout<<"Please enter 1 for X or 2 to be O: ";
cin>>num;
if(num==1)
{
cout <<"player One will be X"<<endl;
p1 = 'X';
p2 = 'O';
}
else
{
cout <<"player Two will be X"<<endl;
p2 = 'X';
p1 = 'O';
}
}
//==============================================
// Methods
//==============================================
#include "stdafx.h"
#include ".\TicTacToe.h"
#using <mscorlib.dll>
using namespace std;
#include<iostream>
//Implementation file where the methods are actually coded.
//---------------------------------------------------------------
void TicTacToe::InitBoard(char board[3][3])
{
for(row=0;row<3;row++)
{
for(col=0;col<3;col++)
{
board[row][col] = '+';
}
}
}
//-----------------------------------------------------------------
void TicTacToe::PrintBoard(char board[3][3])
{
for(row=0;row<3;row++)
{
for(col=0;col<3;col++)
{
cout<< board[row][col];
}
cout<<endl;
}
}
//----------------------------------------------------------------------------------
char TicTacToe::CheckHoriz(char player)
{
if ((board[0][0]=='X' &&board[0][1]=='X' && board[0][2]=='X') ||
(board[1][0]=='X' &&board[1][1]=='X' && board[1][2]=='X') ||
(board[2][0]=='X' &&board[2][1]=='X' && board[2][2]=='X'))
{
return'X';
}
else
if ((board[0][0]=='O' &&board[0][1]=='O' && board[0][2]=='O') ||
(board[1][0]=='O' &&board[1][1]=='O' && board[1][2]=='O') ||
(board[2][0]=='O' &&board[2][1]=='O' && board[2][2]=='O'))
{
return'O';
}
return '\0';
}
//-----------------------------------------------------------------------------------------
char TicTacToe::CheckVert(char player)
{
if ((board[0][0]=='X' && board[1][0]=='X' && board[2][0]=='X') ||
(board[0][1]=='X' && board[1][1]=='X' && board[2][1]=='X') ||
(board[0][2]=='X' && board[1][2]=='X' && board[2][2]=='X'))
{
return 'X';
}
else
if ( (board[0][0]=='O' &&board[1][0]=='O' && board[2][0]=='O') ||
(board[0][1]=='O' &&board[1][1]=='O' && board[2][1]=='O') ||
(board[0][2]=='O' &&board[1][2]=='O' && board[2][2]=='O'))
{
return 'O';
}
return'\0';
}
//-------------------------------------------------------------------------------------
char TicTacToe::CheckDiag(char player)
{
if ((board[0][0]=='X' && board[1][1]=='X' && board[2][2]=='X') ||
(board[0][2]=='X' && board[1][1]=='X' && board[2][0]=='X'))
{
return 'X';
}
else
if ((board[0][0]=='O' && board[1][1]=='O' && board[2][2]=='O') ||
(board[0][2]=='O' && board[1][1]=='O' && board[2][0]=='O'))
{
return 'O';
}
return '\0';
}
//------------------------------------------------------------------------------------------
void TicTacToe::CheckDraw(int turn)
{
char p1, p2;
if(turn<9)
{
PlayTurn(turn, p1, p2);
}
else
{
cout<<"Draw";
}
}
//------------------------------------------------------------------------------------------
void TicTacToe::PlayTurn(int turn, char p1, char p2)
{
if((turn%2) == 0)
{
cout<<"Player 1's turn";
EnterMove(p1);
}
else
{
cout<<"Player 2's turn";
EnterMove(p2);
}
}
//---------------------------------------------------------------------------------
void TicTacToe::EnterMove(char player)
{
cout<<"Enter the 2 coords where you want to place your move: ";
cin>>x>>y;
board[x][y]= player;
PrintBoard(char board[][]);
}
//------------------------------------------------------------------------------------
void TicTacToe::PlayTurn(int turn, char p1, char p2)
{
if((turn % 2) == 0)
{
cout<<"Player 1's turn";
EnterMove(p1);
}
else
{
cout<<"Player 2's turn";
EnterMove(p2);
}
}
//===============================================
// Header
//===============================================
#pragma once
//Header file - this is where all of the declarations are made.
class TicTacToe
{
public:
TicTacToe(void);
~TicTacToe(void);
void InitBoard(char board[3][3]);
void PrintBoard(char board[3][3]);
void DrawBoard();
char CheckHoriz(char player);
char CheckVert(char player);
char CheckDiag(char player);
void CheckDraw(int turn);
void EnterMove(char player);
void PlayTurn(int turn, char p1, char p2);
private:
//Private variables are encapsulated because they cannot be directly accessed
//by the outside world.
char X;
char O;
char board[3][3];
char player;
int turn;
int x;
int y;
int col;
int row;
};