用Excel做的俄罗斯方块游戏
- 格式:xls
- 大小:60.00 KB
- 文档页数:1
2017-5-29ExcelVBA⼩游戏---恢复内容开始---转⼀个Excel VBA的⼩游戏,最近对excel有了更深⼊的了解,功能很强⼤,也刷新了我对待事情的态度。
⼀、准备界⾯我们先来把游戏界⾯准备好,选中前4⾏,⾏⾼调成50,这时候单元格就近似⼀个正⽅形。
然后给4*4的单元格加上全部框线,再加粗外框线。
字体改成微软雅⿊,加粗,居中。
第6⾏A列写上SCORE,C列写上MOVES,都加粗。
⼀般2048这样的游戏需要⽤状态机来实现,就是程序⽆限运⾏直到游戏结束。
在Excel中这种⽅法不太合适,使⽤⼯作表⾃带的Worksheet_SelectionChange⽅法来获取键盘状态使游戏往下进⾏更⽅便。
⼆、初始状态我们先来制作游戏的初始状态,游戏变量很少,需要⼀个4*4的⼆维数组,⽤来记录和操作盘⾯,⼀个score变量记录分数,⼀个moves变量记录步数。
初始状态就是让他们都为0,当然也可以加⼊历史最⾼纪录,不过考虑到在Excel单元格中记录可以随时修改,意义不⼤。
这⾥没有使⽤状态机,也就没有⽤类模块来做⾯向对象式编程,所以⽤全局变量来代替。
Public numAreaArrPublic score As DoublePublic moves As IntegerPublic Sub Reset()ReDim numAreaArr(1 To 4, 1 To 4) As Integerscore = 0moves = 0End Sub这只是变量的初始状态,我们还需要将它输出到单元格上,所以需要⼀个输出⽅法。
Public Sub Output(ByVal numArr, ByVal score As Double, ByVal moves As Integer)'界⾯输出Sheet1.Range("A1:D4") = numArrSheet1.Cells(6, 2) = scoreSheet1.Cells(6, 4) = movesEnd Sub游戏初始时,盘⾯上是有两个随机数字的,我们需要⼀个在空⽩地⽅随机⽣成数字2或4 的⽅法。
#include <stdio.h>#include <dos.h>#include <conio.h>#include <graphics.h>#include <stdlib.h>#ifdef__cplusplus#define __CPPARGS ...#else#define __CPPARGS#endif#define MINBOXSIZE 15 /* 最小方块的尺寸*/#define BGCOLOR 7 /* 背景着色*/#define GX 200#define GY 10#define SJNUM 10000 /* 每当玩家打到一万分等级加一级*/ /* 按键码*/#define VK_LEFT 0x4b00#define VK_RIGHT 0x4d00#define VK_DOWN 0x5000#define VK_UP 0x4800#define VK_HOME 0x4700#define VK_END 0x4f00#define VK_SPACE 0x3920#define VK_ESC 0x011b#define VK_ENTER 0x1c0d/* 定义俄罗斯方块的方向(我定义他为4种)*/#define F_DONG 0#define F_NAN 1#define F_XI 2#define F_BEI 3#define NEXTCOL 20 /* 要出的下一个方块的纵坐标*/#define NEXTROW 12 /* 要出的下一个方块的横从标*/#define MAXROW 14 /* 游戏屏幕大小*/#define MAXCOL 20#define SCCOL 100 /*游戏屏幕大显示器上的相对位置*/#define SCROW 60int gril[22][16]; /* 游戏屏幕坐标*/int col=1,row=7; /* 当前方块的横纵坐标*/int boxfx=0,boxgs=0; /* 当前寺块的形壮和方向*/int nextboxfx=0,nextboxgs=0,maxcol=22;/*下一个方块的形壮和方向*/ int minboxcolor=6,nextminboxcolor=6;int num=0; /*游戏分*/int dj=0,gamedj[10]={18,16,14,12,10,8,6,4,2,1};/* 游戏等级*//* 以下我用了一个3维数组来纪录方块的最初形状和方向*/int boxstr[7][4][16]={{{1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0},{0,1,0,0,1,1,0,0,1,0,0,0,0,0,0,0},{1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0},{0,1,0,0,1,1,0,0,1,0,0,0,0,0,0,0}},{{0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0},{1,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0},{0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0},{1,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0}},{{1,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0},{1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0},{1,0,0,0,1,0,0,0,1,1,0,0,0,0,0,0},{0,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0}},{{1,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0},{1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0},{0,1,0,0,0,1,0,0,1,1,0,0,0,0,0,0},{1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0}},{{0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0},{0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0},{0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0},{0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0}},{{1,1,0,0,1,1,0,0,0,0,0,0.0,0,0,0},{1,1,0,0,1,1,0,0,0,0,0,0.0,0,0,0},{1,1,0,0,1,1,0,0,0,0,0,0.0,0,0,0},{1,1,0,0,1,1,0,0,0,0,0,0.0,0,0,0}},{{0,0,0,0,1,1,1,0,0,1,0,0,0,0,0,0},{1,0,0,0,1,1,0,0,1,0,0,0,0,0,0,0},{0,1,0,0,1,1,1,0,0,0,0,0.0,0,0,0},{0,1,0,0,1,1,0,0,0,1,0,0,0,0,0,0}}};/* 随机得到当前方块和下一个方块的形状和方向*/void boxrad(){minboxcolor=nextminboxcolor;boxgs=nextboxgs;boxfx=nextboxfx;nextminboxcolor=random(14)+1;if(nextminboxcolor==4||nextminboxcolor==7||nextminboxcolor==8) nextminboxcolor=9;nextboxfx=F_DONG;nextboxgs=random(7);}/*初始化图形模试*/void init(int gdrive,int gmode){int errorcode;initgraph(&gdrive,&gmode,"e:\\tc");errorcode=graphresult();if(errorcode!=grOk){printf("error of: %s",grapherrormsg(errorcode));exit(1);}}/* 在图形模式下的清屏*/void cls(){setfillstyle(SOLID_FILL,0);setcolor(0);bar(0,0,640,480);}/*在图形模式下的高级清屏*/void clscr(int a,int b,int c,int d,int color){setfillstyle(SOLID_FILL,color);setcolor(color);bar(a,b,c,d);}/*最小方块的绘制*/void minbox(int asc,int bsc,int color,int bdcolor){int a=0,b=0;a=SCCOL+asc;b=SCROW+bsc;clscr(a+1,b+1,a-1+MINBOXSIZE,b-1+MINBOXSIZE,color);if(color!=BGCOLOR){setcolor(bdcolor);line(a+1,b+1,a-1+MINBOXSIZE,b+1);line(a+1,b+1,a+1,b-1+MINBOXSIZE);line(a-1+MINBOXSIZE,b+1,a-1+MINBOXSIZE,b-1+MINBOXSIZE); line(a+1,b-1+MINBOXSIZE,a-1+MINBOXSIZE,b-1+MINBOXSIZE); }}/*游戏中出现的文字*/void txt(int a,int b,char *txt,int font,int color){setcolor(color);settextstyle(0,0,font);outtextxy(a,b,txt);}/*windows 绘制*/void win(int a,int b,int c,int d,int bgcolor,int bordercolor){clscr(a,b,c,d,bgcolor);setcolor(bordercolor);line(a,b,c,b);line(a,b,a,d);line(a,d,c,d);line(c,b,c,d);}/* 当前方块的绘制*/void funbox(int a,int b,int color,int bdcolor){int i,j;int boxz[4][4];for(i=0;i<16;i++)boxz[i/4][i%4]=boxstr[boxgs][boxfx][i];for(i=0;i<4;i++)for(j=0;j<4;j++)if(boxz[i][j]==1)minbox((j+row+a)*MINBOXSIZE,(i+col+b)*MINBOXSIZE,color,bdcolor); }/*下一个方块的绘制*/void nextfunbox(int a,int b,int color,int bdcolor){int i,j;int boxz[4][4];for(i=0;i<16;i++)boxz[i/4][i%4]=boxstr[nextboxgs][nextboxfx][i];for(i=0;i<4;i++)for(j=0;j<4;j++)if(boxz[i][j]==1)minbox((j+a)*MINBOXSIZE,(i+b)*MINBOXSIZE,color,bdcolor);}/*时间中断定义*/#define TIMER 0x1cint TimerCounter=0;void interrupt ( *oldhandler)(__CPPARGS);void interrupt newhandler(__CPPARGS){TimerCounter++;oldhandler();}void SetTimer(void interrupt (*IntProc)(__CPPARGS)){oldhandler=getvect(TIMER);disable();setvect(TIMER,IntProc);enable();}/*由于游戏的规则,消掉都有最小方块的一行*/void delcol(int a){int i,j;for(i=a;i>1;i--)for(j=1;j<15;j++){minbox(j*MINBOXSIZE,i*MINBOXSIZE,BGCOLOR,BGCOLOR);gril[i][j]=gril[i-1][j];if(gril[i][j]==1)minbox(j*MINBOXSIZE,i*MINBOXSIZE,minboxcolor,0);}/*消掉所有都有最小方块的行*/ void delete(){int i,j,zero,delgx=0;char *nm="00000";for(i=1;i<21;i++){zero=0;for(j=1;j<15;j++)if(gril[j]==0)zero=1;if(zero==0){delcol(i);delgx++;}}num=num+delgx*delgx*10;dj=num/10000;sprintf(nm,"%d",num);clscr(456,173,500,200,4);txt(456,173,"Number:",1,15);txt(456,193,nm,1,15);}/*时间中断结束*/void KillTimer(){disable();setvect(TIMER,oldhandler); enable();}/* 测试当前方块是否可以向下落*/ int downok(){int i,j,k=1,a[4][4];for(i=0;i<16;i++)a[i/4][i%4]=boxstr[boxgs][boxfx][i]; for(i=0;i<4;i++)for(j=0;j<4;j++)if(a[j] && gril[col+i+1][row+j])k=0;return(k);/* 测试当前方块是否可以向左行*/int leftok(){int i,j,k=1,a[4][4];for(i=0;i<16;i++)a[i/4][i%4]=boxstr[boxgs][boxfx][i];for(i=0;i<4;i++)for(j=0;j<4;j++)if(a[j] && gril[col+i][row+j-1])k=0;return(k);}/* 测试当前方块是否可以向右行*/int rightok(){int i,j,k=1,a[4][4];for(i=0;i<16;i++)a[i/4][i%4]=boxstr[boxgs][boxfx][i];for(i=0;i<4;i++)for(j=0;j<4;j++)if(a[j] && gril[col+i][row+j+1])k=0;return(k);}/* 测试当前方块是否可以变形*/int upok(){int i,j,k=1,a[4][4];for(i=0;i<4;i++)for(i=0;i<16;i++)a[i/4][i%4]=boxstr[boxgs][boxfx+1][i];for(i=3;i>=0;i--)for(j=3;j>=0;j--)if(a[j] && gril[col+i][row+j])k=0;return(k);}/*当前方块落下之后,给屏幕坐标作标记*/ void setgril(){int i,j,a[4][4];funbox(0,0,minboxcolor,0);for(i=0;i<16;i++)a[i/4][i%4]=boxstr[boxgs][boxfx][i];for(i=0;i<4;i++)for(j=0;j<4;j++)if(a[j])gril[col+i][row+j]=1;col=1;row=7;}/*游戏结束*/void gameover(){int i,j;for(i=20;i>0;i--)for(j=1;j<15;j++)minbox(j*MINBOXSIZE,i*MINBOXSIZE,2,0);txt(103,203,"Game Over",3,10);}/*按键的设置*/void call_key(int keyx){switch(keyx){case VK_DOWN: { /*下方向键,横坐标加一。
俄罗斯⽅块代码1 #include<iostream>2 #include<string>3 #include<ctime>4 #include<cstdlib>5 #include<windows.h>6 #include<conio.h>78using namespace std;910int block00[4][4] = { { 10,0,0,0 },{ 1,1,1,1 },{ 0,0,0,0 },{ 0,0,0,0 } };11int block01[4][4] = { { 11,0,1,0 },{ 0,0,1,0 },{ 0,0,1,0 },{ 0,0,1,0 } };12int block02[4][4] = { { 12,0,0,0 },{ 0,0,0,0 },{ 1,1,1,0 },{ 0,1,0,0 } };13int block03[4][4] = { { 13,0,0,0 },{ 0,1,0,0 },{ 1,1,0,0 },{ 0,1,0,0 } };14int block04[4][4] = { { 14,0,0,0 },{ 0,0,0,0 },{ 0,1,0,0 },{ 1,1,1,0 } };15int block05[4][4] = { { 15,0,0,0 },{ 0,1,0,0 },{ 0,1,1,0 },{ 0,1,0,0 } };16int block06[4][4] = { { 16,0,0,0 },{ 0,0,0,0 },{ 1,1,1,0 },{ 1,0,0,0 } };17int block07[4][4] = { { 17,0,0,0 },{ 1,1,0,0 },{ 0,1,0,0 },{ 0,1,0,0 } };18int block08[4][4] = { { 18,0,0,0 },{ 0,0,0,0 },{ 0,0,1,0 },{ 1,1,1,0 } };19int block09[4][4] = { { 19,0,0,0 },{ 0,1,0,0 },{ 0,1,0,0 },{ 0,1,1,0 } };20int block10[4][4] = { { 20,0,0,0 },{ 0,0,0,0 },{ 1,1,1,0 },{ 0,0,1,0 } };21int block11[4][4] = { { 21,0,0,0 },{ 0,1,0,0 },{ 0,1,0,0 },{ 1,1,0,0 } };22int block12[4][4] = { { 22,0,0,0 },{ 0,0,0,0 },{ 1,0,0,0 },{ 1,1,1,0 } };23int block13[4][4] = { { 23,0,0,0 },{ 0,1,1,0 },{ 0,1,0,0 },{ 0,1,0,0 } };24int block14[4][4] = { { 24,0,0,0 },{ 0,0,0,0 },{ 0,1,1,0 },{ 1,1,0,0 } };25int block15[4][4] = { { 25,0,0,0 },{ 1,0,0,0 },{ 1,1,0,0 },{ 0,1,0,0 } };26int block16[4][4] = { { 26,0,0,0 },{ 0,0,0,0 },{ 1,1,0,0 },{ 0,1,1,0 } };27int block17[4][4] = { { 27,0,0,0 },{ 0,0,1,0 },{ 0,1,1,0 },{ 0,1,0,0 } };28int block18[4][4] = { { 28,0,0,0 },{ 0,0,0,0 },{ 1,1,0,0 },{ 1,1,0,0 } };2930void initialWindow(HANDLE hOut);//初始化窗⼝31void initialPrint(HANDLE hOut);//初始化界⾯32void gotoXY(HANDLE hOut, int x, int y);//移动光标33void roundBlock(HANDLE hOut, int block[4][4]);//随机⽣成⽅块并打印到下⼀个⽅块位置34bool collisionDetection(int block[4][4], int map[21][12], int x, int y);//检测碰撞35void printBlock(HANDLE hOut, int block[4][4], int x, int y);//打印⽅块36void clearBlock(HANDLE hOut, int block[4][4], int x, int y);//消除⽅块37void myLeft(HANDLE hOut, int block[4][4], int map[21][12], int x, int &y);//左移38void myRight(HANDLE hOut, int block[4][4], int map[21][12], int x, int &y);//右移39void myUp(HANDLE hOut, int block[4][4], int map[21][12], int x, int &y);//顺时针旋转90度40int myDown(HANDLE hOut, int block[4][4], int map[21][12], int &x, int y);//加速下落41void myStop(HANDLE hOut, int block[4][4]);//游戏暂停42void gameOver(HANDLE hOut, int block[4][4], int map[21][12]);//游戏结束43void eliminateRow(HANDLE hOut, int map[21][12], int &val, int &fraction, int &checkpoint);//判断是否能消⾏并更新分值 44int main()45 {46int map[21][12];47int blockA[4][4];//候选区的⽅块48int blockB[4][4];//下落中的⽅块49int positionX, positionY;//⽅块左上⾓的坐标50bool check;//检查⽅块还能不能下落51char key;//⽤来存储按键52int val;//⽤来控制下落速度53int fraction;//⽤来存储得分54int checkpoint;//⽤来存储关卡55int times;56 HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);//获取标准输出设备句柄57 initialWindow(hOut);58 initial:59 gotoXY(hOut, 0, 0);60 initialPrint(hOut);61 check = true;62 val = 50;63 fraction = 0;64 checkpoint = 1;65 times = val;66for (int i = 0; i < 20; ++i)67 {68for (int j = 1; j < 11; ++j)69 {70 map[i][j] = 0;71 }72 }73for (int i = 0; i < 20; ++i)74 {75 map[i][0] = map[i][11] = 1;76 }77for (int i = 0; i < 12; ++i)78 {8182 srand((unsigned)time(NULL));83 roundBlock(hOut, blockA);84while (true)85 {86if (check)87 {88 eliminateRow(hOut, map, val, fraction, checkpoint);89 check = false;90 positionX = -3;91 positionY = 4;92if (collisionDetection(blockA, map, positionX, positionY))93 {94for (int i = 0; i < 4; ++i)95 {96for (int j = 0; j < 4; ++j)97 {98 blockB[i][j] = blockA[i][j];99 }100 }101 roundBlock(hOut, blockA);102 }103else104 {105 gameOver(hOut, blockA, map);106goto initial;107 }108 }109 printBlock(hOut, blockB, positionX, positionY);110if (_kbhit())111 {112 key = _getch();113switch (key)114 {115case72:116 myUp(hOut, blockB, map, positionX, positionY);117break;118case75:119 myLeft(hOut, blockB, map, positionX, positionY);120break;121case77:122 myRight(hOut, blockB, map, positionX, positionY);123break;124case80:125switch (myDown(hOut, blockB, map, positionX, positionY)) 126 {127case0:128 check = false;129break;130case1:131 check = true;132break;133case2:134 gameOver(hOut, blockB, map);135goto initial;136default:137break;138 }139break;140case32:141 myStop(hOut, blockA);142break;143case27:144 exit(0);145default:146break;147 }148 }149 Sleep(20);150if (0 == --times)151 {152switch (myDown(hOut, blockB, map, positionX, positionY)) 153 {154case0:155 check = false;156break;157case1:158 check = true;159break;160case2:161 gameOver(hOut, blockB, map);162goto initial;166 times = val;167 }168 }169 cin.get();170return0;171 }172173void initialWindow(HANDLE hOut)174 {175 SetConsoleTitle("俄罗斯⽅块");176 COORD size = { 80, 25 };177 SetConsoleScreenBufferSize(hOut, size);178 SMALL_RECT rc = { 0, 0, 79, 24 };179 SetConsoleWindowInfo(hOut, true, &rc);180 CONSOLE_CURSOR_INFO cursor_info = { 1, 0 };181 SetConsoleCursorInfo(hOut, &cursor_info);182 }183184void initialPrint(HANDLE hOut)185 {186 SetConsoleTextAttribute(hOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); 187for (int i = 0; i < 20; ++i)188 {189 cout << "■■☆☆" << endl;190 }191 gotoXY(hOut, 26, 0);192 cout << "☆☆☆☆☆☆☆☆☆☆☆";193 gotoXY(hOut, 0, 20);194 cout << "■■■■■■■■■■■■☆☆☆☆☆☆☆☆☆☆☆☆☆";195 gotoXY(hOut, 26, 1);196 cout << "分数: ";197 gotoXY(hOut, 26, 2);198 cout << "关卡: ";199 gotoXY(hOut, 26, 4);200 cout << "下⼀⽅块:";201 gotoXY(hOut, 26, 9);202 cout << "操作⽅法:";203 gotoXY(hOut, 30, 11);204 cout << "↑:旋转↓:速降";205 gotoXY(hOut, 30, 12);206 cout << "→:右移←:左移";207 gotoXY(hOut, 30, 13);208 cout << "空格键:开始/暂停";209 gotoXY(hOut, 30, 14);210 cout << "Esc 键:退出";211 gotoXY(hOut, 26, 16);212 cout << "关于:";213 gotoXY(hOut, 30, 18);214 cout << "俄罗斯⽅块V1.0";215 gotoXY(hOut, 35, 19);216 cout << "作者:潘约尔";217 }218219void gotoXY(HANDLE hOut, int x, int y)220 {221 COORD pos;222 pos.X = x;223 pos.Y = y;224 SetConsoleCursorPosition(hOut, pos);225 }226227void roundBlock(HANDLE hOut, int block[4][4])228 {229 clearBlock(hOut, block, 5, 15);230switch (rand() % 19)231 {232case0:233for (int i = 0; i < 4; ++i)234 {235for (int j = 0; j < 4; ++j)236 {237 block[i][j] = block00[i][j];238 }239 }240break;241case1:242for (int i = 0; i < 4; ++i)243 {244for (int j = 0; j < 4; ++j)245 {246 block[i][j] = block01[i][j];250case2:251for (int i = 0; i < 4; ++i)252 {253for (int j = 0; j < 4; ++j)254 {255 block[i][j] = block02[i][j]; 256 }257 }258break;259case3:260for (int i = 0; i < 4; ++i)261 {262for (int j = 0; j < 4; ++j)263 {264 block[i][j] = block03[i][j]; 265 }266 }267break;268case4:269for (int i = 0; i < 4; ++i)270 {271for (int j = 0; j < 4; ++j)272 {273 block[i][j] = block04[i][j]; 274 }275 }276break;277case5:278for (int i = 0; i < 4; ++i)279 {280for (int j = 0; j < 4; ++j)281 {282 block[i][j] = block05[i][j]; 283 }284 }285break;286case6:287for (int i = 0; i < 4; ++i)288 {289for (int j = 0; j < 4; ++j)290 {291 block[i][j] = block06[i][j]; 292 }293 }294break;295case7:296for (int i = 0; i < 4; ++i)297 {298for (int j = 0; j < 4; ++j)299 {300 block[i][j] = block07[i][j]; 301 }302 }303break;304case8:305for (int i = 0; i < 4; ++i)306 {307for (int j = 0; j < 4; ++j)308 {309 block[i][j] = block08[i][j]; 310 }311 }312break;313case9:314for (int i = 0; i < 4; ++i)315 {316for (int j = 0; j < 4; ++j)317 {318 block[i][j] = block09[i][j]; 319 }320 }321break;322case10:323for (int i = 0; i < 4; ++i)324 {325for (int j = 0; j < 4; ++j)326 {327 block[i][j] = block10[i][j]; 328 }329 }330break;333 {334for (int j = 0; j < 4; ++j)335 {336 block[i][j] = block11[i][j];337 }338 }339break;340case12:341for (int i = 0; i < 4; ++i)342 {343for (int j = 0; j < 4; ++j)344 {345 block[i][j] = block12[i][j];346 }347 }348break;349case13:350for (int i = 0; i < 4; ++i)351 {352for (int j = 0; j < 4; ++j)353 {354 block[i][j] = block13[i][j];355 }356 }357break;358case14:359for (int i = 0; i < 4; ++i)360 {361for (int j = 0; j < 4; ++j)362 {363 block[i][j] = block14[i][j];364 }365 }366break;367case15:368for (int i = 0; i < 4; ++i)369 {370for (int j = 0; j < 4; ++j)371 {372 block[i][j] = block15[i][j];373 }374 }375break;376case16:377for (int i = 0; i < 4; ++i)378 {379for (int j = 0; j < 4; ++j)380 {381 block[i][j] = block16[i][j];382 }383 }384break;385case17:386for (int i = 0; i < 4; ++i)387 {388for (int j = 0; j < 4; ++j)389 {390 block[i][j] = block17[i][j];391 }392 }393break;394case18:395for (int i = 0; i < 4; ++i)396 {397for (int j = 0; j < 4; ++j)398 {399 block[i][j] = block18[i][j];400 }401 }402break;403default:404break;405 }406 printBlock(hOut, block, 5, 15);407 }408409bool collisionDetection(int block[4][4], int map[21][12], int x, int y) 410 {411for (int i = 0; i < 4; ++i)412 {413for (int j = 0; j < 4; ++j)414 {417return false;418 }419 }420 }421return true;422 }423424void printBlock(HANDLE hOut, int block[4][4], int x, int y)425 {426switch (block[0][0])427 {428case10:429case11:430 SetConsoleTextAttribute(hOut, FOREGROUND_GREEN);431break;432case12:433case13:434case14:435case15:436 SetConsoleTextAttribute(hOut, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY); 437break;438case16:439case17:440case18:441case19:442 SetConsoleTextAttribute(hOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY); 443break;444case20:445case21:446case22:447case23:448 SetConsoleTextAttribute(hOut, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);449break;450case24:451case25:452 SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | FOREGROUND_INTENSITY);453break;454case26:455case27:456 SetConsoleTextAttribute(hOut, FOREGROUND_BLUE | FOREGROUND_INTENSITY);457break;458case28:459 SetConsoleTextAttribute(hOut, FOREGROUND_RED | FOREGROUND_INTENSITY);460break;461default:462break;463 }464for (int i = 0; i < 4; ++i)465 {466if (i + x >= 0)467 {468for (int j = 0; j < 4; ++j)469 {470if (block[i][j] == 1)471 {472473 gotoXY(hOut, 2 * (y + j), x + i);474 cout << "■";475 }476 }477 }478 }479 }480481void clearBlock(HANDLE hOut, int block[4][4], int x, int y)482 {483for (int i = 0; i < 4; ++i)484 {485if (i + x >= 0)486 {487for (int j = 0; j < 4; ++j)488 {489if (block[i][j] == 1)490 {491 gotoXY(hOut, 2 * (y + j), x + i);492 cout << "";493 }494 }495 }496 }497 }498501 SetConsoleTextAttribute(hOut, FOREGROUND_RED | FOREGROUND_INTENSITY);502 gotoXY(hOut, 9, 8);503 cout << "GAME OVER";504 gotoXY(hOut, 8, 9);505 cout << "空格键:重来";506 gotoXY(hOut, 8, 10);507 cout << "ESC键:退出";508char key;509while (true)510 {511 key = _getch();512if (key == 32)513 {514return;515 }516if (key == 27)517 {518 exit(0);519 }520 }521 }522523int myDown(HANDLE hOut, int block[4][4], int map[21][12], int &x, int y)524 {525if (collisionDetection(block, map, x + 1, y))526 {527 clearBlock(hOut, block, x, y);528 ++x;529return0;530 }531if (x < 0)532 {533return2;534 }535for (int i = 0; i < 4; ++i)536 {537for (int j = 0; j < 4; ++j)538 {539if (block[i][j] == 1)540 {541 map[x + i][y + j] = 1;542 SetConsoleTextAttribute(hOut, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY); 543 gotoXY(hOut, 2 * (y + j), x + i);544 cout << "■";545 }546 }547 }548return1;549 }550551void myLeft(HANDLE hOut, int block[4][4], int map[21][12], int x, int &y)552 {553if (collisionDetection(block, map, x, y - 1))554 {555 clearBlock(hOut, block, x, y);556 --y;557 }558 }559560void myRight(HANDLE hOut, int block[4][4], int map[21][12], int x, int &y)561 {562if (collisionDetection(block, map, x, y + 1))563 {564 clearBlock(hOut, block, x, y);565 ++y;566 }567 }568569void myUp(HANDLE hOut, int block[4][4], int map[21][12], int x, int &y)570 {571switch (block[0][0])572 {573case10:574if (collisionDetection(block01, map, x, y))575 {576 clearBlock(hOut, block, x, y);577for (int i = 0; i < 4; ++i)578 {579for (int j = 0; j < 4; ++j)580 {581 block[i][j] = block01[i][j];582 }586case11:587if (collisionDetection(block00, map, x, y))588 {589 clearBlock(hOut, block, x, y);590for (int i = 0; i < 4; ++i)591 {592for (int j = 0; j < 4; ++j)593 {594 block[i][j] = block00[i][j];595 }596 }597 }598else if (collisionDetection(block00, map, x, y - 1)) 599 {600 clearBlock(hOut, block, x, y);601for (int i = 0; i < 4; ++i)602 {603for (int j = 0; j < 4; ++j)604 {605 block[i][j] = block00[i][j];606 }607 }608 --y;609 }610else if (collisionDetection(block00, map, x, y + 1)) 611 {612 clearBlock(hOut, block, x, y);613for (int i = 0; i < 4; ++i)614 {615for (int j = 0; j < 4; ++j)616 {617 block[i][j] = block00[i][j];618 }619 }620 ++y;621 }622else if (collisionDetection(block00, map, x, y - 2)) 623 {624 clearBlock(hOut, block, x, y);625for (int i = 0; i < 4; ++i)626 {627for (int j = 0; j < 4; ++j)628 {629 block[i][j] = block00[i][j];630 }631 }632 y = y - 2;633 }634else if (collisionDetection(block00, map, x, y + 2)) 635 {636 clearBlock(hOut, block, x, y);637for (int i = 0; i < 4; ++i)638 {639for (int j = 0; j < 4; ++j)640 {641 block[i][j] = block00[i][j];642 }643 }644 y = y + 2;645 }646break;647case12:648if (collisionDetection(block03, map, x, y))649 {650 clearBlock(hOut, block, x, y);651for (int i = 0; i < 4; ++i)652 {653for (int j = 0; j < 4; ++j)654 {655 block[i][j] = block03[i][j];656 }657 }658 }659else if (collisionDetection(block03, map, x, y - 1)) 660 {661 clearBlock(hOut, block, x, y);662for (int i = 0; i < 4; ++i)663 {664for (int j = 0; j < 4; ++j)665 {666 block[i][j] = block03[i][j];671else if (collisionDetection(block03, map, x, y + 1)) 672 {673 clearBlock(hOut, block, x, y);674for (int i = 0; i < 4; ++i)675 {676for (int j = 0; j < 4; ++j)677 {678 block[i][j] = block03[i][j];679 }680 }681 ++y;682 }683break;684case13:685if (collisionDetection(block04, map, x, y))686 {687 clearBlock(hOut, block, x, y);688for (int i = 0; i < 4; ++i)689 {690for (int j = 0; j < 4; ++j)691 {692 block[i][j] = block04[i][j];693 }694 }695 }696else if (collisionDetection(block04, map, x, y - 1)) 697 {698 clearBlock(hOut, block, x, y);699for (int i = 0; i < 4; ++i)700 {701for (int j = 0; j < 4; ++j)702 {703 block[i][j] = block04[i][j];704 }705 }706 --y;707 }708else if (collisionDetection(block04, map, x, y + 1)) 709 {710 clearBlock(hOut, block, x, y);711for (int i = 0; i < 4; ++i)712 {713for (int j = 0; j < 4; ++j)714 {715 block[i][j] = block04[i][j];716 }717 }718 ++y;719 }720break;721case14:722if (collisionDetection(block05, map, x, y))723 {724 clearBlock(hOut, block, x, y);725for (int i = 0; i < 4; ++i)726 {727for (int j = 0; j < 4; ++j)728 {729 block[i][j] = block05[i][j];730 }731 }732 }733else if (collisionDetection(block05, map, x, y - 1)) 734 {735 clearBlock(hOut, block, x, y);736for (int i = 0; i < 4; ++i)737 {738for (int j = 0; j < 4; ++j)739 {740 block[i][j] = block05[i][j];741 }742 }743 --y;744 }745else if (collisionDetection(block05, map, x, y + 1)) 746 {747 clearBlock(hOut, block, x, y);748for (int i = 0; i < 4; ++i)749 {750for (int j = 0; j < 4; ++j)755 ++y;756 }757break;758case15:759if (collisionDetection(block02, map, x, y))760 {761 clearBlock(hOut, block, x, y);762for (int i = 0; i < 4; ++i)763 {764for (int j = 0; j < 4; ++j)765 {766 block[i][j] = block02[i][j];767 }768 }769 }770else if (collisionDetection(block02, map, x, y - 1)) 771 {772 clearBlock(hOut, block, x, y);773for (int i = 0; i < 4; ++i)774 {775for (int j = 0; j < 4; ++j)776 {777 block[i][j] = block02[i][j];778 }779 }780 --y;781 }782else if (collisionDetection(block02, map, x, y + 1)) 783 {784 clearBlock(hOut, block, x, y);785for (int i = 0; i < 4; ++i)786 {787for (int j = 0; j < 4; ++j)788 {789 block[i][j] = block02[i][j];790 }791 }792 ++y;793 }794break;795796case16:797if (collisionDetection(block07, map, x, y))798 {799 clearBlock(hOut, block, x, y);800for (int i = 0; i < 4; ++i)801 {802for (int j = 0; j < 4; ++j)803 {804 block[i][j] = block07[i][j];805 }806 }807 }808else if (collisionDetection(block07, map, x, y - 1)) 809 {810 clearBlock(hOut, block, x, y);811for (int i = 0; i < 4; ++i)812 {813for (int j = 0; j < 4; ++j)814 {815 block[i][j] = block07[i][j];816 }817 }818 --y;819 }820else if (collisionDetection(block07, map, x, y + 1)) 821 {822 clearBlock(hOut, block, x, y);823for (int i = 0; i < 4; ++i)824 {825for (int j = 0; j < 4; ++j)826 {827 block[i][j] = block07[i][j];828 }829 }830 ++y;831 }832break;833case17:834if (collisionDetection(block08, map, x, y))837for (int i = 0; i < 4; ++i)838 {839for (int j = 0; j < 4; ++j)840 {841 block[i][j] = block08[i][j];842 }843 }844 }845else if (collisionDetection(block08, map, x, y - 1)) 846 {847 clearBlock(hOut, block, x, y);848for (int i = 0; i < 4; ++i)849 {850for (int j = 0; j < 4; ++j)851 {852 block[i][j] = block08[i][j];853 }854 }855 --y;856 }857else if (collisionDetection(block08, map, x, y + 1)) 858 {859 clearBlock(hOut, block, x, y);860for (int i = 0; i < 4; ++i)861 {862for (int j = 0; j < 4; ++j)863 {864 block[i][j] = block08[i][j];865 }866 }867 ++y;868 }869break;870case18:871if (collisionDetection(block09, map, x, y))872 {873 clearBlock(hOut, block, x, y);874for (int i = 0; i < 4; ++i)875 {876for (int j = 0; j < 4; ++j)877 {878 block[i][j] = block09[i][j];879 }880 }881 }882else if (collisionDetection(block09, map, x, y - 1)) 883 {884 clearBlock(hOut, block, x, y);885for (int i = 0; i < 4; ++i)886 {887for (int j = 0; j < 4; ++j)888 {889 block[i][j] = block09[i][j];890 }891 }892 --y;893 }894else if (collisionDetection(block09, map, x, y + 1)) 895 {896 clearBlock(hOut, block, x, y);897for (int i = 0; i < 4; ++i)898 {899for (int j = 0; j < 4; ++j)900 {901 block[i][j] = block09[i][j];902 }903 }904 ++y;905 }906break;907case19:908if (collisionDetection(block06, map, x, y))909 {910 clearBlock(hOut, block, x, y);911for (int i = 0; i < 4; ++i)912 {913for (int j = 0; j < 4; ++j)914 {915 block[i][j] = block06[i][j];916 }921 clearBlock(hOut, block, x, y);922for (int i = 0; i < 4; ++i)923 {924for (int j = 0; j < 4; ++j)925 {926 block[i][j] = block06[i][j];927 }928 }929 --y;930 }931else if (collisionDetection(block06, map, x, y + 1)) 932 {933 clearBlock(hOut, block, x, y);934for (int i = 0; i < 4; ++i)935 {936for (int j = 0; j < 4; ++j)937 {938 block[i][j] = block06[i][j];939 }940 }941 ++y;942 }943break;944case20:945if (collisionDetection(block11, map, x, y))946 {947 clearBlock(hOut, block, x, y);948for (int i = 0; i < 4; ++i)949 {950for (int j = 0; j < 4; ++j)951 {952 block[i][j] = block11[i][j];953 }954 }955 }956else if (collisionDetection(block11, map, x, y - 1)) 957 {958 clearBlock(hOut, block, x, y);959for (int i = 0; i < 4; ++i)960 {961for (int j = 0; j < 4; ++j)962 {963 block[i][j] = block11[i][j];964 }965 }966 --y;967 }968else if (collisionDetection(block11, map, x, y + 1)) 969 {970 clearBlock(hOut, block, x, y);971for (int i = 0; i < 4; ++i)972 {973for (int j = 0; j < 4; ++j)974 {975 block[i][j] = block11[i][j];976 }977 }978 ++y;979 }980break;981case21:982if (collisionDetection(block12, map, x, y))983 {984 clearBlock(hOut, block, x, y);985for (int i = 0; i < 4; ++i)986 {987for (int j = 0; j < 4; ++j)988 {989 block[i][j] = block12[i][j];990 }991 }992 }993else if (collisionDetection(block12, map, x, y - 1)) 994 {995 clearBlock(hOut, block, x, y);996for (int i = 0; i < 4; ++i)997 {998for (int j = 0; j < 4; ++j)999 {1000 block[i][j] = block12[i][j];1005else if (collisionDetection(block12, map, x, y + 1)) 1006 {1007 clearBlock(hOut, block, x, y);1008for (int i = 0; i < 4; ++i)1009 {1010for (int j = 0; j < 4; ++j)1011 {1012 block[i][j] = block12[i][j];1013 }1014 }1015 ++y;1016 }1017break;1018case22:1019if (collisionDetection(block13, map, x, y))1020 {1021 clearBlock(hOut, block, x, y);1022for (int i = 0; i < 4; ++i)1023 {1024for (int j = 0; j < 4; ++j)1025 {1026 block[i][j] = block13[i][j];1027 }1028 }1029 }1030else if (collisionDetection(block13, map, x, y - 1)) 1031 {1032 clearBlock(hOut, block, x, y);1033for (int i = 0; i < 4; ++i)1034 {1035for (int j = 0; j < 4; ++j)1036 {1037 block[i][j] = block13[i][j];1038 }1039 }1040 --y;1041 }1042else if (collisionDetection(block13, map, x, y + 1)) 1043 {1044 clearBlock(hOut, block, x, y);1045for (int i = 0; i < 4; ++i)1046 {1047for (int j = 0; j < 4; ++j)1048 {1049 block[i][j] = block13[i][j];1050 }1051 }1052 ++y;1053 }1054break;1055case23:1056if (collisionDetection(block10, map, x, y))1057 {1058 clearBlock(hOut, block, x, y);1059for (int i = 0; i < 4; ++i)1060 {1061for (int j = 0; j < 4; ++j)1062 {1063 block[i][j] = block10[i][j];1064 }1065 }1066 }1067else if (collisionDetection(block10, map, x, y - 1)) 1068 {1069 clearBlock(hOut, block, x, y);1070for (int i = 0; i < 4; ++i)1071 {1072for (int j = 0; j < 4; ++j)1073 {1074 block[i][j] = block10[i][j];1075 }1076 }1077 --y;1078 }1079else if (collisionDetection(block10, map, x, y + 1)) 1080 {1081 clearBlock(hOut, block, x, y);1082for (int i = 0; i < 4; ++i)1083 {1084for (int j = 0; j < 4; ++j)1090 }1091break;1092case24:1093if (collisionDetection(block15, map, x, y))1094 {1095 clearBlock(hOut, block, x, y);1096for (int i = 0; i < 4; ++i)1097 {1098for (int j = 0; j < 4; ++j)1099 {1100 block[i][j] = block15[i][j];1101 }1102 }1103 }1104else if (collisionDetection(block15, map, x, y - 1)) 1105 {1106 clearBlock(hOut, block, x, y);1107for (int i = 0; i < 4; ++i)1108 {1109for (int j = 0; j < 4; ++j)1110 {1111 block[i][j] = block15[i][j];1112 }1113 }1114 --y;1115 }1116else if (collisionDetection(block15, map, x, y + 1)) 1117 {1118 clearBlock(hOut, block, x, y);1119for (int i = 0; i < 4; ++i)1120 {1121for (int j = 0; j < 4; ++j)1122 {1123 block[i][j] = block15[i][j];1124 }1125 }1126 ++y;1127 }1128break;1129case25:1130if (collisionDetection(block14, map, x, y))1131 {1132 clearBlock(hOut, block, x, y);1133for (int i = 0; i < 4; ++i)1134 {1135for (int j = 0; j < 4; ++j)1136 {1137 block[i][j] = block14[i][j];1138 }1139 }1140 }1141else if (collisionDetection(block14, map, x, y - 1)) 1142 {1143 clearBlock(hOut, block, x, y);1144for (int i = 0; i < 4; ++i)1145 {1146for (int j = 0; j < 4; ++j)1147 {1148 block[i][j] = block14[i][j];1149 }1150 }1151 --y;1152 }1153else if (collisionDetection(block14, map, x, y + 1)) 1154 {1155 clearBlock(hOut, block, x, y);1156for (int i = 0; i < 4; ++i)1157 {1158for (int j = 0; j < 4; ++j)1159 {1160 block[i][j] = block14[i][j];1161 }1162 }1163 ++y;1164 }1165break;1166case26:1167if (collisionDetection(block17, map, x, y))1168 {1174 block[i][j] = block17[i][j];1175 }1176 }1177 }1178else if (collisionDetection(block17, map, x, y - 1))1179 {1180 clearBlock(hOut, block, x, y);1181for (int i = 0; i < 4; ++i)1182 {1183for (int j = 0; j < 4; ++j)1184 {1185 block[i][j] = block17[i][j];1186 }1187 }1188 --y;1189 }1190else if (collisionDetection(block17, map, x, y + 1))1191 {1192 clearBlock(hOut, block, x, y);1193for (int i = 0; i < 4; ++i)1194 {1195for (int j = 0; j < 4; ++j)1196 {1197 block[i][j] = block17[i][j];1198 }1199 }1200 ++y;1201 }1202break;1203case27:1204if (collisionDetection(block16, map, x, y))1205 {1206 clearBlock(hOut, block, x, y);1207for (int i = 0; i < 4; ++i)1208 {1209for (int j = 0; j < 4; ++j)1210 {1211 block[i][j] = block16[i][j];1212 }1213 }1214 }1215else if (collisionDetection(block16, map, x, y - 1))1216 {1217 clearBlock(hOut, block, x, y);1218for (int i = 0; i < 4; ++i)1219 {1220for (int j = 0; j < 4; ++j)1221 {1222 block[i][j] = block16[i][j];1223 }1224 }1225 --y;1226 }1227else if (collisionDetection(block16, map, x, y + 1))1228 {1229 clearBlock(hOut, block, x, y);1230for (int i = 0; i < 4; ++i)1231 {1232for (int j = 0; j < 4; ++j)1233 {1234 block[i][j] = block16[i][j];1235 }1236 }1237 ++y;1238 }1239break;1240default:1241break;1242 }1243 }12441245void myStop(HANDLE hOut, int block[4][4])1246 {1247 clearBlock(hOut, block, 5, 15);1248 SetConsoleTextAttribute(hOut, FOREGROUND_RED | FOREGROUND_INTENSITY); 1249 gotoXY(hOut, 30, 7);1250 cout << "游戏暂停";1251char key;1252while (true)。
python实现简单俄罗斯⽅块游戏本⽂实例为⼤家分享了python实现简单俄罗斯⽅块游戏的具体代码,供⼤家参考,具体内容如下import pygame,sys,random,timeall_block = [[[0,0],[0,-1],[0,1],[0,2]],[[0,0],[0,1],[1,1],[1,0]],[[0,0],[0,-1],[-1,0],[-1,1]],[[0,0],[0,1],[-1,-1],[-1,0]],[[0,0],[0,1],[1,0],[0,-1]],[[0,0],[1,0],[-1,0],[1,-1]],[[0,0],[1,0],[-1,0],[1,1]]]background = [[0 for column in range(0,10)] for row in range(0,22)]background[0] = [1 for column in range(0,10)]select_block = list(random.choice(all_block))block_initial_position = [21,5]times = 0score = [0]gameover = []press = Falsepygame.init()screen = pygame.display.set_mode((250,500))title = pygame.display.set_caption("俄罗斯⽅块")#下落、位置、数组检测、得分、屏幕信息def block_move_down():y_drop=block_initial_position[0]x_move=block_initial_position[1]y_drop-=1for row,column in select_block:row+=y_dropcolumn+=x_moveif background[row][column]==1:breakelse:block_initial_position.clear()block_initial_position.extend([y_drop,x_move])returny_drop,x_move=block_initial_positionfor row,column in select_block:background[y_drop+row][x_move+column]=1complete_row=[]for row in range(1,21):if 0 not in background[row]:complete_row.append(row)complete_row.sort(reverse=True)for row in complete_row:background.pop(row)background.append([0 for column in range(0,10)])score[0]+=len(complete_row)pygame.display.set_caption(str(score[0])+'分')select_block.clear()select_block.extend(list(random.choice(all_block)))block_initial_position.clear()block_initial_position.extend([20,5])y_drop,x_move=block_initial_positionfor row,column in select_block:row+=y_dropcolumn+=x_moveif background[row][column]:gameover.append(1)#⽅块设置、变化、背景改变def new_draw():y_drop,x_move=block_initial_positionfor row,column in select_block:row+=y_dropcolumn+=x_movepygame.draw.rect(screen,(255,165,0),(column*25,500-row*25,23,23))for row in range(0,20):for column in range(0,10):bottom_block=background[row][column]if bottom_block:pygame.draw.rect(screen,(0,0,255),(column*25,500-row*25,23,23)) #⽅块的移动,防⽌出界,碰撞def move_left_right(n):y_drop,x_move=block_initial_positionx_move+=nfor row,column in select_block:row+=y_dropcolumn+=x_moveif column<0 or column>9 or background[row][column]:breakelse:block_initial_position.clear()block_initial_position.extend([y_drop,x_move])#旋转,位置都进⾏变化def rotate():y_drop,x_move=block_initial_positionrotating_position=[(-column,row)for row,column in select_block]for row,column in rotating_position:row+=y_dropcolumn+=x_moveif column<0 or column>9 or background[row][column]:breakelse:select_block.clear()select_block.extend(rotating_position)while True:screen.fill((255,255,255))for event in pygame.event.get():if event.type==pygame.QUIT:sys.exit()elif event.type==pygame.KEYDOWN and event.key==pygame.K_LEFT: move_left_right(-1)elif event.type==pygame.KEYDOWN and event.key==pygame.K_RIGHT: move_left_right(1)elif event.type==pygame.KEYDOWN and event.key==pygame.K_UP:rotate()elif event.type==pygame.KEYDOWN and event.key==pygame.K_DOWN: press=Trueelif event.type==pygame.KEYUP and event.key==pygame.K_DOWN:press=Falseif press:times+=10if times>=50:block_move_down()times=0else:times+=1if gameover:sys.exit()new_draw()pygame.time.Clock().tick(200)pygame.display.flip()效果:以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
游戏策划所需要的素质策划所需的最基础三点基本素质:清晰的逻辑思维: 在策划工作中动笔写策划案前, 项目中所有模块功能全都在策划脑中, 要理清模块间的关系, 理清项目需求必须要有清晰的逻辑思维。
表达沟通能力: 策划的日常工作中, 经常需要跟美术和程序进行沟通, 以保证美术程序对策划内容实现没有或尽量少出现偏差。
敬业精神: 策划平时的工作内容非常枯燥, 并且压力极大, 需要有足够的敬业精神才能保证长时间维持工作。
其他所需素质: 对市面上常见游戏内容了解, 对国内外文学、历史、神话、体育、动漫等各方面知识的了解。
游戏策划的工作内容:主策划: 负责管理游戏策划团队, 分配策划团队工作, 设定游戏产品世界观, 根据制作人提出需求写策划主案等。
系统策划: 负责根据策划主案完成各分模块的功能设计。
数值策划: 负责根据策划主案设计游戏中人物、道具、技能的属性和游戏中的各种公式, 并对游戏的平衡性负责。
剧情策划: 负责根据策划主案设计游戏中剧情、关卡、任务、脚本编写等。
执行策划: 根据主策划、系统、数值、剧情等策划设计, 完成文案或录入工作, 不需要自己的设计构思。
游戏策划面试注意事项:在面试中首先必然会作简短自我介绍, 自我介绍不要掺杂个人想法之类的东西, 只需要介绍个人基本情况, 包括姓名、年龄、工作经历等, 要做到简单和简短, 不要让考官失去耐心。
面试时不要出现冷场, 不用管问题的答案是否正确, 即使答得不对, 只要能找到论据支持自己的说法就行。
答考官提出的问题时要控制语速, 最好可以控制在自己有时间思考, 又不能让人明显看出在思考。
面试有可能不会一次成功, 但是面试失败不要打击信心, 要摆正心态, 无论面试成功与否都要在面试过程中学到一些东西, 比如考官提出的问题你完全无法答出来, 在最后一般考官都会问你有什么想了解的, 你可以提出同样的问题, 听考官怎么回答, 然后用心记下来, 作为自己的积累。
1.面试时时刻注意考官的表情举动等, 根据考官的表情举动可基本判断考官是否满意。
WPS表格构建猜拳小游戏猜拳游戏,我想大家都玩过,就是石头剪刀布。
这种游戏简单、有趣、不需要额外工具,2个人就可以玩。
下面我们用WPS工作表来构建一个猜拳小游戏。
制作思路1.游戏双方为用户和电脑。
2.用户可通过下拉菜单来选择石头、剪刀、布。
3.电脑随机出石头、剪刀、布。
4.用户和电脑之间比较谁赢。
函数应用考虑到只有石头、剪刀、布,3个选项,考虑用randbetween 来随机产生3个数,比如:1-石头,2-剪刀,3-布。
函数用法:Randbetween(最小整数,最大整数)返回大于等于指定的最小值,小于指定最大值之间的一个随机整数。
每次计算工作表时都将返回一个新的数值。
例:randbetween(1,10),返回1到10之间任意整数(包括1和10)。
制作步骤1.建立数字、名称和图示的对应关系新建一个工作表,命名为“图例”,建立如下对应关系这样就可以建立数字1、2、3和剪刀、石头、布相应出拳的对应关系,同时,为下一步数字和图片对应打下基础。
2.新建“游戏”工作表这个工作表就是游戏主界面,设置界面如下:左边为用户出拳选择界面,利用下拉菜单实现,点击数据—有效性—序列,来源里输入=图例!$B$3:$B$5电脑出拳怎么设置呢?这是关键的内容在E4单元格中输入公式:=OFFSET(图例!$B$2,RANDBETWEEN(1,3),0)这里就能随机展示出拳。
3. 设置图片随出拳改变(1)用名称管理器设置2个名称(用于查找对应图例) 名称1:图片=INDEX(图例!$C$3:$C$5,MATCH('游戏'!$B$4,图例!$B$3:$B$5,0))名称2:图片2=INDEX(图例!$C$3:$C$5,MATCH('游戏'!$E$4,图例!$B$3:$B$5,0))用户出拳(B4单元格) 电脑出拳(E4单元格)(2)给图片写入公式这里需要用到VBA编辑器,WPS本身不能给图片写入公式。
Excel Solver的用法电脑相关 2009-06-26, 22:13Solver是Excel一个功能非常强大的插件(Add-Ins),可用于工程上、经济学及其它一些学科中各种问题的优化求解,使用起来非常方便,Solver包括(但不限于)以下一些功能:1、线性规划2、非线性规划3、线性回归,多元线性回归可以用Origin求解,也可以用Excel的linest函数或分析工具求解。
4、非线性回归5、求函数在某区间内的极值注意:Solver插件可以用于解决上面这些问题,并不是说上面这些问题Solver 一定可以解决,而且有时候Solver给出的结果也不一定是最优的。
Solver安装方法:Solver是Excel自带的插件,不需要单独下载安装。
但Excel默认是不启用Solver的,启用方法:在"工具"菜单中点击“插件”,在Solver Add-In前面的方框中打勾,然后点OK,Excel会自动加载Solver,一旦启用成功,以后Sovler 就会在"工具"菜单中显示。
Solver求解非线性回归问题的方法:假设X和Y满足这样一个关系:Y=L(1-10-KX),实验测得一组X和Y的值如下:X Y0 00.54 1830.85 2251.50 2862.46 3803.56 4705.00 544求L和K的值。
在Excel中随便假设一组L和K的值,比如都假设为1,以这组假设的值,求出一组Y’,然后再求出一组(X-Y)2的值,再将求出的这组(X-Y)2的值用Sum函数全部加起来(下面的图中,全部加起来结果在$G$22这个单元格中)。
然后点击“工具”菜单中的Solver,将Set Target Cell设为$G$22这个单元格,将By Changing Cells设为$F$8:$F9这两个单元格,即改变L和K的值,Equal To选中Min这项,其他的选项不用理会,如下图:然后点右上角的Solver,$F$8:$F9就会改变,改变之后的值即为优化的L和K 值。
python实现简单的俄罗斯⽅块本⽂实例为⼤家分享了python实现简单的俄罗斯⽅块的具体代码,供⼤家参考,具体内容如下1. 案例介绍俄罗斯⽅块是由 4 个⼩⽅块组成不同形状的板块,随机从屏幕上⽅落下,按⽅向键调整板块的位置和⽅向,在底部拼出完整的⼀⾏或⼏⾏。
这些完整的横条会消失,给新落下来的板块腾出空间,并获得分数奖励。
没有被消除掉的⽅块不断堆积,⼀旦堆到顶端,便告输,游戏结束。
本例难度为⾼级,适合具有 Python 进阶和 Pygame 编程技巧的⽤户学习。
2. 设计要点边框――由 15*25 个空格组成,⽅块就落在这⾥⾯。
盒⼦――组成⽅块的其中⼩⽅块,是组成⽅块的基本单元。
⽅块――从边框顶掉下的东西,游戏者可以翻转和改变位置。
每个⽅块由 4 个盒⼦组成。
形状――不同类型的⽅块。
这⾥形状的名字被叫做 T, S, Z ,J, L, I , O。
如下图所⽰:模版――⽤⼀个列表存放形状被翻转后的所有可能样式。
全部存放在变量⾥,变量名字如 S or J。
着陆――当⼀个⽅块到达边框的底部或接触到在其他的盒⼦话,就说这个⽅块着陆了。
那样的话,另⼀个⽅块就会开始下落。
3. ⽰例效果4. ⽰例源码import pygameimport randomimport ospygame.init()GRID_WIDTH = 20GRID_NUM_WIDTH = 15GRID_NUM_HEIGHT = 25WIDTH, HEIGHT = GRID_WIDTH * GRID_NUM_WIDTH, GRID_WIDTH * GRID_NUM_HEIGHTSIDE_WIDTH = 200SCREEN_WIDTH = WIDTH + SIDE_WIDTHWHITE = (0xff, 0xff, 0xff)BLACK = (0, 0, 0)LINE_COLOR = (0x33, 0x33, 0x33)CUBE_COLORS = [(0xcc, 0x99, 0x99), (0xff, 0xff, 0x99), (0x66, 0x66, 0x99),(0x99, 0x00, 0x66), (0xff, 0xcc, 0x00), (0xcc, 0x00, 0x33),(0xff, 0x00, 0x33), (0x00, 0x66, 0x99), (0xff, 0xff, 0x33),(0x99, 0x00, 0x33), (0xcc, 0xff, 0x66), (0xff, 0x99, 0x00)]screen = pygame.display.set_mode((SCREEN_WIDTH, HEIGHT))pygame.display.set_caption("俄罗斯⽅块")clock = pygame.time.Clock()FPS = 30score = 0level = 1screen_color_matrix = [[None] * GRID_NUM_WIDTH for i in range(GRID_NUM_HEIGHT)]# 设置游戏的根⽬录为当前⽂件夹base_folder = os.path.dirname(__file__)def show_text(surf, text, size, x, y, color=WHITE):font_name = os.path.join(base_folder, 'font/font.ttc')font = pygame.font.Font(font_name, size)text_surface = font.render(text, True, color)text_rect = text_surface.get_rect()text_rect.midtop = (x, y)surf.blit(text_surface, text_rect)class CubeShape(object):SHAPES = ['I', 'J', 'L', 'O', 'S', 'T', 'Z']I = [[(0, -1), (0, 0), (0, 1), (0, 2)],[(-1, 0), (0, 0), (1, 0), (2, 0)]]J = [[(-2, 0), (-1, 0), (0, 0), (0, -1)],[(-1, 0), (0, 0), (0, 1), (0, 2)],[(0, 1), (0, 0), (1, 0), (2, 0)],[(0, -2), (0, -1), (0, 0), (1, 0)]]L = [[(-2, 0), (-1, 0), (0, 0), (0, 1)],[(1, 0), (0, 0), (0, 1), (0, 2)],[(0, -1), (0, 0), (1, 0), (2, 0)],[(0, -2), (0, -1), (0, 0), (-1, 0)]]O = [[(0, 0), (0, 1), (1, 0), (1, 1)]]S = [[(-1, 0), (0, 0), (0, 1), (1, 1)],[(1, -1), (1, 0), (0, 0), (0, 1)]]T = [[(0, -1), (0, 0), (0, 1), (-1, 0)],[(-1, 0), (0, 0), (1, 0), (0, 1)],[(0, -1), (0, 0), (0, 1), (1, 0)],[(-1, 0), (0, 0), (1, 0), (0, -1)]]Z = [[(0, -1), (0, 0), (1, 0), (1, 1)],[(-1, 0), (0, 0), (0, -1), (1, -1)]]SHAPES_WITH_DIR = {'I': I, 'J': J, 'L': L, 'O': O, 'S': S, 'T': T, 'Z': Z}def __init__(self):self.shape = self.SHAPES[random.randint(0, len(self.SHAPES) - 1)]# ⾻牌所在的⾏列self.center = (2, GRID_NUM_WIDTH // 2)self.dir = random.randint(0, len(self.SHAPES_WITH_DIR[self.shape]) - 1) self.color = CUBE_COLORS[random.randint(0, len(CUBE_COLORS) - 1)] def get_all_gridpos(self, center=None):curr_shape = self.SHAPES_WITH_DIR[self.shape][self.dir]if center is None:center = [self.center[0], self.center[1]]return [(cube[0] + center[0], cube[1] + center[1])for cube in curr_shape]def conflict(self, center):for cube in self.get_all_gridpos(center):# 超出屏幕之外,说明不合法if cube[0] < 0 or cube[1] < 0 or cube[0] >= GRID_NUM_HEIGHT or \ cube[1] >= GRID_NUM_WIDTH:return True# 不为None,说明之前已经有⼩⽅块存在了,也不合法if screen_color_matrix[cube[0]][cube[1]] is not None:return Truereturn Falsedef rotate(self):new_dir = self.dir + 1new_dir %= len(self.SHAPES_WITH_DIR[self.shape])old_dir = self.dirself.dir = new_dirif self.conflict(self.center):self.dir = old_dirreturn Falsedef down(self):# import pdb; pdb.set_trace()center = (self.center[0] + 1, self.center[1])if self.conflict(center):return Falseself.center = centerreturn Truedef left(self):center = (self.center[0], self.center[1] - 1)if self.conflict(center):return Falseself.center = centerreturn Truedef right(self):center = (self.center[0], self.center[1] + 1)if self.conflict(center):return Falseself.center = centerreturn Truedef draw(self):for cube in self.get_all_gridpos():pygame.draw.rect(screen, self.color,(cube[1] * GRID_WIDTH, cube[0] * GRID_WIDTH,GRID_WIDTH, GRID_WIDTH))pygame.draw.rect(screen, WHITE,(cube[1] * GRID_WIDTH, cube[0] * GRID_WIDTH,GRID_WIDTH, GRID_WIDTH),1)def draw_grids():for i in range(GRID_NUM_WIDTH):pygame.draw.line(screen, LINE_COLOR,(i * GRID_WIDTH, 0), (i * GRID_WIDTH, HEIGHT))for i in range(GRID_NUM_HEIGHT):pygame.draw.line(screen, LINE_COLOR,(0, i * GRID_WIDTH), (WIDTH, i * GRID_WIDTH))pygame.draw.line(screen, WHITE,(GRID_WIDTH * GRID_NUM_WIDTH, 0),(GRID_WIDTH * GRID_NUM_WIDTH, GRID_WIDTH * GRID_NUM_HEIGHT)) def draw_matrix():for i, row in zip(range(GRID_NUM_HEIGHT), screen_color_matrix):for j, color in zip(range(GRID_NUM_WIDTH), row):if color is not None:pygame.draw.rect(screen, color,(j * GRID_WIDTH, i * GRID_WIDTH,GRID_WIDTH, GRID_WIDTH))pygame.draw.rect(screen, WHITE,(j * GRID_WIDTH, i * GRID_WIDTH,GRID_WIDTH, GRID_WIDTH), 2)def draw_score():show_text(screen, u'得分:{}'.format(score), 20, WIDTH + SIDE_WIDTH // 2, 100)def remove_full_line():global screen_color_matrixglobal scoreglobal levelnew_matrix = [[None] * GRID_NUM_WIDTH for i in range(GRID_NUM_HEIGHT)]index = GRID_NUM_HEIGHT - 1n_full_line = 0for i in range(GRID_NUM_HEIGHT - 1, -1, -1):is_full = Truefor j in range(GRID_NUM_WIDTH):if screen_color_matrix[i][j] is None:is_full = Falsecontinueif not is_full:new_matrix[index] = screen_color_matrix[i]index -= 1else:n_full_line += 1score += n_full_linelevel = score // 20 + 1screen_color_matrix = new_matrixdef show_welcome(screen):show_text(screen, u'俄罗斯⽅块', 30, WIDTH / 2, HEIGHT / 2)show_text(screen, u'按任意键开始游戏', 20, WIDTH / 2, HEIGHT / 2 + 50)running = Truegameover = Truecounter = 0live_cube = Nonewhile running:clock.tick(FPS)for event in pygame.event.get():if event.type == pygame.QUIT:running = Falseelif event.type == pygame.KEYDOWN:if gameover:gameover = Falselive_cube = CubeShape()breakif event.key == pygame.K_LEFT:live_cube.left()elif event.key == pygame.K_RIGHT:live_cube.right()elif event.key == pygame.K_DOWN:live_cube.down()elif event.key == pygame.K_UP:live_cube.rotate()elif event.key == pygame.K_SPACE:while live_cube.down() == True:passremove_full_line()# level 是为了⽅便游戏的难度,level 越⾼ FPS // level 的值越⼩# 这样屏幕刷新的就越快,难度就越⼤if gameover is False and counter % (FPS // level) == 0:# down 表⽰下移⾻牌,返回False表⽰下移不成功,可能超过了屏幕或者和之前固定的# ⼩⽅块冲突了if live_cube.down() == False:for cube in live_cube.get_all_gridpos():screen_color_matrix[cube[0]][cube[1]] = live_cube.colorlive_cube = CubeShape()if live_cube.conflict(live_cube.center):gameover = Truescore = 0live_cube = Nonescreen_color_matrix = [[None] * GRID_NUM_WIDTH for i in range(GRID_NUM_HEIGHT)] # 消除满⾏remove_full_line()counter += 1# 更新屏幕screen.fill(BLACK)draw_grids()draw_matrix()draw_score()if live_cube is not None:live_cube.draw()if gameover:show_welcome(screen)pygame.display.update()以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
《俄罗斯方块》程序编写超详细解释Tc2.0 编写俄罗斯方块游戏很多编程爱好者都编写过俄罗斯方块的游戏程序。
很久以前,我用Tc2.0也做过一个;最近有好些朋友看见我以前的俄罗斯方块的程序后,问我是怎么做的。
我一直想把这个程序的整个过程写一份详细的东西,与各位编程爱好者分享,一直没空。
正好现在放假了,而且离回家还有几天。
于是我就把这个程序重新写了一遍,尽量使程序的结构比较清晰好懂一些。
同时写了下面的这份东西。
俄罗斯方块游戏的程序中用到了一些方法。
为了比较容易理解这些方法,我在讲述的同时写了些专门针对这些方法的示例程序。
这些示例程序力求短小,目的是用最小的代码能够清楚的示例所用的方法。
这些示例程序都经过tc2.0测试。
最后还附了完整的俄罗斯方块游戏的源代码,和最终的可执行程序。
如果你看了这份东东,有什么意见和想法,请发电子邮件告诉我。
我将会继续更新这分东东,最新的版本可以在我的个人主页上下载。
下面的问题是有关俄罗斯方块程序的,其中有些是朋友问我的,有些是我认为可能会被问到的。
我尽量按问题从易到难排列这些问题。
关于俄罗斯方块程序的一些问题:******************************************************Tc2.0中怎么样设置图形显示?Tc2.0中常用图形函数的用法?怎样获取鍵盘输入?怎样控制方块的移动?怎样控制时间间隔(用于游戏中控制形状的下落)?游戏中的各种形状及整个游戏空间怎么用数据表示?游戏中怎么判断左右及向下移动的可能性?游戏中怎么判断某一形状旋转的可能性?按向下方向键时加速某一形状下落速度的处理?怎么判断某一形状已经到底?怎么判断某一已经被填满?怎么消去已经被填满的一行?怎么消去某一形状落到底后能够消去的所有的行?(如长条最多可以消去四行)怎样修改游戏板的状态?怎样统计分数?怎样处理升级后的加速问题?怎样判断游戏结束?关于计分板设计的问题。
关于“下一个”形状取法的问题。