Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int x, y, c, i;
- int board[3][3]={{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
- int display(){
- system("cls");
- for(y = 0; y <= 2; y++){
- for(x = 0; x <= 2; x++){
- switch(board[y][x]){
- case 0: cout << "[_]";
- break;
- case 1: cout << "[X]";
- break;
- case 2: cout << "[O]";
- break;
- default:cout << "[!]";
- }
- }cout << endl;
- }return 0;
- }
- int player1(){ //[X]
- cout << "[P1] Enter Y coordinate: ";
- cin >> y;
- cout << "[P1] Enter X coordinate: ";
- cin >> x;
- if(board[y][x] == 0){ board[y][x] = 1; }
- display();
- return 0;
- }
- int player2(){ //[O]
- cout << "[P2] Enter Y coordinate: ";
- cin >> y;
- cout << "[P2] Enter X coordinate: ";
- cin >> x;
- if(board[y][x] == 0){ board[y][x] = 2; }
- display();
- return 0;
- }
- int win(){
- for(i = 1; i <= 2; i++){
- for(x = 0; x <= 2; x++){
- if(board[0][x] == i && board[1][x] == i && board[2][x] == i){
- cout << "P" << i << " won!" << endl;
- exit;
- }
- }for(x = 0; x <= 2; x++){
- if(board[x][0] == i && board[x][1] == i && board[x][2] == i){
- cout << "P" << i << " won!" << endl;
- exit;
- }
- }if(board[0][0] == i && board[1][1] == i && board[2][2] == i){
- cout << "P" << i << " won!" << endl;
- exit;
- }if(board[2][0] == i && board[1][1] == i && board[0][2] == i){
- cout << "P" << i << " won!" << endl;
- exit;
- }
- }return 0;
- }
- int main() {
- display();
- player1();
- for(c = 0; c <= 3; c++){
- player2();
- win();
- player1();
- win();
- }return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement