#include<iostream>
#include<time.h>
#include<conio.h>
#include<windows.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
namespace All{
void gotoxy(short x,short y){
COORD pos={x,y};
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut,pos);
}
void noedit(){
HANDLE hStdin=GetStdHandle(STD_INPUT_HANDLE);
DWORD mode;
GetConsoleMode(hStdin,&mode);
mode&=~ENABLE_QUICK_EDIT_MODE;
mode&=~ENABLE_INSERT_MODE;
mode&=~ENABLE_MOUSE_INPUT;
SetConsoleMode(hStdin,mode);
}
namespace ColorTable{
const int BULE=1;const int GREEN=2;
const int SBULE=3;const int RED=4;
const int PURPLE=5;const int YELLO=6;
const int WHITE=7;const int ASH=8;
const int SBBULE=9;const int BGREEN=10;
const int BBULE=11;const int SRED=12;
const int SPURPLE=13;const int BYELLO=14;
const int BWHITE=15;const int BLACK=16;
}
class Button{
int x;int y;int c;const char *n;int pc=-1;int pc_=-1;
void GetPos(POINT &pt){
HWND hwnd=GetForegroundWindow();
GetCursorPos(&pt);
ScreenToClient(hwnd,&pt);
pt.y=pt.y/16,pt.x=pt.x/16;
}
void gto(int x,int y){
COORD pos;pos.X=y*2;pos.Y=x;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
void color(int ForgC, int BackC){
WORD wColor=((BackC&0x0F)<<4)+(ForgC&0x0F);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),wColor);
}
public:
Button(){}
Button(int x_,int y_,int color,const char *neiron,int pcolor=-1,int tcolor=-1){
x=x_,y=y_,c=color,pc=pcolor;n=neiron;pc_=tcolor;
}
void New(int x_,int y_,int color,const char *neiron,int pcolor=-1,int tcolor=-1){
x=x_,y=y_,c=color,pc=pcolor;n=neiron;pc_=tcolor;
}
bool press(int q,int h){
POINT pt;
GetPos(pt);
if(pt.y==x&&(pt.x>=y&&pt.x<=(int)y+(int)strlen(n)/2)&&KEY_DOWN(VK_LBUTTON)){
gto(x,y);
color(c,pc);
std::printf("%s",n);
color(q,h);
return 1;
}
return 0;
}
bool touch(int q,int h){
POINT pt;
GetPos(pt);
if(pt.y==x&&(pt.x>=y&&pt.x<=(int)y+(int)strlen(n)/2)){
gto(x,y);
color(c,pc_);
std::printf("%s",n);
color(q,h);
return 1;
}
return 0;
}
void out(){
gto(x,y);
color(c,ColorTable::BLACK);
printf("%s",n);
}
};
}
using namespace std;
using namespace All;
void chouing(){
system("cls");
while(rand()%100){
gotoxy(15,15);
printf("%d",rand()%100);
Sleep(rand()%20);
}
}
int main(){
All::noedit();
system("color F0");
cerr<<"积分满一百,算你厉害\n(那时截图)\n";
system("pause");
double chuo=10;
time_t t;
time(&t);
double fen=0;
Button b(15,15,7,"抽奖",6,8);
while(1){
system("color F0");
system("cls");
if(time(NULL)-t>=300){
chuo++;
time(&t);
}
if(fen>=100){
cerr<<"恭喜你通关了!\n";
cerr<<"请截图私信!\n";
while(1){
switch(rand()%6){
case 0:
system("color 24");
break;
case 1:
system("color 42");
break;
case 2:
system("color 45");
break;
case 3:
system("color 53");
break;
case 4:
system("color 14");
break;
default:
system("color 65");
break;
}
Sleep(50);
}
}
cerr<<"当前分数:"<<fen;
cerr<<"\n剩余"<<chuo<<"次抽奖\n";
b.out();
if(b.touch(16,7),b.press(16,7)){
if(chuo-->=0){
chouing();
system("cls");
double _fen=rand()%50+rand()%10/100+rand()%10/1000+rand()%10/10000;
while(_fen+fen>=99){
_fen-=0.01;
}
if(fen>=99){
fen-=2;
_fen-=2;
}
char o[100]{};
sprintf(o,"恭喜你,抽到了%lf分!",_fen);
MessageBox(NULL,o,"大转盘",MB_OK);
fen+=_fen;
}else{
chuo=0;
}
}
Sleep(50);
}
}
注*:有点小Bug,如有大佬可以帮忙修改一下吗?