[Di Mo]

DI

Name: Di Mo

Major: Undecided

Contact:

Facebook

My Main Tubmlr and my Tumblr Blogs

some text

Scribbler!!

Draw a Square

#include
#include
#include
#include
using namespace std;


int main()
{
connect("/dev/rfcomm0");
wait(2);
for (int x=0;x<4;x++)
{
robot.move(0.3,0);
wait(3);
robot.motors(-1,1);
wait(4);
}
disconnect();
}


A-Maze-Ing Game


The purpose of this game is to demonstrate and explain control structures, most importantly if-else and while statments

The control structures exist everywhere in our technological life. For example, traffic red light camera and traffic radar are examples of the control strucutres

In this demonstration, the user will be able to manipulate the path of the robot using the program "robot joystick" while trying to touch the "walls" or limits of the mase the least possible.

A timer will be there to keep track of how many seconds it took the user to finish the maze. The least time used will have a higher score.

Here is a video of the demo:


Here is the code for this game:


#include
#include
#include
#include
#include
#include
#include // class needs this inclusion
#include

using namespace std;
//===================
//CLASS
//===================

class Game
{
public:
int findScore(int);
//const static int TIME_MULTIPLIER = 0.5; //set to a specific number

private:
std::vector sense;
int sum; //sum from the senses

};

int Game::findScore(int s)
{
return 60-s;
}


Pixel red = {255,0,0};
Pixel green = {0,255,0};
Pixel blue = {0,0,255};
Pixel white = {255,255,255};
Pixel black = {0,0,0};

int main(int argc, char ** argv){

std::cout<< "Feedback from Friday's demo: "< std::cout<< "A total of 22 people came to my demo"< std::cout<< "Out of 22 people, 3 people found it extremely interesting and addicting"< std::cout<< "Out of the 22 people, 5 people found it very interesting"< std::cout<< "Out of the 22 people, 11 people think it was a good program"< std::cout<< "Out of the 22 people, 3 people thinkg it was an average program"< std::cout<< "One person suggested further improvement of the program"<

if (argc > 1) connect(argv[1]);
else connect();
cout << "Waiting..." << endl;
wait(1);

Game one; // new game
//keep track of time
double duration;
double start;

connect();

robot.setForwardness("fluke-forward");
GraphWin win("Joystick", 500, 500);

Circle cir(Point(250,250), 250);
cir.setWidth(3);
cir.draw(win);

int sum=0;
int size=0; //totall amount of time of IR sensed

// Constantly poll the mouse position and draw a circle
Point dir;
Point m;
Point center(250,250);
Line l(center,center);
int button=0;

//When connected and ready to start
robot.beep(0.02, 783.99); robot.beep(0.02, 987.77); robot.beep(0.02, 1174.66); robot.beep(0.02, 1567.98); robot.beep(0.02, 1975.53); robot.beep(0.02, 830.61); robot.beep(0.02, 1046.50); robot.beep(0.02, 1244.51); robot.beep(0.02, 1661.22); robot.beep(0.02, 2093); robot.beep(0.02, 932.33); robot.beep(0.02, 1174.66); robot.beep(0.02, 1396.91); robot.beep(0.02, 1864.66); robot.beep(0.02, 2349.32); start = currentTime();

while(!win.isClosed())
{
m = win.getCurrentMouse(button);

//start timing now

if (m.getX() >= 0 && m.getY() >= 0 && button){
dir = center - m;
robot.move(dir.getY()/250.0,dir.getX()/250.0);

//senses the maze
vector sense = robot.getIR();
for (int x =0; x {
sum+= sense[x];
size++;
}

l.undraw();
l = Line(center, m);
l.setWidth(3);
l.draw(win);
}

else
{
l.undraw();
robot.move(0,0);
//std::cerr << "l.undraw(): " << std::endl;
}
wait(0.05);
}

//Game ends now, so stop the timer.
double now = currentTime();
duration = ( now - start ) ;
std:cout<<"***********************"< std::cout<<"END OF GAME"< std::cout<<"***********************"< std::cout< std::cout<<"Time: "<

//calcute score
int premscore= 500 - sum; //score prior to time
int tscore = one.findScore(premscore); //score after time limit


int fscore;

if (tscore <=0)
{
std::cout<<"Your Final score is "<
ofstream stat2 ("stats.txt", fstream::app);
stat2< stat2.close();
}


else if (tscore > 499)
{
ofstream stat5 ("stats.txt", fstream::app);
fscore =499;
std::cout<<"Your final score is "<

stat5< stat5.close();

}

else
{

fscore = tscore+premscore*2;
if (fscore > 499)
{
ofstream stat4 ("stats.txt", fstream::app);
fscore =499;
std::cout<<"Your final score is "<
//stat< //stat.close();
ofstream stat3 ("stats.txt", fstream::app);
stat4< stat4.close();

}
else {
std::cout<<"Your final score is "<
ofstream stat3 ("stats.txt", fstream::app);
stat3< stat3.close();
}

}

ifstream graph ("stats.txt");
int num;

Picture graphOne(500,500);

Color blue;
blue.R=30;
blue.G=144;
blue.B=255;
Color white; // = makeColor(255,255,255);
white.R = 255;
white.G = 255;
white.B = 255;

//sets background to white
for (int x=0; x<500; x++ )
{
for (int y=0; y<500; y++)
graphOne.setPixel(x,y,white);
}
for (int x =0; x<500; x++)
{
string s;
getline(graph,s);
int num;
if ((s == "") || (s == "\n"))
break;

else
{
num = atoi (s.c_str());
for (int y =499; y>=500- num; y--)
{ graphOne.setPixel(x,y, blue);

}
}

}
graphOne.show();
graphOne.savePicture("Stat");

disconnect();
return 0;
}



Here is the graph where each run's score of the game was recorded (the highest score could earn was 500)


some text

Here is the run through of the code:

some text some text