diff --git a/TicTacToe-Game.sln b/TicTacToe-Game.sln
new file mode 100644
index 0000000..ba75d51
--- /dev/null
+++ b/TicTacToe-Game.sln
@@ -0,0 +1,31 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.5.33516.290
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TicTacToe-Game", "TicTacToe-Game\TicTacToe-Game.vcxproj", "{A0EF2EB9-11A1-4F5A-B617-12635B8561DB}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {A0EF2EB9-11A1-4F5A-B617-12635B8561DB}.Debug|x64.ActiveCfg = Debug|x64
+ {A0EF2EB9-11A1-4F5A-B617-12635B8561DB}.Debug|x64.Build.0 = Debug|x64
+ {A0EF2EB9-11A1-4F5A-B617-12635B8561DB}.Debug|x86.ActiveCfg = Debug|Win32
+ {A0EF2EB9-11A1-4F5A-B617-12635B8561DB}.Debug|x86.Build.0 = Debug|Win32
+ {A0EF2EB9-11A1-4F5A-B617-12635B8561DB}.Release|x64.ActiveCfg = Release|x64
+ {A0EF2EB9-11A1-4F5A-B617-12635B8561DB}.Release|x64.Build.0 = Release|x64
+ {A0EF2EB9-11A1-4F5A-B617-12635B8561DB}.Release|x86.ActiveCfg = Release|Win32
+ {A0EF2EB9-11A1-4F5A-B617-12635B8561DB}.Release|x86.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {5A632C95-F402-45B9-8986-6CDDF4BF1979}
+ EndGlobalSection
+EndGlobal
diff --git a/TicTacToe-Game/TicTacToe-Game.vcxproj b/TicTacToe-Game/TicTacToe-Game.vcxproj
new file mode 100644
index 0000000..f04c726
--- /dev/null
+++ b/TicTacToe-Game/TicTacToe-Game.vcxproj
@@ -0,0 +1,138 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ 16.0
+ Win32Proj
+ {a0ef2eb9-11a1-4f5a-b617-12635b8561db}
+ TicTacToeGame
+ 10.0
+
+
+
+ Application
+ true
+ v143
+ Unicode
+
+
+ Application
+ false
+ v143
+ true
+ Unicode
+
+
+ Application
+ true
+ v143
+ Unicode
+
+
+ Application
+ false
+ v143
+ true
+ Unicode
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Level3
+ true
+ WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+
+
+ Console
+ true
+
+
+
+
+ Level3
+ true
+ true
+ true
+ WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+
+
+ Console
+ true
+ true
+ true
+
+
+
+
+ Level3
+ true
+ _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+
+
+ Console
+ true
+
+
+
+
+ Level3
+ true
+ true
+ true
+ NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+
+
+ Console
+ true
+ true
+ true
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/TicTacToe-Game/TicTacToe-Game.vcxproj.filters b/TicTacToe-Game/TicTacToe-Game.vcxproj.filters
new file mode 100644
index 0000000..2052bc2
--- /dev/null
+++ b/TicTacToe-Game/TicTacToe-Game.vcxproj.filters
@@ -0,0 +1,27 @@
+
+
+
+
+ {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
+ cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
+
+
+ {93995380-89BD-4b04-88EB-625FBE52EBFB}
+ h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
+
+
+ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
+ rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
+
+
+
+
+ Header Files
+
+
+
+
+ Source Files
+
+
+
\ No newline at end of file
diff --git a/TicTacToe-Game/TicTacToe.cpp b/TicTacToe-Game/TicTacToe.cpp
new file mode 100644
index 0000000..677b037
--- /dev/null
+++ b/TicTacToe-Game/TicTacToe.cpp
@@ -0,0 +1,321 @@
+#define OLC_PGE_APPLICATION
+#include "olcPixelGameEngine.h"
+
+using namespace olc;
+
+// Override base class with your custom functionality
+class TicTacToe : public olc::PixelGameEngine
+{
+public:
+ enum PieceType{
+ BLANK,
+ CROSS,
+ CIRCLE
+ };
+
+ enum GameState{
+ MENU,
+ PLAYING,
+ GAMEOVER
+ };
+
+ enum Winner{
+ PLAYER_1,
+ PLAYER_2,
+ TIE
+ };
+
+ class Piece{
+ public:
+ vi2d coord;
+ PieceType piece;
+ Piece()
+ :Piece({0,0},BLANK){}
+ Piece(vi2d coord,PieceType piece)
+ :coord(coord),piece(piece){};
+ };
+
+ TicTacToe()
+ {
+ // Name your application
+ sAppName = "Tic-Tac-Toe";
+ }
+
+ Decal*circleImg;
+ Decal*crossImg;
+ Decal*gridImg;
+
+ int pieceCount=5;
+ PieceType playerSide=CIRCLE;
+ PieceType opponentSide=CROSS;
+
+ bool dragging=false;
+
+ std::arraygamePieces;
+
+ float aiThinkTime=0;
+
+ bool playingAgainstAI=true;
+ GameState state=PLAYING;
+ Winner outcome=TIE;
+
+ vf2d winLine1,winLine2;
+
+ void SetOutcome(int score){
+ if(score==3){
+ outcome=PLAYER_1;
+ state=GAMEOVER;
+ }else
+ if(score==-3){
+ outcome=PLAYER_2;
+ state=GAMEOVER;
+ }
+ }
+
+ void AnalyzeBoard(){
+ for(int row=0;row<3;row++){
+ int rowScore=0;
+ for(int col=0;col<3;col++){
+ int index=row*3+col;
+ PieceType gridPiece=gamePieces[index].piece;
+ if(gridPiece==BLANK){
+ break;//This row is done...
+ }else
+ if(gridPiece==playerSide){
+ rowScore++;
+ }else{
+ rowScore--;
+ }
+ }
+ if(abs(rowScore)==3){
+ winLine1={0,float(row)};
+ winLine2={2,float(row)};
+ }
+ SetOutcome(rowScore);
+ }
+ for(int col=0;col<3;col++){
+ int colScore=0;
+ for(int row=0;row<3;row++){
+ int index=row*3+col;
+ PieceType gridPiece=gamePieces[index].piece;
+ if(gridPiece==BLANK){
+ break;//This row is done...
+ }else
+ if(gridPiece==playerSide){
+ colScore++;
+ }else{
+ colScore--;
+ }
+ }
+ if(abs(colScore)==3){
+ winLine1={float(col),0};
+ winLine2={float(col),2};
+ }
+ SetOutcome(colScore);
+ }
+
+ std::vectorcheckCoordsDiag1={{0,0},{1,1},{2,2}};
+ std::vectorcheckCoordsDiag2={{0,2},{1,1},{2,0}};
+
+ int diag1Score=0;
+ for(vf2d&coord:checkCoordsDiag1){
+ int index=coord.y*3+coord.x;
+ PieceType gridPiece=gamePieces[index].piece;
+ if(gridPiece==BLANK){
+ break;//This row is done...
+ }else
+ if(gridPiece==playerSide){
+ diag1Score++;
+ }else{
+ diag1Score--;
+ }
+ }
+ SetOutcome(diag1Score);
+ if(abs(diag1Score)==3){
+ winLine1=checkCoordsDiag1[0];
+ winLine2=checkCoordsDiag1[2];
+ }
+
+ int diag2Score=0;
+ for(vf2d&coord:checkCoordsDiag2){
+ int index=coord.y*3+coord.x;
+ PieceType gridPiece=gamePieces[index].piece;
+ if(gridPiece==BLANK){
+ break;//This row is done...
+ }else
+ if(gridPiece==playerSide){
+ diag2Score++;
+ }else{
+ diag2Score--;
+ }
+ }
+ SetOutcome(diag2Score);
+ if(abs(diag2Score)==3){
+ winLine1=checkCoordsDiag2[0];
+ winLine2=checkCoordsDiag2[2];
+ }
+
+ bool allFilled=true;
+ for(int y=0;y<3;y++){
+ for(int x=0;x<3;x++){
+ int index=y*3+x;
+ if(gamePieces[index].piece==BLANK){
+ allFilled=false;
+ }
+ }
+ }
+ if(outcome==TIE&&allFilled){
+ state=GAMEOVER;
+ }
+ }
+
+public:
+ bool OnUserCreate() override
+ {
+ // Called once at the start, so create things here
+ for(int y=0;y<3;y++){
+ for(int x=0;x<3;x++){
+ int index=y*3+x;
+ gamePieces[index]=Piece({x,y},BLANK);
+ }
+ }
+
+ circleImg=new Decal(new Sprite("circle.png"));
+ crossImg=new Decal(new Sprite("cross.png"));
+ gridImg=new Decal(new Sprite("grid.png"));
+ return true;
+ }
+
+ bool OnUserUpdate(float fElapsedTime) override
+ {
+ Clear({196,196,255});
+
+ switch(state){
+ case MENU:{
+ DrawStringDecal({0,0},"This is the menu.");
+ }break;
+ case PLAYING:
+ case GAMEOVER:{
+ vf2d gridOffset={16,16};
+
+ Decal*pieceImg;
+ if(playerSide==CIRCLE){
+ pieceImg=circleImg;
+ }else{
+ pieceImg=crossImg;
+ }
+
+ if(state==GAMEOVER){
+ std::string gameOverText="Game is over!";
+ std::string winnerText;
+
+ if(playingAgainstAI){
+ if(outcome==PLAYER_1){
+ winnerText="You win!";
+ } else{
+ winnerText="AI wins!";
+ }
+ }else{
+ if(outcome==PLAYER_1){
+ winnerText="Player 1 wins!";
+ } else{
+ winnerText="Player 2 wins!";
+ }
+ }
+
+ vf2d gameOverTextSize=vf2d(GetTextSize(gameOverText))*0.5;
+ vf2d winnerTextSize=vf2d(GetTextSize(winnerText))*0.5;
+ DrawStringDecal(vf2d{ScreenWidth()/2.f,4}-gameOverTextSize/2,gameOverText,BLACK,{0.5,0.5});
+ DrawStringDecal(vf2d{ScreenWidth()/2.f,12}-winnerTextSize/2,winnerText,BLACK,{0.5,0.5});
+ }else{
+ if(aiThinkTime>0){
+ aiThinkTime-=fElapsedTime;
+
+ if(aiThinkTime<=0){
+ int chosenIndex=rand()%9;
+ while(gamePieces[chosenIndex].piece!=BLANK){
+ chosenIndex=rand()%9;
+ }
+ gamePieces[chosenIndex].piece=opponentSide;
+ AnalyzeBoard();
+ }
+
+ std::string displayText=" The AI \nis thinking...";
+ vf2d textSize=vf2d{GetTextSize(displayText)}*0.5;
+ DrawStringDecal(vf2d{ScreenWidth()/2.f,8}-textSize/2,displayText,BLACK,{0.5,0.5});
+ }
+ }
+
+ for(int y=0;y<3;y++){
+ for(int x=0;x<3;x++){
+ int index=y*3+x;
+ vf2d upperLeftCorner=gridOffset+vf2d{x*32.f,y*32.f};
+ vf2d lowerRightCorner=gridOffset+vf2d{x*32.f,y*32.f}+vf2d{32,32};
+
+ if(GetMouseX()>=upperLeftCorner.x&&GetMouseX()=upperLeftCorner.y&&GetMouseY()120){
+ FillRectDecal({0,120},{float(ScreenWidth()),40},{0,0,0,64});
+
+ if(GetMouse(Mouse::LEFT).bPressed){
+ if(dragging){
+ pieceCount++;
+ dragging=false;
+ }else
+ if(pieceCount>0){
+ dragging=true;
+ pieceCount--;
+ }
+ }
+ }
+
+
+
+
+
+ DrawDecal(gridOffset,gridImg);
+
+ if(dragging){
+ DrawRotatedDecal(GetMousePos(),pieceImg,0,pieceImg->sprite->Size()/2);
+ }
+
+ for(int i=0;i
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include