commit 7d1ae201b3b3eebf2f0833494d2fff8ab2c74012 Author: fl3ka Date: Sun May 12 11:34:00 2024 +0000 Upload files to "/" diff --git a/iksoks b/iksoks new file mode 100644 index 0000000..7f8091e Binary files /dev/null and b/iksoks differ diff --git a/iksoks.cpp b/iksoks.cpp new file mode 100644 index 0000000..11a2ac3 --- /dev/null +++ b/iksoks.cpp @@ -0,0 +1,83 @@ +#include +using namespace std; + + +void drawBoard(char board[3][3]) { + +cout << board[0][0] << " |" << board[0][1] << "| " << board[0][2] << endl; +cout << "-------\n"; +cout << board[1][0] << " |" << board[1][1] << "| " << board[1][2] << endl; +cout << "-------\n"; +cout << board[2][0] << " |" << board[2][1] << "| " << board[2][2] << endl; +} + + +void checkWin(char board[3][3], char player) { + + for(int i = 0; i < 2; i++){ + if(board[i][0] == player && board[i][1] == player && board[i][2] == player){ + cout << board[i][0] << " WON!" << endl;} + + if(board[0][i] == player && board[1][i] == player && board[2][i] == player){ + cout << board[i][0] << " WON!" << endl;} + + }; + + if(board[0][0] == player && board[1][1] == player && board[2][2] == player){ + cout << board[0][0] << " WON!" << endl;} + if(board[2][0] == player && board[1][1] == player && board[0][2] == player){ + cout << board[2][0] << " WON!" << endl;} +} + +void chooseCaR(int row, int col, char player){ + + cout << "Player " << player << " choose a row (1-3): "; + cin >> row; + while(row > 3){ + cout << "Invalid input\n"; + cout << "Choose a row (1-3): \n"; + cin >> row; + + } + cout << "Choose a column (1-3): "; + cin >> col; + while(col > 3){ + cout << "Invalid input\n"; + cout << "Choose a column (1-3): \n"; + cin >> col; + + } +} + +int main(){ + +int row; +int col; +char player = 'X'; +char board[3][3] = { { ' ', ' ', ' ' }, + { ' ', ' ', ' ' }, + { ' ', ' ', ' ' } }; + + + +cout << "Welcome to Tic-Tac-Toe!\n"; + +for(int i=0; i<8; i++){ + + drawBoard(board); + chooseCaR(row, col, player); + + if(board[col-1][row-1] == 'X' || 'O') + cout << "Place taken\n"; + else + board[col-1][row-1] = player; + + checkWin(board, player); + + player = (player == 'X') ? 'O' : 'X'; + + } + +cout << "It's Draw!" << endl; + +}