//stone.cpp
#include <graphics.h>
#include <iostream.h>
#include <conio.h>
#include <bios.h>
#include <stdlib.h>
#include <time.h>
#include <dos.h>
const int Timer=0x1c;
int count;
int board[20][10];
const int ESC=0x11b,ENTER=0x1c0d,
UP=0x4800,DOWN=0x5000,LEFT=0x4b00,RIGHT=0x4d00;
void analyze(int shapeNum,int (*result)[2]);
void drawShape(int screenX,int screenY,int shapeNum,int fillColor);
void prepare();
void interrupt (*oldHandle)(...);
void interrupt newHandle(...);
void setNewVect();
void recoverOldVect();
int afterChange(int boardX,int boardY,int shapeNum,int key);
int deleteRow(int boardX,int shapeNum);
int rowFull(int row);
void fillBoard(int boardX,int boardY,int shapeNum);
void main()
{ int driver,mode,errorCode;
driver=DETECT;
mode=0;
initgraph(&driver,&mode,"");
errorCode=graphresult();
if(errorCode){
cerr<<"Initgraph Failed!"<<endl;
return;
}
const shape[19]={5410,12840,3210,6542,9840,4210,9510,6210,9851,6540, <br> 8410,5421,9540,6510,8541,6541,8540,5210,9541};
randomize();
int key,start,end,index,randNum,boardX,boardY,screenX,screenY,score;
int speed,TboardX,TboardY,Tindex,sign,shiftPressed,t;
setcolor(LIGHTGRAY);
setNewVect();
for(;;){
cleardevice();
setbkcolor(BLACK);
prepare();
score=0;
speed=18;
gotoxy(1,1);
delline();
cout<<"Your score is: "<<score*10<<endl;
while(1){
randNum=random(5);
switch(randNum)
{case 0:start=end=0;break; <br> case 1:start=1;end=2;break; <br> case 2:start=3;end=10;break; <br> case 3:start=11;end=14;break; <br> case 4:start=15;end=18; <br> }//switch
index=start+random(end-start+1);
boardX=0;boardY=4;
sign=afterChange(boardX,boardY,shape[index],DOWN);
screenX=boardY*10+200;screenY=boardX*10+100;
if(sign==2) {
drawShape(screenX,screenY,shape[index],RED);
break;
}
drawShape(screenX,screenY,shape[index],YELLOW);
count=0;
while(2){
key=0;
if(bioskey(1)) {
key=bioskey(0);
t=bioskey(2);
shiftPressed=(t==0x21||t==0x22?1:0);
}
if(key==ESC) break;
if(count>speed){
if(key==0) shiftPressed=0;
key=DOWN;
count=0;
}
if(key==UP||key==DOWN||key==LEFT||key==RIGHT){
//cout<<"shiftPressed:"<http://zzdxjyzd.com<shiftPressed<<endl;
TboardX=boardX;
TboardY=boardY;
Tindex=index;
switch(key)
{case UP: index=(index==end?start:index+1);break; <br> case DOWN: if(shiftPressed) { <br> for(t=boardX+1;t<=19;t++) <br> if(afterChange(t,boardY,shape[index],key)==3) <br> boardX=t; <br> else break; <br> }
else boardX++;
break;
原文地址:https://www.cnblogs.com/dakunqq/p/11372238.html