Dancing Line
欢迎来到 Daning Line!
目前编写了 6 个曲目,实现较为简陋,敬请谅解。
#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
#define keydown(Key)((GetAsyncKeyState(Key))?1:0)
#define setcolor(x) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),x)
using namespace std;
int SZ=50;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
inline void srand(){int*_=new int;srand(time(0)+*_);delete _;_=0;}
inline int bigrand(){return rand()*32768+rand();}
inline int randrange(int l,int r){return bigrand()%(r-l+1)+l;}
inline bool randpercentage(int p){return bigrand()%100<p;}
inline double rand01(){return bigrand()/32768.0/32768.0;}
inline void printcol(const char* s,int col=0x0f){setcolor(col);printf(s);setcolor(0x0f);}
void hidecursor(){CONSOLE_CURSOR_INFO cursor_info={1,0};SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);}
int stringtoint(string a)
{
static int ret;
ret=0;
for(int i=0;i<a.size();i++) ret=ret*10+a[i]-'0';
return ret;
}
string inttostring(int a)
{
static string ret;
ret="";
while(a)
{
ret+=char(a%10+'0');
a/=10;
}
reverse(ret.begin(),ret.end());
return ret;
}
void gotoxy(int x,int y)
{
COORD coord;
coord.X=x;coord.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
void printprogress(int len)
{
while(len>=8)
{
printf("█ ");
len-=8;
}
if(len==7) printf("▉ ");
if(len==6) printf("▊ ");
if(len==5) printf("▋ ");
if(len==4) printf("▌ ");
if(len==3) printf("▍ ");
if(len==2) printf("▎ ");
if(len==1) printf("▏ ");
}
inline void cls(){system("cls");gotoxy(0,0);}
int getkey()//↑921 ↓923 ←925 →926
{
static int ch;
if(_kbhit())
{
ch=_getch();
fflush(stdin);
if(ch==0 || ch==224)
{
ch=_getch();
if(ch==72) return 921;
if(ch==80) return 923;
if(ch==75) return 925;
if(ch==77) return 926;
}
else return ch;
}
return -1;
}
string getinputstring(int x,int y,string init="")
{
static int ch;
string ret=init;
while(1)
{
gotoxy(x,y);
for(int i=0;i<ret.size()+2;i++) printf(" ");
gotoxy(x,y);
cout<<ret;
while(1)
{
ch=getkey();
if(ch!=-1) break;
}
if(ch==8 && ret.size()) ret.pop_back();
if(isdigit(ch) || isalpha(ch)) ret.push_back(ch);
if(ch==10 || ch==13)
{
return ret;
}
}
}
vector<int> pos[1020];
template<int N>
struct game
{
char a[N+2][N+2];//0=wall 1=road 2=line
char lst[N+2][N+2];
int dir;
int stddir;
int stdx,stdy;
int stp;
int mid;
int sta;
int id;
int len;
map<int,int> mp;
void copy()
{
memcpy(lst,a,sizeof(a));
}
void print()
{
for(int i=1;i<=N;i++)
{
for(int j=1;j<=N;j++)
{
if(a[i][j]==lst[i][j]) continue;
gotoxy(j*2-2,i-1);
if(a[i][j]==0) printcol(" ",0xf0);
if(a[i][j]==1) printcol(" ",0x30);
if(a[i][j]==2) printcol(" ",0x40);
}
}
gotoxy(0,N+2);
static int pro;
pro=8.0*N*(stp+1)/len;
if(pro>N*8) pro=N*8;
gotoxy((pro-1)/8*2,N+2);
printprogress((pro-1)%8+1);
gotoxy(0,N+4);printf("Debug Info:");
gotoxy(0,N+6);printf("step : %d",stp);
}
void fill(int x,int y,int r,int v)
{
for(int i=x-r;i<=x+r;i++)
{
for(int j=y-r;j<=y+r;j++)
{
if(i<1 || i>N || j<1 || j>N) continue;
if(a[i][j]==2) continue;
a[i][j]=v;
}
}
}
void initialize(int _id)
{
memset(a,0,sizeof(a));
memset(lst,-1,sizeof(lst));
id=_id;
stddir=dir=len=0;
stp=798-1;
stdx=stdy=mid=N/2+1;
for(int i=0;i<16;i++) fill(stdx-i,stdy,2,1);
stdx-=16;
a[mid][mid]=2;
mp.clear();
for(int i=0;pos[id][i]!=-1;i++)
{
mp[pos[id][i]]=1;
len=max(len,pos[id][i]+1);
}
sta=0;
}
void turn()
{
dir^=1;
}
void move()
{
copy();
stp++;
if(mp.count(stp)) stddir^=1;
fill(stdx,stdy,2,1);
stdx+=dx[stddir];
stdy+=dy[stddir];
for(int i=N;i>=1;i--)
{
for(int j=1;j<=N;j++)
{
a[i][j]=a[i+dx[dir]][j+dy[dir]];
}
}
if(a[mid][mid]==0)
{
gotoxy(0,N+5);
Sleep(1000);
sta=1;
}
a[mid][mid]=2;
stdx-=dx[dir];
stdy-=dy[dir];
}
};
game<50> g;
void install(int id,...)
{
va_list va;
va_start(va,id);
static int tmp;
while(1)
{
tmp=va_arg(va,int);
pos[id].push_back(tmp);
if(tmp==-1) break;
}
va_end(va);
printf("\n");
}
void overview()
{
cls();
printf("Dancing Line\n\n");
printf("Designed and developed by Silvefish\n\n");
printf("Note: make sure your window size is big enough before playing!\n\n");
printf("Press spacebar to play\n");
}
int selectbarrier()
{
cls();
printf("Enter song id : ");
int ret;
cin>>ret;
return ret;
}
int main()
{
install(1,0,24,48,72,80,88,96,120,144,168,176,184,192,216,240,264,272,280,288,312,336,360,368,376,384,396,400,404,408,420,424,428,432,444,448,452,456,464,472,480,492,496,500,504,516,520,524,528,540,544,548,552,560,568,576,588,592,596,600,612,616,620,624,636,640,644,648,656,664,672,684,688,692,696,708,714,720,732,744,768,772,776,780,784,788,792,-1);
install(2,40,48,56,72,80,88,96,104,112,120,136,144,152,160,168,176,200,208,216,224,232,240,248,264,272,280,288,296,304,312,328,336,344,352,360,368,392,400,408,416,424,432,456,464,472,480,488,496,504,520,528,536,544,552,560,568,584,592,600,608,616,624,632,648,656,664,672,680,688,712,720,728,736,744,752,760,776,784,792,800,808,816,824,840,848,856,864,872,880,904,912,920,928,936,944,968,976,984,992,1000,1008,1016,1032,1048,1056,1064,1072,1080,1088,1104,1120,1136,1160,1168,1176,1184,1192,1200,1208,1216,1232,1248,1264,1288,1296,1304,1312,1320,1328,1336,1344,-1);
install(3,55,65,75,80,90,95,105,115,120,135,145,155,160,170,175,185,195,200,235,240,255,270,280,295,305,315,335,350,355,360,370,375,380,385,390,395,400,480,550,560,570,580,590,595,610,625,640,670,675,710,720,730,735,740,750,760,775,790,795,800,810,815,830,835,840,870,880,890,900,906,913,920,930,945,950,955,960,970,990,995,1000,1030,1040,1050,1055,1060,1070,1080,1095,1110,1115,1120,1130,1135,1150,1155,1160,1190,1200,1210,1220,1226,1233,1240,1250,1265,1270,1275,1280,1290,1295,1305,1315,1320,1420,1426,1433,1440,1500,1510,1520,1535,1580,1590,1600,1615,1650,1660,1670,1680,1730,1740,1746,1753,1760,1810,1820,1830,1840,1910,1915,1920,1930,1950,1955,1960,1965,1970,2000,2030,2040,2060,2066,2073,2080,2140,2150,2160,2175,2220,2230,2240,2255,2290,2300,2310,2320,2370,2380,2386,2393,2400,2450,2460,2470,2480,2545,2550,2555,2560,2570,2585,2590,2595,2600,2605,2610,2640,2650,2655,2670,2675,2680,-1);
install(4,0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,208,212,216,220,224,228,232,236,240,244,248,252,256,-1);
install(5,0,12,24,36,48,72,75,81,87,96,108,120,132,144,168,171,177,183,192,196,200,210,216,222,225,234,237,288,292,296,306,312,318,324,327,336,384,390,393,402,408,414,420,426,429,468,471,480,492,504,516,528,576,579,582,585,588,591,594,597,600,606,609,624,627,630,633,636,639,642,645,648,654,657,663,672,684,696,720,732,744,768,771,774,777,780,783,786,789,792,798,801,816,819,822,825,828,831,834,837,840,846,849,855,864,876,888,912,924,936,945,948,954,957,960,972,984,996,1008,1032,1035,1041,1047,1056,1068,1080,1092,1104,1110,1128,1131,1137,1143,1152,1158,1164,1170,1173,1182,1188,1194,1206,1248,1254,1260,1269,1272,1278,1284,1290,1293,1338,1344,1350,1353,1362,1368,1374,1380,1383,1386,1392,1422,1428,1434,1440,1452,1464,1476,1488,1536,1539,1542,1545,1548,1551,1554,1557,1560,1566,1569,1584,1587,1590,1593,1596,1599,1602,1605,1608,1614,1617,1623,1632,1644,1656,1680,1692,1704,1728,1731,1734,1737,1740,1743,1746,1749,1752,1758,1761,1776,1779,1782,1785,1788,1791,1794,1797,1800,1806,1809,1815,1824,1836,1848,1872,1884,1896,1914,1920,1926,1929,1938,1944,1950,1953,1968,1974,1977,1986,1992,1998,2001,2016,2022,2025,2034,2040,2052,2058,2064,2076,2088,2100,2112,2118,2121,2130,2136,2142,2145,2160,2166,2169,2178,2184,2190,2193,2208,2214,2217,2226,2232,2244,2250,2256,2268,2280,2292,2304,2328,2340,2352,2382,2388,2394,2400,2412,2424,2436,2448,2496,2499,2502,2505,2508,2511,2514,2517,2520,2526,2529,2544,2547,2550,2553,2556,2559,2562,2565,2568,2574,2577,2583,2592,2604,2616,2622,2628,2634,2640,2652,2664,2676,2682,2688,2691,2694,2697,2700,2703,2706,2709,2712,2718,2721,2736,2739,2742,2745,2748,2751,2754,2757,2760,2766,2769,2775,2784,2796,2808,2814,2820,2826,2832,2844,2856,2868,2874,2880,2883,2886,2889,2892,2895,2898,2901,2904,2910,2913,2928,2931,2934,2937,2940,2943,2946,2949,2952,2958,2961,2967,2976,2988,3000,3024,3036,3048,3072,3075,3078,3081,3084,3087,3090,3093,3096,3102,3105,3120,3123,3126,3129,3132,3135,3138,3141,3144,3150,3153,3159,3168,3180,3192,3216,3228,3240,3264,3267,3270,3273,3276,3279,3282,3285,3288,3294,3297,3312,3315,3318,3321,3324,3327,3330,3333,3336,3342,3345,3351,3360,3372,3384,3390,3396,3402,3405,3414,3432,3438,3441,3447,3450,3456,3459,3462,3465,3468,3471,3474,3477,3480,3486,3489,3504,3507,3510,3513,3516,3519,3522,3525,3528,3534,3537,3543,3552,3564,3576,3582,3588,3594,3597,3606,3624,3630,3633,3639,3642,3648,3660,3672,3684,3696,3720,3723,3729,3735,3744,3750,3756,3762,3768,3774,3780,3786,3792,3798,3804,3810,3816,3819,3825,3831,3837,3840,-1);
install(6,0,12,24,36,48,60,72,84,96,102,108,114,120,126,132,138,144,156,168,180,198,204,210,216,222,228,234,240,252,258,264,270,318,324,330,336,354,360,366,372,390,396,402,408,414,420,426,432,444,450,456,462,510,516,522,558,564,570,576,654,660,666,672,750,756,762,768,798,801,804,810,813,816,822,828,846,852,858,864,894,897,900,906,909,912,918,924,930,966,969,972,975,978,981,984,990,996,1002,1008,1014,1020,1023,1026,1029,1032,1038,1044,1050,1056,1062,1068,1074,1080,1086,1092,1098,1104,1110,1116,1119,1122,1125,1128,1134,1140,1146,1152,1158,1164,1170,1176,1182,1188,1194,1200,1206,1212,1215,1218,1221,1224,1230,1236,1242,1248,1254,1260,1266,1272,1278,1284,1290,1296,1302,1308,1311,1314,1317,1320,1326,1332,1338,1344,1350,1356,1362,1368,1374,1380,1386,1392,1398,1404,1407,1410,1413,1416,1422,1428,1434,1440,1446,1452,1458,1464,1470,1476,1482,1488,1494,1500,1503,1506,1509,1512,1518,1524,1530,1536,1542,1548,1554,1560,1566,1572,1578,1584,1590,1596,1599,1602,1605,1608,1614,1620,1626,1632,1638,1644,1650,1656,1662,1668,1674,1680,1686,1692,1695,1698,1701,1704,1710,1716,1722,1728,1734,1740,1746,-1);
static int ch;
while(1)
{
overview();
while(1)
{
ch=getkey();
if(ch==' ') break;
}
srand();
hidecursor();
g.initialize(selectbarrier());
g.print();
system("pause>nul");
int ch;
while(1)
{
int tmp=clock();
ch=getkey();
if(ch!=-1)
{
g.turn();
}
// if(g.mp.count(g.stp-15)) g.turn();
g.move();
g.print();
while(clock()-tmp<=0.04*CLOCKS_PER_SEC);
if(g.sta) break;
}
}
}