Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int Tris[5][5];
  6. int x;
  7. int y;
  8. int scelta;
  9.  
  10. void View();
  11. void Reset();
  12. void Primi_4();
  13. bool FineTris();
  14.  
  15. bool FineTris()
  16. {
  17. ///Verifica Lineare
  18.  
  19. ///Verifica a sinistra
  20. if(Tris[x][y] == Tris[x - 1][y] && Tris[x][y] == Tris[x - 2][y])
  21. {
  22. return true;
  23. }
  24. ///Verifica sopra
  25. if(Tris[x][y] == Tris[x][y + 1] && Tris[x][y] == Tris[x][y + 2])
  26. {
  27. return true;
  28. }
  29. ///Verifica a destra
  30. if(Tris[x][y] == Tris[x + 1][y] && Tris[x][y] == Tris[x + 2][y])
  31. {
  32. return true;
  33. }
  34. ///Verifica sotto
  35. if(Tris[x][y] == Tris[x][y - 1] && Tris[x][y] == Tris[x][y - 2])
  36. {
  37. return true;
  38. }
  39.  
  40. ///Verifica diagonale
  41.  
  42. ///Verifica diagonale sinistra sopra.
  43. if(Tris[x][y] == Tris[x - 1][y + 1] && Tris[x][y] == Tris[x - 2][y + 2])
  44. {
  45. return true;
  46. }
  47. ///Verifica diagionale destra sopra.
  48. if(Tris[x][y] == Tris[x + 1][y + 1] && Tris[x][y] == Tris[x + 2][y + 2])
  49. {
  50. return true;
  51. }
  52. ///Verifica diagionale sinistra sotto.
  53. if(Tris[x][y] == Tris[x - 1][y - 1] && Tris[x][y] == Tris[x - 2][y - 2])
  54. {
  55. return true;
  56. }
  57. ///Verifica diagionale destra sotto.
  58. if(Tris[x][y] == Tris[x + 1][y - 1] && Tris[x][y] == Tris[x + 2][y - 2])
  59. {
  60. return true;
  61. }
  62. return false;
  63. }
  64.  
  65. void Primi_4()
  66. {
  67. for(int i = 0; i < 4; i++)
  68. {
  69. cout<<"Inserisci coordinata x: ";
  70. cin>>x;
  71. cout<<"Inserisci coordinata y: ";
  72. cin>>y;
  73. cout<<"Inserisci simbolo: ";
  74. if(Tris[x][y] == 0)
  75. {
  76. cin>>scelta;
  77. Tris[x][y] = scelta;
  78. }
  79. else
  80. {
  81. cout<<"Mossa gia' inserita, riprova"<<endl;
  82. i--;
  83. }
  84. }
  85. }
  86.  
  87.  
  88. void Reset()
  89. {
  90. for(int i = 0; i < 5; i++)
  91. {
  92. for(int j = 0; j < 5; j++)
  93. {
  94. Tris[i][j] = 0;
  95. }
  96. }
  97. }
  98. void View()
  99. {
  100. for(int i = 0; i < 5; i++)
  101. {
  102. cout<<endl;
  103. for(int j = 0; j < 5; j++)
  104. {
  105. cout<<Tris[i][j]<<" ";
  106. }
  107. }
  108. cout<<endl;
  109. }
  110.  
  111. int main()
  112. {
  113. bool fine;
  114.  
  115. Reset();
  116. View();
  117. Primi_4();
  118.  
  119. for(int i = 0; i < 5; i++)
  120. {
  121. cout<<"Inserisci coordinata x: ";
  122. cin>>x;
  123. cout<<"Inserisci coordinata y: ";
  124. cin>>y;
  125. cout<<"Inserisci simbolo: ";
  126. if(Tris[x][y] == 0)
  127. {
  128. cin>>scelta;
  129. Tris[x][y] = scelta;
  130. FineTris();
  131. fine = FineTris();
  132. }
  133. else
  134. {
  135. cout<<"Mossa gia' inserita, riprova"<<endl;
  136. i--;
  137. }
  138. if(fine)
  139. {
  140. cout<<"Gioco terminato. Vincitore: "<<Tris[x][y]<<endl;
  141. View();
  142. return 0;
  143. }
  144. }
  145.  
  146. cout<<"Nessun vincitore."<<endl;
  147. View();
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement