俄罗斯方块的源代码?

Python011

俄罗斯方块的源代码?,第1张

#include <graphics.h>

#include <stdio.h>

#include <dos.h>

#include <conio.h>

#include <time.h>

#include <math.h>

#include <stdlib.h>

void draw_block(int x,int y,int style,int way)

void kill_line(int y)

void draw_little_block(int x,int y,int z,int style)

int check_block(int x,int y,int style)

int change(int *i,int *j,int key)

int style1,style,score,speed,l

int board[10][20]

char str[100]

struct shape

{

int xy[8],next

}

struct shape shapes[19]=/*19种方块(前

8个点表示4个小方块的相对位置 第9点表示类型) */

{

{

0,-2, 0,-1, 0, 0, 1, 0, 1

},

{-1, 0, 0, 0, 1,-1, 1, 0, 2},

{ 0,-2, 1,-2, 1,-1, 1, 0, 3},

{-1,-1,-1, 0, 0,-1, 1,-1, 0},

{ 0,-2, 0,-1, 0, 0, 1,-2, 5},

{-1,-1, 0,-1, 1,-1, 1, 0, 6},

{ 0, 0, 1,-2, 1,-1, 1, 0, 7},

{-1,-1,-1, 0, 0, 0, 1, 0, 4},

{-1, 0, 0,-1, 0, 0, 1, 0, 9},

{ 0,-2, 0,-1, 0, 0, 1,-1,10},

{-1,-1, 0,-1, 1,-1, 0, 0,11},

{ 0,-1, 1,-2, 1,-1, 1, 0, 8},

{-1, 0, 0,-1, 0, 0, 1,-1,13},

{ 0,-2, 0,-1, 1,-1, 1, 0,12},

{-1,-1, 0,-1, 0, 0, 1, 0,15},

{ 0,-1, 0, 0, 1,-2, 1,-1,14},

{ 0,-3, 0,-2, 0,-1, 0, 0,17},

{-1, 0, 0, 0, 1, 0, 2, 0,16},

{ 0,-1, 0, 0, 1,-1, 1, 0,18}

}

#define MAPXOFT 9/* 第1个方块的位置 */

#define MAPYOFT 5

#define MAPXOFT1 18 /* 下一个方块的位置 */

#define MAPYOFT1 17

#define LEFT 0x4b00

#define RIGHT 0x4d00

#define DOWN 0x5000

#define UP0x4800

#define ESC 0x011b

#define ENTER 0x1c0d

int main()

{

int gdriver,gmode,

i,j,key,x0=5,y0=1,m,n,c,key1,p,q,le=0,b

l=1,score=0

gdriver=DETECT

initgraph(&gdriver,&gmode,"D:\\TURBOC2")

randomize()

for(m=0m<=19m++)

for(n=0n<=19n++)

board[m][n]=0/* 初始游戏版 */

setcolor(10) /* 开机的画面 */

settextstyle(0,0,3)

outtextxy(10,150,"WELCOME TO RUSSIS")

outtextxy(10,250,"READY GO")

setcolor(14)

settextstyle

(0,0,4)

outtextxy(10,350,"^_^")

/*

circle(400,350,60)

ellipse(370,340,60,120,25,25)

ellipse(430,340,60,120,25,25)

ellipse(400,350,225,315,30,30)*/

getch()

settextstyle(0,0,1)

cleardevice()

setcolor(LIGHTRED)/* 画出游戏所在的范围图

*/

setlinestyle(0,0,3)

setfillstyle(1,14)

rectangle(157,419,533,429)

floodfill(300,424,LIGHTRED)

setcolor(LIGHTRED)

setlinestyle(0,0,3)

setfillstyle(1,14)

rectangle(147,95,157,429)

floodfill(152,200,LIGHTRED)

setcolor(LIGHTRED)

setlinestyle(0,0,3)

setfillstyle(1,14)

rectangle(323,95,333,429)

floodfill(330,320,LIGHTRED)

setcolor(LIGHTRED)

setlinestyle(0,0,1)

setfillstyle(1,BLUE)

rectangle(450,50,500,70)

floodfill(455,55,LIGHTRED)

setcolor(10)

for(m=0m<=10m=m+2)

ellipse(240,94,0,180,84+m,84+m)

setcolor(14)

setfillstyle(1,0)

circle(440,330,60)

floodfill(440,330,14)

outtextxy(420,80,"* you can change the game")

/* 对游戏的说明 */

outtextxy(440,90,"-speed and the gradth by") /*

上为变形 左右 为 调整

下为快下 ESC为退出 */

outtextxy(440,100," using 'up'and'down'.")

outtextxy(420,110,"* when you are plying the")

outtextxy(440,120,"game,you can use these pu")

outtextxy(440,130,"-tturns.")

outtextxy(420,140,"* if you want to go into t")

outtextxy(440,150,"-he game,please 'enter'.")

outtextxy(420,160,"* you can chang shapes ")

outtextxy(440,170," using UP")

outtextxy(420,180,"* RIGHT and LEFT can" )

outtextxy(440,190," move shapes")

outtextxy(10,40,"GAMESPEED:")

outtextxy(10,100,"GRADTH:")

printf("\n\n\n 1")

printf("\n\n\n\n 0")

/* setcolor(LIGHTRED)

setlinestyle(0,0,1)

setfillstyle(1,10)

rectangle(10,65,110,85)

floodfill(15,75,LIGHTRED) */

outtextxy(450,40,"SCORES:")

outtextxy(10,190,"**The speed will")

outtextxy(10,200,"increas if score")

outtextxy(10,210,"increas 3")

for(p=0p<=100p++) /* 对速度的调整 */

{ key=bioskey(0)

if(key==ENTER)

break

if(key==UP)

{

if(l==9)

l=9

if(l<9)

l++

}

if(key==DOWN)

{

if(l==1)

l=l

if(l>1)

l--

}

gotoxy(2,4)

printf("%d",l)

}

for(q=0q<=100q++) /* 对高度的调整 */

{

key=bioskey(0)

if(key==ENTER)

break

if(key==UP)

{

if(le==5)

le=le

if(le<5)

le++

}

if(key==DOWN)

{

if(le==0)

le=le

if(le>0)

le--

}

gotoxy(2,8)

printf("%d",le)

}

key=bioskey(0)

if(key==ENTER)

{

style=random(19)

for(m=1m<=lem++) /* 具体的对高度的调整 */

{

b=random(7)+1

for(n=1n<=10n++)

{

if(random(2))

{

board[n-1][20-m]=1

draw_little_block(MAPXOFT+n,MAPYOFT+21-m,1,b)

}

}

}

while(1)

{

while(1)

{

i=x0,j=y0

style1=random(19)

setcolor(14) /* 画出下一个方

块 */

draw_block(MAPXOFT1,MAPYOFT1,style1,1)

for(j=y0j<=20j++)

{

while(1)

{

if(bioskey(1)) /* 方块的

调整 */

{

key=bioskey(0)

change(&i,&j,key)

}

if(!check_block

(i,j+1,style)) /* 判断方块能不能下降 */

break

if(j==20)

break

if(speed==1)

{

draw_block

(i,j,style,0)/* 方块的下降 */

j++

draw_block

(i,j,style,1)

delay(10000)

}

if(speed!=1)

{

m++

delay

(10000)

if(m>=3*(10-l))

{

m=0

draw_block

(i,j,style,0)/* 方块的下降 */

j++

draw_block

(i,j,style,1)

}

}

}

speed=0

for(m=0m<=6m+=2) /* 对有方块的位置给予1

的数值 */

board[i+shapes[style].xy[m]-1]

[j+shapes[style].xy[m+1]-1]=1

if(board[ i][4]==1)

{

setcolor(14)

settextstyle(0,0,2)

outtextxy(10,450,"CAREFUL -_-")

delay(100000000)

delay(100000000)

setcolor(0)

outtextxy(10,450,"CAREFUL -_-")

settextstyle(0,0,1)

setcolor(LIGHTRED)

}

/* setcolor(LIGHTRED)

setlinestyle(0,0,1)

setfillstyle(1,10)

rectangle(10,65,110,85)

floodfill(15,75,LIGHTRED)*/

if(l==1) /* 显示当前游戏等级 */

{

setcolor(LIGHTRED)

setlinestyle(0,0,1)/* 容易的速度 */

setfillstyle(1,10)

rectangle(10,65,110,85)

floodfill(15,75,LIGHTRED)

outtextxy(7,70," easy speed")

}

if(l==4)

{

setcolor(BLACK)

outtextxy(7,70," easy speed")

setcolor(LIGHTRED)/* 中等难度 */

setlinestyle(0,0,1)

setfillstyle(1,10)

rectangle(10,65,110,85)

floodfill(15,75,LIGHTRED)

outtextxy(7,70," normal speed")

}

if(l==7)

{

setcolor(BLACK)

outtextxy(7,70," normal speed")

setcolor(LIGHTRED)

setlinestyle(0,0,1)/* 困难的难度 */

setfillstyle(1,10)

rectangle(10,65,110,85)

floodfill(15,75,LIGHTRED)

outtextxy(7,70," hard speed")

}

kill_line(j)

if(j==20)

break

if(!check_block(i,j+1,style))

break

}

draw_block(MAPXOFT1,MAPYOFT1,style1,0)

/* 对下1个方块显示位置进行覆盖 */

style=style1/* 使的方块和显示的方块一样

*/

if(j==1) /* 关机的画面 */

{

setcolor(14)

settextstyle(0,0,2)

outtextxy(170,200,"GAME OVER")

outtextxy(170,240,"THANK YOU")

sleep(3)

exit(0)

}

}

}

}

getch()

}

int change(int *i,int *j,int key) /* 方块的具体的变化(

移动 变形 下降) */

{

if(key==UP&&check_block(*i,*j,shapes[style].next)) /*

变形 */

{

draw_block(*i,*j,style,0)

style=shapes[style].next

draw_block(*i,*j,style,1)

}

else if(key==LEFT&&check_block(*i-1,*j,style)) /* 移动

*/

{

draw_block(*i,*j,style,0)

(*i)--

draw_block(*i,*j,style,1)

}

else if(key==RIGHT&&check_block(*i+1,*j,style))

{

draw_block(*i,*j,style,0)

(*i)++

draw_block(*i,*j,style,1)

}

else if(key==DOWN&&check_block(*i,*j+1,style)) /* 下降

*/

{

draw_block(*i,*j,style,0)

(*j)++

draw_block(*i,*j,style,1)

speed=1

}

else if(key==ESC) /* 退出 */

exit(0)

}

void draw_block(int x,int y,int style,int way) /* 画出方块

的位置 */

{

int x1=x+MAPXOFT,y1=y+MAPYOFT

int i

if(way==1)

{

setcolor(WHITE)

}

else

{

setcolor(BLACK)

}

for(i=0i<=6i+=2)

{

draw_little_block(x1+shapes[style].xy[

i],y1+shapes[style].xy[i+1],way,style)

}

}

void draw_little_block(int x,int y,int z,int style) /* 画

出方块的每一个小方块的形状(方块的色彩) */

{ int m,n

if(z==1) /* 对色彩的调整 */

{

if(0<=style&&style<=3)

n=2

if(4<=style&&style<=7)

n=3

if(8<=style&&style<=11)

n=4

if(12<=style&&style<=13)

n=5

if(14<=style&&style<=15)

n=6

if(16<=style&&style<=17)

n=7

if(style==18)

n=8

m=1

}

if(z==0)

{

m=0,n=0

}

setcolor(m)

setfillstyle(1,n)

rectangle(x*16,y*16,x*16+16,y*16+16)

floodfill(x*16+2,y*16+2,m)

}

void kill_line(int y) /* 消行 */

{

int i,t=1,j,k,color=random(7)+1

for(y>=1&&t<=4y--,t++) /* 对4行进行验证 */

{

for(i=1i<=10i++)

if(!board[i-1][y-1]) /* 严整1行的数组是不是全

为1 */

break

if(i==11)

{

setcolor(LIGHTRED) /* 对积分底色的画法

*/

setlinestyle(0,0,1)

setfillstyle(1,BLUE)

rectangle(450,50,500,70)

floodfill(455,55,LIGHTRED)

score++/* 每消去1行 可以得1分 */

setcolor(14)

itoa(score,str,10)

outtextxy(460,55,str)

if(score!=0&&score%3==0)

l++/* 每次分到一定位置是 速度进

行提高(目前是3行加1次 可以调整) */

setcolor(14)/* 每次消去是进行庆祝模式 */

settextstyle(0,0,4)

outtextxy(10,310,"COOL")

outtextxy(10,270,"^_^")

delay(100000000)

delay(100000000)

delay(100000000)

setcolor(BLACK)

settextstyle(0,0,4)

outtextxy(10,310,"COOL")

outtextxy(10,270,"^_^")

settextstyle(0,0,1)

if(score%3==0&&score!=0)

{

setcolor(14)

settextstyle(0,0,2)

outtextxy(10,435,"CONGRATULATION ON YOU ^_^")

sleep(2)

setcolor(BLACK)

settextstyle(0,0,2)

outtextxy(10,435,"CONGRATULATION ON YOU ^_^ ")

settextstyle(0,0,1)

}

for(k=1k<=10k++) /* 对满了行进行消去

*/

{

setcolor(BLACK)

draw_little_block

(k+MAPXOFT,y+MAPYOFT,0,2)

}

for(j=y-1j>=1j--) /* 消去1行后 用上面的

累下来(并且调整色彩) */

for(k=1k<=10k++)

{

board[k-1][j]=board[k-1][j-1]

if(board[k-1][j])

{

setcolor(BLACK)

draw_little_block

(k+MAPXOFT,j+MAPYOFT,0,2)

setcolor(WHITE)

draw_little_block

(k+MAPXOFT,j+1+MAPYOFT,1,color)

}

}

delay(100000000000)

y++

}

}

}

int check_block(int x,int y,int style) /* 验证能不能往下1

个位置累方块 */

{

int x1=x+MAPXOFT,y1=y+MAPYOFT

int x2,y2,i

for(i=0i<=6i+=2)

{

x2=x1+shapes[style].xy[ i]

y2=y1+shapes[style].xy[i+1]

if(x2>=10&&x2<20&&y2<26&&(y2<6||board[x2-10][y2-

6]==0))

continue

else

break

}

if(i==8)

return 1

else

return 0

getch()

}

我这里也是别人那里看来的。希望对你有用

#include <windows.h>

#include <conio.h>

#include <string>

#include <time.h>

#include <iostream>

#define up 72

#define down80

#define left75

#define right 77

#define esc 27

using namespace std//-----------------------

// 重要数据定义

typedef struct m_point { //控制台中的坐标点定义, 其中0<=x<=24, 0<=y<79

int x

int y

}m_point

typedef struct block { //方块定义, 一个方块有四个点, 例如: ■■■

// ■

m_point opt

m_point pt2

m_point pt3

m_point pt4

}block

block bloary[6][4]//方块数组,一共有6种,每种有4个方向

bool scrop[15][10]//游戏空间定义,初始值全标记为0,向屏幕打印蓝色方块,

//如果标记为1,则向屏幕找印深蓝色方块

// 数据定义完毕//---------------------------

// 功能函数声明

void begin()//开始函数

void color(int n_color) //设置字符颜色

int getrand(int max)//获得不大于max的随机数

void go(int x, int y) //使光移动到指定位置

void show_unit()//输出 ■ 字符

char getudlr() //接受键盘上的上下左右及回车键并返回相应字符 u d l r k

void show_block(block b)//输出方块

void init() //初始化block bloary[6][4]数组

void show_scrop() //根据scrop[15][10]的值打印相应颜色的方块

bool isexist(block b) //判断当前方块中的四个坐标是否在游戏空间中被标记为 1

void markspace(block b) //当方块停留时,把方块四个点的坐标在游戏空间数组scrop[][]中的相应位置标记为1

void move_block(block &b, char ch, int &lark)//移动方块

void change_block(block &b, int i, int &j, int lark) //改变当前方块的方向,注:一共有四个方向

void check(int &score) //消行函数

void wait(float secs) //让程序等待secs秒

void othergetch() //起暂停功能

void out(char* chars, int n) //相当于C++中的cout功能

void initb(int optx, int opty, //容易看出这个函数中传递了8个int值,分别用于这四点的横坐标和纵坐标,

//另外bloc是一个block结构体,block结构体中含有8个int值来表示方块的4个点

int pt2x, int pt2y,

int pt3x, int pt3y,

int pt4x, int pt4y,

block &bloc)

// 功能函数声明完毕

void show_unit2()

{

WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE)," ",2,0,0)

}

void show_block2(block b)

{

go(b.opt.x, b.opt.y)

show_unit2()

go(b.pt2.x, b.pt2.y)

show_unit2()

go(b.pt3.x, b.pt3.y)

show_unit2()

go(b.pt4.x, b.pt4.y)

show_unit2()

}

int main()

{

system("color ec")

system("title 俄罗斯方块")

color(0xec)

go(33,2)

out("制作人:赵晨晔",22)

go(33,3)

out("游戏规则:",10)

go(33,4)

out("1.按左右下键进行移动",20)

go(33,5)

out("2.按向上键改变形状",18)

go(10,0)

for (int ckh=0ckh<15ckh++)

{

go(20,ckh)

cout<<"║"

}

go(0,15)

cout<<"══════════■"

begin()

return 0

}// 以下是功能函数定义部分

void begin()

{

init()

static int score = 0

for(int i=0i<15i++)

for(int j=0j<10j++)

scrop[i][j]=0

int lev=0

cout<<"请输入速度(1~9)"

cin>>lev

while(1)

{

block b

int lark=1

int i=getrand(6)

int j=getrand(4)

go(20,21)

b = bloary[i][j]

show_scrop()

show_block(b)

if(isexist(b))

{

system("cls")

go(37,12)

out("失败,结束!",10)

othergetch()

exit(-1)

} while(lark!=0)

{

show_scrop()

show_block(b)

int delay=10*lev

int max_delay=100

char ch='\0'

while(delay<max_delay)

{

if(_kbhit())

{

int key=_getch()

switch (key)

{

case up:

show_block2(b)

change_block(b, i, j, lark)

show_block(b)

break

case down:

ch='d'

delay=max_delay

break

case left:

ch='l'

show_block2(b)

move_block(b, ch, lark)

show_block(b)

break

case right:

ch='r'

show_block2(b)

move_block(b, ch, lark)

show_block(b)

break

case esc:

exit(-1)

break

}

}

_sleep(3)

delay++

}

if (ch='d'){

show_block2(b)

move_block(b,ch,lark)

show_block(b)

}

}

if(lark==0)

{

markspace(b)

}

check(score)

}

}// 函数作用:初始化bloary[6][4]数组,这个数组表示16个方块的结构体,具体是,

// 一共有6种方块,每种方块又有4种不同的方向(也就是种不同的形状)

// 其中initb函数将在下面定义

void init(){

////////////////////////////////////////////////////////////

/**/ initb(2, 1, 0, 0, 2, 0, 0, 1, bloary[0][0]) /////

/**/ initb(2, 1, 0, 0, 2, 0, 0, 1, bloary[0][1]) /////

/**/ initb(2, 1, 0, 0, 2, 0, 0, 1, bloary[0][2]) /////

/**/ initb(2, 1, 0, 0, 2, 0, 0, 1, bloary[0][3]) /////

/**/ initb(2, 1, 0, 1, 4, 1, 6, 1, bloary[1][0]) /////

/**/ initb(2, 1, 2, 0, 2, 2, 2, 3, bloary[1][1]) /////

/**/ initb(2, 1, 0, 1, 4, 1, 6, 1, bloary[1][2]) /////

/**/ initb(2, 1, 2, 0, 2, 2, 2, 3, bloary[1][3]) /////

/**/ initb(2, 1, 0, 0, 0, 1, 4, 1, bloary[2][0]) /////

/**/ initb(2, 1, 2, 0, 4, 0, 2, 2, bloary[2][1]) /////

/**/ initb(2, 1, 0, 1, 4, 1, 4, 2, bloary[2][2]) /////

/**/ initb(2, 1, 2, 0, 0, 2, 2, 2, bloary[2][3]) /////

/**/ initb(2, 1, 4, 0, 0, 1, 4, 1, bloary[3][0]) /////

/**/ initb(2, 1, 2, 0, 2, 2, 4, 2, bloary[3][1]) /////

/**/ initb(2, 1, 0, 1, 4, 1, 0, 2, bloary[3][2]) /////

/**/ initb(2, 1, 0, 0, 2, 0, 2, 2, bloary[3][3]) /////

/**/ initb(2, 1, 2, 0, 0, 1, 4, 1, bloary[4][0]) /////

/**/ initb(2, 1, 2, 0, 4, 1, 2, 2, bloary[4][1]) /////

/**/ initb(2, 1, 0, 1, 4, 1, 2, 2, bloary[4][2]) /////

/**/ initb(2, 1, 2, 0, 0, 1, 2, 2, bloary[4][3]) /////

/**/ initb(2, 1, 2, 0, 4, 0, 0, 1, bloary[5][0]) /////

/**/ initb(2, 1, 2, 0, 4, 1, 4, 2, bloary[5][1]) /////

/**/ initb(2, 1, 2, 0, 4, 0, 0, 1, bloary[5][2]) /////

/**/ initb(2, 1, 2, 0, 4, 1, 4, 2, bloary[5][3]) /////

////////////////////////////////////////////////////////////

}

// 函数作用:初始化方块,一个方块具有四个坐标,如 ■■■

//■

// 容易看出这个函数中传递了8个int值,分别用于这四点的横坐标和纵坐标,

// 另外bloc是一个block结构体,block结构体中含有8个int值来表示方块的4个点

void initb(int optx, int opty,

int pt2x, int pt2y,

int pt3x, int pt3y,

int pt4x, int pt4y,

block &bloc)

{

bloc.opt.x = optx

bloc.opt.y = opty

bloc.pt2.x = pt2x

bloc.pt2.y = pt2y

bloc.pt3.x = pt3x

bloc.pt3.y = pt3y

bloc.pt4.x = pt4x

bloc.pt4.y = pt4y

}

// 函数作用:这个函数的作用是在控制台下打印游戏空间,即数组scrop[15][10],

// 如果scrop[i][j]是0,则用0xab色打印■字符

// 如果scrop[i][j]是1,则用0xb3色打印■字符

// 打印效果为10*15的矩形方块,我把它称为游戏空间

void show_scrop(){

go(0,0)

for (int i=0i<15i++)

{

for (int j=0j<10j++)

{

if (0==scrop[i][j])

{

color(0x00)

show_unit()

}

else

{

color(0x03)

show_unit()

}

}

go(0,i+1)

}

go(0,0)

color(0x0c)

}

//函数作用:判断当前方块中的四个坐标是否在游戏空间中被标记为 1

bool isexist(block b)

{

if (scrop[b.opt.y][b.opt.x/2]==1||

scrop[b.pt2.y][b.pt2.x/2]==1||

scrop[b.pt3.y][b.pt3.x/2]==1||

scrop[b.pt4.y][b.pt4.x/2]==1)

return true

else

return false

}

//函数作用:移动方块

void move_block(block &b, char ch, int &lark){

block copyb = b

switch(ch)

{

case 'l': //左移

b.opt.x=b.opt.x-2

b.pt2.x=b.pt2.x-2

b.pt3.x=b.pt3.x-2

b.pt4.x=b.pt4.x-2

break

case 'r': //右移

b.opt.x=b.opt.x+2

b.pt2.x=b.pt2.x+2

b.pt3.x=b.pt3.x+2

b.pt4.x=b.pt4.x+2

break

case 'd': //下移

b.opt.y=b.opt.y+1

b.pt2.y=b.pt2.y+1

b.pt3.y=b.pt3.y+1

b.pt4.y=b.pt4.y+1

break

}

if(b.opt.x<0||b.opt.x>18||

b.pt2.x<0||b.pt2.x>18||

b.pt3.x<0||b.pt3.x>18||

b.pt4.x<0||b.pt4.x>18

) //过左右界还原

{

b = copyb

}

if(b.opt.y>14||

b.pt2.y>14||

b.pt3.y>14||

b.pt4.y>14||

isexist(b)

) //到底还原或重叠还原

{

b = copyb

lark = 0//lark = 0 表示方块停下

}

//消除按左右键导致重叠时发生停留现象

if(ch=='l'||ch=='r')

{

lark = 1

}

//消除按左右键导致重叠时发生停留现象...

}

//函数作用:改变当前方块的方向,注:一共有四个方向

void change_block(block &b, int i, int &j, int lark){

block copyb = b

int orx = b.opt.x

int ory = b.opt.y

j = j+1

j = j%4

b = bloary[i][j]

if(b.opt.x<orx)

{

int i = orx - b.opt.x

for(int j=0j<i/2j++)

{

b.opt.x=b.opt.x+2

b.pt2.x=b.pt2.x+2

b.pt3.x=b.pt3.x+2

b.pt4.x=b.pt4.x+2

}

}

if(b.opt.y<ory)

{

int i = ory - b.opt.y

for(int j=0j<ij++)

{

b.opt.y=b.opt.y+1

b.pt2.y=b.pt2.y+1

b.pt3.y=b.pt3.y+1

b.pt4.y=b.pt4.y+1

}

}

if(b.opt.x<0||b.opt.x>18||

b.pt2.x<0||b.pt2.x>18||

b.pt3.x<0||b.pt3.x>18||

b.pt4.x<0||b.pt4.x>18

)

{

b = copyb

j--

}

if(b.opt.y>14||

b.pt2.y>14||

b.pt3.y>14||

b.pt4.y>14||

isexist(b)

)

{

b = copyb

j--

lark = 0

}

}

// 函数作用:消行

void check(int &score){

bool mark = 1

int line = 0

int line_marked[4] = {0, 0, 0, 0}// line_marked用于记录游戏空间中被全部标记的某一行的行号,(即需要被消去的行的行号)

int kai=0// s 用于记录line_marked中当前被标记的个数

//检查哪些行需要消去

for(int i=0i<15i++)

{

for(int j=0j<10j++)

{

if(scrop[i][j]==0)

mark = 0

}

if(mark==1)

{

line++

line_marked[kai++] = i

score++

}

mark=1

}

//检查哪些行需要消去...

go(25,21)

go(28, 21)

cout<<"分数: "<<score //打印分数

if(score==100)

{

system("cls")

go(37,12)

out("通关",4)

othergetch()

exit(-1)

}

int dis = line

//消行前闪烁

for(int goline=0goline<kaigoline++)

{

color(0x04)

go(0,line_marked[goline])

int s=0

for(s<10s++)

{

out("■",2)

}

wait(.1f)

color(0x0d)

go(0,line_marked[goline])

for(s=0s<10s++)

{

out("■",2)

}

wait(.1f)

}

//消行前闪烁...

kai = 0

//消行

for(int k=1k<=dis++k)

{

for (int p=line_marked[kai++]p>=1p--)

{

for (int q=0q<10q++)

{

scrop[p][q]=scrop[p-1][q]

}

}

for(int h=0h<10h++)

{

scrop[0][h]=0

}

}

//消行...

}

//函数作用:当方块停留时,把方块四个点的坐标在游戏空间数组scrop[][]中的相应位置标记为1

void markspace(block b)

{

for (int i=0i<15i++)

{

for (int j=0j<10j++)

{

if((b.opt.x==2*j &&b.opt.y==i)||

(b.pt2.x==2*j &&b.pt2.y==i)||

(b.pt3.x==2*j &&b.pt3.y==i)||

(b.pt4.x==2*j &&b.pt4.y==i))

{

scrop[i][j]=1

}

}

}

}

//函数作用:输出方块

void show_block(block b)

{

go(b.opt.x, b.opt.y)

show_unit()

public void go()//主调方法 表示 1 step 如果游戏没结束则继续 如此往复直到游戏结束

{

if (downCheck())//如果有下落空间

{

down()//下落操作

}

else//如果到底了 或者 跟其他shape接触

{

merge()//把 “卡住”的方块 “印”到画布(容器gameArea)中去,意思就是把卡住的方块“堆”到游戏区

if (!isOver)//如果游戏没有结束(判断依据为方块是否已经堆积到容器的顶端) 重新实例化一个shape 让他down下来

{

shape s = new shape()

int pindx = 0

for (int i = 0i <s.transform.GetLength(0)i++)

{

for (int j = 0j <s.transform.GetLength(1)j++)

{

if (s.transform[i, j] == true)

{

sh[pindx++] = new Point(j, i)

}

}

}

}

}

setScore()//在重新实例化之前先检查 gameArea 看是否有可消除的行 并计算得分