fork(25) download
  1. /*Создать имитацию игры "однорукий бандит".
  2. Например, при нажатии кнопки "Enter" происходит
  3. "вращение" трех барабанов (естественно,
  4. количество вращений каждого из них выбирается
  5. случайно), на которых изображены разные значки;
  6. и если выпадает определенная комбинация, то
  7. игрок получает какой-то выигрыш.*/
  8. #include <iostream>
  9. #include <time.h>
  10. #include <iomanip>
  11. using namespace std;
  12.  
  13. const int max_elements = 15;
  14.  
  15. class Cgame
  16. {
  17. private:
  18. int **mas;//выделение памяти под очереди(диски)
  19. int put, get, count;//индексы
  20. int size;//реальный размер очереди
  21.  
  22. public:
  23. Cgame()//конст по умолч
  24. {
  25. int mas_chip[max_elements] = {1, 2, 14, 16, 36};
  26. count = 10;
  27. get = NULL;
  28. size = 5;
  29. mas = new int*[3];
  30. for (int i(0); i < 3; i++)//создание строк
  31. mas[i] = new int [size];
  32. for (int i(0); i < 3; i++)//заполнение строк
  33. for (put = 0; put < size; put++)
  34. put_mas(i, put, mas_chip);
  35. }
  36. //ф-ция записи элементов в очередь
  37. void put_mas(int i, int put, int *mas_chip)
  38. {
  39. mas[i][put] = mas_chip[put];
  40. }
  41.  
  42. //печать очереди
  43. void get_mas(Cgame &A)
  44. {
  45. for (int i(0); i < 3; i++, cout<<endl)
  46. for (int j(0); j < 3; j++)
  47. cout<< (char)mas[j][i]<<" ";
  48. }
  49. //вращение циклов (игра)
  50. void play_game()
  51. {
  52. for (int i(0); i < (3 + rand()%3); i++)//крутим диск 1
  53. for (int j(put-1), tmp1 = mas[0][put-1]; j > 0; j--)
  54. {
  55. mas[0][j] = mas[0][j-1];
  56. if (j==1)
  57. mas[0][get] = tmp1;
  58. }
  59.  
  60. for (int i(0); i < (3 + rand()%3); i++)//крутим диск 2
  61. for (int j(put-1), tmp1 = mas[1][put-1]; j > 0; j--)
  62. {
  63. mas[1][j] = mas[1][j-1];
  64. if (j==1)
  65. mas[1][get] = tmp1;
  66. }
  67.  
  68. for (int i(0); i < (3 + rand()%3); i++)//крутим диск 3
  69. for (int j(put-1), tmp1 = mas[2][put-1]; j > 0; j--)
  70. {
  71. mas[2][j] = mas[2][j-1];
  72. if (j==1)
  73. mas[2][get] = tmp1;
  74. }
  75.  
  76. switch (true)
  77. {
  78. case (1): if((mas[0][1] == mas[1][1])&&(mas[1][1] == mas[2][1]))
  79. {
  80. count+=3;
  81. break;
  82. }
  83. case (2):if ((mas[0][1] == mas[1][1])||(mas[1][1] == mas[2][1]))
  84. {
  85. count+=1;
  86. break;
  87. }
  88. case (3):count-=3;
  89. break;
  90. }
  91. }
  92.  
  93. int calculation()
  94. {
  95. return count;
  96. }
  97.  
  98.  
  99. //----------------------------------------
  100. ~Cgame()//деструктор
  101. {
  102. for (int i = 0; i < 3; i++)
  103. delete [] mas[i];
  104. delete [] mas;
  105. cout<<"\ndel\n";
  106. }
  107. };
  108.  
  109.  
  110.  
  111. bool main()
  112. {
  113. double start_time = clock();
  114. Cgame A;
  115. srand(time(NULL));
  116. while (true)
  117. {
  118. A.play_game();
  119. cout<<endl<<endl;
  120. A.get_mas(A);
  121. cout<<endl<<"your points is: "<<A.calculation()<<endl<<endl;
  122.  
  123. double end_time = clock(); // конечное время
  124. double search_time = end_time - start_time;
  125. cout<<"time of execution: "<<search_time/1000<<endl;
  126.  
  127. if (A.calculation() <= 0)
  128. {
  129. cout<<"\n---game over---\n";
  130. return false;
  131. }
  132.  
  133. system("pause");
  134. system("cls");
  135. }
  136. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In member function ‘void Cgame::play_game()’:
prog.cpp:52: error: ‘rand’ was not declared in this scope
prog.cpp:60: error: ‘rand’ was not declared in this scope
prog.cpp:68: error: ‘rand’ was not declared in this scope
prog.cpp:83: warning: case label value exceeds maximum value for type
prog.cpp:88: warning: case label value exceeds maximum value for type
prog.cpp: At global scope:
prog.cpp:111: error: ‘::main’ must return ‘int’
prog.cpp: In function ‘int main()’:
prog.cpp:115: error: ‘srand’ was not declared in this scope
prog.cpp:133: error: ‘system’ was not declared in this scope
stdout
Standard output is empty