玩游戏时为什么会d出游戏程序错误?

玩游戏时为什么会d出游戏程序错误?,第1张

您可以参照下列提示 *** 作下,希望我的回答对您有所帮助! ~

【原因分析】:

1. 虚拟内存不足

2. 游戏启动提示缺少某些D3D文件的报错

3. QQ安装后无法启动及部分游戏启动报错

4. 游戏程序本身故障

【解决晌樱桐方案:】:

方案一:设置虚拟内存(解决游戏内存不足的报错,XP系统使用,Win7基本都是默认系统分配,不需要手动设置)

1. 右键点击【计算机】选择【属性】—【高级系统设置】—【高级】—【设置】。(如图1)

图1

1. 点宴坦击【高级】—【更改】,将C盘的虚拟内存自定颂棚义为最大【4092】,初始【2046】,然后点击【设置】,【确定】即可。(如图2,图3)

图2

图3

方案二:安装常用游戏运行库

1.更新DX9.0(解决游戏启动提示缺少某些D3D文件的报错)

1. 打开【360软件管家】,在搜索框中搜索【DX】关键字,找到【DirectX 9.0C】正式版进行【下载安装】即可。(如图4)

图4

2. 安装VC 运行库(针对QQ安装后无法启动及部分游戏启动报错)

打开【360软件管家】,在左侧找到【编程开发类】点击,将右侧结果中的【VC 2005、2008、2010】进行安装即可。(如图5)

图5

3. 安装PhysX物理加速驱动

可以解决“缺少PhysXLoader.dll”等问题。

打开【360软件管家】,在搜索栏输入“Physx”,点击搜索结果里的NVIDIA PhysX system software进行安装即可。(如图6)

图6

4. 安装OpenAL

可以解决“缺失 openal32.dll”的问题。

打开【360软件管家】,在搜索栏输入“OpenAL”,点击搜索结果里的OpenAL进行安装即可。(如图7)

图7

5.安装Games for Windows-LIVE

可以解决“没有找到xlive.dll”的问题。

打开【360软件管家】,在搜索栏输入“Games for Windows”,点击搜索结果里的Microsoft Games

for Windows进行安装即可。(如图8)

图8

方案三:去到游戏官网下载最新版本的游戏客户端,下载完成后换路径重新安装一下。

#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 15 /* 最小方块的尺寸 */

#define BGCOLOR 7 /* 背景着色 */

#define GX 200

#define GY 10

#define SJNUM 10000 /* 每当玩家打到一万分等级加一级*/

/* 按键码*/

#define VK_LEFT 0x4b00

#define VK_RIGHT 0x4d00

#define VK_DOWN 0x5000

#define VK_UP 0x4800

#define VK_HOME 0x4700

#define VK_END 0x4f00

#define VK_SPACE 0x3920

#define VK_ESC 0x011b

#define VK_ENTER 0x1c0d

/* 定闷绝义俄罗斯方块的方向(我定义他为4种)*/

#define F_DONG 0

#define F_NAN 1

#define F_XI 2

#define F_BEI 3

#define NEXTCOL 20 /* 要出的下一个方块的纵坐标*/

#define NEXTROW 12 /* 要出的下一个方块的横从标*/

#define MAXROW 14 /* 游戏腊罩颂屏幕大小*/

#define MAXCOL 20

#define SCCOL 100 /*游戏屏幕大显示器上的相对位置*/

#define SCROW 60

int gril[22][16]/* 游戏屏幕坐标*/

int col=1,row=7/* 当前方块的横纵坐标*/

int boxfx=0,boxgs=0/* 当前寺块的形壮和方向*/

int nextboxfx=0,nextboxgs=0,maxcol=22/*下一个方块的形壮和方向*/

int minboxcolor=6,nextminboxcolor=6

int num=0/*游戏分轮郑*/

int dj=0,gamedj[10]={18,16,14,12,10,8,6,4,2,1}/* 游戏等级*/

/* 以下我用了一个3维数组来纪录方块的最初形状和方向*/

int boxstr[7][4][16]={{

{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(14)+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,640,480)

}

/*在图形模式下的高级清屏*/

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=0i<16i++)

boxz[i/4][i%4]=boxstr[boxgs][boxfx][i]

for(i=0i<4i++)

for(j=0j<4j++)

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=0i<16i++)

boxz[i/4][i%4]=boxstr[nextboxgs][nextboxfx][i]

for(i=0i<4i++)

for(j=0j<4j++)

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=ai>1i--)

for(j=1j<15j++){

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="00000"

for(i=1i<21i++){

zero=0

for(j=1j<15j++)

if(gril[j]==0)

zero=1

if(zero==0){

delcol(i)

delgx++

}

}

num=num+delgx*delgx*10

dj=num/10000

sprintf(nm,"%d",num)

clscr(456,173,500,200,4)

txt(456,173,"Number:",1,15)

txt(456,193,nm,1,15)

}

/*时间中断结束*/

void KillTimer(){

disable()

setvect(TIMER,oldhandler)

enable()

}

/* 测试当前方块是否可以向下落*/

int downok(){

int i,j,k=1,a[4][4]

for(i=0i<16i++)

a[i/4][i%4]=boxstr[boxgs][boxfx][i]

for(i=0i<4i++)

for(j=0j<4j++)

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=0i<16i++)

a[i/4][i%4]=boxstr[boxgs][boxfx][i]

for(i=0i<4i++)

for(j=0j<4j++)

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=0i<16i++)

a[i/4][i%4]=boxstr[boxgs][boxfx][i]

for(i=0i<4i++)

for(j=0j<4j++)

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=0i<4i++)

for(i=0i<16i++)

a[i/4][i%4]=boxstr[boxgs][boxfx+1][i]

for(i=3i>=0i--)

for(j=3j>=0j--)

if(a[j] &&gril[col+i][row+j])

k=0

return(k)

}

/*当前方块落下之后,给屏幕坐标作标记*/

void setgril(){

int i,j,a[4][4]

funbox(0,0,minboxcolor,0)

for(i=0i<16i++)

a[i/4][i%4]=boxstr[boxgs][boxfx][i]

for(i=0i<4i++)

for(j=0j<4j++)

if(a[j])

gril[col+i][row+j]=1

col=1row=7

}

/*游戏结束*/

void gameover(){

int i,j

for(i=20i>0i--)

for(j=1j<15j++)

minbox(j*MINBOXSIZE,i*MINBOXSIZE,2,0)

txt(103,203,"Game Over",3,10)

}

/*按键的设置*/

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: { /*上方向键,方向形状旋转90度*/

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(423,53,"worng key!",1,4)

txt(428,80,"Plese Enter Anly Key AG!",1,4)

getch()

clscr(420,50,622,97,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=1row=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="00000"

init(VGA,VGAHI)

cls()

/*屏幕坐标初始化*/

for(i=0i<=MAXCOL+1i++)

for(j=0j<=MAXROW+1j++)

gril[i][j]=0

for(i=0i<=MAXCOL+1i++) {

gril[i][0]=1

gril[i][15]=1

}

for(j=1j<=MAXROWj++){

gril[0][j]=1

gril[21][j]=1

}

clscr(0,0,640,480,15)

win(1,1,639,479,4,15)

win(SCCOL+MINBOXSIZE-2,SCROW+MINBOXSIZE-2,SCCOL+15*MINBOXSIZE+2,SCROW+21*MINBOXSIZE+2,BGCOLOR,0)

nextboxgs=random(8)

nextboxfx=random(4)

sprintf(nm,"%d",num)

txt(456,173,"Number:",1,15)

txt(456,193,nm,1,15)

txt(456,243,"Next Box:",1,15)

timezd()

KillTimer()

closegraph()

getch()

}

用c++实现的"贪吃蛇"游戏吵凳源码

// greedsnake.cpp

#include <bios.h>

#include <conio.h>型碰纯

 卜咐 #include <dos.h>

#include <graphics.h>

#include <stdlib.h>

#include <time.h>

#include "conf.h"

typedef struct node

{

int x,y

struct node *next

}Node

typedef struct

{

Node *head,*tail

int length

}Snake

typedef struct

{

int left,top,right,bottom

}Frame

typedef enum //四个方向

{

up,down,left,right

}Direction

typedef enum

{

false,true

}bool//*/

void InitGraphMode()//初始化图形驱动

void CloseGraphMode()

void Foot(int,int)

void Head(int,int)

void CreateFrame()//完成整个游戏框架的绘制

void CreateSnake()//创建一条两个节点的蛇,蛇的每一节是队列中的一个节点

bool PlayGame()//游戏的主体函数,

int Hit(int,int) //判断是否越界,或者撞到自身,两个参数分别是新的头接点的x,y坐标

bool GameOver()//绘制游戏结束时d出的对话框

void Enqueue(Node)//入队函数

Node Dequeue()//出队函数

void ClearKeyBuf()//清除键盘缓冲,此函数可以消除不停的按无效键的影响

Snake snake

Frame frame

void main()

{

InitGraphMode()

do

{

CreateFrame()

}while(PlayGame())

CloseGraphMode()

}

void InitGraphMode()

{

int gdriver=DETECT,gmode

initgraph(&gdriver,&gmode,"../bgi/")

cleardevice()

}

void CloseGraphMode()

{

cleardevice()

closegraph()

}

void CreateFrame()

{

setbkcolor(CYAN)

//下面的四行代码用于计算主框架的左上角和右下角的坐标

frame.left=(getmaxx()+1-BlockWidth*RowOfFrame)/2

frame.top=(getmaxy()+1-BlockHeight*ColumnOfFrame)/2

frame.right=frame.left+BlockWidth*RowOfFrame

frame.bottom=frame.top+BlockHeight*ColumnOfFrame

Head(frame.left+100,frame.top-20)

setfillstyle(SOLID_FILL,LIGHTGRAY)

bar(frame.left,frame.top,frame.right,frame.bottom)

setlinestyle(SOLID_LINE,1,1)

setcolor(DARKGRAY)

line(frame.left,frame.top,frame.right,frame.top)

line(frame.left,frame.top,frame.left,frame.bottom)

setlinestyle(SOLID_LINE,1,1)

setcolor(WHITE)

line(frame.left,frame.bottom,frame.right,frame.bottom)

line(frame.right,frame.top,frame.right,frame.bottom)

setlinestyle(DOTTED_LINE,1,1)

setcolor(BLUE)

for(int row=1row<RowOfFramerow++)

line(frame.left+row*BlockWidth,frame.top,frame.left+row*BlockWidth,frame.bottom)

for(int column=1column<ColumnOfFramecolumn++)

line(frame.left,frame.top+column*BlockHeight,frame.right,frame.top+column*BlockHeight)

Foot(frame.left,frame.bottom+20)

}

void CreateSnake()

{

Node *node1=new Node

Node *node2=new Node

node1->x=frame.left+BlockWidth

node1->y=frame.top

node1->next=NULL

snake.tail=node1

node2->x=frame.left

node2->y=frame.top

node2->next=snake.tail

snake.head=node2

snake.length=2

setfillstyle(SOLID_FILL,BLUE)

bar(snake.head->x+1,snake.head->y+1,snake.head->x+BlockWidth-1,snake.head->y+BlockHeight-1)

bar(snake.tail->x+1,snake.tail->y+1,snake.tail->x+BlockWidth-1,snake.tail->y+BlockHeight-1)

}

bool PlayGame()

{

int speed=300,key

Direction CurrentDirection=right

Node randomNode

Node newNode,outNode

bool neednode=true

bool overlap=false

int randx,randy

CreateSnake()

while(true)

{

if(neednode==true)

{

randomize()

do

{

randx=frame.left+rand()%RowOfFrame*BlockWidth

randy=frame.top+rand()%ColumnOfFrame*BlockHeight

for(Node *p=snake.headp!=NULLp=p->next)//hit itself

if(randx==p->x&&randy==p->y)

{overlap=truebreak}

}

while(overlap==true)

randomNode.x=randx

randomNode.y=randy

randomNode.next=NULL

setfillstyle(SOLID_FILL,RED)

bar(randomNode.x+1,randomNode.y+1,randomNode.x+BlockWidth-1,randomNode.y+BlockHeight-1)

neednode=false

}

if((key=bioskey(1))!=0)

{

switch(key)

{

case ESC: return false

case UP:

if(CurrentDirection!=down)

CurrentDirection=up

ClearKeyBuf()

break

case DOWN:

if(CurrentDirection!=up)

CurrentDirection=down

ClearKeyBuf()

break

case LEFT:

if(CurrentDirection!=right)

CurrentDirection=left

ClearKeyBuf()

break

case RIGHT:

if(CurrentDirection!=left)

CurrentDirection=right

ClearKeyBuf()

break

case PAGEUP:speed=speed-100

if(speed<100)

speed=100

ClearKeyBuf()

break

case PAGEDOWN:speed=speed+100

if(speed>500)

speed=500

ClearKeyBuf()

break

default :break

}

}

int headx=snake.tail->x

int heady=snake.tail->y

switch(CurrentDirection)

{

case up: heady-=BlockHeightbreak

case down: heady+=BlockHeightbreak

case left: headx-=BlockWidthbreak

case right: headx+=BlockWidthbreak

}

if(Hit(headx,heady)) //whether the snake hit the wall or itself

return GameOver()

else

{ //eat

if(headx==randomNode.x&&heady==randomNode.y)

{

Enqueue(randomNode)

setfillstyle(SOLID_FILL,BLUE)

bar(randomNode.x+1,randomNode.y+1,randomNode.x-1+BlockWidth,randomNode.y-1+BlockHeight)

neednode=true

}

else //no eat

{

newNode.x=headx

newNode.y=heady

newNode.next=NULL

Enqueue(newNode)

outNode=Dequeue()

setfillstyle(SOLID_FILL,LIGHTGRAY)

bar(outNode.x+1,outNode.y+1,outNode.x+BlockWidth-1,outNode.y+BlockHeight-1)

setfillstyle(SOLID_FILL,BLUE)

bar(newNode.x+1,newNode.y+1,newNode.x-1+BlockWidth,newNode.y-1+BlockHeight)

}

}

delay(speed)

}

}

void ClearKeyBuf()

{

do

bioskey(0)

while(bioskey(1))

}

void Foot(int x,int y)

{

setcolor(BLUE)

outtextxy(x,y,"writer:[T]RealXL E-MAIL:realgeneral@hotmail.com")

}

void Head(int x,int y)

{

setcolor(RED)

outtextxy(x,y,"GREEDY SNAKE")

}

void Enqueue(Node inNode)

{

Node *p=new Node

p->x=inNode.x

p->y=inNode.y

p->next=inNode.next

snake.tail->next=p

snake.tail=p

snake.length++

}

Node Dequeue()

{

Node *p=snake.head

Node outNode=*p

snake.head=p->next

snake.length--

delete p

return outNode

}

int Hit(int x,int y)

{

if(x<frame.left||x>=frame.right||y<frame.top||y>=frame.bottom)//hit the wall

return 1

Node *p=snake.head->next

for(int i=snake.length-1i>3i--,p=p->next)//hit itself

if(x==p->x&&y==p->y)

return 1

return 0

}

bool GameOver()

{

int x=getmaxx()/2-50

int y=getmaxy()/2-20

setfillstyle(SOLID_FILL,DARKGRAY)

bar(x+3,y+3,x+103,y+43)

setfillstyle(SOLID_FILL,MAGENTA)

bar(x,y,x+100,y+40)

setlinestyle(0,3,1)

setcolor(RED)

rectangle(x,y,x+100,y+40)

outtextxy(x+20,y+10,"GAGE OVER!")

char c

while(true) //按q或Q表示退出程序,按r或R表示重新开始游戏

{

c=getch()

if(c=='q'||c=='Q')

return false

else if(c=='r'||c=='R')

return true

}

}

C++五子棋源程序:

#include

#include

#include

#define backcolor CYAN

#define defaultcolor BLACK

#define linecolor MAGENTA

#define player1_color RED

#define player2_color WHITE

#define error_color RED

#define winner_color RED

const int left=40

const int top=390

const int d=30

const int line_num=9

const int turn=0

const int r=d/3

const int j=10

int x,y,k=1,step=(line_num+1)*(line_num+1)

union REGS regs1,regs2

class player1

class player2

class qipan{

public:

qipan()

~qipan(){}

void init_qipan()

friend void fall(player1 &num1,player2 &num2,qipan &num)

friend void input(player1 &num1,player2 &num2,qipan &num)

private:

int point[line_num+1][line_num+1]

}

class player1{

public:

player1()

~player1(){}

friend void fall(player1 &num1,player2 &num2,qipan &num)

friend void input(player1 &num1,player2 &num2)

friend int judge_winner(player1 &num1,player2 &num2)

private:

int point1[line_num+1][line_num+1]

}

class player2{

public:

player2()

~player2(){}

friend void fall(player1 &num1,player2 &num2,qipan &num)

friend void input(player1 &num1,player2 &num2,qipan &num)

friend int judge_winner(player1 &num1,player2 &num2)

private:

int point2[line_num+1][line_num+1]

}

void input(player1 &num1,player2 &num2)

void fall(player1 &num1,player2 &num2,qipan &num)

int judge_winner(qipan &num,player1 &num1,player2 &num2)

void inputerror()

void display_winner(int)

void main()

{

int driver=DETECT,mode

initgraph(&driver,&mode,"e:\tc30\bgi")

qipan num

player1 num1

player2 num2

while(step--)

{

input(num1,num2,num)

fall(num1,num2,num)

if(judge_winner(num1,num2))

{

display_winner(k)

}

}

// getchar()

}

qipan::qipan(void)

{ int j,i

char ch[2]="0"

setbkcolor(backcolor)

setcolor(linecolor)

for(i=0i<=line_numi++)

{

line(left,top-i*d,left+line_num*d,top-i*d)

}

for(i=0i<=line_numi++)

{

line(left+i*d,top,left+i*d,top-line_num*d)

}

for(i=0i<=line_numi++)

{ if(*ch=='9'+1) *ch='a'

settextstyle(DEFAULT_FONT,HORIZ_DIR,1)

outtextxy(left+i*d-2,top+r+3,ch)

(*ch)=(*ch)+1

}

*ch='0'

for(i=0i<=line_numi++)

{if(*ch=='9'+1) *ch='a'

settextstyle(DEFAULT_FONT,HORIZ_DIR,1)

outtextxy(left-r-10,top-d*i-3,ch)

(*ch)=(*ch)+1

}

setcolor(defaultcolor)

for(i=0i<=line_numi++)

{

for(j=0j<=line_numj++)

point[i][j]=0

}

}

void fall(player1 &num1,player2 &num2,qipan &num)

{

int flag=k%2

if(flag)

{ setcolor(player2_color)

num2.point2[x][y]=1

num.point[x][y]=2

circle(left+d*x,top-d*y,r)

setfillstyle(1,player2_color)

floodfill(left+d*x,top-d*y,player2_color)

}

else

{ num1.point1[x][y]=1

num.point[x][y]=1

setcolor(player1_color)

circle(left+d*x,top-d*y,r)

setfillstyle(1,player1_color)

floodfill(left+d*x,top-d*y,player1_color)

}

setcolor(defaultcolor)

}

void input(player1 &num1,player2 &num2,qipan &num)

{ char xx,yy

k++

while(1)

{

regs1.h.ah=0

xx=int86(22,®s1,®s1)-'0'

if(xx==('q'-'0')||xx==('Q'-'0'))

{ step=0

return

}

regs1.h.ah=0

yy=int86(22,®s1,®s1)-'0'

if(yy==('q'-'0')||yy==('Q'-'0'))

{

step=0

return

}

if(xx<0||xx>line_num)

{ inputerror()

continue

}

if(yy<0||yy>line_num)

{inputerror()

continue

}

if(num.point[xx][yy]==0)

{

break

}

else

{

inputerror()

continue

}

}

x=(int)xx

y=(int)yy

setcolor(backcolor)

settextstyle(DEFAULT_FONT,HORIZ_DIR,1)

outtextxy(left+d*line_num/3,top+d*2,"Input error")

setcolor(defaultcolor)

}

player1::player1()

{

int i,j

for(i=0i<=line_numi++)

{

for(j=0j<=line_numj++)

point1[i][j]=0

}

}

player2::player2()

{ int i,j

for(i=0i<=line_numi++)

{

for(j=0j<=line_numj++)

point2[i][j]=0

}

}

void inputerror(void)

{ setcolor(error_color)

settextstyle(DEFAULT_FONT,HORIZ_DIR,1)

outtextxy(left+d*line_num/3,top+d*2,"Input error")

setcolor(defaultcolor)

}

int judge_winner(player1 &num1,player2 &num2)

{

int count=0,m=0,n=0,a=0,b=0,xx0,yy0

int flag=k%2

xx0=xyy0=y

if(!flag)

{ //left <------->right

while(xx0>=1&&m<4) {xx0--m++}

while(n<9&&xx0<=line_num)

{

if(num1.point1[xx0][y]==1)

{

count++

if(count==5) return 1

}

else

{

count=0

}

n++

xx0++

}

//up <------>down

count=0xx0=xm=0n=0

while(yy0>=1&&m<4){yy0--m++}

while(n<9&&yy0<=line_num)

{

if(num1.point1[x][yy0]==1)

{

count++

if(count==5)

return 1

}

else

{

count=0

}

n++

yy0++

}

//left up ----- right down

xx0=x

yy0=y

m=0

n=0

count=0

while(xx0>=1&&m<4){ xx0--a++m++} m=0

while(yy0<=line_num&&m<4){ yy0++b++m++}

if(a<=b)

{

xx0=x-ayy0=y+a

}

else

{

xx0=x-byy0=y+b

}

while(xx0<=line_num&&yy0>=0&&n<9)

{

if(num1.point1[xx0][yy0]==1)

{

count++

if(count==5)

return 1

}

else

{

count=0

}

xx0++

yy0--

n++

}

//right up <----->left down

count=0

a=0

b=0

n=0

m=0

xx0=x

yy0=y

while(xx0while(yy0if(a<=b)

{

xx0=x+a

yy0=y+a

}

else

{

xx0=x+b

yy0=y+b

}

while(xx0>=0&&yy0>=0&&n<9)

{

if(num1.point1[xx0][yy0]==1)

{

count++

if(count==5)

return 1

}

else

count=0

xx0--

yy0--

n++

}

//no winer

return 0

}

else

{

//left <------->right

while(xx0>=1&&m<4) {xx0--m++}

while(n<9&&xx0<=line_num)

{

if(num1.point1[xx0][y]==1)

{

count++

if(count==5) return 1

}

else

{

count=0

}

n++

xx0++

}

//up <------>down

count=0xx0=xm=0n=0

while(yy0>=1&&m<4){yy0--m++}

while(n<9&&yy0<=line_num)

{

if(num2.point2[x][yy0]==1)

{

count++

if(count==5)

return 1

}

else

{

count=0

}

n++

yy0++

}

//left up ----- right down

xx0=x

yy0=y

m=0

n=0

count=0

while(xx0>=1&&m<4){ xx0--a++m++} m=0

while(yy0<=line_num&&m<4){ yy0++b++m++}

if(a<=b)

{

xx0=x-ayy0=y+a

}

else

{

xx0=x-byy0=y+b

}

while(xx0<=line_num&&yy0>=0&&n<9)

{

if(num2.point2[xx0][yy0]==1)

{

count++

if(count==5)

return 1

}

else

{

count=0

}

xx0++

yy0--

n++

}

//right up <----->left down

count=0

a=0

b=0

n=0

m=0

xx0=x

yy0=y

while(xx0while(yy0if(a<=b)

{

xx0=x+a

yy0=y+a

}

else

{

xx0=x+b

yy0=y+b

}

while(xx0>=0&&yy0>=0&&n<9)

{

if(num2.point2[xx0][yy0]==1)

{

count++

if(count==5)

return 1

}

else

count=0

xx0--

yy0--

n++

}

//no winer

return 0

}

}

void display_winner(int k)

{

int flag=k%2

if(!flag)

{ setcolor(winner_color)

settextstyle(DEFAULT_FONT,HORIZ_DIR,2)

outtextxy(left+d*2,top+40,"Red is winner")

setcolor(defaultcolor)

step=0

getchar()

}

else

{ setcolor(winner_color)

settextstyle(DEFAULT_FONT,HORIZ_DIR,2)

outtextxy(left+2*d,top+40,"White is winner")

setcolor(defaultcolor)

step=0

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12281209.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存