Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int Tris[5][5];
- int x;
- int y;
- int scelta;
- void View();
- void Reset();
- void Primi_4();
- bool FineTris();
- bool FineTris()
- {
- ///Verifica Lineare
- ///Verifica a sinistra
- if(Tris[x][y] == Tris[x - 1][y] && Tris[x][y] == Tris[x - 2][y])
- {
- return true;
- }
- ///Verifica sopra
- if(Tris[x][y] == Tris[x][y + 1] && Tris[x][y] == Tris[x][y + 2])
- {
- return true;
- }
- ///Verifica a destra
- if(Tris[x][y] == Tris[x + 1][y] && Tris[x][y] == Tris[x + 2][y])
- {
- return true;
- }
- ///Verifica sotto
- if(Tris[x][y] == Tris[x][y - 1] && Tris[x][y] == Tris[x][y - 2])
- {
- return true;
- }
- ///Verifica diagonale
- ///Verifica diagonale sinistra sopra.
- if(Tris[x][y] == Tris[x - 1][y + 1] && Tris[x][y] == Tris[x - 2][y + 2])
- {
- return true;
- }
- ///Verifica diagionale destra sopra.
- if(Tris[x][y] == Tris[x + 1][y + 1] && Tris[x][y] == Tris[x + 2][y + 2])
- {
- return true;
- }
- ///Verifica diagionale sinistra sotto.
- if(Tris[x][y] == Tris[x - 1][y - 1] && Tris[x][y] == Tris[x - 2][y - 2])
- {
- return true;
- }
- ///Verifica diagionale destra sotto.
- if(Tris[x][y] == Tris[x + 1][y - 1] && Tris[x][y] == Tris[x + 2][y - 2])
- {
- return true;
- }
- return false;
- }
- void Primi_4()
- {
- for(int i = 0; i < 4; i++)
- {
- cout<<"Inserisci coordinata x: ";
- cin>>x;
- cout<<"Inserisci coordinata y: ";
- cin>>y;
- cout<<"Inserisci simbolo: ";
- if(Tris[x][y] == 0)
- {
- cin>>scelta;
- Tris[x][y] = scelta;
- }
- else
- {
- cout<<"Mossa gia' inserita, riprova"<<endl;
- i--;
- }
- }
- }
- void Reset()
- {
- for(int i = 0; i < 5; i++)
- {
- for(int j = 0; j < 5; j++)
- {
- Tris[i][j] = 0;
- }
- }
- }
- void View()
- {
- for(int i = 0; i < 5; i++)
- {
- cout<<endl;
- for(int j = 0; j < 5; j++)
- {
- cout<<Tris[i][j]<<" ";
- }
- }
- cout<<endl;
- }
- int main()
- {
- bool fine;
- Reset();
- View();
- Primi_4();
- for(int i = 0; i < 5; i++)
- {
- cout<<"Inserisci coordinata x: ";
- cin>>x;
- cout<<"Inserisci coordinata y: ";
- cin>>y;
- cout<<"Inserisci simbolo: ";
- if(Tris[x][y] == 0)
- {
- cin>>scelta;
- Tris[x][y] = scelta;
- FineTris();
- fine = FineTris();
- }
- else
- {
- cout<<"Mossa gia' inserita, riprova"<<endl;
- i--;
- }
- if(fine)
- {
- cout<<"Gioco terminato. Vincitore: "<<Tris[x][y]<<endl;
- View();
- return 0;
- }
- }
- cout<<"Nessun vincitore."<<endl;
- View();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement