2 Replies - 16834 Views - Last Post: 20 November 2010 - 01:59 PM Rate Topic: -----

#1 JANNET  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 11-October 10

C++: Snake Game

Posted 11 October 2010 - 09:02 PM

please help me how make the snake game... i try search the coding in C++ and i want snake game without graphics.
Is This A Good Question/Topic? 0
  • +

Replies To: C++: Snake Game

#2 Alex6788  Icon User is offline

  • kitties == adorable


Reputation: 144
  • View blog
  • Posts: 1,667
  • Joined: 15-July 10

Re: C++: Snake Game

Posted 11 October 2010 - 09:05 PM

We won't give you code, but we will help you. Try doing the program yourself and if you get stuck come back here and post the code you have in code tags like this :code: and list the errors you're getting and we will help you.

This post has been edited by Alex6788: 11 October 2010 - 09:06 PM

Was This Post Helpful? 0
  • +
  • -

#3 Guest_Adeel Irfan*


Reputation:

Re: C++: Snake Game

Posted 20 November 2010 - 01:59 PM

iam having trouble in moving my snake in different positions, i mean, i cant make the snake move towards the right if its moving down, or towards the left if its moving down or up etc, heres the code, please help ASAP!!!
#include <iostream>
#include <windows.h>
#include <stdlib.h>
#include <conio.h>
using namespace std;

void grid(char array[][79],int row, int col)
{
	system("color 0C");
	int i, j, k=178;
	for(i=0, j=0; j<col; j++)
	{
		array[i][j]=k;
	}
	for(i=23, j=0; j<col; j++)
	{
		array[i][j]=k;
	}
	for(i=0, j=0; i<row; i++)
	{
		array[i][j]=k;
	}
	for(i=0, j=78; i<row; i++)
	{
		array[i][j]=k;
	}
	for(i=0; i<24; i++)
	{
	for(j=0; j<79; j++)
	{
		cout<<array[i][j];
	}
	cout<<endl;
	}
}
void main()
{
	int f=237;
	char a;
	char array[24][79]={32};
	int p=3+rand()%78;
	int u=p;
	srand(p);
	for(int i=0;i<3;i++,p++)
	{
		array[3][p]=f;
	}

	grid(array,24,79);
	a=getch();
	
	    if(a=='d')
		{
		  
		   for(int z=p; z<78; z++)
		   {
			  int t=z-1;
			  t=t-2;
	          system("cls");
		      array[3][t]=' ';
			  array[3][z]=f;
			  grid(array,24,79);
		    if ( kbhit() )
			{
			  int c;
		      a = getch();
			  if(a=='x'||a=='w'||a=='a')
			  {
		      switch(a)
			  {
			  case('x'): 
                for(c=3;c<24;)
				{
			    int t=z-3;
			    t++;
		        int e=c-3;			   
			    system("cls");
		        array[3][t]=' '; 
		        array[e][z]=' ';
			    array[c][z]=f;
		        grid(array,24,79);
		        c++;
				}
				break;
			  case('w'):
			    for(c=3;c>0;)
				  {
					 int t=z-3;
			         t++;
                    int e=c-3;
			        system("cls");
			        array[3][t]=' ';
			        u++;
			        array[e][z]=' ';
			        array[c][z]=f;
			        grid(array,24,79);
			        c--;
				  }
				  break;
			  case('a'):
				  for(int z=p-4; z>0; z--)
				  {  
                     int t=z+1;
			         t=t+2;
	                 system("cls");
		             array[3][t]=' ';
			         array[3][z]=f;
			         grid(array,24,79); 
				  }
				  break;
			  }
			  }
			}
		   }
		}
		else if(a=='a')
		{
			
			for(int z=p-4; z>0; z--)
			{  
              int t=z+1;
			  t=t+2;
	          system("cls");
		      array[3][t]=' ';
			  array[3][z]=f;
			  grid(array,24,79); 
			}
		}
	   else	if(a=='x')
	   {
		   for(int c=3;c<24;)
			{
		       int e=c-3;			   
			   system("cls");
		       array[3][u]=' ';
		       u++;
		       array[e][p]=' ';
			   array[c][p]=f;
		       grid(array,24,79);
		       c++;
			}
	   }
	   else if(a=='w')
	   {
		   for(int c=3;c>0;)
		   {
			   int e=c-3;
			   system("cls");
			   array[3][u]=' ';
			   u++;
			   array[e][p]=' ';
			   array[c][p]=f;
			   grid(array,24,79);
			   c--;
		   }
		   
	   }
}


Was This Post Helpful? 0

Page 1 of 1