⑴ C語言設計俄羅斯方塊
1、將游戲區域劃分為18行*10列的棋盤,設立一個布爾型的二維數組變數,以表示棋盤上各個地方是否有方塊。
2、用4個頂點代表各種不同形狀的方塊,一旦方塊在游戲區域中,就把對應的布爾型二維數組變數置為真,表示該方格已經有方塊了。
3、如上做方便方塊移動是否會碰撞的判斷。
4、代碼已經修正了一個小BUG。
5、壓縮包中的文件是未經修改的源代碼,此處的代碼為最新。
6、方向鍵上為改變形狀,下為直接落到底部。p鍵為暫停(或者Pause鍵)。
⑵ 做俄羅斯方塊時,如何判斷方塊有沒有到底啊
public void CheckAndOverBlock()//檢查轉塊是否到底,如果到底則把當前轉塊歸入coorArr,並產生新的轉塊
{
bool over = false;//設置一個當前運行轉塊是否到底
for (int i = 0; i < runBlock.Length;i++ )//遍歷當前運行轉塊的所有小方塊
{
int x = runBlock.XPos + runBlock[i].X;
int y = runBlock.YPos - runBlock[i].Y;
if (y == _height - 1)//如果到達下邊界,則結束當前轉塊
{
over = true;
// runBlock.erase(gpPaltte);
break;
}
if (!coorArr[x, y+1].IsEmpty) //如果下面有轉塊,則當前轉塊結束
{
over = true;
break;
}
}
if (over)
{
for (int i = 0; i < runBlock.Length; i++)//把當前轉塊歸入coordinateArr
{
coorArr[runBlock.XPos + runBlock[i].X, runBlock.YPos - runBlock[i].Y] = runBlock.BlockColor;
}
////檢查是否有滿行情況,如果有則刪除
CheckAndDelFullRow();
////產生新轉塊
runBlock = readyBlock;//新的轉塊為准備好的轉塊
runBlock.XPos = _width / 2;//確定當前運行轉塊的出生位置
int y = 0;//確定轉塊Ypos,確定剛出生的轉塊頂上沒空行
for (int i = 0; i < runBlock.Length; i++)
{
if (runBlock[i].Y > y)
y = runBlock[i].Y;
}
runBlock.YPos = y;
//檢查新生成的轉塊所佔用的地方是否已經有轉塊存在,如果有,游戲結束
for (int i = 0; i < runBlock.Length; i++)
{
if (!coorArr[runBlock.XPos + runBlock[i].X, runBlock.YPos - runBlock[i].Y].IsEmpty)
{
StringFormat drawFormat = new StringFormat();
drawFormat.Alignment = StringAlignment.Center;
gpPaltte.DrawString("GAME OVER",
new Font("Arial Black", 25f),
new SolidBrush(Color.White),
new RectangleF(0, _height * rectPix / 2 - 100, _width * rectPix, 100),
drawFormat);
timerBlock.Stop();//關閉定時器
return;
}
}
runBlock.Paint(gpPaltte);
//獲取新的准備轉塊
readyBlock = bGroup.GetABlock();
readyBlock.XPos = 2;
readyBlock.YPos = 2;
gpReady.Clear(Color.Black);
readyBlock.Paint(gpReady);
}
}
⑶ 紙嫁衣1俄羅斯方塊怎麼拼
對於你的問題回答如下:
第四章方法:
這個俄羅斯方塊是不需要拼的,因為在拼湊之前,主角已經說了這個箱子有點腐朽,所以玩家可以點擊錘子,然後使用錘子來砸這個俄羅斯方塊,就可以直接把箱子給砸爛,然後順利過關。
所以無需費盡心思地去拼湊俄羅斯方塊,直接使用錘子砸掉就可以了,一定要注意聽主角的話,有的解密其實沒有多麼復雜。
其他章節方法:
1、俄羅斯方塊初始是散落在各個位置的,我們需要利用棋盤的空間,把方塊放進裡面;
2、首先點擊上面的棋子,然後把棋子放在棋盤中;
3、最後把方塊擺放成下圖這個形狀,全部放在棋盤中;
4、最後就能解鎖關卡,得到任務獎勵,是一把鑰匙。
希望我的回答能對你有所幫助。
⑷ 做俄羅斯方塊的思路或演算法是什麼
我用MFC做過俄羅斯方塊:
整個場景是一個10*20的長方形空間,你要建立一個10*20的數組int num[20][10]模仿之,你可以想像這是200個小塊,每個小塊只有0和1兩種狀態,為0時相應該位置為空白,為1時相應該位置畫一個小方塊.
每一個圖形由4個小方塊組成,當他落到底停住時,你就要把數組num的相應數項由0改成1(num數組初始化全為0),同時在OnPaint(可能有時是OnDraw)函數中根據數組的0,1情況重繪,思路就是這樣的.很簡單
⑸ 哪位大神給我講解一下俄羅斯方塊的演算法C語言
首先你得有個俄羅斯方塊界面的概念,它就是M*N的一個2維數組,那麼一個方塊向左移動的極限就是有一個點已經到了最左邊。
拿一個豎條為例,他本身是一個4*4的小格子,當他是豎條時可以看成
0010
0010
0010
0010
向左移動時,只要判斷1是否在左邊邊界,沒有就往左一格,另外要注意邊橫桿時,要先判斷是否最左邊越界,有越界就不能變化
⑹ 俄羅斯方塊演算法
用二維數組表示方塊所在的整個區域,0表示有方塊,1表示有方塊。從上往下,從左往右開始輸出區域。
判斷消行,也就是當方塊下落後,從它所停留那一行(記錄此行)開始,計算每一行是否全為1,如果全為1,則往下繼續判斷下一行,再記錄消行的行數。
判斷完畢後,開始將這幾行數據全變為0即可。然後就是下降。
比如從第8行開始,消2行,也就是8,9行消掉。此時應該讓前面7行往下落2行。也就是第9行數據等於第7行,第8行數據等於第6行,以此類推。寫一個循環
就可以了。
⑺ C語言中的俄羅斯方塊
我給你,我有源代碼,可以運行
/*************************
<Russia Diamonds Ver 1.0>
Copyright by forever_chang
[email protected]
2001.11.1
*************************/
/*****************************************************************************************/
#include "graphics.h" /*頭文件*/
#include "time.h"
#include "stdlib.h"
#include "bios.h"
#include "dos.h"
#include "stdio.h"
#define ESC 0x11b /*鍵盤掃描碼*/
#define UP 0x4800
#define DOWN 0x5000
#define LEFT 0x4b00
#define F1 0x3b00
#define RIGHT 0x4d00
#define YES 0x1579
#define NO 0x316e
#define RESTART 0x1372
/*****************************************************************************************/
struct diamond /*記錄每種方塊每種狀態的信息*/
{
int x[4];
int y[4];
int start_x;
int start_y;
int color;
struct diamond *next;
};
int grid[12][23]; /*記錄所有格子的狀態 (0)沒有方塊 (1)有固定方塊 (2)有活動方塊*/
int x; /*活動方塊所在位置*/
int y;
int level; /*游戲難度*/
int count; /*計數器*/
int score;/*得分*/
struct diamond *nowinfo; /*當前活動方塊*/
struct diamond *nextinfo; /*下一個方塊*/
int color;/*畫格子的顏色*/
int backcolor;/*游戲區域背景色*/
/*****************************************************************************************/
void show_interface (int mode);/*顯示游戲界面*/
void show_copsign (int topx,int topy,int size,int color);/*顯示公司標志--恆基偉業*/
void show_intro (int xs,int ys);/*顯示軟體介紹區*/
/*void print(); 測試用函數*/
void scandel();/*掃描所有格子看是否有可消除行*/
void show_down ();/*方塊下落後的下一個狀態*/
void show_next ();/*方塊翻轉後的下一個狀態*/
void show_left ();/*方塊向左移動後的下一個狀態*/
void show_right ();/*方塊向右移動後的下一個狀態*/
void interrupt (*oldtimer)();/*指向未安裝前的中斷向量,即函數指針,指向一段可執行的代碼*/
void install();/*安裝新的中斷向量,即將中斷服務程序安裝到中斷向量表中*/
void interrupt newtimer();/*中斷服務程序*/
struct diamond *get_diamond();/*隨機得到一個方塊*/
struct diamond *create_I();/*函數用來構造各種類形方塊的環形鏈表*/
struct diamond *create_T();/*返回鏈表中隨機一個狀態的指針*/
struct diamond *create_L();
struct diamond *create_J();
struct diamond *create_Z();
struct diamond *create_N();
struct diamond *create_H();
void delinfo (struct diamond *info);/*釋放當前方塊所佔用的空間*/
void addtobuffer(int c);/*向鍵盤緩沖區中增加一個DOWN*/
/*void clrkey();調用dos中斷清空鍵盤緩沖區,未使用此方法.*/
void showsubwin(struct diamond *next);/*在小窗口顯示下一個方塊*/
void showscore(int scoreget);/*顯示分數*/
void startset();/*初始化游戲*/
/*****************************************************************************************/
main ()
{
int driver=VGA;
int mode=VGAHI;
int i;/*計數器*/
int j;
int key;/*記錄鍵盤掃描碼*/
initgraph (&driver,&mode,"");/*初始化*/
color=8;
backcolor=7;
level=1;
score=298;
count=0;
show_interface (9);/*顯示界面*/
setfillstyle(SOLID_FILL,1);
bar(0,465,640,480);
outtextxy(5,469,"Press any key to start...");
getch();
setfillstyle(SOLID_FILL,9);
bar(0,465,640,480);
showscore(0);/*顯示分數*/
randomize();
nowinfo=get_diamond ();/*得到一個當前方塊*/
oldtimer=getvect(0x1c);
install(newtimer);
for(i=0;i<=21;i++)/*初始化grid[12][23]*/
{
for(j=1;j<=10;j++)
grid[j][i]=0;
}
for(i=0;i<=22;i++)
{
grid[0][i]=1;
grid[11][i]=1;
}
for(i=0;i<=11;i++)
{
grid[i][22]=1;
}
x=nowinfo->start_x;/*初始化方塊位置*/
y=nowinfo->start_y;
nextinfo=get_diamond ();/*得到下一個方塊*/
showsubwin(nextinfo);
for (;
{
key=bioskey(0);/*得到鍵盤掃描碼*/
if (key)
{
switch(key)
{
case DOWN:{
show_down ();
break;
}
case UP:{
show_next ();
break;
}
case LEFT:{
show_left();
break;
}
case RIGHT:{
show_right();
break;
}
case RESTART:{
install(oldtimer);
setfillstyle(SOLID_FILL,1);
bar(0,465,640,480);
outtextxy(5,469,"Are you sure to restart (Y/N)...");
for (;
{
key=bioskey(0);/*得到鍵盤掃描碼*/
if (key==YES)
{
startset();
setfillstyle(SOLID_FILL,9);
bar(0,465,640,480);
break;
}
if (key==NO)
{
setfillstyle(SOLID_FILL,9);
bar(0,465,640,480);
install(newtimer);
break;
}
}
break;
}
/* case F1:{
print();
break;
}
*/
case ESC:{
install(oldtimer);
setfillstyle(SOLID_FILL,1);
bar(0,465,640,480);
outtextxy(5,469,"Are you sure to exit (Y/N)...");
for (;
{
key=bioskey(0);/*得到鍵盤掃描碼*/
if (key==YES)
{
closegraph();
exit(0);
}
if (key==NO)
{
setfillstyle(SOLID_FILL,9);
bar(0,465,640,480);
install(newtimer);
break;
}
}
}
}
}
}
}
/*****************************************************************************************/
struct diamond *get_diamond()
{
struct diamond *now;
switch (random(7)+1)
{
case 1:{
now=create_I();
return now;
}
case 2:{
now=create_T();
return now;
}
case 3:{
now=create_L();
return now;
}
case 4:{
now=create_J();
return now;
}
case 5:{
now=create_Z();
return now;
}
case 6:{
now=create_N();
return now;
}
case 7:{
now=create_H();
return now;
}
}
}
/*****************************************************************************************/
void show_interface (int fill_mode)
{
int i;
setbkcolor (9);
setcolor (color);
setfillstyle (SOLID_FILL,backcolor);
bar (100,60,300,420);
bar (360,60,440,140);
rectangle (100,60,300,420);
rectangle (96,56,304,424);
rectangle (360,60,440,140);
rectangle (356,56,444,144);
setfillstyle (fill_mode,14);
floodfill (97,57,color);
floodfill (397,57,color);
setcolor(1);
rectangle(96,56,304,424);
setcolor (color);
for (i=80;i<=400;i+=20)
{
line (100,i,300,i);
}
for (i=120;i<=280;i+=20)
{
line (i,60,i,420);
}
for (i=80;i<=120;i+=20)
{
line (360,i,440,i);
}
for (i=380;i<=420;i+=20)
{
line (i,60,i,140);
}
show_intro (360,180);
show_copsign (475,320,40,1);
setfillstyle(SOLID_FILL,1);
setcolor(14);
rectangle(420,405,534,417);
floodfill (421,406,14);
outtextxy(422,408,"HI-TECH WEALTH");
}
/*****************************************************************************************/
void show_copsign (int topx,int topy,int size,int color)
{
int halfsize,qtrsize;
int xadd,xdel,yadd1,yadd2;
halfsize=0.5*size;
qtrsize=0.25*size;
xadd=topx+size;
xdel=topx-size;
yadd1=topy+size;
yadd2=topy+2*size;
setcolor(color);
line (topx,topy,xdel,yadd1);
line (xdel,yadd1,topx,yadd2);
line (topx,yadd2,xadd,yadd1);
line (xadd,yadd1,topx,topy);
rectangle (topx-halfsize,topy+halfsize,topx+halfsize,yadd1+halfsize);
setfillstyle (SOLID_FILL,color);
floodfill (topx,topy+1,color);
floodfill (xdel+1,yadd1,color);
floodfill (topx,yadd2-1,color);
floodfill (xadd-1,yadd1,color);
rectangle (topx-halfsize,yadd1-qtrsize,topx-0.75*halfsize,yadd1+qtrsize);
floodfill (topx-halfsize+1,yadd1-qtrsize+1,color);
rectangle (topx-qtrsize,yadd1-halfsize,topx+qtrsize,yadd1-0.25*halfsize);
floodfill (topx-qtrsize+1,yadd1-halfsize+1,color);
rectangle (topx+0.75*halfsize,yadd1-qtrsize,topx+halfsize,yadd1+qtrsize);
floodfill (topx+0.75*halfsize+1,yadd1-qtrsize+1,color);
rectangle (topx-qtrsize,yadd1+0.25*halfsize,topx+qtrsize,yadd2-halfsize);
floodfill (topx-qtrsize+1,yadd1+0.25*halfsize+1,color);
setcolor(14);
line (topx,topy-1,xdel-1,yadd1);
line (xdel-1,yadd1,topx,yadd2+1);
line (topx,yadd2+1,xadd+1,yadd1);
line (xadd+1,yadd1,topx,topy-1);
setfillstyle (SOLID_FILL,14);
floodfill (topx,yadd1,color);
}
/*****************************************************************************************/
void show_intro (int xs,int ys)
{
char stemp[20];
setcolor (15);
rectangle(xs-3,ys-3,xs+239,ys+115);
line (xs-3,ys+26,xs+239,ys+26);
line (xs-3,ys+72,xs+239,ys+72);
outtextxy(xs,ys,"Level:");
outtextxy(xs,ys+15,"Score:");
sprintf(stemp," -Roll -Downwards");
stemp[0]=24;
stemp[7]=25;
outtextxy(xs,ys+30,"Help:");
setcolor(14);
outtextxy(xs+40,ys+30,stemp);
outtextxy(xs+40,ys+45,"<-Turn Left >-Turn Right");
outtextxy(xs+40,ys+60,"Esc-Exit R-Restart");
outtextxy(xs,ys+75,"Russia Diamonds Ver 1.0");
outtextxy(xs,ys+90,"CopyRight By ChangYong.01-11-1");
outtextxy(xs,ys+105,"Email:[email protected]");
}
/*****************************************************************************************/
struct diamond *create_I()
{
struct diamond *info;
struct diamond *first;
first=(struct diamond *)malloc(sizeof(struct diamond));
info=(struct diamond *)malloc(sizeof(struct diamond));
first->next=info;
info->next=first;
first->x[0]=0;
first->y[0]=0;
first->x[1]=-1;
first->y[1]=0;
first->x[2]=1;
first->y[2]=0;
first->x[3]=2;
first->y[3]=0;
first->start_x=5;
first->start_y=3;
first->color=2;
info->x[0]=0;
info->y[0]=0;
info->x[1]=0;
info->y[1]=-1;
info->x[2]=0;
info->y[2]=1;
info->x[3]=0;
info->y[3]=2;
info->start_x=5;
info->start_y=1;
info->color=2;
if(random(2)==0) {return first;}
else {return first->next;}
}
/*****************************************************************************************/
struct diamond *create_T()
{
struct diamond *info;
struct diamond *first;
struct diamond *last;
int i;
info=(struct diamond *)malloc(sizeof(struct diamond));
info->x[0]=0;
info->y[0]=0;
info->x[1]=-1;
info->y[1]=0;
info->x[2]=0;
info->y[2]=-1;
info->x[3]=1;
info->y[3]=0;
info->start_x=5;
info->start_y=3;
info->color=4;
first=info;
last=info;
info=(struct diamond *)malloc(sizeof(struct diamond));
info->x[0]=0;
info->y[0]=0;
info->x[1]=0;
info->y[1]=1;
info->x[2]=0;
info->y[2]=-1;
info->x[3]=1;
info->y[3]=0;
info->start_x=5;
info->start_y=2;
info->color=4;
last->next=info;
last=info;
info=(struct diamond *)malloc(sizeof(struct diamond));
info->x[0]=0;
info->y[0]=0;
info->x[1]=-1;
info->y[1]=0;
info->x[2]=1;
info->y[2]=0;
info->x[3]=0;
info->y[3]=1;
info->start_x=5;
info->start_y=2;
info->color=4;
last->next=info;
last=info;
info=(struct diamond *)malloc(sizeof(struct diamond));
info->x[0]=0;
info->y[0]=0;
info->x[1]=0;
info->y[1]=1;
info->x[2]=0;
info->y[2]=-1;
info->x[3]=-1;
info->y[3]=0;
info->start_x=5;
info->start_y=2;
info->color=4;
last->next=info;
last=info;
last->next=first;
for (i=0;i<=random(4);i++)
{
first=first->next;
}
return first;
}
/*****************************************************************************************/
struct diamond *create_L()
{
struct diamond *info;
struct diamond *first;
struct diamond *last;
int i;
info=(struct diamond *)malloc(sizeof(struct diamond));
info->x[0]=0;
info->y[0]=0;
info->x[1]=0;
info->y[1]=1;
info->x[2]=0;
info->y[2]=-1;
info->x[3]=1;
info->y[3]=1;
info->start_x=5;
info->start_y=2;
info->color=5;
first=info;
last=info;
info=(struct diamond *)malloc(sizeof(struct diamond));
info->x[0]=0;
info->y[0]=0;
info->x[1]=-1;
info->y[1]=0;
info->x[2]=1;
info->y[2]=0;
info->x[3]=-1;
info->y[3]=1;
info->start_x=5;
info->start_y=2;
info->color=5;
last->next=info;
last=info;
info=(struct diamond *)malloc(sizeof(struct diamond));
info->x[0]=0;
info->y[0]=0;
info->x[1]=0;
info->y[1]=1;
info->x[2]=0;
info->y[2]=-1;
info->x[3]=-1;
info->y[3]=-1;
info->start_x=5;
info->start_y=2;
info->color=5;
last->next=info;
last=info;
info=(struct diamond *)malloc(sizeof(struct diamond));
info->x[0]=0;
info->y[0]=0;
info->x[1]=-1;
info->y[1]=0;
info->x[2]=1;
info->y[2]=0;
info->x[3]=1;
info->y[3]=-1;
info->start_x=5;
info->start_y=2;
info->color=5;
last->next=info;
last=info;
last->next=first;
for (i=0;i<=random(4);i++)
{
first=first->next;
}
return first;
}
/*****************************************************************************************/
struct diamond *create_J()
{
struct diamond *info;
struct diamond *first;
struct diamond *last;
int i;
info=(struct diamond *)malloc(sizeof(struct diamond));
info->x[0]=0;
info->y[0]=0;
info->x[1]=0;
info->y[1]=1;
info->x[2]=0;
info->y[2]=-1;
info->x[3]=-1;
info->y[3]=1;
info->start_x=5;
info->start_y=2;
info->color=6;
first=info;
last=info;
info=(struct diamond *)malloc(sizeof(struct diamond));
info->x[0]=0;
info->y[0]=0;
info->x[1]=-1;
info->y[1]=0;
info->x[2]=1;
info->y[2]=0;
info->x[3]=-1;
info->y[3]=-1;
info->start_x=5;
info->start_y=2;
info->color=6;
last->next=info;
last=info;
info=(struct diamond *)malloc(sizeof(struct diamond));
info->x[0]=0;
info->y[0]=0;
info->x[1]=0;
info->y[1]=1;
info->x[2]=0;
info->y[2]=-1;
info->x[3]=1;
info->y[3]=-1;
info->start_x=5;
info->start_y=2;
info->color=6;
last->next=info;
last=info;
info=(struct diamond *)malloc(sizeof(struct diamond));
info->x[0]=0;
info->y[0]=0;
info->x[1]=-1;
info->y[1]=0;
info->x[2]=1;
info->y[2]=0;
info->x[3]=1;
info->y[3]=1;
info->start_x=5;
info->start_y=2;
info->color=6;
last->next=info;
last=info;
last->next=first;
for (i=0;i<=random(4);i++)
{
first=first->next;
}
return first;
}
/*****************************************************************************************/
struct diamond *create_Z()
{
struct diamond *info;
struct diamond *first;
first=(struct diamond *)malloc(sizeof(struct diamond));
info=(struct diamond *)malloc(sizeof(struct diamond));
first->next=info;
info->next=first;
first->x[0]=0;
first->y[0]=0;
first->x[1]=-1;
first->y[1]=0;
first->x[2]=0;
first->y[2]=1;
first->x[3]=1;
first->y[3]=1;
first->start_x=5;
first->start_y=2;
first->color=9;
info->x[0]=0;
info->y[0]=0;
info->x[1]=0;
info->y[1]=1;
info->x[2]=1;
info->y[2]=0;
info->x[3]=1;
info->y[3]=-1;
info->start_x=5;
info->start_y=2;
info->color=9;
if(random(2)==0) {return first;}
else {return first->next;}
}
/*****************************************************************************************/
struct diamond *create_N()
{
struct diamond *info;
struct diamond *first;
first=(struct diamond *)malloc(sizeof(struct diamond));
info=(struct diamond *)malloc(sizeof(struct diamond));
first->next=info;
info->next=first;
first->x[0]=0;
first->y[0]=0;
first->x[1]=0;
first->y[1]=1;
first->x[2]=-1;
first->y[2]=1;
first->x[3]=1;
first->y[3]=0;
first->start_x=5;
first->start_y=2;
first->color=14;
info->x[0]=0;
info->y[0]=0;
info->x[1]=0;
info->y[1]=-1;
info->x[2]=1;
info->y[2]=0;
info->x[3]=1;
info->y[3]=1;
info->start_x=5;
info->start_y=2;
info->color=14;
if(random(2)==0) {return first;}
else {return first->next;}
}
/*****************************************************************************************/
struct diamond *create_H()
{
struct diamond *first;
first=(struct diamond *)malloc(sizeof(struct diamond));
first->next=first;
first->x[0]=0;
first->y[0]=0;
first->x[1]=0;
first->y[1]=1;
first->x[2]=1;
first->y[2]=0;
first->x[3]=1;
first->y[3]=1;
first->start_x=5;
first->start_y=2;
first->color=1;
return first;
}
/*****************************************************************************************/
void show_next ()
{
int nowx;/*記錄當前每個格子的位置*/
int nowy;
int i;/*計數器*/
int j;
int haveit;/*當前格子是否已經顯示*/
struct diamond *next;/*當前方塊的翻轉後的下一個狀態*/
next=nowinfo->next;
if (next==NULL) {gotoxy(1,1);printf("null");}
for (i=0;i<=3;i++)/*判斷是否能夠翻轉,若不能,就直接退出該函數*/
{
if (grid[x+next->x[i]][y+next->y[i]]==1)
{
return;
}
}
setfillstyle(SOLID_FILL,backcolor);/*設置背景色以消除不需要的格子*/
for (i=0;i<=3;i++)
{
haveit=0;
for (j=0;j<=3;j++)
{
if (next->x[j]==nowinfo->x[i]&&next->y[j]==nowinfo->y[i]) {haveit=1;break;}
}
if (haveit==0) /*判斷翻轉後該格子是否顯示,若不顯示,將該格子設為背景色*/
{
grid[x+nowinfo->x[i]][y+nowinfo->y[i]]=0;
if (y+nowinfo->y[i]>=4)/*判斷該格子是否到了可以顯示的區域*/
floodfill(80+(nowinfo->x[i]+x)*20+1,-20+(nowinfo->y[i]+y)*20+1,color);
}
}
nowinfo=next;
nowx=x;
nowy=y;
setfillstyle(SOLID_FILL,nowinfo->color);/*設置填沖色為方塊的顏色*/
for (i=0;i<=3;i++)
{
if (grid[x+nowinfo->x[i]][y+nowinfo->y[i]]!=2)/*如果該格子還沒有被顯示*/
{
nowx=x+nowinfo->x[i];
nowy=y+nowinfo->y[i];
if (y+nowinfo->y[i]>=4)
floodfill(80+nowx*20+1,-20+nowy*20+1,color);
grid[nowx][nowy]=2; /*設置該格子當前有活動方塊*/
}
}
return;
}
/*****************************************************************************************/
void show_left ()
{
int i;/*計數器*/
int j;
int haveit;/*當前格子是否已經顯示*/
int nowx;/*記錄當前每個格子的位置*/
int nowy;
for (i=0;i<=3;i++)/*判斷是否可以向左移動*/
{
if (grid[x-1+nowinfo->x[i]][y+nowinfo->y[i]]==1)
{
return;
}
}
setfillstyle(SOLID_FILL,backcolor);/*設置背景色以消除不需要的格子*/
for (i=0;i<=3;i++)
{
haveit=0;
for (j=0;j<=3;j++)
{
if (nowinfo->x[i]==nowinfo->x[j]-1&&nowinfo->y[i]==nowinfo->y[j]) {haveit=1;break;}
}
if (haveit==0) /*判斷翻轉後該格子是否顯示,若不顯示,將該格子設為背景色*/
{
grid[x+nowinfo->x[i]][y+nowinfo->y[i]]=0;
if (y+nowinfo->y[i]>=4)/*判斷該格子是否到了可以顯示的區域*/
floodfill(80+(nowinfo->x[i]+x)*20+1,-20+(nowinfo->y[i]+y)*20+1,color);
}
}
setfillstyle(SOLID_FILL,nowinfo->color);/*設置填沖色為方塊的顏色*/
for (i=0;i<=3;i++)
{
nowx=x+nowinfo->x[i]-1;
nowy=y+nowinfo->y[i];
if (grid[nowx][nowy]!=2)/*如果該格子還沒有被顯示*/
{
if (nowy>=4)
floodfill(80+nowx*20+1,-20+nowy*20+1,color);
grid[nowx][nowy]=2;
}
}
x=x-1;
return;
}
/*****************************************************************************************/
void show_right ()
{
int i;/*計數器*/
int j;
int haveit;/*當前格子是否已經顯示*/
int nowx;/*記錄當前每個格子的位置*/
int nowy;
for (i=0;i<=3;i++)
{
if (grid[x+1+nowinfo->x[i]][y+nowinfo->y[i]]==1)
{
return;/*判斷是否可以向右移動*/
}
}
setfillstyle(SOLID_FILL,backcolor);/*設置背景色以消除不需要的格子*/
for (i=0;i<=3;i++)
{
haveit=0;
for (j=0;j<=3;j++)
{
if (nowinfo->x[i]==nowinfo->x[j]+1&&nowinfo->y[i]==nowinfo->y[j]) {haveit=1;break;}
}
if (haveit==0)/*判斷翻轉後該格子是否顯示,若不顯示,將該格子設為背景色*/
{
grid[x+nowinfo->x[i]][y+nowinfo->y[i]]=0;
if (y+nowinfo->y[i]>=4)/*判斷該格子是否到了可以顯示的區域*/
floodfill(80+(nowinfo->x[i]+x)*20+1,-20+(nowinfo->y[i]+y)*20+1,color);
}
}
setfillstyle(SOLID_FILL,nowinfo->color);/*設置填沖色為方塊的顏色*/
for (i=0;i<=3;i++)
{
nowx=x+nowinfo->x[i]+1;
nowy=y+nowinfo->y[i];
if (grid[nowx][nowy]!=2)
{
if (nowy>=4)/*判斷該格子是否到了可以顯示的區域*/
floodfill(80+nowx*20+1,-20+nowy*20+1,color);
grid[nowx][nowy]=2;
}
}
x=x+1;
return;
}
/*****************************************************************************************/
void show_down ()
{
int i;/*計數器*/
int j;
int haveit;/*當前格子是否已經顯示*/
int nowx;/*記錄當前每個格子的位置*/
int nowy;
int key;
for (i=0;i<=3;i++)
{
if (grid[x+nowinfo->x[i]][y+nowinfo->y[i]+1]==1)/*判斷方塊是否能夠下落*/
{
for (j=0;j<=3;j++)
{
grid[x+nowinfo->x[j]][y+nowinfo->y[j]]=1;
if (y+nowinfo->y[j]<=3)
{/*判斷游戲是否已經玩完*/
install(oldtimer);
setfillstyle(SOLID_FILL,1);
bar(0,465,640,480);
outtextxy(5,469,"Do you want to restart (Y/N)...");
for (;
{
key=bioskey(0);
if (key==YES)
{
startset();
setfillstyle(SOLID_FILL,9);
bar(0,465,640,480);
return;
}
if (key==NO)
{
closegraph();
exit (0);}
}
}
}
delinfo(nowinfo);
scandel();/*掃描,刪除*/
delay(2500);
while(bioskey(1)) bioskey(0);/*清除鍵盤緩沖區*/
/* clrkey();*/
nowinfo=nextinfo;/*得到新的方塊*/
nextinfo=get_diamond();/*得到下一個方塊*/
showsubwin(nextinfo);
x=nowinfo->start_x;/*重新設置方塊位置*/
y=nowinfo->start_y;
return;
}
}
setfillstyle(SOLID_FILL,backcolor);/*設置背景色以消除不需要的格子*/
for (i=0;i<=3;i++)
{
haveit=0;
for (j=0;j<=3;j++)
{
if (nowinfo->x[i]==nowinfo->x[j]&&nowinfo->y[i]==nowinfo->y[j]+1) {haveit=1;break;}
}
......
詳見:
http://topic.csdn.net/t/20030409/15/1638691.html
http://www.anyter.com/doc/doc.asp?doc_id=87
⑻ 用七個俄羅斯方塊形能否不重復的覆蓋一個4×7的棋盤為什麼
特殊方格必位於4個較小子棋盤之一中,其餘3個子棋盤中無特殊方格。為了將這3個無特殊方格的子棋盤轉化為特殊棋盤,可以用一個L型骨牌覆蓋這3個較小棋盤
⑼ 俄羅斯方塊的游戲規則
游戲規則:完整的橫條會隨即消失。
由小方塊組成的不同形狀的板塊陸續從屏幕上方落下來,玩家通過調整板塊的位置和方向,使它們在屏幕底部拼出完整的一條或幾條。這些完整的橫條會隨即消失,給新落下來的板塊騰出空間,與此同時,玩家得到分數獎勵。沒有被消除掉的方塊不斷堆積起來,一旦堆到屏幕頂端,玩家便告輸,游戲結束。
名字起源
俄羅斯方塊自然是俄羅斯人發明的。這人叫阿列克謝·帕基特諾夫(Алексей Пажитнов 英文:Alexey Patnov)。
俄羅斯方塊原名是俄語Тетрис(英語是Tetris),這個名字來源於希臘語tetra,意思是「四」,而游戲的作者最喜歡網球(tennis)。於是,他把兩個詞tetra和tennis合而為一,命名為Tetris,這也就是俄羅斯方塊名字的由來。