Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <windows.h>
  4. using namespace std;
  5. bool waiting=false;
  6. const unsigned int DIM1 = 3;
  7. const unsigned int DIM2 = 5;
  8. bool next_step=true;
  9. char ary[DIM1][DIM2]={{'E','E','E'},{'E','E','E'},{'E','E','E'}};
  10. void print_array(){
  11. for (int i = 0; i < DIM1; i++) {
  12. for (int j = 0; j < DIM2; j++) {
  13.  
  14. cout<< ary[i][j];
  15. }
  16. cout << endl;
  17. }
  18. }
  19. void step2(){
  20. if (!(ary[0][0]==ary[1][0] and ary[1][0]==ary[2][0] and ary[0][0]=='X')) {
  21. waiting=true;
  22. system("cls");
  23. int x,y;
  24. x=rand()%3;
  25. y=rand()%3;
  26. if (ary[x][y]!='X'){
  27. ary[y][x]='O';
  28. system("cls");
  29. print_array();
  30. }
  31. else{
  32. step2();
  33. }
  34. waiting=false;
  35. }
  36. }
  37. void step(){
  38. waiting=true;
  39. int x,y;
  40. cout<<"cell.x"<<endl;
  41. cin>>x;
  42. cout<<"cell.y"<<endl;
  43. cin>>y;
  44. system("cls");
  45. ary[y-1][x-1]='X';
  46. print_array();
  47. if (ary[0][0]==ary[1][0] and ary[1][0]==ary[2][0] and ary[0][0]=='X'){
  48. next_step=false;
  49. }
  50. step2();
  51. waiting=false;
  52. }
  53. int main() {
  54. while (!(ary[0][0]==ary[1][0] and ary[1][0]==ary[2][0] and ary[0][0]=='X')){
  55. if (!waiting) {
  56.  
  57. print_array();
  58.  
  59. step();
  60. }
  61. else{
  62. break;
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement