Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- char arr[3][3];
- int n = 1;
- int x, y;
- bool turn = true;
- cout << "Our gamezone now:\n";
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- arr[i][j] = '-';
- cout << arr[i][j] << " ";
- }
- cout << endl;
- }
- while (n <= 9) {
- cout << "\nWrite cords (example: 0 2 or 1 1): ";
- cin >> x;
- cin >> y;
- if (arr[x][y] == '-') {
- turn ? arr[x][y] = 'X' : arr[x][y] = '0';
- turn ? turn = false : turn = true;
- }
- else {
- cout << "Wrong cords! Try again!";
- continue;
- }
- cout << "Our gamezone now:\n";
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- cout << arr[i][j] << " ";
- }
- cout << endl;
- }
- if (arr[0][0] == arr[1][1] && arr[0][0] == arr[2][2] && arr[1][1] != '-') {
- cout << "Winner - " << arr[1][1];
- return 0;
- }
- if (arr[1][1] == arr[0][2] && arr[2][0] == arr[1][1] && arr[1][1] != '-') {
- cout << "Winner - " << arr[1][1];
- return 0;
- }
- for (int i = 0; i < 3; i++) {
- if (arr[i][1] == arr[i][0] && arr[i][1] == arr[i][2] && arr[i][1] != '-') {
- cout << "Winner - " << arr[i][1];
- return 0;
- }
- if (arr[1][i] == arr[0][i] && arr[1][i] == arr[2][i] && arr[1][i] != '-') {
- cout << "Winner - " << arr[1][i];
- return 0;
- }
- }
- n++;
- }
- cout << "\nThe end! No one cant win";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement