|
Hello
It's a maze program,but is not completed. I want to define move function to move the ** (worm). when I ask the value of arrow_keys() it has no response(see move function) in other word move function doesn't work(it is not completed).
#include <stdio.h>
#include <conio.h>
create_wall();
arrow_keys();
move();
void main()
{
create_wall();
arrow_keys();
move();
}
create_wall(){
clrscr();
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},
};
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("*");
}
int arrow_keys()
{
int ch;
while(1)
{
ch=getch();
if(ch==0)
{
ch=getch();
if(ch==72) return 72;
if(ch==75) return 75;
if(ch==77) return 77;
if(ch==80) return 80;
}
else break;
}
}
move(){
if (arrow_keys()==75)
{
clrscr();
printf("bvccvbncvnvbnvb");
}
}
|
|
|
|
|
Only by reading the input keys, **(worm) will not move, for that you need to add some code here
if (arrow_keys()==75)
{
}
Don't die, until you do.
http://nnhamane.googlepages.com
|
|
|
|
|
if i understood it correctly, your problem is that, you are unable to scan the keys Right??.
i dont think getch will do for you here in this context.
there is some other mechanism to get the key code here.
let me refer my backups and let you know.
parallelly, you can also try it.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
hasani2007 wrote: when I ask the value of arrow_keys() it has no response...
Possibly because not every logic path has a return value. If the first getch() returns a non-zero value, the while() loop breaks and arrow_keys() will return what?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
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},
};
void create_wall();
void arrow_keys();
void move();
void clrscr();
void gotoxy(int x, int y);
void main()
{
create_wall();
while(ch!=ESCAPE)
{
arrow_keys();
move();
}
gotoxy(1,21);printf("\n");
}
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("*");
}
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;
}
}
}
void move()
{
gotoxy(worm.x,worm.y);printf("*");
}
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;
}
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
|
|
|
|
|
I am working on transcoding using ffmpeg.For that,i have one class decoder for decoding purpose.That file name is video_decoder.h.
Inside this file,im using the ffmpeg header files as
extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
};
And,Im using the functions of this decoder class in my existing class say FileWriter.This file name is Video_Writer.h.
so,i have included video_decoder.h in video_writer.cpp file.And ofcourse,video_writer.h also there.The problem starts here.
Inside video_writer.h the variable type int8_t is defined in <lib_mp4v2\mpeg4ip_win32.h>.
Also,Inside video_decoder.h the same variable type int8_t is defined in stdint.h.
So,the compile time error is coming as
e:\workspace\build_recorder_plugins.root\build_recorder_plugins\include\stdint.h(82) : error C2371: 'int8_t' : redefinition; different basic types
e:\workspace\build_recorder_plugins.root\build_recorder_plugins\_build\include\lib_mp4v2\mpeg4ip_win32.h(52) : see declaration of 'int8_t'
Pls help me to solve this..
|
|
|
|
|
You've got a couple of choices...
The first one is to work out if the types are compatible and if they are just use one of the definitions (presumably the one from stdint.h).
If you can't do that then isolate the includes from each other behind interfaces. This might not be a bad idea as you won't be using the third party libraries directly and if you ever need to swap them out you can do it far easier. Have a search for the facade pattern online, that's the sort of thing (or pair of things) you need here.
Cheers,
Ash
|
|
|
|
|
Facade pattern can be used in same namespace..am i right?here,Video_writer.h and video_decoder.h are in different namespaces.how can i solve?Is facade pattern useful in this situation?
|
|
|
|
|
The first thing to do is eliminate any usage of those two libraries in the interfaces of your classes. Then make sure you only depend on one of the libraries in the implementation of each class. This provides the facade behind which it doesn't matter how int8_t is defined.
So hide the video stream format stuff behind one class, your decoder behind another:
video_decoder ---> libavdecoder
|
|
|
\--> video_format ---> libavformat
---> means "depends on"
No single implementation file needs to include both avdecoder.h and avformat.h.
Anyway, the point is this lot will work however you package your classes, whether in a namsepaces or not. It doesn't matter.
Also, as a couple of general points:
- don't stick class implementations in header files
- only include header files that contain types that are used in the interface of a class in a header file
This reduces the sort of problems you're having no end.
Cheers,
Ash
|
|
|
|
|
How to block port using programing . suppose any port 8080 of any computer
Trioum
|
|
|
|
|
My application is having one Main window. Which has two child windows. I am showing the child windows side by side.Once if we scroll any of the child windows scrollbar. Both should scroll together.
Please let me know if you have any idea.
Thanks in advance
|
|
|
|
|
Whenever a scroll operation happens in a child window, the window will receive a WM_HSCROLL or WM_VSCROLL message depending on what scroll operation is done.
To make the other child window also do the similar scroll operation you could propogate the same scroll message to the other child window from the WM_HSCROLL or WM_VSCROLL handler using PostMessage .
|
|
|
|
|
The trouble with forwarding messages to another window is what happens (as in the questioners case) if that window has the same behaviour? Each window will send WM_*SCROLL back and forth until someone gets bored.
Cheers,
Ash
|
|
|
|
|
The lParam for these messages are there to handle this situation.
|
|
|
|
|
Good point, I forgot about the NULL lParam,
Cheers,
Ash
|
|
|
|
|
Thanks.. It was really helpfull
|
|
|
|
|
If I were you I'd stick the scroll bars on the frame window. When someone clicks the scroll bar you can scroll the child windows, either by forwarding them the scroll bar messages or using a custom message.
Cheers,
Ash
|
|
|
|
|
Hello all
I want to programa maze in c.
Does anyone have a paper about it.
Thanks in advance.
|
|
|
|
|
Writting a 'maze type game' would be a great project but no one here is going to do your reaearch for you.
If you genuinely want to write a program then try to research it yourself (there are plenty of great articles on this website and Google is a good place to start too), then come back with specific questions.
Good Luck!
Ali
|
|
|
|
|
Hi,
I'm now using the File* to save the data into text file. But i notice that if the file i want to save is in open mode, then the program will crash. Any way to prevent it? Below is snap of my code..
In *.h file
FILE *handle;
in *.cpp file
fopen_s(&handle,cPathName,"wt");
fprintf(handle,"<?xml version=\"1.0\"?>\n")
|
|
|
|
|
fopen_s has a return value that you must check for errors.
This way you will write only if the open operation was successful, thereby avoiding the crash.
|
|
|
|
|
Are you checking that handle actually points to something? i.e. check the handle for being NULL. If you call any file function with a zero pointer it might very well crash if it dereferences a NULL pointer.
Cheers,
Ash
|
|
|
|
|
Please check if the "handle" is NULL.
fopen_s(&handle,cPathName,"wt");
if (handle != NULL)
{
fprintf(handle,"<?xml version=\"1.0\"?>\n")
}
|
|
|
|
|
Hi,
If use bitblt to change the Background of a bitmap
The later I use that bit map in some other fuction will the background remain or is the bsckground only
valid while the bitmap is selected in the DeviceContext
Thankx
|
|
|
|
|
BitBlt works on a device context.
A device context can only have one bitmap selected into it.
So what ever you draw to that DC will remain valid through out its life time.
So taking the device handle from the device context to draw else where will work as you expect.
|
|
|
|
|