class moving
{
private :
short x;
short y;
int value;
public :
moving (short xa ,short ya,int va);
void gotoxy(short x, short y);
void gotoxy(short x, short y,bool clear);
void shiftright(int x, int y);
short get_x() ;
short get_y() ;
int get_value();
void set_x(int newx );
void set_y(int newy);
void set_value(int newvalue);
int generate_number();
int generate_random_number();
};
#include "moving.h"
#include <iostream>
#include <conio.h>
#include <windows.h>
#include <ctime> // to use the time function
#include <cstdlib>
using namespace std;
moving ::moving(short xa ,short ya,int va)
{
x = xa ;
y = ya ;
value =va ;
}
void moving :: gotoxy(short x , short y)
{
COORD pos = {x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void moving ::gotoxy(short x ,short y,bool clear)
{
COORD pos = {x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
cout<<" ";
}
void moving::shiftright(int x ,int y )
{
gotoxy(x,y);
cout<<"1";
}
short moving ::get_x()
{
return x ;
}
short moving ::get_y()
{
return y ;
}
int moving ::get_value()
{
return value ;
}
void moving ::set_x(int newx)
{
x=newx;
}
void moving ::set_y(int newy)
{
y=newy ;
}
void moving ::set_value(int newvalue)
{
value=newvalue ;
}
int moving::generate_number()
{
srand(time(NULL));
int value= rand() % 100;
return value;
}
int moving ::generate_random_number()
{ srand(time(NULL));
int x= rand() % 50;
int y= rand() % 50;
//return y;
gotoxy(x,y);
int rand_num=generate_number();
cout<<rand_num;
return rand_num;
}
#include <moving.h>
#include <iostream>
#include <conio.h>
#include <windows.h>
#include <ctime> // to use the time function
#include <cstdlib>
using namespace std;
int main ()
{
// while(m2.get_value() < 500)
//{
unsigned char a;
int x=0;
int y=0;
moving m1(0,0,0);
int v1=0;
x=m1.get_x();
y=m1.get_y();
v1=m1.get_value();
moving m2 (0,0,0);
m2.generate_number();
m2.generate_random_number();
while(1)
{
a=getch();
switch(a)
{
case 77:
m1.gotoxy(y,x,true);
y=y+1;
if(y>50)
m1.set_y(50);
m1.shiftright(y,x);
break;
case 75:
m1.gotoxy(y,x,true);
y=y-1;
if(y<0)
m1.set_y(0);
m1.shiftright(y,x);
break;
case 72:
m1.gotoxy(y,x,true);
x=x-1;
if(x<0)
m1.set_x(0);
m1.shiftright(y,x);
break;
case 80:
m1.gotoxy(y,x,true);
x=x+1;
if(x>50)
m1.set_x(50);
m1.shiftright(y,x);
break;
case 'e':
break;
}
}
v1=v1+m1.generate_random_number();
cout<<v1;
//m1.set_value(m2.get_value()));
//m1.set_value(m1.get_value() + m2.get_value());
// cout<<m1.set_value;
//}
}
i want what the x y cordinates reaches at the random numbers position the value of that number is added in to the 1 that blinks trying so many things but no solution !!!!