Click here to Skip to main content
15,885,680 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Error while compiling Pin
pasztorpisti30-Jan-15 23:20
pasztorpisti30-Jan-15 23:20 
GeneralRe: Error while compiling Pin
Member 109440042-Feb-15 20:05
Member 109440042-Feb-15 20:05 
GeneralRe: Error while compiling Pin
pasztorpisti3-Feb-15 12:25
pasztorpisti3-Feb-15 12:25 
GeneralRe: Error while compiling Pin
Member 109440045-Feb-15 0:23
Member 109440045-Feb-15 0:23 
AnswerRe: Error while compiling Pin
Mike Nordell2-Feb-15 10:44
Mike Nordell2-Feb-15 10:44 
GeneralRe: Error while compiling Pin
Member 109440042-Feb-15 17:30
Member 109440042-Feb-15 17:30 
GeneralRe: Error while compiling Pin
Mike Nordell7-Feb-15 14:55
Mike Nordell7-Feb-15 14:55 
QuestionSnake Game please help me Pin
Member 1141203429-Jan-15 3:16
Member 1141203429-Jan-15 3:16 
This is a code for snake game using dev c++. now i would like to know how can i create:

- a new snake (2nd snake) which eats the apple(so called apple) on its own..
- which means.. 1st snake will be handled by user. while the 2nd snake works on its own. and both snake fights to get the apple.

can any1 suggest me how can i do this.

C++
#include <iostream>
#include <windows.h>
#include <stdlib.h>
#include <conio.h>

using namespace std;

typedef struct tailpos
{
  int x;   
  int y;  
  struct tailpos *next;  
  struct tailpos *prev;    
} 
  tail;

// d used to set the direction
int d=4; // up = 1 , down = 2 , left =3 , right = 4;

class snake
{
public:  
      
       int foodx,foody;             
      
       HANDLE console_handle;   
       COORD cur_cord;        
      
       tail *start,*current,*newtail;
       snake(); 
       void insert(int x , int y); 
       void draw();    
       void drawWall(); 
       void move();    
       bool collision();  
       void drawfood(int x=0);      
     
};

snake::snake()
{
  start = NULL; 
  current = NULL; 
  newtail = NULL;   
  console_handle=GetStdHandle( STD_OUTPUT_HANDLE );  

  foodx=12;                   
  foody=14;   
}


void snake::drawWall()
{
     // draw left column
     cur_cord.X=0;
     for(int y=0;y<=30;y++)
           {.....
       

}  

void snake::drawfood(int x)
{
  tail *tmp;
  tmp=start->next;
  if(x==1) .....
}

void snake :: insert(int x , int y)
{
     
     if(start == NULL)
     {
       newtail = new tail;
       newtail->x=x;
       newtail->y=y;
       newtail->next=NULL;
       newtail->prev=NULL;
       start=newtail;
       current=newtail;
     }
     else            
     {
       newtail = new tail;
       newtail->x=x;
       newtail->y=y;
       newtail->next=NULL;
       newtail->prev=current;  
       current->next=newtail;
       current=newtail;
     }
     
}

void snake::move()
{
    tail *tmp,*cur; 

    tmp =current; 
                  

  while(tmp->prev!=NULL)
  {
    tmp->x=tmp->prev->x;        
    tmp->y=tmp->prev->y;
    tmp=tmp->prev;              
                     
  }
           
if(d==1)
  start->y--;

if(d==2)
  start->y++; 

if(d==3)
  start->x--;

if(d==4)
  start->x++;                 
                     
}

bool snake::collision()
{
    tail *tmp;
    tmp=start->next;
    //check collision with itself
  while(tmp->next!=NULL)
     {
       if(start->x == tmp->x && start->y == tmp->y)
       return true;
                                                    
       tmp=tmp->next;                
     }
     //check collision with food
  if(start->x == foodx && start->y == foody)
     {
       insert(foodx,foody);          
       drawfood(1);  // draw food at new position
                      
     }
//check collision with wall
     //collision top
  for(int x=0;x<=30;x++)
     {
       if(start->x == x .....
}


void snake::draw()
{

tail *tmp , *last;
tmp=start;
last = current;

                     

while(tmp!=NULL)
                      {
                        cur_cord.X=tmp->x;
                        cur_cord.Y=tmp->y;
                        SetConsoleCursorPosition(console_handle,cur_cord);
                       
                        cout << "#";
                        tmp=tmp->next;                         
                      }
// remove tail
cur_cord.X=last->x;
cur_cord.Y=last->y;
SetConsoleCursorPosition(console_handle,cur_cord);
cout << ' ';

//draw the food
 cur_cord.X.....
 
}


int main()
{  
......
}

getch();
return 0;   
}

Questionerror C2059: syntax error: '<tag>::*' Pin
jeff629-Jan-15 0:43
jeff629-Jan-15 0:43 
AnswerRe: error C2059: syntax error: '<tag>::*' Pin
Freak3030-Jan-15 3:51
Freak3030-Jan-15 3:51 
GeneralRe: error C2059: syntax error: '<tag>::*' Pin
jeff630-Jan-15 4:16
jeff630-Jan-15 4:16 
AnswerRe: error C2059: syntax error: '<tag>::*' Pin
Stefan_Lang30-Jan-15 4:52
Stefan_Lang30-Jan-15 4:52 
QuestionCMFCRibbonBar and recent file list Pin
Leif Simon Goodwin27-Jan-15 4:09
Leif Simon Goodwin27-Jan-15 4:09 
QuestionGet info from video capture card but no SDK Pin
peterkoller12327-Jan-15 2:05
peterkoller12327-Jan-15 2:05 
AnswerRe: Get info from video capture card but no SDK Pin
Mike Nordell2-Feb-15 9:36
Mike Nordell2-Feb-15 9:36 
GeneralRe: Get info from video capture card but no SDK Pin
peterkoller1232-Feb-15 10:40
peterkoller1232-Feb-15 10:40 
Questionexample c++ application Pin
Member 1139333326-Jan-15 21:20
Member 1139333326-Jan-15 21:20 
AnswerRe: example c++ application Pin
Richard MacCutchan26-Jan-15 21:22
mveRichard MacCutchan26-Jan-15 21:22 
GeneralRe: example c++ application Pin
jeron127-Jan-15 3:59
jeron127-Jan-15 3:59 
AnswerRe: example c++ application Pin
Stefan_Lang30-Jan-15 5:00
Stefan_Lang30-Jan-15 5:00 
QuestionHow do I know my dual display in span mode in windows xp? Pin
cedricvictor26-Jan-15 16:49
cedricvictor26-Jan-15 16:49 
QuestionWin8.1 UEFI block WINIO? Pin
ICEric25-Jan-15 22:32
ICEric25-Jan-15 22:32 
SuggestionRe: Win8.1 UEFI block WINIO? Pin
Richard MacCutchan25-Jan-15 23:25
mveRichard MacCutchan25-Jan-15 23:25 
GeneralRe: Win8.1 UEFI block WINIO? Pin
ICEric26-Jan-15 14:47
ICEric26-Jan-15 14:47 
AnswerRe: Win8.1 UEFI block WINIO? Pin
Randor 26-Jan-15 15:24
professional Randor 26-Jan-15 15:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.