1.俄罗斯方块的俄罗俄罗源代码?
2.c语言俄罗斯方块代码
3.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语言俄罗斯方块代码
#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 /* 最小方块的斯的斯方尺寸 */
#define BGCOLOR 7 /* 背景着色 */
#define GX
#define GY
#define SJNUM /* 每当玩家打到一万分等级加一级*/
/* 按键码*/
#define VK_LEFT 0x4b
#define VK_RIGHT 0x4d
#define VK_DOWN 0x
#define VK_UP 0x
#define VK_HOME 0x
#define VK_END 0x4f
#define VK_SPACE 0x
#define VK_ESC 0xb
#define VK_ENTER 0x1c0d
/* 定义俄罗斯方块的方向(我定义他为4种)*/
#define F_DONG 0
#define F_NAN 1
#define F_XI 2
#define F_BEI 3
#define NEXTCOL /* 要出的下一个方块的纵坐标*/
#define NEXTROW /* 要出的下一个方块的横从标*/
#define MAXROW /* 游戏屏幕大小*/
#define MAXCOL
#define SCCOL /*游戏屏幕大显示器上的相对位置*/
#define SCROW
int gril[][]; /* 游戏屏幕坐标*/
int col=1,row=7; /* 当前方块的横纵坐标*/
int boxfx=0,boxgs=0; /* 当前寺块的形壮和方向*/
int nextboxfx=0,nextboxgs=0,maxcol=;/*下一个方块的形壮和方向*/
int minboxcolor=6,nextminboxcolor=6;
int num=0; /*游戏分*/
int dj=0,gamedj[]={ ,,,,,8,6,4,2,1};/* 游戏等级*/
/* 以下我用了一个3维数组来纪录方块的最初形状和方向*/
int boxstr[7][4][]={ {
{ 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()+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,,);
}
/*在图形模式下的高级清屏*/
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<;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<;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 0x1c
int 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<;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="";
for(i=1;i<;i++){
zero=0;
for(j=1;j<;j++)
if(gril[j]==0)
zero=1;
if(zero==0){
delcol(i);
delgx++;
}
}
num=num+delgx*delgx*;
dj=num/;
sprintf(nm,"%d",num);
clscr(,,,,4);
txt(,,"Number:",1,);
txt(,,nm,1,);
}
/*时间中断结束*/
void KillTimer(){
disable();
setvect(TIMER,oldhandler);
enable();
}
/* 测试当前方块是否可以向下落*/
int downok(){
int i,j,k=1,a[4][4];
for(i=0;i<;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<;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<;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<;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,块源jquery load 源码j,a[4][4];
funbox(0,0,minboxcolor,0);
for(i=0;i<;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=;i>0;i--)
for(j=1;j<;j++)
minbox(j*MINBOXSIZE,i*MINBOXSIZE,2,0);
txt(,,"Game Over",3,);
}
/*按键的设置*/
void call_key(int keyx){
switch(keyx){
case VK_DOWN: { /*下方向键,横坐标加一。俄罗俄罗*/
if(downok()){
col++;
funbox(0,斯的斯方免费快三源码0,minboxcolor,0);}
else{
funbox(0,0,minboxcolor,0);
setgril();
nextfunbox(NEXTCOL,NEXTROW,4,4);
boxrad();
nextfunbox(NEXTCOL,NEXTROW,nextminboxcolor,0);
delete();
}
break;
}
case VK_UP: { /*上方向键,方向形状旋转度*/
if(upok())
boxfx++;
if(boxfx>3)
boxfx=0;
funbox(0,源码语0,minboxcolor,0);
break;
}
case VK_LEFT:{ /*左方向键,纵坐标减一*/
if(leftok())
row--;
funbox(0,块源0,minboxcolor,0);
break;
}
case VK_RIGHT:{ /*右方向键,纵坐标加一*/
if(rightok())
row++;
funbox(0,俄罗俄罗0,minboxcolor,0);
break;
}
case VK_SPACE: /*空格键,直接落到最后可以落到的斯的斯方们置*/
while(downok())
col++;
funbox(0,0,minboxcolor,0);
setgril();
nextfunbox(NEXTCOL,NEXTROW,4,4);
boxrad();
nextfunbox(NEXTCOL,NEXTROW,nextminboxcolor,0);
delete();
break;
default:
{
txt(,,"worng key!",1,4);
txt(,,"Plese Enter Anly Key AG!",1,4);
getch();
clscr(,,,,BGCOLOR);
}
}
}
/*时间中断开始*/
void timezd(void){
int key;
SetTimer(newhandler);
boxrad();
nextfunbox(NEXTCOL,NEXTROW,nextminboxcolor,0);
for(;;){
if(bioskey(1)){
key=bioskey(0);
funbox(0,0,BGCOLOR,BGCOLOR);
if(key==VK_ESC)
break;
call_key(key);
}
if(TimerCounter>gamedj[dj]){
TimerCounter=0;
if(downok()){
funbox(0,0,BGCOLOR,BGCOLOR);
col++;
funbox(0,0,minboxcolor,0);
}
else {
if(col==1){
gameover();
getch();
break;
}
setgril();
delete();
funbox(0,0,minboxcolor,0);
col=1;row=7;
funbox(0,0,BGCOLOR,BGCOLOR);
nextfunbox(NEXTCOL,NEXTROW,4,4);
boxrad();
nextfunbox(NEXTCOL,NEXTROW,nextminboxcolor,0);
}
}
}
}
/*主程序开始*/
void main(void){
int i,j;
char *nm="";
init(VGA,VGAHI);
cls();
/*屏幕坐标初始化*/
for(i=0;i<=MAXCOL+1;i++)
for(j=0;j<=MAXROW+1;j++)
gril[i][j]=0;
for(i=0;i<=MAXCOL+1;i++) {
gril[i][0]=1;
gril[i][]=1;
}
for(j=1;j<=MAXROW;j++){
gril[0][j]=1;
gril[][j]=1;
}
clscr(0,0,,,);
win(1,1,,,4,);
win(SCCOL+MINBOXSIZE-2,SCROW+MINBOXSIZE-2,SCCOL+*MINBOXSIZE+2,SCROW+*MINBOXSIZE+2,BGCOLOR,0);
nextboxgs=random(8);
nextboxfx=random(4);
sprintf(nm,"%d",num);
txt(,,"Number:",1,);
txt(,,nm,1,);
txt(,,"Next Box:",1,);
timezd();
KillTimer();
closegraph();
getch();
}
C++教程:俄罗斯方块源码+注释+解答
俄罗斯方块(Tetris,俄文:Тетрис)是源码语一款电视游戏机和掌上游戏机游戏,它由俄罗斯人阿列克谢·帕基特诺夫发明,块源故得此名。俄罗俄罗c语言源码搭建
顾名思义,斯的斯方俄罗斯方块自然是源码语俄罗斯人发明的。这人叫阿列克谢·帕基特诺夫(Алексей Пажитнов 英文:Alexey Pazhitnov)。黑金步数源码俄罗斯方块原名是俄语Тетрис(英语是Tetris),这个名字来源于希腊语tetra,意思是负115的源码"四",而游戏的作者最喜欢网球(tennis)。于是,他把两个词tetra和tennis合而为一,命名为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/...,如有侵权,请联系我!