Okay, so I am not quite making a game. I am trying to write some code that will play a snake game for me. Yes, cheating, thats right.
So, there is this stupid flash snake game that I play on some site. Being the curious computer science student that I am, I am trying to write a programming that will play the game.
At this point, it works to move the snake around the grid and even manage to eat a couple of apples. But I am just doing this by trying to time everything perfectly and by starting the program at exactly the right time ...with little success.
Heres what I have so far.
At this point, I'm a little stuck.Code:#include <windows.h>
#include <iostream>
const static double LONG_WAYS = 3937.5;
const static double SHORT_WAYS = 1950;
using namespace std;
void snake()
{
cout << "Go!" << endl;
for(int j = 0; j < 410; j++)
{
for(int i = 0; i < 15; i++)
{
cout << i << endl;
keybd_event(VK_DOWN,0x28,0 , 0); // Down Arrow Press
keybd_event(VK_DOWN,0x28,KEYEVENTF_KEYUP,0); // Down Arrow Release
keybd_event(VK_RIGHT,0x27,0 , 0); // Right Arrow Press
keybd_event(VK_RIGHT,0x27,KEYEVENTF_KEYUP,0); // Right Arrow Release
Sleep(LONG_WAYS);
keybd_event(VK_DOWN,0x28,0 , 0); // Down Arrow Press
keybd_event(VK_DOWN,0x28,KEYEVENTF_KEYUP,0); // Down Arrow Release
keybd_event(VK_LEFT,0x25,0 , 0); // Left Arrow Press
keybd_event(VK_LEFT,0x25,KEYEVENTF_KEYUP,0); // Left Arrow Release
Sleep(LONG_WAYS);
}
keybd_event(VK_DOWN,0x28,0 , 0); // Down Arrow Press
keybd_event(VK_DOWN,0x28,KEYEVENTF_KEYUP,0); // Down Arrow Release
keybd_event(VK_RIGHT,0x27,0 , 0); // Right Arrow Press
keybd_event(VK_RIGHT,0x27,KEYEVENTF_KEYUP,0); // Right Arrow Release
Sleep(LONG_WAYS+62.5);
keybd_event(VK_UP,0x26,0 , 0); // Up Arrow Press
keybd_event(VK_UP,0x26,KEYEVENTF_KEYUP,0); // Up Arrow Release
Sleep(SHORT_WAYS);
keybd_event(VK_LEFT,0x25,0 , 0); // Left Arrow Press
keybd_event(VK_LEFT,0x25,KEYEVENTF_KEYUP,0); // Left Arrow Release
Sleep(LONG_WAYS+62.5);
}
}
void main()
{
system("PAUSE");
cout << endl << "10" << endl;
Sleep(1000);
cout << "9" << endl;
Sleep(1000);
cout << "8" << endl;
Sleep(1000);
cout << "7" << endl;
Sleep(1000);
cout << "6" << endl;
Sleep(1000);
cout << "5" << endl;
Sleep(1000);
cout << "4" << endl;
Sleep(1000);
cout << "3" << endl;
Sleep(1000);
cout << "2" << endl;
Sleep(1000);
cout << "1" << endl;
Sleep(1000);
snake();
}
Does anyone have any ideas/ suggestions that might help get me going again?
Thanks!