#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;}

}

here is my code i tried GetAsyncKeyState but it happens too fast
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

This article has been dead for over six months. Start a new discussion instead.