Click here to Skip to main content
15,896,606 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to differentiate a floppy drive and a USB drive in VC++? Pin
Nuri Ismail1-Jun-10 22:18
Nuri Ismail1-Jun-10 22:18 
GeneralRe: How to differentiate a floppy drive and a USB drive in VC++? Pin
Subrat Patnaik2-Jun-10 0:04
Subrat Patnaik2-Jun-10 0:04 
AnswerRe: How to differentiate a floppy drive and a USB drive in VC++? [modified] Pin
Jackson20102-Jun-10 4:40
Jackson20102-Jun-10 4:40 
Questionmove function in maze does not work correctly Pin
hasani20071-Jun-10 21:40
hasani20071-Jun-10 21:40 
AnswerRe: move function in maze does not work correctly Pin
Nilesh Hamane1-Jun-10 22:17
Nilesh Hamane1-Jun-10 22:17 
AnswerRe: move function in maze does not work correctly Pin
chandu0042-Jun-10 0:00
chandu0042-Jun-10 0:00 
QuestionRe: move function in maze does not work correctly Pin
David Crow2-Jun-10 2:57
David Crow2-Jun-10 2:57 
AnswerRe: Nice work.. i made some changes in your code Pin
Software_Developer2-Jun-10 3:43
Software_Developer2-Jun-10 3:43 
Hello hasani2007.
Nice work on the maze.

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>


#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77
#define SPACE 32
#define ENTER 13
#define ESCAPE 27

  /******************/
 /*                */
/******************/

typedef struct t_worm
{ int x,y,dirx,diry; } ;

  t_worm worm;
  int ch;
   int i,j;
   char wall[15][26]={
   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
   {1,0,0,0,1,1,1,0,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1},
   {1,1,0,1,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,0,1},
   {1,1,0,1,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,0,1},
   {1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1},
   {1,1,0,1,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,0,1,1,0,1},
   {1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1},
   {1,1,1,1,1,0,0,0,1,1,1,0,0,0,0,1,1,1,1,0,0,0,1,1,0,1},
   {1,0,1,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1},
   {1,1,1,1,1,1,1,1,0,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1},
   {1,1,0,1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,1,0,1},
   {1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1},
   {1,1,1,1,1,0,0,0,1,1,1,0,0,0,0,1,1,1,1,0,0,0,1,1,0,1},
   {1,0,1,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1},
   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
   };


  /******************/
 /*                */
/******************/

/* prototypes */
void create_wall();
void arrow_keys();
void move();
void clrscr();
void gotoxy(int x, int y);
/* end of prototypes */



  /******************/
 /*                */
/******************/

void main()
{
	create_wall();
	

   while(ch!=ESCAPE)
   {
    arrow_keys();
	move();
   }

    gotoxy(1,21);printf("\n");

}



/* function to create the walls */

  /******************/
 /* function for   */
/******************/

void create_wall(){
   clrscr();

   for(i=0;i<15;i++){
      for(j=0;j<26;j++){
      if (wall[i][j]==1) printf("²");
      else printf(" ");
      }
   printf("\n");
   }
gotoxy(2,2);
printf("*");
gotoxy(3,2);
printf("*");

}


/* end of create_wall function */
////////////////////////////////////
/* function to define arrow keys */

  /******************/
 /* function for   */
/******************/

void arrow_keys()
{   
 
    if (kbhit())
	{
       ch=getch();
	   switch (ch)
	   {
           /////////////////////
	       case UP:
                  worm.y--;
		   break;
           /////////////////////
	       case DOWN:
                  worm.y++;
		   break;
           /////////////////////
	       case LEFT:
                  worm.x--;
		   break;
           /////////////////////
	       case RIGHT:
                 worm.x++;
		   break;
           /////////////////////
	   }
       
     }
}


  /******************/
 /* function for   */
/******************/

/* function for move */
// up=72 , down=80 , left=75 , right=77
void move()
{
  gotoxy(worm.x,worm.y);printf("*");
}

  /******************/
 /* function for   */
/******************/
void clrscr()
{
	COORD coordScreen = { 0, 0 };
	DWORD cCharsWritten;
	CONSOLE_SCREEN_BUFFER_INFO csbi;
	DWORD dwConSize;
	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

	GetConsoleScreenBufferInfo(hConsole, &csbi);
	dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
	FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
	GetConsoleScreenBufferInfo(hConsole, &csbi);
	FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
	SetConsoleCursorPosition(hConsole, coordScreen);
	return;
}

  /******************/
 /* function for   */
/******************/
void gotoxy(int x, int y)
{
	COORD coord;
	coord.X = x; coord.Y = y;
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
	return;
}


..

modified on Wednesday, June 2, 2010 9:55 AM

QuestionCompile time error - 'int8_t' : redefinition; different basic types Pin
gmallax1-Jun-10 20:21
gmallax1-Jun-10 20:21 
AnswerRe: Compile time error - 'int8_t' : redefinition; different basic types Pin
Aescleal1-Jun-10 20:41
Aescleal1-Jun-10 20:41 
GeneralRe: Compile time error - 'int8_t' : redefinition; different basic types Pin
gmallax1-Jun-10 22:23
gmallax1-Jun-10 22:23 
GeneralRe: Compile time error - 'int8_t' : redefinition; different basic types Pin
Aescleal1-Jun-10 23:40
Aescleal1-Jun-10 23:40 
Questionblcoking port Pin
trioum1-Jun-10 20:12
trioum1-Jun-10 20:12 
QuestionScroll two windows together WIN32 Pin
arun_pk1-Jun-10 19:43
arun_pk1-Jun-10 19:43 
AnswerRe: Scroll two windows together WIN32 Pin
«_Superman_»1-Jun-10 20:12
professional«_Superman_»1-Jun-10 20:12 
GeneralRe: Scroll two windows together WIN32 Pin
Aescleal1-Jun-10 20:32
Aescleal1-Jun-10 20:32 
GeneralRe: Scroll two windows together WIN32 Pin
«_Superman_»1-Jun-10 20:36
professional«_Superman_»1-Jun-10 20:36 
GeneralRe: Scroll two windows together WIN32 Pin
Aescleal1-Jun-10 20:56
Aescleal1-Jun-10 20:56 
GeneralRe: Scroll two windows together WIN32 Pin
sourabhmehta12-Aug-10 0:55
sourabhmehta12-Aug-10 0:55 
AnswerRe: Scroll two windows together WIN32 Pin
Aescleal1-Jun-10 20:34
Aescleal1-Jun-10 20:34 
Questionmaze in c Pin
hasani20071-Jun-10 19:25
hasani20071-Jun-10 19:25 
AnswerRe: maze in c Pin
LittleYellowBird2-Jun-10 0:18
LittleYellowBird2-Jun-10 0:18 
QuestionFILE* problem Pin
DevelopmentNoob1-Jun-10 19:12
DevelopmentNoob1-Jun-10 19:12 
AnswerRe: FILE* problem Pin
«_Superman_»1-Jun-10 19:50
professional«_Superman_»1-Jun-10 19:50 
AnswerRe: FILE* problem Pin
Aescleal1-Jun-10 20:28
Aescleal1-Jun-10 20:28 

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.