Advertisement
Guest User

Butilrka

a guest
Jan 29th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.11 KB | None | 0 0
  1. #define HOMESTATE 0
  2. #define STREETSTATE 1
  3. #define PARKSTATE 2
  4. #define SHOPSTATE 3
  5. #define TURMASTATE 4
  6. #define SCHOOLSTATE 5
  7.  
  8. bool is_first = true;
  9. int state = 0, new_state = 0;
  10. int food_count = 5, money_count = 0;
  11.  
  12.  
  13.  
  14. int home(bool first)
  15. {
  16.   if (first)
  17.   {
  18.     Serial.println("Welcome to the home! Press S to go street or press 1 to eat.");
  19.   }
  20.   char c = Serial.read();
  21.   if (c == 'S' || c == 's')
  22.   {
  23.     return STREETSTATE;
  24.   }
  25.   else if (c == '1')
  26.   {
  27.     if (food_count > 0)
  28.     {
  29.       Serial.println("Eating...");
  30.       food_count--;
  31.     }
  32.     else
  33.     {
  34.       Serial.println("404 Eat not found");
  35.     }
  36.   }
  37.   return HOMESTATE;
  38. }
  39. int street(bool first)
  40. {
  41.   if (first)
  42.   {
  43.     Serial.println("Welcome to the street! Press P to go park or press H to go home. Press S to steal eat.");
  44.   }
  45.   char c = Serial.read();
  46.   if (c == 'P' || c == 'p')
  47.   {
  48.     return PARKSTATE;
  49.   }
  50.   else if (c == 'H' || c == 'h')
  51.   {
  52.     return HOMESTATE;
  53.   } else if (c == 'S' || c == 's')
  54.   {
  55.     int i = rand() % 10;
  56.     if (i < 2) {
  57.       if (money_count > 20 ) {
  58.         Serial.println("You na butilki. -20 money");
  59.         money_count -= 20;
  60.       }
  61.       else {
  62.         Serial.println("You na butilki and v turme");
  63.         return TURMASTATE;
  64.       }
  65.     } else if (i >= 2 and i <= 8) {
  66.       Serial.println("You stealed 5 eat sucsessfull!");
  67.       food_count += 5;
  68.     } else {
  69.       Serial.println("You stealed 20 money sucsessfull!");
  70.       money_count += 20;
  71.     }
  72.   }
  73.  
  74.   return STREETSTATE;
  75. } int park(bool first)
  76. {
  77.   if (first)
  78.   {
  79.     Serial.println("Welcome to the park! Press F to go home, press s to go shop,press v to go school");
  80.   }
  81.   char c = Serial.read();
  82.   if (c == 'F' || c == 'f')
  83.   {
  84.     return HOMESTATE;
  85.   } else if (c == 'S' || c == 's')
  86.   {
  87.     return SHOPSTATE;
  88.  
  89.  } else if (c == 'V' || c == 'v')
  90.   {
  91.     return SCHOOLSTATE;
  92.   }
  93.  
  94.  
  95.   return PARKSTATE;
  96. } void balance_show() {
  97.   Serial.print("Balance: ");
  98.   Serial.print(money_count);
  99.   Serial.print(", Eat: ");
  100.   Serial.println(food_count);
  101. }
  102.  
  103.  
  104. int shop(bool first)
  105. {
  106.   if (first)
  107.   {
  108.     Serial.println("Welcome to the shop!");
  109.     balance_show();
  110.     Serial.println("1 - Sold eat (3 money per 1 eat)");
  111.     Serial.println("2 - Buy eat (5 money per 1 eat)");
  112.     Serial.println("N - Go home");
  113.     Serial.println(" Press F to go school");
  114.  
  115.   }
  116.   char c = Serial.read();
  117.   if (c == 'N' || c == 'n')
  118.   {
  119.     return HOMESTATE;
  120.   } else if (c == '1')
  121.   {
  122.     if (food_count > 0)
  123.     {
  124.       food_count -= 1;
  125.       money_count += 3;
  126.       balance_show();
  127.     } else
  128.     {
  129.       Serial.println("404 Eat not found");
  130.     }
  131.  
  132.   } else if (c == '2')
  133.   {
  134.   } else if (c == 'F' || c == 'f') {
  135.     return SCHOOLSTATE;
  136.   }
  137.   if (money_count > 0)
  138.   {
  139.     food_count += 1;
  140.     money_count -= 5;
  141.     balance_show();
  142.   } else
  143.   {
  144.     Serial.println("404 Money not found");
  145.   }
  146.   return SHOPSTATE;
  147. }
  148. int turma(bool first)
  149. {
  150.   if (first)
  151.   {
  152.     Serial.println("Welcome to the turma! Press g to go on the bottle, press h to go home and give mysor 5 eda");
  153.   }
  154.   char c = Serial.read();
  155.   if (c == 'H' || c == 'h')
  156.   {
  157.     if (food_count >= 5) {
  158.       food_count -= 5;
  159.       return HOMESTATE;
  160.     }
  161.     else {
  162.       Serial.println("you dont have eda you can clean parasha to give eda(3) or bit patroller to go away(4)");
  163.     }
  164.   } else if (c == 'G' || c == 'g')
  165.   {
  166.     Serial.println("Oyy my. shalyniska");
  167.   } else if (c == '3') {
  168.  
  169.     Serial.println(" you good worker and na edy");
  170.     food_count += 1 ;
  171.   } else if (c == '4') {
  172.     int i = rand() % 2;
  173.     if (i == 0) {
  174.       return HOMESTATE ;
  175.     } else {
  176.       Serial.println(" Game over you on the big bottle!");
  177.       money_count = 0;
  178.       food_count = 5;
  179.     }
  180.   }
  181.  
  182.  
  183.  
  184.   return TURMASTATE;
  185. }
  186. int school(bool first) {
  187.   static int q_number = 0;
  188.   if (first) {
  189.     Serial.println("Welcome to the shool");
  190.     Serial.println("Press n to ho home");
  191.     Serial.println("Here you may get the moooneyy,you can asered  my qestions for each question you will get 5 money");
  192.     Serial.println("The first qestion : how much is 240:6? a: 1, b:40, c: 10 ");
  193.   }
  194.   char c = Serial.read();
  195.   if (q_number == 0) {
  196.     if (c == 'b') {
  197.       Serial.println("Nice you righ");
  198.       money_count += 5 ;
  199.       Serial.println("qestion namber two : how much is 999 : 2? a : 499,5 ; b:500 ; c:499,9");
  200.       q_number++;
  201.     } else if (c != -1) {
  202.       Serial.println("NO no no");
  203.     }
  204.   } else if (q_number == 1) {
  205.     if (c == 'a') {
  206.       Serial.println("Nice you righ");
  207.       money_count += 5 ;
  208.       Serial.println("qestion namber three : how much is 500 :25? a:20,b:25,c:22 ");
  209.       q_number++;
  210.     } else if (c != -1) {
  211.       Serial.println("NO no no");
  212.     }
  213.   } else if (q_number == 2) {
  214.     if (c == 'a') {
  215.       Serial.println("Nice you righ");
  216.       money_count += 5 ;
  217.       Serial.println("qestion namber four : how much is 344 : 2? a:154,b:162,c:172");
  218.       q_number++;
  219.     } else if (c != -1) {
  220.       Serial.println("NO no no");
  221.     }
  222.   } else if (q_number == 3) {
  223.     if (c == 'c') {
  224.       Serial.println("Nice you righ");
  225.       money_count += 5 ;
  226.       q_number++;
  227.     } else if (c == 'N' || c == 'n')
  228.     {
  229.       return HOMESTATE;
  230.     } else if (c != -1) {
  231.       Serial.println("NO no no");
  232.     }
  233.   }
  234.  
  235.  
  236.   return SCHOOLSTATE;
  237.  
  238. }
  239.  
  240.  
  241. void setup()
  242. {
  243.   Serial.begin(9600);
  244. }
  245.  
  246. void loop()
  247. {
  248.   srand(millis());
  249.   switch (state)
  250.   {
  251.     case HOMESTATE:
  252.       new_state = home(is_first);
  253.       is_first = false;
  254.       break;
  255.     case STREETSTATE:
  256.       new_state = street(is_first);
  257.       is_first = false;
  258.       break;
  259.     case PARKSTATE:
  260.       new_state = park(is_first);
  261.       is_first = false;
  262.       break;
  263.     case SHOPSTATE:
  264.       new_state = shop(is_first);
  265.       is_first = false;
  266.       break;
  267.     case TURMASTATE:
  268.       new_state = turma(is_first);
  269.       is_first = false;
  270.       break;
  271.     case SCHOOLSTATE:
  272.       new_state = school(is_first);
  273.       is_first = false;
  274.       break;
  275.   }
  276.   if (state != new_state)
  277.   {
  278.     state = new_state;
  279.     is_first = true;
  280.   }
  281.   delay(100);
  282. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement