?
DUMM schrieb:
HI ich komm damit voll nicht kla ...
wisonich
DUMM schrieb:
achja diese seite da basirtz nur auf Pixel und hat fürmich kaum was mit konsolenspiele zutuhn
kann man doch viel mehr mit machen, als mit den buchstabenzellen^^
hast du dir die beispiele angeguckt ?
die programme laufen alle in der konsole. wenn das nix mit konsolenspiel zu tun hat.
#include <stdio.h>
#include <windows.h>
HANDLE hOut, hIn;
INPUT_RECORD ir;
typedef int bool;
enum{false, true};
const char* title = " - - Big Brothers Player Movement Demo - - ";
#define ConsoleX 80
#define ConsoleY 25
const int Player = 'O';
const int Background = ' ';
int X, Y;
bool Run;
int InitConsole( const char* title )
{
if ( ( hIn = GetStdHandle(STD_INPUT_HANDLE) ) == INVALID_HANDLE_VALUE )
return 1;
if ( ( hOut = GetStdHandle(STD_OUTPUT_HANDLE) ) == INVALID_HANDLE_VALUE )
return 1;
SetConsoleTitle( title );
Run = true;
return 0;
}
void GotoXY ( int x, int y )
{
COORD pos = { x, y };
SetConsoleCursorPosition( hOut, pos );
}
bool PositionValid( int X, int Y )
{
return X >= 0 && X <= ConsoleX-1 && Y >= 0 && Y <= ConsoleY-1;
}
void MovePlayer( int prev_x, int prev_y, int x, int y )
{
GotoXY( prev_x, prev_y );
putchar( Background );
GotoXY( x, y );
putchar( Player );
X=x;
Y=y;
}
void Up()
{
if ( ! PositionValid ( X, Y-1 ) )
return;
MovePlayer( X, Y, X, Y-1 );
}
void Down()
{
if ( ! PositionValid ( X, Y+1 ) )
return;
MovePlayer( X, Y, X, Y+1 );
}
void Left()
{
if ( ! PositionValid ( X-1, Y ) )
return;
MovePlayer( X, Y, X-1, Y );
}
void Right()
{
if ( ! PositionValid ( X+1, Y ) )
return;
MovePlayer( X, Y, X+1, Y );
}
int ShowConsoleCursor( bool show )
{
CONSOLE_CURSOR_INFO ci = {0};
if ( ! GetConsoleCursorInfo( hOut, &ci ) )
return 1;
ci.bVisible = show;
if ( ! SetConsoleCursorInfo( hOut, &ci ) )
return 1;
return 0;
}
int ConsoleDimension( short x, short y )
{
SMALL_RECT windowCorners = {0,0,x-1,y-1};
COORD screenBufSize = {x, y};
if ( ! SetConsoleWindowInfo( hOut, 1, &windowCorners ) )
return 1;
if( ! SetConsoleScreenBufferSize( hOut, screenBufSize ))
return 1;
return 0;
}
int Init()
{
if( InitConsole( title ) )
return 1;
if( ConsoleDimension( ConsoleX, ConsoleY ))
return 1;
if ( ShowConsoleCursor( false ) )
return 1;
MovePlayer( 0, 0, 20, 20 );
return 0;
}
void TheEnd()
{
system("cls");
puts("Good Bye! ;)");
}
int ConsoleEvents( int count )
{
switch( ir.EventType )
{
case KEY_EVENT:
{
switch ( ir.Event.KeyEvent.wVirtualKeyCode )
{
case VK_UP:
if( ir.Event.KeyEvent.bKeyDown )
Up();
break;
case VK_DOWN:
if( ir.Event.KeyEvent.bKeyDown )
Down();
break;
case VK_LEFT:
if( ir.Event.KeyEvent.bKeyDown )
Left();
break;
case VK_RIGHT:
if( ir.Event.KeyEvent.bKeyDown )
Right();
break;
case VK_ESCAPE:
Run = false;
TheEnd();
break;
}
}
}
return 0;
}
int MainLoop()
{
int count = 0;
while( Run )
{
if ( ! ReadConsoleInput( hIn, &ir, 1, &count ))
return 1;
while( count-- )
{
if ( ConsoleEvents(count) )
return 1;
}
}
return 0;
}
int main()
{
if ( Init() )
return 1;
if ( MainLoop() )
return 1;
return 0;
}