Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int XX;
- int YY;
- int Winner=2;
- int CheckTurn=0;
- struct Position
- {
- int x;
- int y;
- void SetPos(int X, int Y)
- {
- this->x = X;
- this->y = Y;
- }
- int GetX()
- {
- return this->x;
- }
- int GetY()
- {
- return this->y;
- }
- };
- void Init(char board[3][3])
- {
- for(int i = 0; i<3; i++)
- for(int j = 0; j<3; j++)
- board[i][j]=' ';
- }
- void PrintBoard(char board[3][3])
- {
- for(int i = 0; i<3; i++)
- {
- for(int j = 0; j<3; j++)
- cout << board[i][j] << ' ';
- cout << endl;
- }
- }
- void GetPos(Position &pos)
- {
- pos.SetPos(XX,YY);
- }
- void ChangeTurn(bool &turn)
- {
- /* Función encargada de modificar la variable global turno, que indica al programa que
- jugador debe marcar la casilla con el símbolo correspondiente en la siguiente jugada*/
- if(CheckTurn%2 == 0)
- turn = false;
- else if(CheckTurn != 0)
- turn = true;
- }
- /*
- int WhoWins( ) {
- Que retorna 1 si gana el primer jugador, 0 si empatan, 1 si gana el segundo jugador, 2 si
- aún no termina la partida.
- }
- */
- int main(){
- /*El main debe ser capaz de inicializar el tablero, imprimirlo y pedir las coordenadas para
- cada turno según corresponda, además debe alertar por pantalla cuando un jugador gane la
- partida */
- Position Pos;
- char Board[3][3];
- bool Turn=true;
- Init(Board);
- while(Winner == 2)
- {
- PrintBoard(Board);
- do{
- cin >> XX;}while(XX > 2 && XX <0);
- do{
- cin >> YY;}while(YY > 2 && YY <0);
- GetPos(Pos);
- ChangeTurn(Turn);
- if(Turn == true)
- Board[Pos.GetX()][Pos.GetY()] = 'X';
- else
- Board[Pos.GetX()][Pos.GetY()] = 'O';
- CheckTurn++;
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement