From 2c8cede8d9fe783cec6fd20f77eacad8203cd550 Mon Sep 17 00:00:00 2001 From: "Richard Horton (hortonr6)" Date: Sun, 11 Aug 2019 00:02:14 +0100 Subject: [PATCH] Allowed player and ai classes access to grid object via a pointer --- AI.cpp | 4 ++++ AI.h | 7 +++++++ Player.cpp | 5 +++++ Player.h | 7 +++++++ 4 files changed, 23 insertions(+) diff --git a/AI.cpp b/AI.cpp index 4e5a7b0..8434d70 100644 --- a/AI.cpp +++ b/AI.cpp @@ -3,6 +3,10 @@ AI::AI() { // Constructor + +void AI::setTargetGrid(Grid *grid) +{ + gridPtr = grid; } void AI::aiTurn() diff --git a/AI.h b/AI.h index 5b4d84a..5cf6881 100644 --- a/AI.h +++ b/AI.h @@ -3,10 +3,13 @@ #include +#include "Grid.h" + class AI { public: AI(); + AI(Grid *grid); void aiTurn(); @@ -15,12 +18,16 @@ class AI void setDifficulty(); + void setTargetGrid(Grid *grid); + private: enum difficultyScale{Normal = 1, Impossible = 2}; void normalAITurn(); void impossibleAITurn(); + Grid *gridPtr; + int difficulty = 0; char symbol = ' '; }; diff --git a/Player.cpp b/Player.cpp index 27461aa..ee70519 100644 --- a/Player.cpp +++ b/Player.cpp @@ -5,6 +5,11 @@ Player::Player() // Constructor } +void Player::setTargetGrid(Grid *grid) +{ + gridPtr = grid; +} + void Player::chooseSymbol() { // Allows the player to choose whether they are noughts or crosses diff --git a/Player.h b/Player.h index 12e156c..6395f2a 100644 --- a/Player.h +++ b/Player.h @@ -4,10 +4,13 @@ #include #include +#include "Grid.h" + class Player { public: Player(); + Player(Grid *grid); void playerTurn(); @@ -17,9 +20,13 @@ class Player void setName(); std::string getName(); + void setTargetGrid(Grid *grid); + private: int getInput(); + Grid *gridPtr; + std::string name = ""; char symbol = ' '; };