1
#include
#include
#include
#include
#include
#include
using namespace std;
#define TIMER int
clock_t start, end;
struct module {
string title;
TIMER teamA, teamB;
module* next = nullptr;
module* pre = nullptr;
} * Begin = new module, *handle = Begin;
int input();
int timer(string title, int a, int b);
void SetConsoleWindowSize( SHORT width, SHORT height )
{
HANDLE hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SMALL_RECT wrt = { 0, 0, width - 1, height - 1 };
SetConsoleWindowInfo( hStdOutput, TRUE, &wrt ); // 璁剧疆绐椾綋灏哄
COORD coord = { width, height };
SetConsoleScreenBufferSize( hStdOutput, coord ); // 璁剧疆缂撳啿灏哄
}
int main(int argc, char** argv) {
SetConsoleWindowSize(32, 12);
ios_base::sync_with_stdio(FALSE);
CONSOLE_FONT_INFOEX cfi;
cfi.cbSize = sizeof(cfi);
cfi.nFont = 0;
cfi.dwFontSize.X = 0; // Width of each character in the font
cfi.dwFontSize.Y = 48; // Height
cfi.FontFamily = FF_DONTCARE;
cfi.FontWeight = FW_LIGHT;
std::wcscpy(cfi.FaceName, L"Arial"); // Choose your font
SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);
input();
module* now = Begin;
cout << "Press any key to start." << endl;
while (!kbhit());
while (now->next != nullptr) {
if (timer(now->title, now->teamA, now->teamB)) {
now = now->next;
} else {
break;
}
}
cout << "Reaching the End!" << endl;
// 閲婃斁鍔ㄦ€佸垎閰嶇殑鍐呭瓨
while(handle != Begin){
handle = handle->pre;
delete handle->next;
}
delete Begin;
handle = NULL;
system("Pause");
return 0;
}
int input() {
ifstream init("Process.txt");
while (init >> handle->title >> handle->teamA >> handle->teamB) {
handle->next = new module;
handle->next->pre = handle;
handle = handle->next;
}
return 0;
}
int timer(string title, int a, int b) {
int* p[2] = {&a, &b};
int i = 0;
int* now = p[i];
clock_t rec = 0;
start = clock();
while(1) {
if(kbhit()){
char c = getch();
if (c == ' ') {
now = p[i = (~i) & 1];
start = clock();
}else if(c == 'q'){
cout<<"Quit..."<= CLOCKS_PER_SEC) {
system("cls");
*now -= (int)(((rec = clock()) - start) / CLOCKS_PER_SEC);
start = rec;
}
else continue;
cout << title << endl << "Team A Team B\n" << a << " " << b << endl;
if ((a <= 0 && now == p[0]) || (b <= 0 && now == p[1])) {
Beep(880, 500);
MessageBox(NULL, "Timer End!", "End", IDOK);
start = clock();
}
if (a == 30 || b == 30) {
Beep(440, 500);
}
if ((a <= 3 && a != 0 && now == p[0]) || (b <= 3 && b != 0 && now == p[1])) {
Beep(440, 300);
}
if (a == 0) now = p[1];
if (b == 0) now = p[0];
if (a <= 0 && b <= 0) break;
}
return 1;
}