Creative Commons License Foxbond's Repo

/** (c) 2012 Michał (Foxbond) Chraniuk */
#include <iostream>
#include <time.h>
#include <conio.h>
#include <sys/timeb.h>
#include <Windows.h>

using namespace std;

int getMilliCount(){
	timeb tb;
	ftime(&tb);
	int nCount = tb.millitm + (tb.time & 0xfffff) * 1000;
	return nCount;
}

int getMilliSpan(int nTimeStart){
	int nSpan = getMilliCount() - nTimeStart;
	if(nSpan < 0)
		nSpan += 0x100000 * 1000;
	return nSpan;
}

int main () {

	int ch,random,tStart;
	int clicked = 0;
	int missed = 0;
	int speedSum=0;
	unsigned long long int score=0;
	int avgSpeed=0;
	int currentSpeed=0;
	bool firstRun=true;
	srand((int)time(NULL));
	cout << "Twoim zadaniem jest jak najszybciej klinac klawisz odpowiadajacy literze, ktora pojawila sie na ekranie\nNacisnij dowolny klawisz, aby kontynuowac";
	_getch();
	cout << endl;
	while (true){
		system("cls");
		cout << "Clicked: "<<clicked<<"\nMissed: "<<missed<<"\navgSpeed: "<<avgSpeed<<"ms\nCurrSpeed: "<<currentSpeed<<"ms\nScore: "<<score<<"\n";
		random = rand()%25+97;
		cout << "\t\t>>>>>   "<<(char)random<<"   <<<<<\t\t\n\n";

		tStart = getMilliCount();
		ch = _getch();
		currentSpeed = getMilliSpan(tStart);
		speedSum+=getMilliSpan(tStart);
		clicked++;
		avgSpeed = speedSum/clicked;


		if (ch == 27){
			break;
		}else if (ch == random){
			//ok
			int temp = getMilliSpan(tStart);
			if (temp <=100) temp = 100000;
			score+=(int)(1/((float)temp/100)*1000);
		}else{
			//błędny
			missed++;
			if (score <= 50){
				score=0;
			}else{
				score-=50;
			}
		}

	}

	
	return 0;
}

> Back