Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Snake the Game !

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
educofu
Expert Cheater
Reputation: 3

Joined: 21 Aug 2009
Posts: 171
Location: Brazil,MG,OP

PostPosted: Thu Dec 30, 2010 10:37 am    Post subject: Snake the Game ! Reply with quote

i spend the last week w/o internet. so i decided to create the game snake.

also i made 2 diferent game modes:
Tron Mode and Shit Mode,

here it goes:

Code:


#include <windows.h>
#include <iostream>
using namespace std;

void cs()
{
    system("CLS");
    }

int random(int min,int max)
{
    int r=rand();
    while(r>max || r<min)r=rand();
    return r;
    }

#define UP 1
#define LEFT 2
#define RIGHT 3
#define DOWN 4

int dificult;
int size = 10;
int p[32][32];
int snake_old_posX[1024];
int snake_old_posY[1024];
int headX=16;
int headY=16;
int tailX=16;
int tailY=16;
int points=0;
int direction=LEFT;
int pointX=6;
int pointY=6;
int grow;
int mode;
void print();
void move_snake();
void loose();
void check();
     

int main()
{
    cs();
    pointX=6;
    pointY=6;
    cout << "Snake - By EdCoFu\n";
    cout << "Set the mode:\n\n1-Normal Mode;\n2-Shit Mode;\n3-Tron Mode;\n";
    cin >> mode;
    switch(mode)
    {
         case 1:
              {grow=2;break;}
         case 2:
              {grow=-1;break;}
         case 3:
              {grow=10;break;}
         }
    while(true)
    {
         if(GetAsyncKeyState( VK_UP ) && direction!=DOWN)direction=UP;
         if(GetAsyncKeyState( VK_DOWN )&& direction !=UP)direction=DOWN;
         if(GetAsyncKeyState( VK_RIGHT ) && direction !=LEFT)direction=RIGHT;
         if(GetAsyncKeyState( VK_LEFT ) && direction !=RIGHT)direction=LEFT;
         move_snake();
         check();
         if(mode==2){if(size==3)size=10;};
         print();
         }
    }
     
void check()
{
     p[pointX][pointY]=3;
     int restart;
     if (p[headX][headY]==2 || headX==0 || headX==33 || headY==0 || headY==32)
     {
         cout << "You loose. Restart? (1-Yes/0-No)\n";
         cin >> restart;
         switch(restart)
         {
              case 1:
              {
                   int clean_x=0;
                   int clean_y=0;
                   while(clean_x<33 && clean_y<33)
                   {
                        p[clean_x][clean_y]=0;
                        clean_x++;
                        if (clean_x==33){clean_x=0;clean_y++;}
                        }
                   size = 10;
                   headX=16;
                   headY=16;
                   tailX=16;
                   tailY=16;
                   points=0;
                   direction=LEFT;
                   main();
                   break;
                   }
              }
         exit(0);
         }
     else if (headX==pointX && headY==pointY)
     {
          points++;
          size+=grow;
          pointX=random(2,31);
          pointY=random(2,30);
          p[pointX][pointY]=3;
          }
     }

void move_snake()
{
    int old=size;

    snake_old_posX[1]=headX;
    snake_old_posY[1]=headY;

    switch (direction)
    {
         case UP:
         {
              headY--;;
              break;     
              }
         case DOWN:
         {
              headY++;;
              break;
              }
         case LEFT:
         {
              headX--;;
              break;
              }
         case RIGHT:
         {
              headX++;;
              break;
              }
         }
    p[headX][headY]+=1;

    while(old>=2)
    {   
         snake_old_posX[old]=snake_old_posX[old-1];
         snake_old_posY[old]=snake_old_posY[old-1];
         old--;
         }
    tailX=snake_old_posX[size];
    tailY=snake_old_posY[size];
    p[tailX][tailY]=0;
    }
   
void print()
{
    cs();
    int pX=1;
    int pY=1;
    cout << "|-------------------------------|\n";
    cout << "|";
    while(pX!=32 && pY!=32)
    {   
         if (p[pX][pY]==1) cout << "O";
         else if (p[pX][pY]==3) cout << "#";
         else cout << " ";
         pX++;
         if(pX==32)
         {
              cout << "|\n|";
              pY++;
              pX=1;
              }
         }
    cout << "-------------------------------|\n";
    cout << "Points: " << points << endl;
    }


binary: http://ifile.it/lvdys2u
have fun and comment with bugs etc!

_________________
"I finally started thinking outside of the box, only to find myself in a larger box."
Back to top
View user's profile Send private message MSN Messenger
NoMercy
Master Cheater
Reputation: 1

Joined: 09 Feb 2009
Posts: 289

PostPosted: Thu Dec 30, 2010 4:23 pm    Post subject: Reply with quote

I did not look at the code, just played it. It does work, but you can't play. The window space, it lags, you can't move nicely. Recode it to something funnies:D
Back to top
View user's profile Send private message
M.CORP
Grandmaster Cheater Supreme
Reputation: 28

Joined: 28 Oct 2009
Posts: 1010

PostPosted: Thu Dec 30, 2010 8:11 pm    Post subject: Reply with quote

It's hard too see. There are too many snakes (3) that are moving and sometimes confusing. The snake should be shorter.
_________________
Shameless Self Advertising Very Happy!
Steam
Just lurking around...
Back to top
View user's profile Send private message
educofu
Expert Cheater
Reputation: 3

Joined: 21 Aug 2009
Posts: 171
Location: Brazil,MG,OP

PostPosted: Fri Dec 31, 2010 8:51 am    Post subject: Reply with quote

forgot to say to maximize the screen ^^
_________________
"I finally started thinking outside of the box, only to find myself in a larger box."
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites