| | |
get key input without pausing the program
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 11
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <ctime> #include <cstdlib> #include <string> #include <windows.h> #include <ctime> #include <conio.h> #include <ctype.h> #include <iomanip> using namespace std; void gotoy(int y); void timechange(time_t start1); void timeevent(); int boost=0; int Eboost=0; int power=40; int HP=100; int EHP=100; int Epower=10; int dtime=0; time_t start, end,start1; int main() { start=time(NULL); srand((unsigned)time(0)); cout<<"Fighting Game\n"; cout<<"-------------\n"; cout<<"Player 1\n"; cout<<"HP: "<<HP<<"/100"<<endl<<endl<<endl; cout<<"Player 2\n"; cout<<"HP: "<<EHP<<"/100"<<endl<<endl<<endl; cout<<"1. Attack (10 power)\n"; cout<<"2. Power Attack (10 power)\n"; cout<<"3. Cocaine (10 power)\n"; cout<<"4. Heal (10 power)\n"; do { gotoy(3); cout<<"Player 1\n"; cout<<"HP: "<<right<<setw(3)<<HP<<"/100"<<endl; cout<<"Power: "<<right<<setw(3)<<power<<"/100"<<endl<<endl; gotoy(7); cout<<"Player 2\n"; cout<<"HP: "<<right<<setw(3)<<EHP<<"/100"<<endl; cout<<"Power: "<<right<<setw(3)<<Epower<<"/100"<<endl<<endl; timechange(start); if (GetAsyncKeyState(VK_UP)&&power>=10) { power-=10; EHP-=10; } } while(EHP>1||HP>1); return 0; } void gotoy (int y) { y-=1; COORD coord; coord.X = 0; coord.Y = y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); } void timechange(time_t start1) { end=time(NULL); dtime=difftime(end, start1); if (dtime==1) { timeevent(); dtime=0; start=end; } } void timeevent() { power+=1; if (boost>0) { boost-=1; power+=3; } if (power>100) {power=100;} Epower+=1; if (Eboost>0) { Eboost-=1; Epower+=3; } if (Epower>100) {Epower=100;} }
and getch pauses the program.
so ill explain how my program works it uses a timer and the power builds up based on seconds so it needs to be in a constant loop to keep my screen updated
once a player has enough power you can preform a move
is there a command where it reads the key when the finger leaves the keyboard
Thanks
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: break statement
- Next Thread: Simple File i/o Problem
Views: 818 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int integer java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






