aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.cpp
diff options
context:
space:
mode:
authorGravatar alecdwm 2015-01-28 20:06:01 +1000
committerGravatar alecdwm 2015-01-28 20:09:43 +1000
commit300b8a6734f52bd25bfe542d8e4405e122e81b51 (patch)
tree008c7ec1d9c26efadfa1a0009148f66c9f0b34b1 /src/main.cpp
parent12d1ab840ea5fa1ec3fdda380f95ae79bdc60548 (diff)
Moved src to src folder
Added short readme description
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..526516a
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,43 @@
+#include <iostream>
+
+#include "Player.h"
+#include "Gameboard.h"
+
+using namespace std;
+
+int main()
+{
+ // Initialize game
+ cout << "Welcome to TicTacToe!" << endl << endl;
+
+ // Initialize gameboard
+ Gameboard gameboard;
+
+ // Initialize players
+ Player player1(1);
+ Player player2(2);
+
+ // Do gameloop
+ int endGame = 0;
+ while(!endGame) {
+ gameboard.printGameboard();
+ cout << player1.getName() << "'s turn:" << endl;
+ gameboard.playMove(player1.getSymbol(),player1.getMoveY(),player1.getMoveX());
+ endGame = gameboard.checkWin(player1.getPlayerID(),player1.getSymbol());
+ if(endGame){break;}
+ gameboard.printGameboard();
+ cout << player2.getName() << "'s turn:" << endl;
+ gameboard.playMove(player2.getSymbol(),player2.getMoveY(),player2.getMoveX());
+ endGame = gameboard.checkWin(player2.getPlayerID(),player2.getSymbol());
+ }
+
+ // Print winning player
+ if(endGame == player1.getPlayerID()) {
+ cout << player1.getName() << " Wins!" << endl;
+ }
+ if(endGame == player2.getPlayerID()) {
+ cout << player2.getName() << " Wins!" << endl;
+ }
+
+ return 0;
+}