B
b69316
Hi,
I am a little confused on something.
I am using DevC++.
I am working on a project to make a "dinosaur walk across a map".
I am not sure about the distance formula....i have no clue how to
figure delta.
I had it moving before I changed it to user input.
any help would be greatly appreciated.
I have included all my code
********************************************************
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
#include "windows.h"
#include "location.h"
#include "dinosaur.h"
#include "map.h"
int x = static_cast<int>(x);
int y = static_cast<int>(y);
int main()
{
int xx, yy, s;
map M;
location L1, L2;
float D;
int tempi=-1,tempj=10;
dinosaur * bronto=new dinosaur(x, y);
cout << "Please select a starting location for you dino:";
cin >> x >> y;
cout << endl;
cout << "Please select a starting destination for you dino:";
cin >> xx >> yy;
cout << endl;
cout << "Please select the speed you want the dino to move:";
cin >> s;
cout << endl;
L1.setxy(x,y);
L2.setxy(xx,yy);
D=L2.distance_to(L1);
cout<<D<<endl;
cout<<endl;
D=L1.distance_to(L2);
cout<<D<<endl;
M.adddino(bronto);
int co = 0;
float xn, yn;
while(co < 20)
{
x=xn;
y=yn;
L1.setxy(x,y);
L2.setxy(xx,yy);
M.movedino(bronto,x,y);
M.display();
yn = y + (yy - y)/D);
xn = x + ((xx - x))/D);
Sleep(2000);
system("cls");
co++;
}
system("pause");
return 0;
}
***********************************************************************
************
class map
{
public:
map();
void display();
void adddino(dinosaur * d);
void movedino(dinosaur * d, int i, int j);
private:
location * M[10][10];
};
map::map()
{
for(int i=0;i<10; i++)
for(int j=0; j<10; j++)
{M[j]=new location;
M[j]->setxy(i,j);
}
}
void map::display()
{cout<<endl<<endl<<endl;
for(int i=0;i<10; i++)
{cout<<setw(41)<<setfill('_');
cout<<'\n';
for(int j=0; j<10; j++)
{M[j]->display();}
cout<<"|"<<endl;
}
cout<<setw(41)<<setfill('_');
cout<<'\n';
cout<<endl<<endl;
}
void map::adddino(dinosaur * d)
{
int i, j;
char t;
i=d->getx();
j=d->gety();
t=d->gettype();
M[j]->settype(t);
}
void map::movedino(dinosaur * d, int i, int j)
{ int iold, jold;
char t;
iold=d->getx();
jold=d->gety();
M[iold][jold]->settype(' ');
t=d->gettype();
d->setxy(i,j);
M[j]->settype(t);
}
***********************************************************************
*************************
class dinosaur
{
public:
dinosaur (int i, int j) {Curr.settype ('D');
Curr.setxy (i,j);}
void setxy(int i, int j){Curr.setxy(i,j);}
char gettype(){Curr.gettype();}
int getx () {Curr.getx();}
int gety () {Curr.gety();}
private:
location Curr;
};
***********************************************************************
****************************
class location
{
public:
location(){xx=0; yy=0;type=' ';}
void setxy(int x, int y){xx=x; yy=y;}
void settype (char t){type=t;}
char gettype(){return type;}
float distance_to(location l);
double getx (){return xx;}
double gety(){return yy;}
void display();
private:
double xx, yy;
char type;
};
void location::display()
{
cout<<"| "<<type<<" ";
}
float location::distance_to(location l)
{
float D;
D=sqrt( pow(l.getx()-xx,2) + pow(l.gety()-yy,2) );
return D;
}
***********************************************************************
********
I am a little confused on something.
I am using DevC++.
I am working on a project to make a "dinosaur walk across a map".
I am not sure about the distance formula....i have no clue how to
figure delta.
I had it moving before I changed it to user input.
any help would be greatly appreciated.
I have included all my code
********************************************************
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
#include "windows.h"
#include "location.h"
#include "dinosaur.h"
#include "map.h"
int x = static_cast<int>(x);
int y = static_cast<int>(y);
int main()
{
int xx, yy, s;
map M;
location L1, L2;
float D;
int tempi=-1,tempj=10;
dinosaur * bronto=new dinosaur(x, y);
cout << "Please select a starting location for you dino:";
cin >> x >> y;
cout << endl;
cout << "Please select a starting destination for you dino:";
cin >> xx >> yy;
cout << endl;
cout << "Please select the speed you want the dino to move:";
cin >> s;
cout << endl;
L1.setxy(x,y);
L2.setxy(xx,yy);
D=L2.distance_to(L1);
cout<<D<<endl;
cout<<endl;
D=L1.distance_to(L2);
cout<<D<<endl;
M.adddino(bronto);
int co = 0;
float xn, yn;
while(co < 20)
{
x=xn;
y=yn;
L1.setxy(x,y);
L2.setxy(xx,yy);
M.movedino(bronto,x,y);
M.display();
yn = y + (yy - y)/D);
xn = x + ((xx - x))/D);
Sleep(2000);
system("cls");
co++;
}
system("pause");
return 0;
}
***********************************************************************
************
class map
{
public:
map();
void display();
void adddino(dinosaur * d);
void movedino(dinosaur * d, int i, int j);
private:
location * M[10][10];
};
map::map()
{
for(int i=0;i<10; i++)
for(int j=0; j<10; j++)
{M[j]=new location;
M[j]->setxy(i,j);
}
}
void map::display()
{cout<<endl<<endl<<endl;
for(int i=0;i<10; i++)
{cout<<setw(41)<<setfill('_');
cout<<'\n';
for(int j=0; j<10; j++)
{M[j]->display();}
cout<<"|"<<endl;
}
cout<<setw(41)<<setfill('_');
cout<<'\n';
cout<<endl<<endl;
}
void map::adddino(dinosaur * d)
{
int i, j;
char t;
i=d->getx();
j=d->gety();
t=d->gettype();
M[j]->settype(t);
}
void map::movedino(dinosaur * d, int i, int j)
{ int iold, jold;
char t;
iold=d->getx();
jold=d->gety();
M[iold][jold]->settype(' ');
t=d->gettype();
d->setxy(i,j);
M[j]->settype(t);
}
***********************************************************************
*************************
class dinosaur
{
public:
dinosaur (int i, int j) {Curr.settype ('D');
Curr.setxy (i,j);}
void setxy(int i, int j){Curr.setxy(i,j);}
char gettype(){Curr.gettype();}
int getx () {Curr.getx();}
int gety () {Curr.gety();}
private:
location Curr;
};
***********************************************************************
****************************
class location
{
public:
location(){xx=0; yy=0;type=' ';}
void setxy(int x, int y){xx=x; yy=y;}
void settype (char t){type=t;}
char gettype(){return type;}
float distance_to(location l);
double getx (){return xx;}
double gety(){return yy;}
void display();
private:
double xx, yy;
char type;
};
void location::display()
{
cout<<"| "<<type<<" ";
}
float location::distance_to(location l)
{
float D;
D=sqrt( pow(l.getx()-xx,2) + pow(l.gety()-yy,2) );
return D;
}
***********************************************************************
********