| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1839 人关注过本帖
标题:编写俄罗斯方块
只看楼主 加入收藏
weikeli19
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2013-2-25
结帖率:40%
收藏
 问题点数:0 回复次数:6 
编写俄罗斯方块
如果我想编写俄罗斯方块小游戏,需要看哪些专业书籍  请一一列举出来  谢谢啦!各位大侠
搜索更多相关主题的帖子: 俄罗斯方块 小游戏 专业 
2013-03-27 12:57
lsnaimei
Rank: 2
等 级:论坛游民
帖 子:25
专家分:47
注 册:2012-3-30
收藏
得分:0 
专业书籍不是必需的,先了解一些有关c语言的基础知识,然后尝试做一些简单的编辑,慢慢来吧
2013-04-01 21:51
好聚好散
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:138
专家分:123
注 册:2012-12-4
收藏
得分:0 

无节操,无真相
2013-04-02 09:14
a271885843
Rank: 2
等 级:论坛游民
帖 子:291
专家分:58
注 册:2011-11-24
收藏
得分:0 
C语言俄罗斯方块就是那个图形函数难以理解

认为事物非黑即白是缺智慧的表现……
2013-04-11 23:09
寒星血泪
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-1-16
收藏
得分:0 
如果要用2005编的话,推荐windows程序设计。很厚的一本书!
2013-04-24 16:55
黎忘
Rank: 1
等 级:新手上路
帖 子:6
专家分:4
注 册:2013-4-25
收藏
得分:0 
这也是我在其它的论坛上找的,但还是有一个地方和错误,在这也请教一下各位大神……

#include <conio.h>
#include <stdlib.h>
#include <windows.h>
#include "colorConsole.h"     //老师的模板

#define SQUARE_COLOR FOREGROUND_RED| FOREGROUND_GREEN|FOREGROUND_INTENSITY  //方块的颜色
#define up      72
#define down    80
#define left    75
#define right   77
#define esc     27
#define MAPW    12     //地图的宽度
#define MAPH    20     //地图的高度

BOOL isavailable(int a[],int x,int y,int w,int h); //判定是否能放下
void turn(int a[][4],int w,int h,int *x,int y);    //转动
int * create();                                    //创建方块
void init();    //初始化工作
void drawblocks(int a[],int w,int h,int x,int y,WORD wColors[],int nColors);
void clearcache();                                 //清除键盘缓冲区
void end();
void clearsquare(int *a,int w,int h,int x,int y);
void gameover();
void deletemap(int m[][MAPW],int row,int w,int h); //消除一行

int dx=30,dy=5;             //屏幕上的偏移量
int score=0,level=0;
int map[MAPH][MAPW];
int a1[4][4]={{1},{1,1,1}};
int a2[4][4]={{0,1},{1,1,1}};
int a3[4][4]={{1,1},{0,1,1}};
int a4[4][4]={{0,0,1},{1,1,1}};
int a5[4][4]={{0,1,1},{1,1}};
int a6[4][4]={{1,1,1,1}};
int a7[4][4]={{1,1},{1,1}};
int a[4][4];

int main()
{
init();
int *b=NULL;
b=create();   //预创建方块

int sign,blank,x,y;
while(1)
{
for(int i=0;i<4;i++)          //复制方块
for(int j=0;j<4;j++)
if(a[i][j]=*(b+i*4+j)) blank=i;
y=1-blank;x=4;
clearsquare(&a[0][0],4,4,13,13);
b=create();

HANDLE handle;
handle=initiate();
WORD wColors[1]={FOREGROUND_RED| FOREGROUND_GREEN|FOREGROUND_INTENSITY };
drawblocks(b,4,4,13,13,wColors,1);
wColors[0]=SQUARE_COLOR;
drawblocks(&a[0][0],4,4,x,y,wColors,1);
clearcache();

char string[5];
wColors[0]=FOREGROUND_RED| FOREGROUND_GREEN|FOREGROUND_INTENSITY;
textout(handle,26+dx,5+dy,wColors,1,itoa(score,string,10));
textout(handle,26+dx,9+dy,wColors,1,itoa(level,string,10));

sign=1;
while(sign)
{
int delay=0,max_delay=100-10*level; //延迟量
while(delay<max_delay)
{
if(_kbhit())  //用if避免按住键使方块卡住
{
int draw=0;
int key=_getch();
switch (key)
{
case up:
clearsquare(&a[0][0],4,4,x,y);
turn(a,4,4,&x,y);
draw=1;
break;
case down:
delay=max_delay;
break;
case left:
if(isavailable(&a[0][0],x-1,y,4,4))
{
clearsquare(&a[0][0],4,4,x,y);
x--;
draw=1;
}
break;
case right:
if(isavailable(&a[0][0],x+1,y,4,4))
{
clearsquare(&a[0][0],4,4,x,y);
x++;
draw=1;
}
break;
case esc:
end();
break;
}
if(draw)
{
HANDLE handle;
handle=initiate();
WORD wColors[1]={SQUARE_COLOR};
drawblocks(&a[0][0],4,4,x,y,wColors,1);
draw=0;
}
}
_sleep(8);delay++;
}
if(isavailable(&a[0][0],x,y+1,4,4)) //是否能下移
{
clearsquare(&a[0][0],4,4,x,y);
y++;
HANDLE handle;
handle=initiate();
WORD wColors[1]={SQUARE_COLOR};
drawblocks(&a[0][0],4,4,x,y,wColors,1);
}
else
{
sign=0;    //标记,使跳出 while(sign) 循环,产生新方块
if(y<=1) gameover();     //是否结束
for(int i=0;i<4;i++)     //放下方块
for(int j=0;j<4;j++)
if(a[i][j]&&((i+y)<MAPH-1)&&((j+x)<MAPW-1)) 
map[i+y][j+x]=a[i][j];
int full,k=0;
for(i=y;i<min(y+4,MAPH-1);i++)
{
full=1;
for(int j=1;j<11;j++)
if(!map[i][j]) full=0;
if(full)   //消掉一行
{
deletemap(map,i,MAPW,MAPH);
k++;
score=score+k;
level=min(score/30,9);
}
}
}
}
}
return EXIT_SUCCESS;
}

BOOL isavailable(int a[],int x,int y,int w,int h)
{
for(int i=max(y,1);i<y+h;i++)
for(int j=x;j<x+w;j++)
if(map[i][j]&&a[w*(i-y)+j-x])
return 0;
return 1;
}
int * create()
{
int * a=NULL;
int c=rand()%7;
switch(c)
{
case 0:
a=&a1[0][0];break;
case 1:
a=&a2[0][0];break;
case 2:
a=&a3[0][0];break;
case 3:
a=&a4[0][0];break;
case 4:
a=&a5[0][0];break;
case 5:
a=&a6[0][0];break;
case 6:
a=&a7[0][0];break;
}
return a;
}
void init()
{
for(int i=0;i<20;i++)
{
map[i][0]=-2;
map[i][11]=-2;
}
for(i=0;i<12;i++)
{
map[0][i]=-1;
map[19][i]=-1;
}
map[0][0]=-3;
map[0][11]=-3;
map[19][0]=-3;
map[19][11]=-3;

HANDLE handle;
handle=initiate();
WORD wColors[1]={FOREGROUND_RED| FOREGROUND_GREEN|FOREGROUND_INTENSITY};
textout(handle,26+dx,3+dy,wColors,1,"SCORE");
textout(handle,26+dx,7+dy,wColors,1,"LEVEL");
textout(handle,26+dx,11+dy,wColors,1,"NEXT");
wColors[0]=FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_INTENSITY;
drawblocks(&map[0][0],12,20,0,0,wColors,1);
textout(handle,dx,dy,wColors,1,"◇══════════◇");
wColors[0]=FOREGROUND_RED| FOREGROUND_GREEN|FOREGROUND_INTENSITY;
textout(handle,dx-16,dy,wColors,1,"按任意键开始");
wColors[0]=FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_INTENSITY ;
textout(handle,dx-15,dy+3,wColors,1,"制作者");
wColors[0]=FOREGROUND_RED| FOREGROUND_GREEN|FOREGROUND_INTENSITY ;
textout(handle,dx-15,dy+5,wColors,1,"吴德盛");
textout(handle,dx-15,dy+7,wColors,1,"王山风");
textout(handle,dx-15,dy+9,wColors,1,"张悦");
textout(handle,dx-15,dy+11,wColors,1,"罗晓斌");
textout(handle,dx-15,dy+13,wColors,1,"刘亚辉");
wColors[0]=FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_INTENSITY ;
textout(handle,dx-15,dy+15,wColors,1,"测试者");
wColors[0]=FOREGROUND_RED| FOREGROUND_GREEN|FOREGROUND_INTENSITY ;
textout(handle,dx-15,dy+17,wColors,1,"唐程毅");

int x=_getch();
srand(x);
textout(handle,dx-16,dy,wColors,1,"            ");

}
void drawblocks(int a[],int w,int h,int x,int y,WORD wColors[],int nColors)
{
HANDLE handle;
handle = initiate(); 
int temp;

for(int i=0;i<h;i++)
for(int j=0;j<w;j++)
if((temp=a[i*w+j])&&y+i>0)
{
if(temp==-3)
textout(handle,2*(x+j)+dx,y+i+dy,wColors,nColors,"◆");
else if(temp==-2)
textout(handle,2*(x+j)+dx,y+i+dy,wColors,nColors,"║");
else if(temp==-1)
textout(handle,2*(x+j)+dx,y+i+dy,wColors,nColors,"═");
else if(temp==1)
textout(handle,2*(x+j)+dx,y+i+dy,wColors,nColors,"■");
}
}

void clearcache()
{
while(_kbhit())
{
_getch();
}
}
void end()
{
exit(EXIT_SUCCESS);
}
void turn(int a[][4],int w,int h,int *x,int y)
{
int b[4][4]={{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}};
int sign=0,line=0;
for(int i=h-1;i>=0;i--)
{
for(int j=0;j<w;j++)
if(a[i][j])
{
b[j][line]=a[i][j];
sign=1;
}
if(sign) 
{
line++;
sign=0;
}
}
for(i=0;i<4;i++)
if(isavailable(&b[0][0],*x-i,y,w,h))
{
*x-=i;
for(int k=0;k<h;k++)
for(int j=0;j<w;j++)
a[k][j]=b[k][j];
break;
}
}
void clearsquare(int *a,int w,int h,int x,int y)
{
HANDLE handle;
handle=initiate();
WORD wColors[1]={SQUARE_COLOR};
for(int i=0;i<h;i++)
for(int j=0;j<w;j++)
if(a[i*w+j]&&i+y>0)
textout(handle,2*(x+j)+dx,y+i+dy,wColors,1,"  ");
}

void gameover()
{
HANDLE handle;
handle=initiate();
WORD wColors[1]={FOREGROUND_RED| FOREGROUND_GREEN};
textout(handle,7+dx,10+dy,wColors,1,"GAME OVER");
clearcache();
_getch();
exit(EXIT_SUCCESS);
}

void deletemap(int m[][MAPW],int row,int w,int h)
{
HANDLE handle;
handle=initiate();
WORD wColors[1]={SQUARE_COLOR};
textout(handle,2+dx,row+dy,wColors,1,"﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌");
_sleep(100);

for(int i=row;i>1;i--)
{
clearsquare(&m[i][1],MAPW-2,1,1,i);
for(int j=1;j<MAPW-1;j++)
m[i][j]=m[i-1][j];
drawblocks(&m[i][1],MAPW-2,1,1,i,wColors,1);
}
for(i=1;i<MAPW-1;i++)
m[1][i]=0;
}
2013-04-25 13:18
邓士林
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:淮河河畔
等 级:贵宾
威 望:61
帖 子:2392
专家分:13384
注 册:2013-3-3
收藏
得分:0 
c语言为基础,还有数据结构

Maybe
2013-04-26 23:49
快速回复:编写俄罗斯方块
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018130 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved