1.俄罗斯方块的安卓源代码?
2.C++教程:俄罗斯方块源码+注释+解答
3.java编写的俄罗斯方块游戏
4.求俄罗斯方块源代码
5.求一份用C语言编写的俄罗斯方块的源代码!
俄罗斯方块的俄罗俄罗源代码?
#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[][];
char str[];
struct shape
{
int xy[8],next;
};
struct shape shapes[]= /* 种方块(前
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,},
{ -1,-1, 0,-1, 1,-1, 0, 0,},
{ 0,-1, 1,-2, 1,-1, 1, 0, 8},
{ -1, 0, 0,-1, 0, 0, 1,-1,},
{ 0,-2, 0,-1, 1,-1, 1, 0,},
{ -1,-1, 0,-1, 0, 0, 1, 0,},
{ 0,-1, 0, 0, 1,-2, 1,-1,},
{ 0,-3, 0,-2, 0,-1, 0, 0,},
{ -1, 0, 0, 0, 1, 0, 2, 0,},
{ 0,-1, 0, 0, 1,-1, 1, 0,}
};
#define MAPXOFT 9 /* 第1个方块的位置 */
#define MAPYOFT 5
#define MAPXOFT1 /* 下一个方块的位置 */
#define MAPYOFT1
#define LEFT 0x4b
#define RIGHT 0x4d
#define DOWN 0x
#define UP 0x
#define ESC 0xb
#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=0;m<=;m++)
for(n=0;n<=;n++)
board[m][n]=0; /* 初始游戏版 */
setcolor(); /* 开机的画面 */
settextstyle(0,0,3);
outtextxy(,,"WELCOME TO RUSSIS");
outtextxy(,,"READY GO");
setcolor();
settextstyle
(0,0,4);
outtextxy(,,"^_^");
/
*circle(,,);
ellipse(,,,,,);
ellipse(,,,,,);
ellipse(,,,,,);*/
getch();
settextstyle(0,0,1);
cleardevice();
setcolor(LIGHTRED); /* 画出游戏所在的范围图
*/
setlinestyle(0,0,3);
setfillstyle(1,);
rectangle(,,,);
floodfill(,,LIGHTRED);
setcolor(LIGHTRED);
setlinestyle(0,0,3);
setfillstyle(1,);
rectangle(,,,);
floodfill(,,LIGHTRED);
setcolor(LIGHTRED);
setlinestyle(0,0,3);
setfillstyle(1,);
rectangle(,,,);
floodfill(,,LIGHTRED);
setcolor(LIGHTRED);
setlinestyle(0,0,1);
setfillstyle(1,BLUE);
rectangle(,,,);
floodfill(,,LIGHTRED);
setcolor();
for(m=0;m<=;m=m+2)
ellipse(,,0,,+m,+m);
setcolor();
setfillstyle(1,0);
circle(,,);
floodfill(,,);
outtextxy(,,"* you can change the game");
/* 对游戏的说明 */
outtextxy(,,"-speed and the gradth by"); /
*上为变形 左右 为 调整
下为快下 ESC为退出 */
outtextxy(,," using 'up'and'down'.");
outtextxy(,,"* when you are plying the");
outtextxy(,,"game,you can use these pu");
outtextxy(,,"-tturns.");
outtextxy(,,"* if you want to go into t");
outtextxy(,,"-he game,please 'enter'.");
outtextxy(,,"* you can chang shapes ");
outtextxy(,," using UP");
outtextxy(,,"* RIGHT and LEFT can" );
outtextxy(,," move shapes");
outtextxy(,,"GAMESPEED:");
outtextxy(,,"GRADTH:");
printf("\n\n\n 1");
printf("\n\n\n\n 0");
/* setcolor(LIGHTRED);
setlinestyle(0,0,1);
setfillstyle(1,);
rectangle(,,,);
floodfill(,,LIGHTRED); */
outtextxy(,,"SCORES:");
outtextxy(,,"**The speed will");
outtextxy(,,"increas if score");
outtextxy(,,"increas 3");
for(p=0;p<=;p++) /* 对速度的调整 */
{ 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=0;q<=;q++) /* 对高度的调整 */
{
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();
for(m=1;m<=le;m++) /* 具体的对高度的调整 */
{
b=random(7)+1;
for(n=1;n<=;n++)
{
if(random(2))
{
board[n-1][-m]=1;
draw_little_block(MAPXOFT+n,MAPYOFT+-m,1,b);
}
}
}
while(1)
{
while(1)
{
i=x0,j=y0;
style1=random();
setcolor(); /* 画出下一个方
块 */
draw_block(MAPXOFT1,MAPYOFT1,style1,1);
for(j=y0;j<=;j++)
{
while(1)
{
if(bioskey(1)) /* 方块的
调整 */
{
key=bioskey(0);
change(&i,&j,key);
}
if(!check_block
(i,j+1,style)) /* 判断方块能不能下降 */
break;
if(j==)
break;
if(speed==1)
{
draw_block
(i,j,style,0); /* 方块的下降 */
j++;
draw_block
(i,j,style,1);
delay();
}
if(speed!=1)
{
m++;
delay
();
if(m>=3*(-l))
{
m=0;
draw_block
(i,j,style,0); /* 方块的下降 */
j++;
draw_block
(i,j,style,1);
}
}
}
speed=0;
for(m=0;m<=6;m+=2) /* 对有方块的位置给予1
的数值 */
board[i+shapes[style].xy[m]-1]
[j+shapes[style].xy[m+1]-1]=1;
if(board[ i][4]==1)
{
setcolor();
settextstyle(0,0,2);
outtextxy(,,"CAREFUL -_-");
delay();
delay();
setcolor(0);
outtextxy(,,"CAREFUL -_-");
settextstyle(0,0,1);
setcolor(LIGHTRED);
}
/* setcolor(LIGHTRED);
setlinestyle(0,0,1);
setfillstyle(1,);
rectangle(,,,);
floodfill(,,LIGHTRED);*/
if(l==1) /* 显示当前游戏等级 */
{
setcolor(LIGHTRED);
setlinestyle(0,0,1); /* 容易的速度 */
setfillstyle(1,);
rectangle(,,,);
floodfill(,,LIGHTRED);
outtextxy(7,," easy speed");
}
if(l==4)
{
setcolor(BLACK);
outtextxy(7,," easy speed");
setcolor(LIGHTRED); /* 中等难度 */
setlinestyle(0,0,1);
setfillstyle(1,);
rectangle(,,,);
floodfill(,,LIGHTRED);
outtextxy(7,," normal speed");
}
if(l==7)
{
setcolor(BLACK);
outtextxy(7,," normal speed");
setcolor(LIGHTRED);
setlinestyle(0,0,1); /* 困难的难度 */
setfillstyle(1,);
rectangle(,,,);
floodfill(,,LIGHTRED);
outtextxy(7,," hard speed");
}
kill_line(j);
if(j==)
break;
if(!check_block(i,j+1,style))
break;
}
draw_block(MAPXOFT1,MAPYOFT1,style1,0);
/* 对下1个方块显示位置进行覆盖 */
style=style1; /* 使的方块和显示的方块一样
*/
if(j==1) /* 关机的画面 */
{
setcolor();
settextstyle(0,0,2);
outtextxy(,,"GAME OVER");
outtextxy(,,"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=0;i<=6;i+=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<=)
n=4;
if(<=style&&style<=)
n=5;
if(<=style&&style<=)
n=6;
if(<=style&&style<=)
n=7;
if(style==)
n=8;
m=1;
}
if(z==0)
{
m=0,n=0;
}
setcolor(m);
setfillstyle(1,n);
rectangle(x*,y*,x*+,y*+);
floodfill(x*+2,y*+2,m);
}
void kill_line(int y) /* 消行 */
{
int i,t=1,j,k,color=random(7)+1;
for(;y>=1&&t<=4;y--,t++) /* 对4行进行验证 */
{
for(i=1;i<=;i++)
if(!board[i-1][y-1]) /* 严整1行的数组是不是全
为1 */
break;
if(i==)
{
setcolor(LIGHTRED); /* 对积分底色的画法
*/
setlinestyle(0,0,1);
setfillstyle(1,BLUE);
rectangle(,,,);
floodfill(,,LIGHTRED);
score++; /* 每消去1行 可以得1分 */
setcolor();
itoa(score,str,);
outtextxy(,,str);
if(score!=0&&score%3==0)
l++; /* 每次分到一定位置是 速度进
行提高(目前是3行加1次 可以调整) */
setcolor(); /* 每次消去是进行庆祝模式 */
settextstyle(0,0,4);
outtextxy(,,"COOL");
outtextxy(,,"^_^");
delay();
delay();
delay();
setcolor(BLACK);
settextstyle(0,0,4);
outtextxy(,,"COOL");
outtextxy(,,"^_^");
settextstyle(0,0,1);
if(score%3==0&&score!=0)
{
setcolor();
settextstyle(0,0,2);
outtextxy(,,"CONGRATULATION ON YOU ^_^");
sleep(2);
setcolor(BLACK);
settextstyle(0,0,2);
outtextxy(,,"CONGRATULATION ON YOU ^_^ ");
settextstyle(0,0,1);
}
for(k=1;k<=;k++) /* 对满了行进行消去
*/
{
setcolor(BLACK);
draw_little_block
(k+MAPXOFT,y+MAPYOFT,0,2);
}
for(j=y-1;j>=1;j--) /* 消去1行后 用上面的
累下来(并且调整色彩) */
for(k=1;k<=;k++)
{
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();
y++;
}
}
}
int check_block(int x,int y,int style) /* 验证能不能往下1
个位置累方块 */
{
int x1=x+MAPXOFT,y1=y+MAPYOFT;
int x2,y2,i;
for(i=0;i<=6;i+=2)
{
x2=x1+shapes[style].xy[ i];
y2=y1+shapes[style].xy[i+1];
if(x2>=&&x2<&&y2<&&(y2<6||board[x2-][y2-
6]==0))
continue;
else
break;
}
if(i==8)
return 1;
else
return 0;
getch();
}
我这里也是别人那里看来的。希望对你有用
C++教程:俄罗斯方块源码+注释+解答
俄罗斯方块(Tetris,斯方斯方俄文:Тетрис)是块源块源一款电视游戏机和掌上游戏机游戏,它由俄罗斯人阿列克谢·帕基特诺夫发明,码a码刀枪剑传奇源码故得此名。安卓苏州ios源码
顾名思义,俄罗俄罗俄罗斯方块自然是斯方斯方俄罗斯人发明的。这人叫阿列克谢·帕基特诺夫(Алексей Пажитнов 英文:Alexey Pazhitnov)。块源块源俄罗斯方块原名是码a码俄语Тетрис(英语是Tetris),这个名字来源于希腊语tetra,安卓意思是俄罗俄罗"四",而游戏的斯方斯方node系统源码作者最喜欢网球(tennis)。于是块源块源,他把两个词tetra和tennis合而为一,码a码命名为Tetris,这也就是源码如何删除俄罗斯方块名字的由来。
俄罗斯方块源码
#include
#include
#include
/*#define SUSHU
oid ab(int *b, int *c){
int p = *b;
*b = *c; //c = b = b = p =
*c = p;
}
*/
#include
char LEETER[4][5][5] = {
{
0, 1, 0, 0, 0, //表示字母L
0, 1, 0, 0, 0,
0, 1, 0, 0, 0,
0, 1, 0, 0, 0,
0, 1, 1, 1, 0
}, {
0, 0, 1, 0, 0, //表示字母O
0, 1, 0, 1, 0,
0, 1, 0, 1, 0,
0, 1, 0, 1, 0,
0, 0, 1, 0, 0
}, {
0, 1, 0, 1, 0, //表示字母V
0, 1, 0, 1, 0,
0, 1, 0, 1, 0,
0, 1, 0, 1, 0,
0, 0, 1, 0, 0
}, {
0, 1, 1, 1, 0, //表示字母E
0, 1, 0, 0, 0,
0, 1, 1, 1, 0,
0, 1, 0, 0, 0,
0, 1, 1, 1, 0
}
};
int status = 1; //控制线程函数的运行状态
int speed = ; //控制字符变换的速度
HANDLE hout; //控制台标准输出的句柄
CONSOLE_SCREEN_BUFFER_INFO csbi; //控制台屏幕缓冲区信息结构体
char *symbol[] = { "☆", "★", "●", "◆", "▲", "■", "□" }; //字母符号☆mm
WORD attrbute[] = {
FOREGROUND_RED | FOREGROUND_INTENSITY, //红色
FOREGROUND_BLUE | FOREGROUND_INTENSITY, //蓝色
FOREGROUND_GREEN | FOREGROUND_INTENSITY //绿色
};
void drawLetter()
{
int i, j, c;
COORD pos; //光标的坐标
DWORD len; //实际填充字符属性的个数
for (c = 0; c < sizeof LEETER / sizeof LEETER[0]; ++c)
{
for (i = 0; i < 5; ++i)
{
pos.X = c * 5 * 2;
pos.Y = i;
SetConsoleCursorPosition(hout, pos);
for (j = 0; j < 5; ++j)
{
if (LEETER[c][i][j])
{
GetConsoleScreenBufferInfo(hout, &csbi);
printf("%s", symbol[rand() % (sizeof symbol / sizeof symbol[0])]);
FillConsoleOutputAttribute(hout,
attrbute[rand() % (sizeof attrbute / sizeof attrbute[0])],
2, csbi.dwCursorPosition, &len);
}
else
{
printf(" "); //两个空格
}
}
}
}
}
DWORD WINAPI ThreadProc(LPVOID lpParam) //线程处理函数
{
while (1)
{
if (status)
{
drawLetter(); //画字符
Sleep(speed);
}
}
return 0;
}
int main()
{
int ctrl; //控制游戏
hout = GetStdHandle(STD_OUTPUT_HANDLE);
HANDLE hThread; //线程句柄
srand((unsigned)time(0)); //初始化随机种子
hThread = CreateThread(NULL, 0, ThreadProc, NULL, 0, NULL);
CloseHandle(hThread);
while (1)
{
ctrl = _getch();
if (ctrl == 'q')
break;
else if (ctrl == 'w')
{
if (speed < )
speed += ;
}
else if (ctrl == 's')
{
if (speed > )
speed -= ;
}
else if (ctrl == 'p')
status = 0;
else if (ctrl == 'c')
status = 1;
}
return 0;
本文摘自: cdtedu.com/c/course/...,如有侵权,请联系我!
java编写的vs源码文件俄罗斯方块游戏
以下为一个俄罗斯方块的源代码,以---------线分隔一个类。
郁闷太长了,不能全部粘贴上来,要的话在线M我吧。
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.IOException;
/**
* <p>Title: 俄罗斯方块</p>
*
* <p>Description: 俄罗斯方块游戏</p>
*
* <p>Copyright: Copyright (c) </p>
*
* <p>Company: Star Group</p>
*
* @author: Part of this programe comes from a open-source project in the Web(www.hyweb.net).
* Our group makes some remakeble improvement to it.
* @version 1.0
*/
public class RussianGameMIDlet extends MIDlet {
static RussianGameMIDlet instance;
private UIController controller = new UIController(this);
private Splash splash;
private Image imgStart;
Display display = null;
public RussianGameMIDlet() {
instance = this;
display = Display.getDisplay(this);
}
public void startApp() {
try
{
imgStart = Image.createImage("/start.png");
} catch (IOException e) {
}
StringBuffer infoStart = new StringBuffer("俄罗斯方块");
splash = new Splash(this.controller,infoStart, imgStart);
controller.setSplash(splash);
controller.handleEvent(UIController.EventID.EVENT_START_SPLASH);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public static void quitApp() {
instance.destroyApp(true);
instance.notifyDestroyed();
instance = null;
}
}
--------------------------------------------------------------------------------------------------------------------------------------------
求俄罗斯方块源代码
手机游戏---俄罗斯方块
俄罗斯方块——java源代码提供
import java.awt.*;
import java.awt.event.*;
//俄罗斯方块类
public class ERS_Block extends Frame{
public static boolean isPlay=false;
public static int level=1,score=0;
public static TextField scoreField,levelField;
public static MyTimer timer;
GameCanvas gameScr;
public static void main(String[] argus){
ERS_Block ers = new ERS_Block("俄罗斯方块游戏 V1.0 Author:Vincent");
WindowListener win_listener = new WinListener();
ers.addWindowListener(win_listener);
}
//俄罗斯方块类的构造方法
ERS_Block(String title){
super(title);
setSize(,);
setLayout(new GridLayout(1,2));
gameScr = new GameCanvas();
gameScr.addKeyListener(gameScr);
timer = new MyTimer(gameScr);
timer.setDaemon(true);
timer.start();
timer.suspend();
add(gameScr);
Panel rightScr = new Panel();
rightScr.setLayout(new GridLayout(2,1,0,));
rightScr.setSize(,);
add(rightScr);
//右边信息窗体的布局
MyPanel infoScr = new MyPanel();
infoScr.setLayout(new GridLayout(4,1,0,5));
infoScr.setSize(,);
rightScr.add(infoScr);
//定义标签和初始值
Label scorep = new Label("分数:",Label.LEFT);
Label levelp = new Label("级数:",Label.LEFT);
scoreField = new TextField(8);
levelField = new TextField(8);
scoreField.setEditable(false);
levelField.setEditable(false);
infoScr.add(scorep);
infoScr.add(scoreField);
infoScr.add(levelp);
infoScr.add(levelField);
scorep.setSize(new Dimension(,));
scoreField.setSize(new Dimension(,));
levelp.setSize(new Dimension(,));
levelField.setSize(new Dimension(,));
scoreField.setText("0");
levelField.setText("1");
//右边控制按钮窗体的布局
MyPanel controlScr = new MyPanel();
controlScr.setLayout(new GridLayout(5,1,0,5));
rightScr.add(controlScr);
//定义按钮play
Button play_b = new Button("开始游戏");
play_b.setSize(new Dimension(,));
play_b.addActionListener(new Command(Command.button_play,gameScr));
//定义按钮Level UP
Button level_up_b = new Button("提高级数");
level_up_b.setSize(new Dimension(,));
level_up_b.addActionListener(new Command(Command.button_levelup,gameScr));
//定义按钮Level Down
Button level_down_b =new Button("降低级数");
level_down_b.setSize(new Dimension(,));
level_down_b.addActionListener(new Command(Command.button_leveldown,gameScr));
//定义按钮Level Pause
Button pause_b =new Button("游戏暂停");
pause_b.setSize(new Dimension(,));
pause_b.addActionListener(new Command(Command.button_pause,gameScr));
//定义按钮Quit
Button quit_b = new Button("退出游戏");
quit_b.setSize(new Dimension(,));
quit_b.addActionListener(new Command(Command.button_quit,gameScr));
controlScr.add(play_b);
controlScr.add(level_up_b);
controlScr.add(level_down_b);
controlScr.add(pause_b);
controlScr.add(quit_b);
setVisible(true);
gameScr.requestFocus();
}
}
//重写MyPanel类,使Panel的四周留空间
class MyPanel extends Panel{
public Insets getInsets(){
return new Insets(,,,);
}
}
//游戏画布类
class GameCanvas extends Canvas implements KeyListener{
final int unitSize = ; //小方块边长
int rowNum; //正方格的行数
int columnNum; //正方格的列数
int maxAllowRowNum; //允许有多少行未削
int blockInitRow; //新出现块的起始行坐标
int blockInitCol; //新出现块的起始列坐标
int [][] scrArr; //屏幕数组
Block b; //对方快的引用
//画布类的构造方法
GameCanvas(){
rowNum = ;
columnNum = ;
maxAllowRowNum = rowNum - 2;
b = new Block(this);
blockInitRow = rowNum - 1;
blockInitCol = columnNum/2 - 2;
scrArr = new int [][];
}
//初始化屏幕,并将屏幕数组清零的方法
void initScr(){
for(int i=0;i<rowNum;i++)
for (int j=0; j<columnNum;j++)
scrArr[j]=0;
b.reset();
repaint();
}
//重新刷新画布方法
public void paint(Graphics g){
for(int i = 0; i < rowNum; i++)
for(int j = 0; j < columnNum; j++)
drawUnit(i,j,scrArr[j]);
}
//画方块的方法
public void drawUnit(int row,int col,int type){
scrArr[row][col] = type;
Graphics g = getGraphics();
tch(type){ //表示画方快的方法
case 0: g.setColor(Color.black);break; //以背景为颜色画
case 1: g.setColor(Color.blue);break; //画正在下落的方块
case 2: g.setColor(Color.magenta);break; //画已经落下的方法
}
g.fill3DRect(col*unitSize,getSize().height-(row+1)*unitSize,unitSize,unitSize,true);
g.dispose();
}
public Block getBlock(){
return b; //返回block实例的引用
}
//返回屏幕数组中(row,col)位置的属性值
public int getScrArrXY(int row,int col){
if (row < 0 || row >= rowNum || col < 0 || col >= columnNum)
return(-1);
else
return(scrArr[row][col]);
}
//返回新块的初始行坐标方法
public int getInitRow(){
return(blockInitRow); //返回新块的初始行坐标
}
//返回新块的初始列坐标方法
public int getInitCol(){
return(blockInitCol); //返回新块的初始列坐标
}
//满行删除方法
void deleteFullLine(){
int full_line_num = 0;
int k = 0;
for (int i=0;i<rowNum;i++){
boolean isfull = true;
L1:for(int j=0;j<columnNum;j++)
if(scrArr[j] == 0){
k++;
isfull = false;
break L1;
}
if(isfull) full_line_num++;
if(k!=0 && k-1!=i && !isfull)
for(int j = 0; j < columnNum; j++){
if (scrArr[j] == 0)
drawUnit(k-1,j,0);
else
drawUnit(k-1,j,2);
scrArr[k-1][j] = scrArr[j];
}
}
for(int i = k-1 ;i < rowNum; i++){
for(int j = 0; j < columnNum; j++){
drawUnit(i,j,0);
scrArr[j]=0;
}
}
ERS_Block.score += full_line_num;
ERS_Block.scoreField.setText(""+ERS_Block.score);
}
//判断游戏是否结束方法
boolean isGameEnd(){
for (int col = 0 ; col <columnNum; col ++){
if(scrArr[maxAllowRowNum][col] !=0)
return true;
}
return false;
}
public void keyTyped(KeyEvent e){
}
public void keyReleased(KeyEvent e){
}
//处理键盘输入的方法
public void keyPressed(KeyEvent e){
if(!ERS_Block.isPlay)
return;
tch(e.getKeyCode()){
case KeyEvent.VK_DOWN:b.fallDown();break;
case KeyEvent.VK_LEFT:b.leftMove();break;
case KeyEvent.VK_RIGHT:b.rightMove();break;
case KeyEvent.VK_SPACE:b.leftTurn();break;
}
}
}
//处理控制类
class Command implements ActionListener{
static final int button_play = 1; //给按钮分配编号
static final int button_levelup = 2;
static final int button_leveldown = 3;
static final int button_quit = 4;
static final int button_pause = 5;
static boolean pause_resume = true;
int curButton; //当前按钮
GameCanvas scr;
//控制按钮类的构造方法
Command(int button,GameCanvas scr){
curButton = button;
this.scr=scr;
}
//按钮执行方法
public void actionPerformed (ActionEvent e){
tch(curButton){
case button_play:if(!ERS_Block.isPlay){
scr.initScr();
ERS_Block.isPlay = true;
ERS_Block.score = 0;
ERS_Block.scoreField.setText("0");
ERS_Block.timer.resume();
}
scr.requestFocus();
break;
case button_levelup:if(ERS_Block.level < ){
ERS_Block.level++;
ERS_Block.levelField.setText(""+ERS_Block.level);
ERS_Block.score = 0;
ERS_Block.scoreField.setText(""+ERS_Block.score);
}
scr.requestFocus();
break;
case button_leveldown:if(ERS_Block.level > 1){
ERS_Block.level--;
ERS_Block.levelField.setText(""+ERS_Block.level);
ERS_Block.score = 0;
ERS_Block.scoreField.setText(""+ERS_Block.score);
}
scr.requestFocus();
break;
case button_pause:if(pause_resume){
ERS_Block.timer.suspend();
pause_resume = false;
}else{
ERS_Block.timer.resume();
pause_resume = true;
}
scr.requestFocus();
break;
case button_quit:System.exit(0);
}
}
}
//方块类
class Block {
static int[][] pattern = {
,//用十六进至表示,本行表示长条四种状态
,
,
,
,
,
};
int blockType; //块的模式号(0-6)
int turnState; //块的翻转状态(0-3)
int blockState; //快的下落状态
int row,col; //块在画布上的坐标
GameCanvas scr;
//块类的构造方法
Block(GameCanvas scr){
this.scr = scr;
blockType = (int)(Math.random() * )%7;
turnState = (int)(Math.random() * )%4;
blockState = 1;
row = scr.getInitRow();
col = scr.getInitCol();
}
//重新初始化块,并显示新块
public void reset(){
blockType = (int)(Math.random() * )%7;
turnState = (int)(Math.random() * )%4;
blockState = 1;
row = scr.getInitRow();
col = scr.getInitCol();
dispBlock(1);
}
//实现“块”翻转的方法
public void leftTurn(){
if(assertValid(blockType,(turnState + 1)%4,row,col)){
dispBlock(0);
turnState = (turnState + 1)%4;
dispBlock(1);
}
}
//实现“块”的左移的方法
public void leftMove(){
if(assertValid(blockType,turnState,row,col-1)){
dispBlock(0);
col--;
dispBlock(1);
}
}
//实现块的右移
public void rightMove(){
if(assertValid(blockType,turnState,row,col+1)){
dispBlock(0);
col++;
dispBlock(1);
}
}
//实现块落下的操作的方法
public boolean fallDown(){
if(blockState == 2)
return(false);
if(assertValid(blockType,turnState,row-1,col)){
dispBlock(0);
row--;
dispBlock(1);
return(true);
}else{
blockState = 2;
dispBlock(2);
return(false);
}
}
//判断是否正确的方法
boolean assertValid(int t,int s,int row,int col){
int k = 0x;
for(int i = 0; i < 4; i++){
for(int j = 0; j < 4; j++){
if((int)(pattern[t][s]&k) != 0){
int temp = scr.getScrArrXY(row-i,col+j);
if (temp<0||temp==2)
return false;
}
k = k >> 1;
}
}
return true;
}
//同步显示的方法
public synchronized void dispBlock(int s){
int k = 0x;
for (int i = 0; i < 4; i++){
for(int j = 0; j < 4; j++){
if(((int)pattern[blockType][turnState]&k) != 0){
scr.drawUnit(row-i,col+j,s);
}
k=k>>1;
}
}
}
}
//定时线程
class MyTimer extends Thread{
GameCanvas scr;
public MyTimer(GameCanvas scr){
this.scr = scr;
}
public void run(){
while(true){
try{
sleep((-ERS_Block.level + 1)*);
}
catch(InterruptedException e){ }
if(!scr.getBlock().fallDown()){
scr.deleteFullLine();
if(scr.isGameEnd()){
ERS_Block.isPlay = false;
suspend();
}else
scr.getBlock().reset();
}
}
}
class WinListener extends WindowAdapter{
public void windowClosing (WindowEvent l){
System.exit(0);
}
}
求一份用C语言编写的俄罗斯方块的源代码!
俄罗斯方块C源代码#include <stdio.h>
#include <windows.h>
#include <conio.h>
#include <time.h>
#define ZL 4 //坐标增量, 不使游戏窗口靠边
#define WID //游戏窗口的宽度
#define HEI //游戏窗口的高度
int i,j,Ta,Tb,Tc; // Ta,Tb,Tc用于记住和转换方块变量的值
int a[][]={ 0}; //标记游戏屏幕各坐标点:0,1,2分别为空、方块、边框
int b[4]; //标记4个"口"方块:1有,0无,类似开关
int x,y, level,score,speed; //方块中心位置的x,y坐标,游戏等级、得分和游戏速度
int flag,next; //当前要操作的方块类型序号,下一个方块类型序号
void gtxy(int m, int n); //以下声明要用到的自编函数
void gflag( ); //获得下一方块序号
void csh( ); //初始化界面
void start( ); //开始部分
void prfk ( ); //打印方块
void clfk( ); //清除方块
void mkfk( ); //制作方块
void keyD( ); //按键操作
int ifmov( ); //判断方块能否移动或变体
void clHA( ); //清除满行的方块
void clNEXT( ); //清除边框外的NEXT方块
int main( )
{ csh( );
while(1)
{ start( ); //开始部分
while(1)
{ prfk( );
Sleep(speed); //延时
clfk( );
Tb=x;Tc=flag; //临存当前x坐标和序号,以备撤销操作
keyD( );
y++; //方块向下移动
if (ifmov( )==0) { y--; prfk( ); dlHA( ); break;} //不可动放下,删行,跨出循环
}
for(i=y-2;i<y+2;i++){ if (i==ZL) { j=0; } } //方块触到框顶
if (j==0) { system("cls");gtxy(,);printf("游戏结束!"); getch(); break; }
clNEXT( ); //清除框外的NEXT方块
}
return 0;
}
void gtxy(int m, int n) //控制光标移动
{ COORD pos; //定义变量
pos.X = m; //横坐标
pos.Y = n; //纵坐标
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void csh( ) //初始化界面
{ gtxy(ZL+WID/2-5,ZL-2); printf("俄罗斯方块"); //打印游戏名称
gtxy(ZL+WID+3,ZL+7); printf("