Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <time.h>
- #include <windows.h>
- #include <ctime>
- #include <conio.h>
- using namespace std;
- // W,A,S,D - move
- //You need solve a math problem
- // coordinates of map
- int x=3,y=3;
- /////////////////
- // coordinates our character
- int xx=0,yy=0;
- ////////////////////////////
- // coordinates solving math
- int mathX=0,mathY=0;
- ///////////////////////////
- //some variables use in functions
- int a=0;
- int b=0;
- int temp=0;
- bool dontMath = false;
- int Points=0;
- void spr(int tab[4][4]){
- for(int i=0;i<=x;i++){
- for(int j=0;j<=y;j++){
- tab[i][j]=i+j+1;
- if(xx == i && yy==j){temp=tab[i][j];tab[i][j]=0;}
- if(mathX == i && mathY==j){tab[i][j]=0;}
- cout << tab[i][j]<<" ";
- }cout<<endl;
- }
- }
- void input(){
- char znak;
- //cout << "Number: "<<temp<<endl; // debugging numbers
- cout << "Points: "<<Points<<endl;
- znak = getch();
- if(znak == 119)xx--;
- else if(znak == 97)yy--;
- else if(znak == 100)yy++;
- else if(znak == 115)xx++;
- }
- void logic(){
- if(xx < 0){
- xx=0;
- }else if(xx > x){
- xx=x;
- }else if(yy < 0){
- yy=0;
- }else if(yy > y){
- yy=y;
- }
- if(xx == mathX && yy == mathY){
- int elo;
- int pwin=0;
- int good=0;
- mathX=rand()%3;
- mathY=rand()%3;
- if(dontMath == true){
- elo=rand()%30+1;
- cout << "what is "<<elo<< " + " << elo << "?\n";
- cout << "Enter: ";
- cin >> good;
- pwin=elo+elo;
- if(good == pwin){
- system("cls");
- Points+=1;
- cout << "you solve a math!\n";
- }else cout << "bad.. u dont solve a math is "<<pwin<<" !"<<endl;
- }
- }
- dontMath = true;
- }
- int main(){
- srand(time(NULL));
- // map 4x4
- int tab[4][4];
- // at the beginning we randomize the numbers x y
- // of the math solving if player position == math solve
- // we get to solve a math problem...
- mathX=rand()%3;
- mathY=rand()%3;
- while(true){
- system("cls");
- logic();
- spr(tab);
- input();
- Sleep(25);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment