用c开发的游戏
申明:前不久选修了c语言,因为老师把用c写一个游戏作为考试题。于是我写了这个常见的俄罗斯方块,感觉良好就 写到 博客里了,见笑了。 #include #include #include #include <stdio.h>#include <stdlib.h>
#include <dos.h>
#include <conio>
#include <time.h>
#include <grapgics.h>
#define L 1
#define LX 15
#define LY 4
static struct BLOCK{
int x0,y0,x1,y1,x2,y2,x3,y3;
int color,next;}b={{0,1,1,1,2,1,3,1,4,1}, {1,0,1,3,1,2,1,1,4,0},{1,1,2,2,1,2,2,1,1,2},
{0,1,1,1,1,0,2,0,2,4},{0,0,0,1,1,2,1,1,2,3},{0,0,1,0,1,1,2,1,3,8},
{1,0,1,1,2,2,2,1,2,5},{0,2,1,2,1,1,2,1,2,6},{0,1,0,2,1,1,1,0,3,9},
{0,1,1,1,1,2,2,2,3,10},{1,1,1,2,2,1,2,0,3,7},{ 1,0,1,1,1,2,2,2,7,12},
{0,1,1,1,2,1,2,0,7,13},{0,0,1,2,1,1,1,0,7,14},{0,1,0,2,1,1,2,1,7,11},
{0,2,1,2,1,1,1,0,5,16},{0,1,1,1,2,2,2,1,5,17},{1,0,1,1,1,2,2,0,5,18},
{0,0,0,1,1,11,2,1,5,15},{0,1,1,1,1,0,2,1,6,2,0},{0,1,1,2,1,1,1,0,6,21},
{0,1,1,2,1,1,2,1,6,22},{1,0,1,1,1,2,2,1,6,19}};
static int d={33000,3000,1600,1200,900,800,600,400,300,200};
int Llevel,Lcurrent,Lnext,Lable,lx,ly,Lsum;
unsigned Lpoint;
int La,FLAG,sum;
unsigned ldelay;
void scrint(),datainit(),dispb(),eraseeb();
void throw(),judge(),delayp(),move(0,note(0,show();
int Ldrop(),Ljudge(),nextb(),routejudge();
main(){
char c;
datainit();
Label=nextb();
Label=Ldrop();
while(1) {
delayp();
if(Label!=0){
Ljudge();
Lable=nextb();}
ldelay--;
if(ldelay==0){
Label=Ldrop();
ldelay=d;}
if(FLAG!=0) break;}
whlie(getch()!='\r');
{
goto xy(38,16);
cputs("again?");
c=getch();
while(c!='n'&&c!='N')
clscr();}
int nextb(){
if(La[(b.y0)][(3+b.x0)]!=0 || La[(b.y1)][(3+b.x1)]
!=0 || La[(b.y2)][(3+b.x2)]!=0 || La[(b.y3)][(3+
b.x3)]!=0){
FLAG= L;
return ( -1 );}
eraseb(0,3,5,Lnext);
Lcurrent = Lnext;
lx=3;ly=0;
Label=0;
ldelay=d;
Lsum ++;
Lpoint += 1;
Lnext=random(23);
dispb(0,3,5,Lnext);
textcolor(7);
goto xy(3,14);cprintf("%#5d",Lsum);
goto xy(3,17);cprintf("%#5d",Lpoint);
return(0); }
void delayp(0{
char key;
if(kbhit()!=0){
key=getch();
move(key);
if(key=='\\')
getch();
}}
void move(funkey)
char funkey;{
int tempcode;
switch( funkey){
case 'k': if(lx+b.x0>0){
if(La.y0)]
current].x0)]==0&& La[(ly+b.y1)][(lx-1+b.x10]==0 && La.y2)].x2)]==0&&La.y3)].x3)]==0){
eraseb(L,lx,lyLcurrent);
lx--;
dispb(L,lx,ly,Lcurrent);} break;
case 0x20: tempcode=b.next;
if (lx+b.x0>=0&&lx+b.x3<=9&&
ly+b.y1<=19&&ly+b.y2<=19)
if(routejudge()!+-1)
if(La+(b.y0)].x0)]==0&&
La.y1)].x1)]==0&&La.y2)].x2)]==0&&La.y3)].x3)]==0)
{
eraseb(L,lx,ly,Lcurrent);
Lcurrent=tempcode;
dispb(L,lx,ly,Lcurrent);} break;
case 'M': if(lx+b.x3<9)
if(La.y0)].x0)]==0&&La.y1)].x1)]==0&&La.y2)].x2)]==0&&La.y3)].x3)]==0){
eraseb(L,lx,ly,Lcurrent);
lx++;
disb(L,lx,ly,Lcurrent);}break;
case 'p': throw();break;
case 0x1b: clrscr();exit(0);break;
default:break;}}
void throw(0{
int tempy;tempy=ly;
while(ly+b.y1<19&& ly+b.y2<19&&La.y0)].x0)]==0&&La.y1)].x1)]==0&&La.y2)].x2)]==0&&La.y3)].x3)]==0)
ly++;ly--;
eraseb(L,lx,tempy,Lcurrent);dispb(L,lx,ly,Lcurrent);
La.y0)].x0)]=
La.y1)].x1)]=
La.y2)].x2)]=
La.y3)].x3)]=b.color;
Label=-1;}
int routejudge(){
int i,j;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
if(La!=0)
return(-1);
return(1);}
int Ldrop(){
if(ly+b.y1>=18||ly+b.y2>=18)
{La.y0)].x0)]=
La.y1)].x1)]=
La.y2)].x2)]=
La.y3)].x3)]=b.color;
return(-1);}
if(La(ly+1+(b.y0)].x0)]!=0||La(ly+1+(b.y1)].x1)]!=0||La(ly+1+(b.y2)].x2)]!=0||La(ly+1+(b.y3)].x3)]!=0){La.y0)].x0)]=
La.y1)].x1)]=
La.y2)].x2)]=
La.y3)].x3)]=b.color;
return(-1);}
eraseb(L,lx,ly,Lcurrent);
dispb(L,lx,++ly,Lcurrent);
return(0);}
int Ljudge(){
int i,j,k,lines,f;
static int p={0,1,3,6,10};
lines=0;
for(k=0;k<=3;k++){
f=0;if((ly+k)>18)
continue;
for(i=0;i<10;i++)
if(La==0);i>0;i--){
f++;break;}
if(f==0){
movetext(LX,LY,LX+19,LY+ly+k-1,LX,LY+1);
for(i=(ly+k);i>0;i--){
for(j=0;j<10;j++)
La=La;
for(j=0;j<10;j++)
La=0;
lines++;}}
Lpoint+=p*10;
return(0);}
void scrint(){
int i;
char lft;
textbackground(1);
clrscr();
gotoxy(30,9);
cputs("enter your name");
scanf("%s",lft);
gotoxy(25,14);
scanf("%s",lft);
textbackground(0);clrscr();
textcolor(15);gotoxy(17,1);
cprintf("%s",lft);
gotoxy(5,3);
cputs("next");
gotoxy(4,13);cputs("block");
gotoxy(4,16);cputs("point");
for(i=0;i<19;i++)
{
gotoxy(LX-2,LY+1);
cputs("** **");
}gotoxy(LX-2,LY+19);cputs("**********************");
}
void datainit(){
int i,j;
for(i=0;i<19;i++)
for(j=0;j<10;j++)
La=0;
Label=0;FLAG=0;
ldelay=d;Lsum=0;Lpoint=0;
randomize();
Lnext=random(23);}
void dispb(LRflag,x,y,blockcode)
int realx,realy;
if(LRflag==L)
{realx=LX+x*2;realy=LY+y;}
else
{realx=x,raly=y;}
textcolor(b.color);
gotoxy(realx+2*b.x0,realy+b.y0);cputs("**");
gotoxy(realx+2*b.x1,realy+b.y1);cputs("**");
gotoxy(realx+2*b.x2,realy+b.y2);cputs("**");
gotoxy(realx+2*b.x3,realy+b.y3);cputs("**");}
void eraseb(LRflag,x,y,blockcode)
int LRflag,x,y,blockcode;
{
int realx,realy;
if(LRflag==L)
{ realx=LX+x*2;realy=LY+y;}
else
{realx=Lx+x*2;realy=LY+y;}
textcolor(0);
gotoxy(realx+2*b.x0,realy+b.y0);cputs("**");
gotoxy(realx+2*b.x1,realy+b.y1);cputs("**");
gotoxy(realx+2*b.x2,realy+b.y2);cputs("**");
gotoxy(realx+2*b.x3,realy+b.y3);cputs("**");}
}
【冲三钻特价】清华同方通用小手柄特价销售 TF2601/
页:
[1]