Witam , mam taki problem, że nie wiem jak użyć getcha w pętli ale w taki sposób by nie zatrzymywał jej po prostu pętla sobie "idzie" naciskamy dany klawisz (czyli spacje) i program zwraca daną wartość np. Brawo udało ci się nadążyć !
Kod mojego programu:
#include <iostream>
#include <windows.h> /// dla sleep()
#include <cstdlib> /// dla system("clear")
#include <conio.h>
using namespace std;
void rys()
{
cout<<" |"<<endl;
cout<<" |"<<endl;
cout<<" /=\\"<<endl;
cout<<" /===\\"<<endl;
cout<<" /=====\\"<<endl;
cout<<" (=======)"<<endl;
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\\=====/~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
}
void rys1()
{
cout<<" |"<<endl;
cout<<" |"<<endl;
cout<<" /=\\"<<endl;
cout<<" /===\\"<<endl;
cout<<" /=====\\"<<endl;
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(=======)~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
cout<<"~~~~~~~~~~~~~~~~~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~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
}
void rys7()
{
cout<<" "<<endl;
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
}
#pragma argsused
main( int argc, char **argv)
{
int znak;
int graf;
int kbhit( void );
while (true)
{
graf=rand()%8+1; ///stworzyć program reagujacy na klawisz i zwracajacy informacje
if(graf==1)
{
Sleep(1000);
rys();
}
if(graf==2)
{
Sleep(1000);
rys1();
}
if(graf==3)
{
Sleep(1000);
rys2();
}
if(graf==4)
{
Sleep(1000);
rys3();
}
if(graf==5)
{
Sleep(1000);
rys4();
}
if(graf==6)
{
Sleep(1000);
rys5();
}
if(graf==7)
{
Sleep(1000);
rys6();
}
if(graf==8)
{
Sleep(1000);
rys7();
while(1)
{
if( khbit() )
{
znak=getch();
if(znak== 32)
{
cout<<"Nacisnales Spacje .Koniec petli."<<endl;
break;
}
}
}
getch();
} //koniec ifa
} //koniec while'a
}
Logi:
Z:\media\kamil\Gry1\Programy\Untitled1.cpp In function 'int main(int, char**)':
165 14 Z:\media\kamil\Gry1\Programy\Untitled1.cpp [Error] 'khbit' was not declared in this scope
P.S.Program pisze w Devie, ale miałbym prośbę abyście mogli ewentualnie pokazać jak coś takiego można zrobić na linuxie