[sweden]
Super Moderator

Status:
[sweden] is Offline
Last Visit:
Yesterday, 09:49 PM
Total Likes Received: 60 (0.16 per day | 4.41 percent of total 1361)
(Find All Threads Liked ForFind All Posts Liked For) Total Likes Given: 0 (0 per day | 0 percent of total 1361)
(Find All Liked ThreadsFind All Liked Posts)
Reputation: 1
Time Spent Online:
4 Days, 2 Hours, 38 Minutes, 56 Seconds
DOB:
Hidden (20 years old)
Location:
sweden
Bio:
Other
Bio: Tic Tac Toe C++:
#include <Windows.h>
#include <iostream>
using namespace std;

bool checkForVictory(char board[][3], char currentPlayer)
{

for (int i = 0; i < 3; i++) {
if ((board[i][0] == currentPlayer) && (board[i][0] == board[i][1]) && (board[i][1] == board[i][2])) {
return true;
}
}

for (int i = 0; i < 3; i++) {
if ((board[0][i] == currentPlayer) && (board[0][i] == board[1][i]) && (board[1][i] == board[2][i])) {
return true;
}
}

if ((board[0][0] == currentPlayer) && (board[0][0] == board[1][1]) && (board[1][1] == board[2][2])) {
return true;
}

if ((board[2][0] == currentPlayer) && (board[2][0] == board[1][1]) && (board[1][1] == board[0][2])) {
return true;
}

return false;
}

void clearBoard(char board[][3])
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
board[i][j] = ' ';
}
}
}

void drawBoard(char board[][3])
{
cout << "|1|2|3|\n";
for (int i = 0; i < 3; i++)
{
cout << "|-----|\n";
cout << "|" << board[i][0] << "|" << board[i][1] << "|" << board[i][2] << "|\n";
}
}

int xCoord(char currentPlayer)
{
bool badInput = true;
int x;
while (badInput == true) {
cout << "Enter X coordinate: ";
cin >> x;

if (x < 0 || x > 2) {
cout << "Bad coordinate!\n";
}
else {
badInput = false;
}
}
return x;
}

int yCoord(char currentPlayer)
{
bool badInput = true;
int y;
while (badInput == true) {
cout << "Enter Y coordinate: ";
cin >> y;

if (y < 0 || y > 2) {
cout << "Bad coordinate!\n";
}
else {
badInput = false;
}
}
return y;
}

bool placeMarker(char board[][3], int x, int y, char currentPlayer)
{
/*if (board[x][y] != ' ')
{
return false;
}*/

board[x][y] = currentPlayer;
}

void game(char board[][3])
{
bool gameOver = false;
int x, y;
char player1 = 'X';
char player2 = 'O';

char currentPlayer = player1;

int turn = 0;

while (gameOver == false)
{
drawBoard(board);
x = xCoord(currentPlayer);
y = yCoord(currentPlayer);
if (placeMarker(board, x, y, currentPlayer) == false)
{
cout << "Spot is taken!\n";

}
else
{
turn++;
}

if (checkForVictory(board, currentPlayer) == true)
{
cout << "Game is over, Player " << currentPlayer << " won!\n";
cout << "\n";
cout << "End Result:\n";
drawBoard(board);
gameOver = true;
}
else if (turn == 9)
{
cout << "It's a tie!\n";
cout << "\n";
cout << "End Result:\n";
drawBoard(board);
gameOver = true;
}

if (currentPlayer == player1)
{
currentPlayer = player2;
}
else
{
currentPlayer = player1;
}
}
}


int main()
{
cout << "\t\t\t" << "Created By Anton Larsson 2016\n";
char board[3][3];
clearBoard(board);
//drawBoard(board);
game(board);
system("pause");
}
Sex:
Male
Total Posts:
29 (0.08 posts per day | 2.82 percent of total posts) (Find All Posts)
Total Threads:
7 (0.02 threads per day | 5.83 percent of total threads) (Find All Threads)
[sweden]'s Signature
[Image: d_a_n_c_i_n_doge.gif]


It's raw