跳到正文

休闲·娱乐

【研究性作品】MsTimer

wizard_Marshall约 16 分钟
原文
文章信息与版本

文章信息

发布
2024年7月31日
收录
2025年12月12日
更新
2026年10月28日
篇幅
约 16 分钟

版本

  1. v1当前

似乎仿csTimer?

一款基础魔方计时器。

flag:存储、分组、图示、四阶。

没有更新日志。

C++
#include <bits/stdc++.h>
#include <windows.h>
#include <stdio.h>
#include <fstream>
#include <conio.h>
#include <time.h>
#include <random>

using namespace std;

inline void SetPos(int x,int y)
{
    COORD pos;
    pos.X=y*2,pos.Y=x;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}

inline void HideCursor() {
	CONSOLE_CURSOR_INFO cursor_info = {1, 0};
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}

inline void Color(int a)
{
    if(a==0) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
    if(a==1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE);
    if(a==2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);
    if(a==3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),5);
    if(a==4) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
    if(a==5) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE);
    if(a==6) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);
    if(a==7) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY);
    if(a==8) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE); 
    if(a==9) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),13);
}//白蓝绿紫红靛黄 深灰 浅灰 粉

struct cube3{
	int uc[3][3] = {1, 1, 1, 1, 1, 1, 1, 1, 1};
	int dc[3][3] = {2, 2, 2, 2, 2, 2, 2, 2, 2};
	int fc[3][3] = {3, 3, 3, 3, 3, 3, 3, 3, 3};
	int bc[3][3] = {4, 4, 4, 4, 4, 4, 4, 4, 4};
	int rc[3][3] = {5, 5, 5, 5, 5, 5, 5, 5, 5};
	int lc[3][3] = {6, 6, 6, 6, 6, 6, 6, 6, 6};
};//白1黄2绿3蓝4红5橙6

string d3[20] = {
	"xx",
	"R", "R'", "R2",
	"L", "L'", "L2",
	"U", "U'", "U2",
	"D", "D'", "D2",
	"F", "F'", "F2",
	"B", "B'", "B2",
};
string d2[10] = {
	"xx",
	"R", "R'", "R2",
	"U", "U'", "U2",
	"F", "F'", "F2",
};

string dl3() {//生成三阶打乱
	int lst = -100, lstt = -200;
	string ans = "";
	for (int i = 1; i <= 20; i++) {
		int id = (rand() % 18) + 1;
		if ((lst - 1) / 3 == (id - 1) / 3 || ((lst - 1) / 6 == (id - 1) / 6 && (lstt - 1) / 3 == (id - 1) / 3)) {
			i--;
		}else {
			if (i != 1)ans += " ";
			ans += d3[id];lstt = lst;lst = id;
		}
	}return ans;
}

string dl2() {//生成2阶打乱
	int lst = -100;
	string ans = "";
	for (int i = 1; i <= 9; i++) {
		int id = (rand() % 9) + 1;
		if ((lst - 1) / 3 == (id - 1) / 3) {
			i--;
		}else {
			if (i != 1)ans += " ";
			ans += d2[id];lst = id;
		}
	}return ans;
}
int jmid;//1为主界面,2说明
int now_cid;
string now;
int lst_time;//上一个时间

void print_number(int x, int y, int num) {
	switch (num) {
		case 0:
			SetPos(x, y);
			printf("■■■");
			SetPos(x + 1, y);
			printf("■  ■");
			SetPos(x + 2, y);
			printf("■  ■");
			SetPos(x + 3, y);
			printf("■  ■");
			SetPos(x + 4, y);
			printf("■■■");
			break;
		case 1:
			SetPos(x, y);
			printf("■■  ");
			SetPos(x + 1, y);
			printf("  ■  ");
			SetPos(x + 2, y);
			printf("  ■  ");
			SetPos(x + 3, y);
			printf("  ■  ");
			SetPos(x + 4, y);
			printf("■■■");
			break;
		case 2:
			SetPos(x, y);
			printf("■■■");
			SetPos(x + 1, y);
			printf("    ■");
			SetPos(x + 2, y);
			printf("■■■");
			SetPos(x + 3, y);
			printf("■    ");
			SetPos(x + 4, y);
			printf("■■■");
			break;
		case 3:
			SetPos(x, y);
			printf("■■■");
			SetPos(x + 1, y);
			printf("    ■");
			SetPos(x + 2, y);
			printf("■■■");
			SetPos(x + 3, y);
			printf("    ■");
			SetPos(x + 4, y);
			printf("■■■");
			break;
		case 4:
			SetPos(x, y);
			printf("■  ■");
			SetPos(x + 1, y);
			printf("■  ■");
			SetPos(x + 2, y);
			printf("■■■");
			SetPos(x + 3, y);
			printf("    ■");
			SetPos(x + 4, y);
			printf("    ■");
			break;
		case 5:
			SetPos(x, y);
			printf("■■■");
			SetPos(x + 1, y);
			printf("■    ");
			SetPos(x + 2, y);
			printf("■■■");
			SetPos(x + 3, y);
			printf("    ■");
			SetPos(x + 4, y);
			printf("■■■");
			break;
		case 6:
			SetPos(x, y);
			printf("■■■");
			SetPos(x + 1, y);
			printf("■    ");
			SetPos(x + 2, y);
			printf("■■■");
			SetPos(x + 3, y);
			printf("■  ■");
			SetPos(x + 4, y);
			printf("■■■");
			break;
		case 7:
			SetPos(x, y);
			printf("■■■");
			SetPos(x + 1, y);
			printf("    ■");
			SetPos(x + 2, y);
			printf("    ■");
			SetPos(x + 3, y);
			printf("    ■");
			SetPos(x + 4, y);
			printf("    ■");
			break;
		case 8:
			SetPos(x, y);
			printf("■■■");
			SetPos(x + 1, y);
			printf("■  ■");
			SetPos(x + 2, y);
			printf("■■■");
			SetPos(x + 3, y);
			printf("■  ■");
			SetPos(x + 4, y);
			printf("■■■");
			break;
		case 9:
			SetPos(x, y);
			printf("■■■");
			SetPos(x + 1, y);
			printf("■  ■");
			SetPos(x + 2, y);
			printf("■■■");
			SetPos(x + 3, y);
			printf("    ■");
			SetPos(x + 4, y);
			printf("■■■");
			break;
	}
	return;
}

void print_time(int x, int col) {//col = 0:黑色 1:绿色(计时前)
//	system("cls");
	if (col)Color(2);
	if (x > 60000) {
		if (x < 60010)system("cls");
		Color(4);
		SetPos(4, 17);
		printf("■■■  ■    ■  ■■■");
		SetPos(5, 17);
		printf("  ■    ■■  ■  ■");
		SetPos(6, 17);
		printf("  ■    ■ ■ ■  ■■■");
		SetPos(7, 17);
		printf("  ■    ■  ■■  ■");
		SetPos(8, 17);
		printf("■■■  ■    ■  ■");
		Color(0);
	}else {
		if (x < 10000) {
			print_number(4, 17, (x / 1000) % 10);
			SetPos(8, 21);
			printf("■");
			print_number(4, 23, (x / 100) % 10);
			print_number(4, 27, (x / 10) % 10);
		}else {
			if (x < 10010)system("cls");
			print_number(4, 15, (x / 10000) % 10);
			print_number(4, 19, (x / 1000) % 10);
			SetPos(8, 23);
			printf("■");
			print_number(4, 25, (x / 100) % 10);
			print_number(4, 29, (x / 10) % 10);
		}
	}
	Color(0);
}

void print1() {
	SetPos(1, 1);
	printf("MsTimer v1.0");
	if (now_cid == 3)SetPos(1, 11);
	else if (now_cid == 2)SetPos(1, 18);
	cout << now;
	SetPos(2, 1);
	printf("说明[r]");
//	for (int i =1; i <= 200; i++)if (GetAsyncKeyState(i)&0x8000) cout << i;
	if (GetAsyncKeyState(82)&0x8000) {
		while (GetAsyncKeyState(82)&0x8000);
		jmid = 2;
		system("cls");
		return;
	}
//	for (int i = 1; i <= 200; i++) {
//		if (GetAsyncKeyState(i)&0x8000)cout << i;
//	}
	SetPos(2, 20);
	printf("换一条[↑]");
	if (GetAsyncKeyState(38)&0x8000) {
		while (GetAsyncKeyState(38)&0x8000);
		if (now_cid == 3)now = dl3();
		else if (now_cid == 2)now = dl2();
		system("cls");
	}
	SetPos(2, 26);
	if (now_cid == 3)printf("二阶[e]");
	else printf("三阶[e]");
	if (GetAsyncKeyState(69)&0x8000) {
		while (GetAsyncKeyState(69)&0x8000);
		if (now_cid == 3)now_cid = 2, now = dl2();
		else if (now_cid == 2)now_cid = 3, now = dl3();
		system("cls");
	}
	if (GetAsyncKeyState(32)&0x8000) {
		int temp1_time = clock();
		print_time(lst_time, 1);
		while (GetAsyncKeyState(32)&0x8000);
		system("cls");
		int temp2_time = clock();
		if (temp2_time - temp1_time > 500) {
			while (1) {
				int now_time = clock();
				print_time(now_time - temp2_time, 0);
				lst_time = now_time - temp2_time;
				if (GetAsyncKeyState(32)&0x8000) {
					while (GetAsyncKeyState(32)&0x8000);
					if (now_cid == 3)now = dl3();//一次计时完毕,自动切换打乱
					else if (now_cid == 2)now = dl2();
					system("cls");
					break;
				}
			}
		}
	}else {
		print_time(lst_time, 0);
	}
	return;
}
void print2() {
	SetPos(1, 1);
	printf("这是由Marshall开发的一款仿CSTimer 魔方虚拟计时器——MsTimer");
	SetPos(2, 1);
	printf("目前支持二阶、三阶的打乱及计时");//图示 
//	SetPos(3, 1);
//	printf("同时对于成绩计算三次及五次去尾平均");
//	SetPos(4, 1);
//	printf("按下数字键可更改左侧分组");
	SetPos(5, 1);
	printf("作者联系: Luogu uid 474470 & WeChat username wizardMarshall62442");
	SetPos(6, 1);
	printf("[r]返回");
	if (GetAsyncKeyState(82)&0x8000) {
		while (GetAsyncKeyState(82)&0x8000);
		jmid = 1;
		system("cls");
		return;
	}
	return;
}
signed main() {
	srand(time(NULL));
	system("mode con cols=100 lines=30");
	HideCursor();
	jmid = 1;now_cid = 3;
	now = dl3();
	while (1) {
		if (jmid == 1) {
			print1();
		}else if (jmid == 2) {
			print2();
		}
	}
	return 0;
}
原文