码迷,mamicode.com
首页 > 其他好文 > 详细

如何编写简单的游戏程序?

时间:2019-08-18 15:54:09      阅读:100      评论:0      收藏:0      [点我收藏+]

标签:nal   clu   rup   cli   case   col   new   fill   randn   

//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;
 

如何编写简单的游戏程序?

标签:nal   clu   rup   cli   case   col   new   fill   randn   

原文地址:https://www.cnblogs.com/dakunqq/p/11372238.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!