lamerski problem

0

oto kod gry lamerskiej
(w cpp siedze od 2 dni)
chce zeby sie poruszala ta gwiazdka strzalkami lewo i prawo.
lecz gdy naciskam je to stoi w miejscu
co jest nie tak???
i poprawcie moj kod bo watpie zeby byl optymalny.
aha w chars.h mam zdefinowane LEFT_ARROW etc. i to akurat jest ok

// Quake 4 =)
// Copyright 2004 by Matthew
// Date 4.03.2004 

#include <iostream.h>
#include <windows.h> 
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <dos.h>
#include "chars.h"


int posx,ch,posy;

void ReDraw();
void gotoxy(short x,short y);

void main ()
{
  posx = 0;
  posy = 22;
  printf("yo");
  system("PAUSE");
  
  for(;;)
  {
      ch = getch();
      switch(ch)
        {
          case LEFT_ARROW: // Lewo
            posx=posx+1;
            ReDraw();
          case RIGHT_ARROW: // Prawo
            posx=posx-1;
            ReDraw();
         }
  }

}

void gotoxy(short x,short y) 
{ 
HANDLE hConsoleOutput; 
COORD Cursor_an_Pos = { x,y}; 
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE); 
SetConsoleCursorPosition(hConsoleOutput , Cursor_an_Pos); 
} 

void ReDraw()
{
  system("cls");
  gotoxy(posx,posy);
  cprintf("*");
}

POMOOOOOCY!!!!!

0
system("PAUSE");
   
   for(;;)
   {
         ch = getch();
         switch(ch)
            {
               case LEFT_ARROW: // Lewo
                  posx=posx+1;
                  ReDraw();
               case RIGHT_ARROW: // Prawo
                  posx=posx-1;
                  ReDraw();
             }
   }

To jest ogólnie źle napisane, lepiej wykorzystać kbhit() z conio.h

0

poprawilem to ale i tak gwiazka nie rusza :/

0
#include <iostream.h>
#include <windows.h> 
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <dos.h>
int posx,ch,posy;
void ReDraw();
void gotoxy(short x,short y);
void main ()
{
   posx = 10;
   posy = 22;
   gotoxy(10,10);
   printf("yo");
   for(;;)
   {
   if(kbhit())
   {
         ch = getch();
         switch(ch)
            {
               case ',': // Lewo
                  posx+=1;
                  ReDraw();
                  break;
               case '.': // Prawo
                  posx-=1;
                  ReDraw();
                  break;
             }
   }
   }
}
void gotoxy(short x,short y)
{
HANDLE hConsoleOutput;
COORD Cursor_an_Pos = { x,y};
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsoleOutput , Cursor_an_Pos);
}
void ReDraw()
{
   system("cls");
   gotoxy(posx,posy);
   fprintf(stdout,"*");
}

Działa, choć mogłoby sporo lepiej ;)...

0

thx zara sprawdze

0

To jest ogólnie źle napisane, lepiej wykorzystać kbhit() z conio.h

Nie radzę. conio.h po prostu nie istnieje - to jakiś wymysł M$ czy Borlanda... Należy korzystać ze standardowych nagłówków (większa przenośność...).

0

Nie radzę. conio.h po prostu nie istnieje - to jakiś wymysł M$ czy Borlanda... Należy korzystać ze standardowych nagłówków (większa przenośność...).

Z jakich ?? [???]

1 użytkowników online, w tym zalogowanych: 0, gości: 1