Marcel12311

Math Solve(Game C++)

Oct 29th, 2021 (edited)
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <time.h>
  4. #include <windows.h>
  5. #include <ctime>
  6. #include <conio.h>
  7. using namespace std;
  8.  
  9. // W,A,S,D - move
  10. //You need solve a math problem
  11.  
  12. // coordinates of map
  13. int x=3,y=3;
  14. /////////////////
  15.  
  16. // coordinates our character
  17. int xx=0,yy=0;
  18. ////////////////////////////
  19.  
  20. // coordinates solving math
  21. int mathX=0,mathY=0;
  22. ///////////////////////////
  23.  
  24. //some variables use in functions
  25. int a=0;
  26. int b=0;
  27. int temp=0;
  28. bool dontMath = false;
  29. int Points=0;
  30.  
  31.  
  32. void spr(int tab[4][4]){
  33.     for(int i=0;i<=x;i++){
  34.         for(int j=0;j<=y;j++){
  35.             tab[i][j]=i+j+1;
  36.             if(xx == i && yy==j){temp=tab[i][j];tab[i][j]=0;}
  37.             if(mathX == i && mathY==j){tab[i][j]=0;}
  38.             cout << tab[i][j]<<" ";
  39.         }cout<<endl;
  40.     }
  41.  
  42. }
  43.  
  44. void input(){
  45.     char znak;
  46.     //cout << "Number: "<<temp<<endl; // debugging numbers
  47.     cout << "Points: "<<Points<<endl;
  48.     znak = getch();
  49.     if(znak == 119)xx--;
  50.     else if(znak == 97)yy--;
  51.     else if(znak == 100)yy++;
  52.     else if(znak == 115)xx++;
  53. }
  54. void logic(){
  55.     if(xx < 0){
  56.         xx=0;
  57.     }else if(xx > x){
  58.         xx=x;
  59.     }else if(yy < 0){
  60.         yy=0;
  61.     }else if(yy > y){
  62.         yy=y;
  63.     }
  64.  
  65.     if(xx == mathX && yy == mathY){
  66.         int elo;
  67.         int pwin=0;
  68.         int good=0;
  69.         mathX=rand()%3;
  70.         mathY=rand()%3;
  71.  
  72.  
  73.         if(dontMath == true){
  74.         elo=rand()%30+1;
  75.         cout << "what is "<<elo<< " + " << elo << "?\n";
  76.         cout << "Enter: ";
  77.         cin >> good;
  78.         pwin=elo+elo;
  79.         if(good == pwin){
  80.             system("cls");
  81.             Points+=1;
  82.             cout << "you solve a math!\n";
  83.         }else cout << "bad.. u dont solve a math is "<<pwin<<" !"<<endl;
  84.       }
  85.     }
  86.     dontMath = true;
  87. }
  88. int main(){
  89.     srand(time(NULL));
  90.  
  91.     // map 4x4
  92.     int tab[4][4];
  93.  
  94.     // at the beginning we randomize the numbers x y
  95.     // of the math solving if player position == math solve
  96.     // we get to solve a math problem...
  97.     mathX=rand()%3;
  98.     mathY=rand()%3;
  99.  
  100.     while(true){
  101.     system("cls");
  102.     logic();
  103.     spr(tab);
  104.     input();
  105.  
  106.     Sleep(25);
  107.  
  108. }
  109.  
  110.     return 0;
  111. }
  112.  
Add Comment
Please, Sign In to add comment