Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <ctime>
- using namespace std;
- class myGame {
- private:
- static const int arrSIZE = 4;
- unsigned char wait[arrSIZE + 1]{};
- int queueLen;
- public:
- myGame() : queueLen(0) {};
- ~myGame() { Clear(); }
- void Clear();
- void add(char c);
- bool extract();
- bool isFull() const;
- bool isEmpty() const;
- void show();
- void showTwo();
- friend void showDrums(myGame *A, int SIZE);
- friend void initDrums(myGame *A, int SIZE);
- friend void ronateDrums(myGame *A, int SIZE);
- friend void isWin(myGame *A, int SIZE);
- };
- void myGame::Clear() {
- queueLen = 0;
- }
- bool myGame::isFull() const {
- return queueLen == arrSIZE;
- }
- void myGame::add(char c) {
- if (!isFull()) {
- wait[queueLen++] = c;
- } else {
- cout << "Oh, no… Array is full! " << endl;
- }
- }
- bool myGame::isEmpty() const {
- return queueLen == 0;
- }
- bool myGame::extract() {
- if (!isEmpty()) {
- int tmp;
- tmp = wait[0];
- for (int i = 0; i < queueLen; ++i) {
- wait[i + 1] = wait[i];
- }
- wait[queueLen + 1] = tmp;
- return true;
- } else {
- cout << "Oops… Array is empty! " << endl;
- return false;
- }
- }
- void myGame::show() {
- showTwo();
- cout << endl;
- }
- void myGame::showTwo() {
- for (int i = 0; i < queueLen; ++i) {
- cout << wait[i] << " ";
- }
- }
- void showDrums(myGame *A, int SIZE) {
- for (int i = 0; i < SIZE; ++i) {
- (A + i)->show();
- }
- }
- void initDrums(myGame *A, int SIZE) {
- for (int i = 0; i < SIZE; ++i) {
- int num, num2 = 0;
- while (!(A + i)->isFull()) {
- num = rand() % (myGame::arrSIZE) + 1;
- if (num == num2) {
- cout << " " << endl;
- } else {
- (A + i)->add(num);
- num2 = num;
- }
- }
- }
- }
- void ronateDrums(myGame *A, int SIZE) {
- for (int i = 0; i < SIZE; ++i) {
- int n;
- n = rand() % 200;
- for (int j = 0; j < n; ++j) {
- (A + i)->extract();
- for (int k = 0; k < 20000000; k = k + 7) {
- }
- (A + i)->showTwo();
- for (int k = 0; k < myGame::arrSIZE; ++k) {
- cout << "\r\r";
- }
- }
- (A + i)->showTwo();
- cout << " Drum was " << n << " rotated" << endl;
- }
- }
- void isWin(myGame *A, int SIZE) {
- int w = rand() % 20 + 10;
- for (int i = 0; i < myGame::arrSIZE; ++i) {
- int flag = 0;
- for (int j = 1; j < SIZE; ++j) {
- if ((A + j - 1)->wait[i] == (A + j)->wait[i]) {
- flag++;
- } else {
- flag = 0;
- break;
- }
- }
- if (flag)
- w *= 10;
- }
- if (w) {
- cout << "You Win! " << " " << w << "$" << endl;
- } else {
- cout << "You Lose! " << endl;
- }
- }
- int main() {
- srand(time(nullptr));
- const int SIZE = 20;
- myGame A[SIZE];
- initDrums(A, SIZE);
- showDrums(A, SIZE);
- puts("Press Enter: ");
- getchar();
- system("clear");
- ronateDrums(A, SIZE);
- isWin(A, SIZE);
- /*
- queue<int> q;
- q.push(55);
- q.push(22);
- q.push(19);
- q.push(7);
- while (!q.empty()) {
- cout << q.front() << endl;
- cout << "Elements count: " << q.size() << endl;
- q.pop();
- }
- */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement