当前位置:首页 » 编程语言 » c语言c40

c语言c40

发布时间: 2024-06-19 01:11:20

1. 用c语言编写一个五子棋的游戏程序

**********************************************************/
/* 程序中用到的库函数所在头文件应用 #include 命令包含进来 */

#include <stdio.h>
#include <bios.h>
#include <ctype.h>
#include <conio.h>
#include <dos.h>

/**********************************************************/
/* 定义符号常量 */

/*定义画棋盘所需的制表符*/
#define CROSSRU 0xbf /*右上角点*/
#define CROSSLU 0xda /*左上角点*/
#define CROSSLD 0xc0 /*左下角点*/
#define CROSSRD 0xd9 /*右下角点*/
#define CROSSL 0xc3 /*左边*/
#define CROSSR 0xb4 /*右边*/
#define CROSSU 0xc2 /*上边*/
#define CROSSD 0xc1 /*下边*/
#define CROSS 0xc5 /*十字交叉点*/

/*定义棋盘左上角点在屏幕上的位置*/
#define MAPXOFT 5
#define MAPYOFT 2

/*定义1号玩家的操作键键码*/
#define PLAY1UP 0x1157/*上移--'W'*/
#define PLAY1DOWN 0x1f53/*下移--'S'*/
#define PLAY1LEFT 0x1e41/*左移--'A'*/
#define PLAY1RIGHT 0x2044/*右移--'D'*/
#define PLAY1DO 0x3920/*落子--空格键*/

/*定义2号玩家的操作键键码*/
#define PLAY2UP 0x4800/*上移--方向键up*/
#define PLAY2DOWN 0x5000/*下移--方向键down*/
#define PLAY2LEFT 0x4b00/*左移--方向键left*/
#define PLAY2RIGHT 0x4d00/*右移--方向键right*/
#define PLAY2DO 0x1c0d/*落子--回车键Enter*/

/*若想在游戏中途退出, 可按 Esc 键*/
#define ESCAPE 0x011b

/*定义棋盘上交叉点的状态, 即该点有无棋子 */
/*若有棋子, 还应能指出是哪个玩家的棋子 */
#define CHESSNULL 0 //没有棋子
#define CHESS1 'O'//一号玩家的棋子
#define CHESS2 'X'//二号玩家的棋子

/*定义按键类别*/
#define KEYEXIT 0/*退出键*/
#define KEYFALLCHESS 1/*落子键*/
#define KEYMOVECURSOR 2/*光标移动键*/
#define KEYINVALID 3/*无效键*/

/*定义符号常量: 真, 假 --- 真为1, 假为0 */
#define TRUE 1
#define FALSE 0

/**********************************************************/
/* 定义数据结构 */

/*棋盘交叉点坐标的数据结构*/
struct point
{
int x,y;
};

/**********************************************************/
/*自定义函数原型说明 */
void Init(void);
int GetKey(void);
int CheckKey(int press);
int ChangeOrder(void);
int ChessGo(int Order,struct point Cursor);
void DoError(void);
void DoOK(void);
void DoWin(int Order);
void MoveCursor(int Order,int press);
void DrawCross(int x,int y);
void DrawMap(void);
int JudgeWin(int Order,struct point Cursor);
int JudgeWinLine(int Order,struct point Cursor,int direction);
void ShowOrderMsg(int Order);
void EndGame(void);
/**********************************************************/

/**********************************************************/
/* 定义全局变量 */
int gPlayOrder; /*指示当前行棋方 */
struct point gCursor; /*光标在棋盘上的位置 */
char gChessBoard[19][19];/*用于记录棋盘上各点的状态*/
/**********************************************************/

/**********************************************************/
/*主函数*/
void main()
{
int press;
int bOutWhile=FALSE;/*退出循环标志*/

Init();/*初始化图象,数据*/

while(1)
{
press=GetKey();/*获取用户的按键值*/
switch(CheckKey(press))/*判断按键类别*/
{
/*是退出键*/
case KEYEXIT:
clrscr();/*清屏*/
bOutWhile = TRUE;
break;

/*是落子键*/
case KEYFALLCHESS:
if(ChessGo(gPlayOrder,gCursor)==FALSE)/*走棋*/
DoError();/*落子错误*/
else
{
DoOK();/*落子正确*/

/*如果当前行棋方赢棋*/
if(JudgeWin(gPlayOrder,gCursor)==TRUE)
{
DoWin(gPlayOrder);
bOutWhile = TRUE;/*退出循环标志置为真*/
}
/*否则*/
else
/*交换行棋方*/
ChangeOrder();
}
break;

/*是光标移动键*/
case KEYMOVECURSOR:
MoveCursor(gPlayOrder,press);
break;

/*是无效键*/
case KEYINVALID:
break;
}

if(bOutWhile==TRUE)
break;
}

/*游戏结束*/
EndGame();
}
/**********************************************************/

/*界面初始化,数据初始化*/
void Init(void)
{
int i,j;
char *Msg[]=
{
"Player1 key:",
" UP----w",
" DOWN--s",
" LEFT--a",
" RIGHT-d",
" DO----space",
"",
"Player2 key:",
" UP----up",
" DOWN--down",
" LEFT--left",
" RIGHT-right",
" DO----ENTER",
"",
"exit game:",
" ESC",
NULL,
};

/*先手方为1号玩家*/
gPlayOrder = CHESS1;
/*棋盘数据清零, 即棋盘上各点开始的时候都没有棋子*/
for(i=0;i<19;i++)
for(j=0;j<19;j++)
gChessBoard[i][j]=CHESSNULL;
/*光标初始位置*/
gCursor.x=gCursor.y=0;

/*画棋盘*/
textmode(C40);
DrawMap();

/*显示操作键说明*/
i=0;
textcolor(BROWN);
while(Msg[i]!=NULL)
{
gotoxy(25,3+i);
cputs(Msg[i]);
i++;
}

/*显示当前行棋方*/
ShowOrderMsg(gPlayOrder);
/*光标移至棋盘的左上角点处*/
gotoxy(gCursor.x+MAPXOFT,gCursor.y+MAPYOFT);
}

/*画棋盘*/
void DrawMap(void)
{
int i,j;

clrscr();

for(i=0;i<19;i++)
for(j=0;j<19;j++)
DrawCross(i,j);

}

/*画棋盘上的交叉点*/
void DrawCross(int x,int y)
{
gotoxy(x+MAPXOFT,y+MAPYOFT);
/*交叉点上是一号玩家的棋子*/
if(gChessBoard[x][y]==CHESS1)
{
textcolor(LIGHTBLUE);
putch(CHESS1);
return;
}
/*交叉点上是二号玩家的棋子*/
if(gChessBoard[x][y]==CHESS2)
{
textcolor(LIGHTBLUE);
putch(CHESS2);
return;
}

textcolor(GREEN);

/*左上角交叉点*/
if(x==0&&y==0)
{
putch(CROSSLU);
return;
}

/*左下角交叉点*/
if(x==0&&y==18)
{
putch(CROSSLD);
return;
}

/*右上角交叉点*/
if(x==18&&y==0)
{
putch(CROSSRU);
return;
}

/*右下角交叉点*/
if(x==18&&y==18)
{
putch(CROSSRD);
return;
}

/*左边界交叉点*/
if(x==0)
{
putch(CROSSL);
return;
}

/*右边界交叉点*/
if(x==18)
{
putch(CROSSR);
return;
}

/*上边界交叉点*/
if(y==0)
{
putch(CROSSU);
return;
}

/*下边界交叉点*/
if(y==18)
{
putch(CROSSD);
return;
}

/*棋盘中间的交叉点*/
putch(CROSS);
}

/*交换行棋方*/
int ChangeOrder(void)
{
if(gPlayOrder==CHESS1)
gPlayOrder=CHESS2;
else
gPlayOrder=CHESS1;

return(gPlayOrder);
}

/*获取按键值*/
int GetKey(void)
{
char lowbyte;
int press;

while (bioskey(1) == 0)
;/*如果用户没有按键,空循环*/

press=bioskey(0);
lowbyte=press&0xff;
press=press&0xff00 + toupper(lowbyte);
return(press);
}

/*落子错误处理*/
void DoError(void)
{
sound(1200);
delay(50);
nosound();
}

/*赢棋处理*/
void DoWin(int Order)
{
sound(1500);delay(100);
sound(0); delay(50);
sound(800); delay(100);
sound(0); delay(50);
sound(1500);delay(100);
sound(0); delay(50);
sound(800); delay(100);
sound(0); delay(50);
nosound();

textcolor(RED+BLINK);
gotoxy(25,20);
if(Order==CHESS1)
cputs("PLAYER1 WIN!");
else
cputs("PLAYER2 WIN!");
gotoxy(25,21);
cputs(" \\<^+^>/");
getch();
}

/*走棋*/
int ChessGo(int Order,struct point Cursor)
{
/*判断交叉点上有无棋子*/
if(gChessBoard[Cursor.x][Cursor.y]==CHESSNULL)
{
/*若没有棋子, 则可以落子*/
gotoxy(Cursor.x+MAPXOFT,Cursor.y+MAPYOFT);
textcolor(LIGHTBLUE);
putch(Order);
gotoxy(Cursor.x+MAPXOFT,Cursor.y+MAPYOFT);
gChessBoard[Cursor.x][Cursor.y]=Order;
return TRUE;
}
else
return FALSE;
}

/*判断当前行棋方落子后是否赢棋*/
int JudgeWin(int Order,struct point Cursor)
{
int i;
for(i=0;i<4;i++)
/*判断在指定方向上是否有连续5个行棋方的棋子*/
if(JudgeWinLine(Order,Cursor,i))
return TRUE;
return FALSE;
}

/*判断在指定方向上是否有连续5个行棋方的棋子*/
int JudgeWinLine(int Order,struct point Cursor,int direction)
{
int i;
struct point pos,dpos;
const int testnum = 5;
int count;

switch(direction)
{
case 0:/*在水平方向*/
pos.x=Cursor.x-(testnum-1);
pos.y=Cursor.y;
dpos.x=1;
dpos.y=0;
break;
case 1:/*在垂直方向*/
pos.x=Cursor.x;
pos.y=Cursor.y-(testnum-1);
dpos.x=0;
dpos.y=1;
break;
case 2:/*在左下至右上的斜方向*/
pos.x=Cursor.x-(testnum-1);
pos.y=Cursor.y+(testnum-1);
dpos.x=1;
dpos.y=-1;
break;
case 3:/*在左上至右下的斜方向*/
pos.x=Cursor.x-(testnum-1);
pos.y=Cursor.y-(testnum-1);
dpos.x=1;
dpos.y=1;
break;
}

count=0;
for(i=0;i<testnum*2+1;i++)
{
if(pos.x>=0&&pos.x<=18&&pos.y>=0&&pos.y<=18)
{
if(gChessBoard[pos.x][pos.y]==Order)
{
count++;
if(count>=testnum)
return TRUE;
}
else
count=0;
}
pos.x+=dpos.x;
pos.y+=dpos.y;
}

return FALSE;
}

/*移动光标*/
void MoveCursor(int Order,int press)
{
switch(press)
{
case PLAY1UP:
if(Order==CHESS1&&gCursor.y>0)
gCursor.y--;
break;
case PLAY1DOWN:
if(Order==CHESS1&&gCursor.y<18)
gCursor.y++;
break;
case PLAY1LEFT:
if(Order==CHESS1&&gCursor.x>0)
gCursor.x--;
break;
case PLAY1RIGHT:
if(Order==CHESS1&&gCursor.x<18)
gCursor.x++;
break;

case PLAY2UP:
if(Order==CHESS2&&gCursor.y>0)
gCursor.y--;
break;
case PLAY2DOWN:
if(Order==CHESS2&&gCursor.y<18)
gCursor.y++;
break;
case PLAY2LEFT:
if(Order==CHESS2&&gCursor.x>0)
gCursor.x--;
break;
case PLAY2RIGHT:
if(Order==CHESS2&&gCursor.x<18)
gCursor.x++;
break;
}

gotoxy(gCursor.x+MAPXOFT,gCursor.y+MAPYOFT);
}

/*游戏结束处理*/
void EndGame(void)
{
textmode(C80);
}

/*显示当前行棋方*/
void ShowOrderMsg(int Order)
{
gotoxy(6,MAPYOFT+20);
textcolor(LIGHTRED);
if(Order==CHESS1)
cputs("Player1 go!");
else
cputs("Player2 go!");

gotoxy(gCursor.x+MAPXOFT,gCursor.y+MAPYOFT);
}

/*落子正确处理*/
void DoOK(void)
{
sound(500);
delay(70);
sound(600);
delay(50);
sound(1000);
delay(100);
nosound();
}

/*检查用户的按键类别*/
int CheckKey(int press)
{
if(press==ESCAPE)
return KEYEXIT;/*是退出键*/

else
if
( ( press==PLAY1DO && gPlayOrder==CHESS1) ||
( press==PLAY2DO && gPlayOrder==CHESS2)
)
return KEYFALLCHESS;/*是落子键*/

else
if
( press==PLAY1UP || press==PLAY1DOWN ||
press==PLAY1LEFT || press==PLAY1RIGHT ||
press==PLAY2UP || press==PLAY2DOWN ||
press==PLAY2LEFT || press==PLAY2RIGHT
)
return KEYMOVECURSOR;/*是光标移动键*/

else
return KEYINVALID;/*按键无效*/
}

2. c语言编的五子棋源代码

//自定义控件,然后在工具箱拖过来用再把BackColor设置为Transparent
:ListBox
{
publicTransparentListBox()
{
this.SetStyle(ControlStyles.UserPaint,true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor,true);
}
(EventArgse)
{
this.Invalidate();
base.OnSelectedIndexChanged(e);
}
protectedoverridevoidOnPaint(PaintEventArgse)
{
if(this.Focused&&this.SelectedItem!=null)
{
RectangleitemRect=this.GetItemRectangle(this.SelectedIndex);
e.Graphics.FillRectangle(Brushes.Green,itemRect);
}
for(inti=0;i<Items.Count;i++)
{
e.Graphics.DrawString(this.GetItemText(Items[i]),this.Font,newSolidBrush(this.ForeColor),this.GetItemRectangle(i));
}
base.OnPaint(e);
}
}

3. 求一个C语言小程序(五子棋)源代码

*******************************************************************/
/* ALEX_LEE 五子棋 C语言小程序 */
/* o(∩_∩)o...可以用来复习一下C语言的小程序 */
/* My Blog:hi..com/alexlee321 */
/******************************************************************/

/**********************************************************/
#include <stdio.h>
#include <bios.h>
#include <ctype.h>
#include <conio.h>
#include <dos.h>
/**********************************************************/
/* 定义符号常量 */

/*定义画棋盘所需的制表符*/
#define CROSSRU 0xbf /*右上角点*/
#define CROSSLU 0xda /*左上角点*/
#define CROSSLD 0xc0 /*左下角点*/
#define CROSSRD 0xd9 /*右下角点*/
#define CROSSL 0xc3 /*左边*/
#define CROSSR 0xb4 /*右边*/
#define CROSSU 0xc2 /*上边*/
#define CROSSD 0xc1 /*下边*/
#define CROSS 0xc5 /*十字交叉点*/

/*定义棋盘左上角点在屏幕上的位置*/
#define MAPXOFT 5
#define MAPYOFT 2

/*定义1号玩家的操作键键码*/
#define PLAY1UP 0x1157/*上移--'W'*/
#define PLAY1DOWN 0x1f53/*下移--'S'*/
#define PLAY1LEFT 0x1e41/*左移--'A'*/
#define PLAY1RIGHT 0x2044/*右移--'D'*/
#define PLAY1DO 0x3920/*落子--空格键*/

/*定义2号玩家的操作键键码*/
#define PLAY2UP 0x4800/*上移--方向键up*/
#define PLAY2DOWN 0x5000/*下移--方向键down*/
#define PLAY2LEFT 0x4b00/*左移--方向键left*/
#define PLAY2RIGHT 0x4d00/*右移--方向键right*/
#define PLAY2DO 0x1c0d/*落子--回车键Enter*/

/*若想在游戏中途退出, 可按 Esc 键*/
#define ESCAPE 0x011b

/*定义棋盘上交叉点的状态, 即该点有无棋子 */
/*若有棋子, 还应能指出是哪个玩家的棋子 */
#define CHESSNULL 0 //没有棋子
#define CHESS1 'O'//一号玩家的棋子
#define CHESS2 'X'//二号玩家的棋子

/*定义按键类别*/
#define KEYEXIT 0/*退出键*/
#define KEYFALLCHESS 1/*落子键*/
#define KEYMOVECURSOR 2/*光标移动键*/
#define KEYINVALID 3/*无效键*/

/*定义符号常量: 真, 假 --- 真为1, 假为0 */
#define TRUE 1
#define FALSE 0

/**********************************************************/
/* 定义数据结构 */

/*棋盘交叉点坐标的数据结构*/
struct point
{
int x,y;
};

/**********************************************************/
/*自定义函数原型说明 */
void Init(void);
int GetKey(void);
int CheckKey(int press);
int ChangeOrder(void);
int ChessGo(int Order,struct point Cursor);
void DoError(void);
void DoOK(void);
void DoWin(int Order);
void MoveCursor(int Order,int press);
void DrawCross(int x,int y);
void DrawMap(void);
int JudgeWin(int Order,struct point Cursor);
int JudgeWinLine(int Order,struct point Cursor,int direction);
void ShowOrderMsg(int Order);
void EndGame(void);
/**********************************************************/

/**********************************************************/
/* 定义全局变量 */
int gPlayOrder; /*指示当前行棋方 */
struct point gCursor; /*光标在棋盘上的位置 */
char gChessBoard[19][19];/*用于记录棋盘上各点的状态*/
/**********************************************************/

/**********************************************************/
/*主函数*/
void main()
{
int press;
int bOutWhile=FALSE;/*退出循环标志*/

Init();/*初始化图象,数据*/

while(1)
{
press=GetKey();/*获取用户的按键值*/
switch(CheckKey(press))/*判断按键类别*/
{
/*是退出键*/
case KEYEXIT:
clrscr();/*清屏*/
bOutWhile = TRUE;
break;

/*是落子键*/
case KEYFALLCHESS:
if(ChessGo(gPlayOrder,gCursor)==FALSE)/*走棋*/
DoError();/*落子错误*/
else
{
DoOK();/*落子正确*/

/*如果当前行棋方赢棋*/
if(JudgeWin(gPlayOrder,gCursor)==TRUE)
{
DoWin(gPlayOrder);
bOutWhile = TRUE;/*退出循环标志置为真*/
}
/*否则*/
else
/*交换行棋方*/
ChangeOrder();
}
break;

/*是光标移动键*/
case KEYMOVECURSOR:
MoveCursor(gPlayOrder,press);
break;

/*是无效键*/
case KEYINVALID:
break;
}

if(bOutWhile==TRUE)
break;
}

/*游戏结束*/
EndGame();
}
/**********************************************************/

/*界面初始化,数据初始化*/
void Init(void)
{
int i,j;
char *Msg[]=
{
"Player1 key:",
" UP----w",
" DOWN--s",
" LEFT--a",
" RIGHT-d",
" DO----space",
"",
"Player2 key:",
" UP----up",
" DOWN--down",
" LEFT--left",
" RIGHT-right",
" DO----ENTER",
"",
"exit game:",
" ESC",
NULL,
};

/*先手方为1号玩家*/
gPlayOrder = CHESS1;
/*棋盘数据清零, 即棋盘上各点开始的时候都没有棋子*/
for(i=0;i<19;i++)
for(j=0;j<19;j++)
gChessBoard[i][j]=CHESSNULL;
/*光标初始位置*/
gCursor.x=gCursor.y=0;

/*画棋盘*/
textmode(C40);
DrawMap();

/*显示操作键说明*/
i=0;
textcolor(BROWN);
while(Msg[i]!=NULL)
{
gotoxy(25,3+i);
cputs(Msg[i]);
i++;
}

/*显示当前行棋方*/
ShowOrderMsg(gPlayOrder);
/*光标移至棋盘的左上角点处*/
gotoxy(gCursor.x+MAPXOFT,gCursor.y+MAPYOFT);
}

/*画棋盘*/
void DrawMap(void)
{
int i,j;

clrscr();

for(i=0;i<19;i++)
for(j=0;j<19;j++)
DrawCross(i,j);

}

/*画棋盘上的交叉点*/
void DrawCross(int x,int y)
{
gotoxy(x+MAPXOFT,y+MAPYOFT);
/*交叉点上是一号玩家的棋子*/
if(gChessBoard[x][y]==CHESS1)
{
textcolor(LIGHTBLUE);
putch(CHESS1);
return;
}
/*交叉点上是二号玩家的棋子*/
if(gChessBoard[x][y]==CHESS2)
{
textcolor(LIGHTBLUE);
putch(CHESS2);
return;
}

textcolor(GREEN);

/*左上角交叉点*/
if(x==0&&y==0)
{
putch(CROSSLU);
return;
}

/*左下角交叉点*/
if(x==0&&y==18)
{
putch(CROSSLD);
return;
}

/*右上角交叉点*/
if(x==18&&y==0)
{
putch(CROSSRU);
return;
}

/*右下角交叉点*/
if(x==18&&y==18)
{
putch(CROSSRD);
return;
}

/*左边界交叉点*/
if(x==0)
{
putch(CROSSL);
return;
}

/*右边界交叉点*/
if(x==18)
{
putch(CROSSR);
return;
}

/*上边界交叉点*/
if(y==0)
{
putch(CROSSU);
return;
}

/*下边界交叉点*/
if(y==18)
{
putch(CROSSD);
return;
}

/*棋盘中间的交叉点*/
putch(CROSS);
}

/*交换行棋方*/
int ChangeOrder(void)
{
if(gPlayOrder==CHESS1)
gPlayOrder=CHESS2;
else
gPlayOrder=CHESS1;

return(gPlayOrder);
}

/*获取按键值*/
int GetKey(void)
{
char lowbyte;
int press;

while (bioskey(1) == 0)
;/*如果用户没有按键,空循环*/

press=bioskey(0);
lowbyte=press&0xff;
press=press&0xff00 + toupper(lowbyte);
return(press);
}

/*落子错误处理*/
void DoError(void)
{
sound(1200);
delay(50);
nosound();
}

/*赢棋处理*/
void DoWin(int Order)
{
sound(1500);delay(100);
sound(0); delay(50);
sound(800); delay(100);
sound(0); delay(50);
sound(1500);delay(100);
sound(0); delay(50);
sound(800); delay(100);
sound(0); delay(50);
nosound();

textcolor(RED+BLINK);
gotoxy(25,20);
if(Order==CHESS1)
cputs("PLAYER1 WIN!");
else
cputs("PLAYER2 WIN!");
gotoxy(25,21);
cputs(" \\<^+^>/");
getch();
}

/*走棋*/
int ChessGo(int Order,struct point Cursor)
{
/*判断交叉点上有无棋子*/
if(gChessBoard[Cursor.x][Cursor.y]==CHESSNULL)
{
/*若没有棋子, 则可以落子*/
gotoxy(Cursor.x+MAPXOFT,Cursor.y+MAPYOFT);
textcolor(LIGHTBLUE);
putch(Order);
gotoxy(Cursor.x+MAPXOFT,Cursor.y+MAPYOFT);
gChessBoard[Cursor.x][Cursor.y]=Order;
return TRUE;
}
else
return FALSE;
}

/*判断当前行棋方落子后是否赢棋*/
int JudgeWin(int Order,struct point Cursor)
{
int i;
for(i=0;i<4;i++)
/*判断在指定方向上是否有连续5个行棋方的棋子*/
if(JudgeWinLine(Order,Cursor,i))
return TRUE;
return FALSE;
}

/*判断在指定方向上是否有连续5个行棋方的棋子*/
int JudgeWinLine(int Order,struct point Cursor,int direction)
{
int i;
struct point pos,dpos;
const int testnum = 5;
int count;

switch(direction)
{
case 0:/*在水平方向*/
pos.x=Cursor.x-(testnum-1);
pos.y=Cursor.y;
dpos.x=1;
dpos.y=0;
break;
case 1:/*在垂直方向*/
pos.x=Cursor.x;
pos.y=Cursor.y-(testnum-1);
dpos.x=0;
dpos.y=1;
break;
case 2:/*在左下至右上的斜方向*/
pos.x=Cursor.x-(testnum-1);
pos.y=Cursor.y+(testnum-1);
dpos.x=1;
dpos.y=-1;
break;
case 3:/*在左上至右下的斜方向*/
pos.x=Cursor.x-(testnum-1);
pos.y=Cursor.y-(testnum-1);
dpos.x=1;
dpos.y=1;
break;
}

count=0;
for(i=0;i<testnum*2+1;i++)
{
if(pos.x>=0&&pos.x<=18&&pos.y>=0&&pos.y<=18)
{
if(gChessBoard[pos.x][pos.y]==Order)
{
count++;
if(count>=testnum)
return TRUE;
}
else
count=0;
}
pos.x+=dpos.x;
pos.y+=dpos.y;
}

return FALSE;
}

/*移动光标*/
void MoveCursor(int Order,int press)
{
switch(press)
{
case PLAY1UP:
if(Order==CHESS1&&gCursor.y>0)
gCursor.y--;
break;
case PLAY1DOWN:
if(Order==CHESS1&&gCursor.y<18)
gCursor.y++;
break;
case PLAY1LEFT:
if(Order==CHESS1&&gCursor.x>0)
gCursor.x--;
break;
case PLAY1RIGHT:
if(Order==CHESS1&&gCursor.x<18)
gCursor.x++;
break;

case PLAY2UP:
if(Order==CHESS2&&gCursor.y>0)
gCursor.y--;
break;
case PLAY2DOWN:
if(Order==CHESS2&&gCursor.y<18)
gCursor.y++;
break;
case PLAY2LEFT:
if(Order==CHESS2&&gCursor.x>0)
gCursor.x--;
break;
case PLAY2RIGHT:
if(Order==CHESS2&&gCursor.x<18)
gCursor.x++;
break;
}

gotoxy(gCursor.x+MAPXOFT,gCursor.y+MAPYOFT);
}

/*游戏结束处理*/
void EndGame(void)
{
textmode(C80);
}

/*显示当前行棋方*/
void ShowOrderMsg(int Order)
{
gotoxy(6,MAPYOFT+20);
textcolor(LIGHTRED);
if(Order==CHESS1)
cputs("Player1 go!");
else
cputs("Player2 go!");

gotoxy(gCursor.x+MAPXOFT,gCursor.y+MAPYOFT);
}

/*落子正确处理*/
void DoOK(void)
{
sound(500);
delay(70);
sound(600);
delay(50);
sound(1000);
delay(100);
nosound();
}

/*检查用户的按键类别*/
int CheckKey(int press)
{
if(press==ESCAPE)
return KEYEXIT;/*是退出键*/

else
if
( ( press==PLAY1DO && gPlayOrder==CHESS1) ||
( press==PLAY2DO && gPlayOrder==CHESS2)
)
return KEYFALLCHESS;/*是落子键*/

else
if
( press==PLAY1UP || press==PLAY1DOWN ||
press==PLAY1LEFT || press==PLAY1RIGHT ||
press==PLAY2UP || press==PLAY2DOWN ||
press==PLAY2LEFT || press==PLAY2RIGHT
)
return KEYMOVECURSOR;/*是光标移动键*/

else
return KEYINVALID;/*按键无效*/
}

4. 关于C语言在编译时常出现的错误有哪些

1、fatal error C1010: unexpected end of file while looking for precompiled header directive。

寻找预编译头文件路径时遇到了不该遇到的文件尾。(一般是没有#include "stdafx.h")

2、fatal error C1083: Cannot open include file: 'R…….h': No such file or directory

不能打开包含文件“R…….h”:没有这样的文件或目录。

3、error C2011: 'C……': 'class' type redefinition

类“C……”重定义。

4、error C2018: unknown character '0xa3'

不认识的字符'0xa3'。(一般是汉字或中文标点符号)

5、error C2057: expected constant expression

希望是常量表达式。(一般出现在switch语句的case分支中)

6、error C2065: 'IDD_MYDIALOG' : undeclared identifier

“IDD_MYDIALOG”:未声明过的标识符。

7、error C2082: redefinition of formal parameter 'bReset'

函数参数“bReset”在函数体中重定义。

8、error C2143: syntax error: missing ':' before '{'

句法错误:“{”前缺少“;”。

9、error C2146: syntax error : missing ';' before identifier 'dc'

句法错误:在“dc”前丢了“;”。

10、error C2196: case value '69' already used

值69已经用过。(一般出现在switch语句的case分支中)

11、error C2509: 'OnTimer' : member function not declared in 'CHelloView'

成员函数“OnTimer”没有在“CHelloView”中声明。

12、error C2511: 'reset': overloaded member function 'void (int)' not found in 'B'

重载的函数“void reset(int)”在类“B”中找不到。

13、error C2555: 'B::f1': overriding virtual function differs from 'A::f1' only by return type or calling convention

类B对类A中同名函数f1的重载仅根据返回值或调用约定上的区别。

14、error C2660: 'SetTimer' : function does not take 2 parameters

“SetTimer”函数不传递2个参数。

15、warning C4035: 'f……': no return value

“f……”的return语句没有返回值。

16、warning C4553: '= =' : operator has no effect; did you intend '='?

没有效果的运算符“= =”;是否改为“=”?

17、warning C4700: local variable 'bReset' used without having been initialized

局部变量“bReset”没有初始化就使用。

18、error C4716: 'CMyApp::InitInstance' : must return a value

“CMyApp::InitInstance”函数必须返回一个值。

19、LINK : fatal error LNK1168: cannot open Debug/P1.exe for writing

连接错误:不能打开P1.exe文件,以改写内容。(一般是P1.Exe还在运行,未关闭)

20、error LNK2001: unresolved external symbol "public: virtual _ _thiscall C……::~C……(void)"

连接时发现没有实现的外部符号(变量、函数等)。

function call missing argument list 调用函数的时候没有给参数。

member function definition looks like a ctor, but name does not match enclosing class 成员函数声明了但没有使用

unexpected end of file while looking for precompiled header directive 在寻找预编译头文件时文件意外结束,编译不正常终止可能造成这种情况

5. C语言中的俄罗斯方块

我给你,我有源代码,可以运行
/*************************
<Russia Diamonds Ver 1.0>
Copyright by forever_chang
[email protected]
2001.11.1
*************************/
/*****************************************************************************************/
#include "graphics.h" /*头文件*/
#include "time.h"
#include "stdlib.h"
#include "bios.h"
#include "dos.h"
#include "stdio.h"
#define ESC 0x11b /*键盘扫描码*/
#define UP 0x4800
#define DOWN 0x5000
#define LEFT 0x4b00
#define F1 0x3b00
#define RIGHT 0x4d00
#define YES 0x1579
#define NO 0x316e
#define RESTART 0x1372
/*****************************************************************************************/
struct diamond /*记录每种方块每种状态的信息*/
{
int x[4];
int y[4];
int start_x;
int start_y;
int color;
struct diamond *next;
};
int grid[12][23]; /*记录所有格子的状态 (0)没有方块 (1)有固定方块 (2)有活动方块*/
int x; /*活动方块所在位置*/
int y;
int level; /*游戏难度*/
int count; /*计数器*/
int score;/*得分*/
struct diamond *nowinfo; /*当前活动方块*/
struct diamond *nextinfo; /*下一个方块*/
int color;/*画格子的颜色*/
int backcolor;/*游戏区域背景色*/
/*****************************************************************************************/
void show_interface (int mode);/*显示游戏界面*/
void show_copsign (int topx,int topy,int size,int color);/*显示公司标志--恒基伟业*/
void show_intro (int xs,int ys);/*显示软件介绍区*/
/*void print(); 测试用函数*/
void scandel();/*扫描所有格子看是否有可消除行*/
void show_down ();/*方块下落后的下一个状态*/
void show_next ();/*方块翻转后的下一个状态*/
void show_left ();/*方块向左移动后的下一个状态*/
void show_right ();/*方块向右移动后的下一个状态*/
void interrupt (*oldtimer)();/*指向未安装前的中断向量,即函数指针,指向一段可执行的代码*/
void install();/*安装新的中断向量,即将中断服务程序安装到中断向量表中*/
void interrupt newtimer();/*中断服务程序*/
struct diamond *get_diamond();/*随机得到一个方块*/
struct diamond *create_I();/*函数用来构造各种类形方块的环形链表*/
struct diamond *create_T();/*返回链表中随机一个状态的指针*/
struct diamond *create_L();
struct diamond *create_J();
struct diamond *create_Z();
struct diamond *create_N();
struct diamond *create_H();
void delinfo (struct diamond *info);/*释放当前方块所占用的空间*/
void addtobuffer(int c);/*向键盘缓冲区中增加一个DOWN*/
/*void clrkey();调用dos中断清空键盘缓冲区,未使用此方法.*/
void showsubwin(struct diamond *next);/*在小窗口显示下一个方块*/
void showscore(int scoreget);/*显示分数*/
void startset();/*初始化游戏*/
/*****************************************************************************************/
main ()
{
int driver=VGA;
int mode=VGAHI;
int i;/*计数器*/
int j;
int key;/*记录键盘扫描码*/
initgraph (&driver,&mode,"");/*初始化*/
color=8;
backcolor=7;
level=1;
score=298;
count=0;
show_interface (9);/*显示界面*/
setfillstyle(SOLID_FILL,1);
bar(0,465,640,480);
outtextxy(5,469,"Press any key to start...");
getch();
setfillstyle(SOLID_FILL,9);
bar(0,465,640,480);
showscore(0);/*显示分数*/
randomize();
nowinfo=get_diamond ();/*得到一个当前方块*/
oldtimer=getvect(0x1c);
install(newtimer);
for(i=0;i<=21;i++)/*初始化grid[12][23]*/
{
for(j=1;j<=10;j++)
grid[j][i]=0;
}
for(i=0;i<=22;i++)
{
grid[0][i]=1;
grid[11][i]=1;
}
for(i=0;i<=11;i++)
{
grid[i][22]=1;
}

x=nowinfo->start_x;/*初始化方块位置*/
y=nowinfo->start_y;
nextinfo=get_diamond ();/*得到下一个方块*/
showsubwin(nextinfo);

for (;
{
key=bioskey(0);/*得到键盘扫描码*/
if (key)
{
switch(key)
{

case DOWN:{
show_down ();
break;
}
case UP:{
show_next ();
break;
}
case LEFT:{
show_left();
break;
}
case RIGHT:{
show_right();
break;
}
case RESTART:{
install(oldtimer);
setfillstyle(SOLID_FILL,1);
bar(0,465,640,480);
outtextxy(5,469,"Are you sure to restart (Y/N)...");
for (;
{
key=bioskey(0);/*得到键盘扫描码*/
if (key==YES)
{
startset();
setfillstyle(SOLID_FILL,9);
bar(0,465,640,480);
break;
}
if (key==NO)
{
setfillstyle(SOLID_FILL,9);
bar(0,465,640,480);
install(newtimer);
break;
}
}
break;
}
/* case F1:{
print();
break;
}
*/
case ESC:{
install(oldtimer);
setfillstyle(SOLID_FILL,1);
bar(0,465,640,480);
outtextxy(5,469,"Are you sure to exit (Y/N)...");
for (;
{
key=bioskey(0);/*得到键盘扫描码*/
if (key==YES)
{
closegraph();
exit(0);
}
if (key==NO)
{
setfillstyle(SOLID_FILL,9);
bar(0,465,640,480);
install(newtimer);
break;
}
}

}
}
}
}
}
/*****************************************************************************************/
struct diamond *get_diamond()
{
struct diamond *now;
switch (random(7)+1)
{
case 1:{
now=create_I();
return now;
}
case 2:{
now=create_T();
return now;
}
case 3:{
now=create_L();
return now;
}
case 4:{
now=create_J();
return now;
}
case 5:{
now=create_Z();
return now;
}
case 6:{
now=create_N();
return now;
}
case 7:{
now=create_H();
return now;
}
}
}
/*****************************************************************************************/
void show_interface (int fill_mode)
{
int i;
setbkcolor (9);
setcolor (color);
setfillstyle (SOLID_FILL,backcolor);
bar (100,60,300,420);
bar (360,60,440,140);
rectangle (100,60,300,420);
rectangle (96,56,304,424);

rectangle (360,60,440,140);
rectangle (356,56,444,144);
setfillstyle (fill_mode,14);
floodfill (97,57,color);
floodfill (397,57,color);
setcolor(1);
rectangle(96,56,304,424);
setcolor (color);
for (i=80;i<=400;i+=20)
{
line (100,i,300,i);
}
for (i=120;i<=280;i+=20)
{
line (i,60,i,420);
}
for (i=80;i<=120;i+=20)
{
line (360,i,440,i);
}
for (i=380;i<=420;i+=20)
{
line (i,60,i,140);
}
show_intro (360,180);
show_copsign (475,320,40,1);
setfillstyle(SOLID_FILL,1);
setcolor(14);
rectangle(420,405,534,417);
floodfill (421,406,14);
outtextxy(422,408,"HI-TECH WEALTH");
}
/*****************************************************************************************/
void show_copsign (int topx,int topy,int size,int color)
{
int halfsize,qtrsize;
int xadd,xdel,yadd1,yadd2;
halfsize=0.5*size;
qtrsize=0.25*size;

xadd=topx+size;
xdel=topx-size;
yadd1=topy+size;
yadd2=topy+2*size;

setcolor(color);
line (topx,topy,xdel,yadd1);
line (xdel,yadd1,topx,yadd2);
line (topx,yadd2,xadd,yadd1);
line (xadd,yadd1,topx,topy);
rectangle (topx-halfsize,topy+halfsize,topx+halfsize,yadd1+halfsize);
setfillstyle (SOLID_FILL,color);
floodfill (topx,topy+1,color);
floodfill (xdel+1,yadd1,color);
floodfill (topx,yadd2-1,color);
floodfill (xadd-1,yadd1,color);
rectangle (topx-halfsize,yadd1-qtrsize,topx-0.75*halfsize,yadd1+qtrsize);
floodfill (topx-halfsize+1,yadd1-qtrsize+1,color);
rectangle (topx-qtrsize,yadd1-halfsize,topx+qtrsize,yadd1-0.25*halfsize);
floodfill (topx-qtrsize+1,yadd1-halfsize+1,color);
rectangle (topx+0.75*halfsize,yadd1-qtrsize,topx+halfsize,yadd1+qtrsize);
floodfill (topx+0.75*halfsize+1,yadd1-qtrsize+1,color);
rectangle (topx-qtrsize,yadd1+0.25*halfsize,topx+qtrsize,yadd2-halfsize);
floodfill (topx-qtrsize+1,yadd1+0.25*halfsize+1,color);
setcolor(14);
line (topx,topy-1,xdel-1,yadd1);
line (xdel-1,yadd1,topx,yadd2+1);
line (topx,yadd2+1,xadd+1,yadd1);
line (xadd+1,yadd1,topx,topy-1);
setfillstyle (SOLID_FILL,14);
floodfill (topx,yadd1,color);
}
/*****************************************************************************************/
void show_intro (int xs,int ys)
{
char stemp[20];
setcolor (15);
rectangle(xs-3,ys-3,xs+239,ys+115);
line (xs-3,ys+26,xs+239,ys+26);
line (xs-3,ys+72,xs+239,ys+72);
outtextxy(xs,ys,"Level:");
outtextxy(xs,ys+15,"Score:");
sprintf(stemp," -Roll -Downwards");
stemp[0]=24;
stemp[7]=25;
outtextxy(xs,ys+30,"Help:");
setcolor(14);
outtextxy(xs+40,ys+30,stemp);
outtextxy(xs+40,ys+45,"<-Turn Left >-Turn Right");
outtextxy(xs+40,ys+60,"Esc-Exit R-Restart");
outtextxy(xs,ys+75,"Russia Diamonds Ver 1.0");
outtextxy(xs,ys+90,"CopyRight By ChangYong.01-11-1");
outtextxy(xs,ys+105,"Email:[email protected]");
}
/*****************************************************************************************/
struct diamond *create_I()
{
struct diamond *info;
struct diamond *first;
first=(struct diamond *)malloc(sizeof(struct diamond));
info=(struct diamond *)malloc(sizeof(struct diamond));
first->next=info;
info->next=first;
first->x[0]=0;
first->y[0]=0;
first->x[1]=-1;
first->y[1]=0;
first->x[2]=1;
first->y[2]=0;
first->x[3]=2;
first->y[3]=0;
first->start_x=5;
first->start_y=3;
first->color=2;

info->x[0]=0;
info->y[0]=0;
info->x[1]=0;
info->y[1]=-1;
info->x[2]=0;
info->y[2]=1;
info->x[3]=0;
info->y[3]=2;
info->start_x=5;
info->start_y=1;
info->color=2;

if(random(2)==0) {return first;}
else {return first->next;}
}
/*****************************************************************************************/
struct diamond *create_T()
{
struct diamond *info;
struct diamond *first;
struct diamond *last;
int i;

info=(struct diamond *)malloc(sizeof(struct diamond));
info->x[0]=0;
info->y[0]=0;
info->x[1]=-1;
info->y[1]=0;
info->x[2]=0;
info->y[2]=-1;
info->x[3]=1;
info->y[3]=0;
info->start_x=5;
info->start_y=3;
info->color=4;
first=info;
last=info;

info=(struct diamond *)malloc(sizeof(struct diamond));
info->x[0]=0;
info->y[0]=0;
info->x[1]=0;
info->y[1]=1;
info->x[2]=0;
info->y[2]=-1;
info->x[3]=1;
info->y[3]=0;
info->start_x=5;
info->start_y=2;
info->color=4;
last->next=info;
last=info;

info=(struct diamond *)malloc(sizeof(struct diamond));
info->x[0]=0;
info->y[0]=0;
info->x[1]=-1;
info->y[1]=0;
info->x[2]=1;
info->y[2]=0;
info->x[3]=0;
info->y[3]=1;
info->start_x=5;
info->start_y=2;
info->color=4;
last->next=info;
last=info;

info=(struct diamond *)malloc(sizeof(struct diamond));
info->x[0]=0;
info->y[0]=0;
info->x[1]=0;
info->y[1]=1;
info->x[2]=0;
info->y[2]=-1;
info->x[3]=-1;
info->y[3]=0;
info->start_x=5;
info->start_y=2;
info->color=4;
last->next=info;
last=info;
last->next=first;

for (i=0;i<=random(4);i++)
{
first=first->next;
}
return first;
}
/*****************************************************************************************/
struct diamond *create_L()
{
struct diamond *info;
struct diamond *first;
struct diamond *last;
int i;

info=(struct diamond *)malloc(sizeof(struct diamond));
info->x[0]=0;
info->y[0]=0;
info->x[1]=0;
info->y[1]=1;
info->x[2]=0;
info->y[2]=-1;
info->x[3]=1;
info->y[3]=1;
info->start_x=5;
info->start_y=2;
info->color=5;
first=info;
last=info;

info=(struct diamond *)malloc(sizeof(struct diamond));
info->x[0]=0;
info->y[0]=0;
info->x[1]=-1;
info->y[1]=0;
info->x[2]=1;
info->y[2]=0;
info->x[3]=-1;
info->y[3]=1;
info->start_x=5;
info->start_y=2;
info->color=5;
last->next=info;
last=info;

info=(struct diamond *)malloc(sizeof(struct diamond));
info->x[0]=0;
info->y[0]=0;
info->x[1]=0;
info->y[1]=1;
info->x[2]=0;
info->y[2]=-1;
info->x[3]=-1;
info->y[3]=-1;
info->start_x=5;
info->start_y=2;
info->color=5;
last->next=info;
last=info;

info=(struct diamond *)malloc(sizeof(struct diamond));
info->x[0]=0;
info->y[0]=0;
info->x[1]=-1;
info->y[1]=0;
info->x[2]=1;
info->y[2]=0;
info->x[3]=1;
info->y[3]=-1;
info->start_x=5;
info->start_y=2;
info->color=5;
last->next=info;
last=info;
last->next=first;

for (i=0;i<=random(4);i++)
{
first=first->next;
}
return first;
}
/*****************************************************************************************/
struct diamond *create_J()
{
struct diamond *info;
struct diamond *first;
struct diamond *last;
int i;

info=(struct diamond *)malloc(sizeof(struct diamond));
info->x[0]=0;
info->y[0]=0;
info->x[1]=0;
info->y[1]=1;
info->x[2]=0;
info->y[2]=-1;
info->x[3]=-1;
info->y[3]=1;
info->start_x=5;
info->start_y=2;
info->color=6;
first=info;
last=info;

info=(struct diamond *)malloc(sizeof(struct diamond));
info->x[0]=0;
info->y[0]=0;
info->x[1]=-1;
info->y[1]=0;
info->x[2]=1;
info->y[2]=0;
info->x[3]=-1;
info->y[3]=-1;
info->start_x=5;
info->start_y=2;
info->color=6;
last->next=info;
last=info;

info=(struct diamond *)malloc(sizeof(struct diamond));
info->x[0]=0;
info->y[0]=0;
info->x[1]=0;
info->y[1]=1;
info->x[2]=0;
info->y[2]=-1;
info->x[3]=1;
info->y[3]=-1;
info->start_x=5;
info->start_y=2;
info->color=6;
last->next=info;
last=info;

info=(struct diamond *)malloc(sizeof(struct diamond));
info->x[0]=0;
info->y[0]=0;
info->x[1]=-1;
info->y[1]=0;
info->x[2]=1;
info->y[2]=0;
info->x[3]=1;
info->y[3]=1;
info->start_x=5;
info->start_y=2;
info->color=6;
last->next=info;
last=info;
last->next=first;

for (i=0;i<=random(4);i++)
{
first=first->next;
}
return first;
}
/*****************************************************************************************/
struct diamond *create_Z()
{
struct diamond *info;
struct diamond *first;
first=(struct diamond *)malloc(sizeof(struct diamond));
info=(struct diamond *)malloc(sizeof(struct diamond));
first->next=info;
info->next=first;
first->x[0]=0;
first->y[0]=0;
first->x[1]=-1;
first->y[1]=0;
first->x[2]=0;
first->y[2]=1;
first->x[3]=1;
first->y[3]=1;
first->start_x=5;
first->start_y=2;
first->color=9;

info->x[0]=0;
info->y[0]=0;
info->x[1]=0;
info->y[1]=1;
info->x[2]=1;
info->y[2]=0;
info->x[3]=1;
info->y[3]=-1;
info->start_x=5;
info->start_y=2;
info->color=9;

if(random(2)==0) {return first;}
else {return first->next;}
}
/*****************************************************************************************/
struct diamond *create_N()
{
struct diamond *info;
struct diamond *first;
first=(struct diamond *)malloc(sizeof(struct diamond));
info=(struct diamond *)malloc(sizeof(struct diamond));
first->next=info;
info->next=first;
first->x[0]=0;
first->y[0]=0;
first->x[1]=0;
first->y[1]=1;
first->x[2]=-1;
first->y[2]=1;
first->x[3]=1;
first->y[3]=0;
first->start_x=5;
first->start_y=2;
first->color=14;

info->x[0]=0;
info->y[0]=0;
info->x[1]=0;
info->y[1]=-1;
info->x[2]=1;
info->y[2]=0;
info->x[3]=1;
info->y[3]=1;
info->start_x=5;
info->start_y=2;
info->color=14;

if(random(2)==0) {return first;}
else {return first->next;}
}
/*****************************************************************************************/
struct diamond *create_H()
{
struct diamond *first;
first=(struct diamond *)malloc(sizeof(struct diamond));
first->next=first;
first->x[0]=0;
first->y[0]=0;
first->x[1]=0;
first->y[1]=1;
first->x[2]=1;
first->y[2]=0;
first->x[3]=1;
first->y[3]=1;
first->start_x=5;
first->start_y=2;
first->color=1;
return first;
}
/*****************************************************************************************/
void show_next ()
{
int nowx;/*记录当前每个格子的位置*/
int nowy;
int i;/*计数器*/
int j;
int haveit;/*当前格子是否已经显示*/
struct diamond *next;/*当前方块的翻转后的下一个状态*/
next=nowinfo->next;
if (next==NULL) {gotoxy(1,1);printf("null");}
for (i=0;i<=3;i++)/*判断是否能够翻转,若不能,就直接退出该函数*/
{
if (grid[x+next->x[i]][y+next->y[i]]==1)
{
return;
}
}

setfillstyle(SOLID_FILL,backcolor);/*设置背景色以消除不需要的格子*/
for (i=0;i<=3;i++)
{
haveit=0;
for (j=0;j<=3;j++)
{
if (next->x[j]==nowinfo->x[i]&&next->y[j]==nowinfo->y[i]) {haveit=1;break;}
}
if (haveit==0) /*判断翻转后该格子是否显示,若不显示,将该格子设为背景色*/
{
grid[x+nowinfo->x[i]][y+nowinfo->y[i]]=0;
if (y+nowinfo->y[i]>=4)/*判断该格子是否到了可以显示的区域*/
floodfill(80+(nowinfo->x[i]+x)*20+1,-20+(nowinfo->y[i]+y)*20+1,color);
}
}

nowinfo=next;
nowx=x;
nowy=y;
setfillstyle(SOLID_FILL,nowinfo->color);/*设置填冲色为方块的颜色*/
for (i=0;i<=3;i++)
{
if (grid[x+nowinfo->x[i]][y+nowinfo->y[i]]!=2)/*如果该格子还没有被显示*/
{
nowx=x+nowinfo->x[i];
nowy=y+nowinfo->y[i];
if (y+nowinfo->y[i]>=4)
floodfill(80+nowx*20+1,-20+nowy*20+1,color);
grid[nowx][nowy]=2; /*设置该格子当前有活动方块*/
}
}
return;
}
/*****************************************************************************************/
void show_left ()
{
int i;/*计数器*/
int j;
int haveit;/*当前格子是否已经显示*/
int nowx;/*记录当前每个格子的位置*/
int nowy;
for (i=0;i<=3;i++)/*判断是否可以向左移动*/
{
if (grid[x-1+nowinfo->x[i]][y+nowinfo->y[i]]==1)
{
return;
}
}

setfillstyle(SOLID_FILL,backcolor);/*设置背景色以消除不需要的格子*/
for (i=0;i<=3;i++)
{
haveit=0;
for (j=0;j<=3;j++)
{
if (nowinfo->x[i]==nowinfo->x[j]-1&&nowinfo->y[i]==nowinfo->y[j]) {haveit=1;break;}
}
if (haveit==0) /*判断翻转后该格子是否显示,若不显示,将该格子设为背景色*/
{
grid[x+nowinfo->x[i]][y+nowinfo->y[i]]=0;
if (y+nowinfo->y[i]>=4)/*判断该格子是否到了可以显示的区域*/
floodfill(80+(nowinfo->x[i]+x)*20+1,-20+(nowinfo->y[i]+y)*20+1,color);
}
}

setfillstyle(SOLID_FILL,nowinfo->color);/*设置填冲色为方块的颜色*/
for (i=0;i<=3;i++)
{
nowx=x+nowinfo->x[i]-1;
nowy=y+nowinfo->y[i];
if (grid[nowx][nowy]!=2)/*如果该格子还没有被显示*/
{
if (nowy>=4)
floodfill(80+nowx*20+1,-20+nowy*20+1,color);
grid[nowx][nowy]=2;
}
}
x=x-1;
return;
}
/*****************************************************************************************/
void show_right ()
{
int i;/*计数器*/
int j;
int haveit;/*当前格子是否已经显示*/
int nowx;/*记录当前每个格子的位置*/
int nowy;
for (i=0;i<=3;i++)
{
if (grid[x+1+nowinfo->x[i]][y+nowinfo->y[i]]==1)
{
return;/*判断是否可以向右移动*/
}
}

setfillstyle(SOLID_FILL,backcolor);/*设置背景色以消除不需要的格子*/
for (i=0;i<=3;i++)
{
haveit=0;
for (j=0;j<=3;j++)
{
if (nowinfo->x[i]==nowinfo->x[j]+1&&nowinfo->y[i]==nowinfo->y[j]) {haveit=1;break;}
}
if (haveit==0)/*判断翻转后该格子是否显示,若不显示,将该格子设为背景色*/
{
grid[x+nowinfo->x[i]][y+nowinfo->y[i]]=0;
if (y+nowinfo->y[i]>=4)/*判断该格子是否到了可以显示的区域*/
floodfill(80+(nowinfo->x[i]+x)*20+1,-20+(nowinfo->y[i]+y)*20+1,color);
}
}

setfillstyle(SOLID_FILL,nowinfo->color);/*设置填冲色为方块的颜色*/
for (i=0;i<=3;i++)
{
nowx=x+nowinfo->x[i]+1;
nowy=y+nowinfo->y[i];
if (grid[nowx][nowy]!=2)
{
if (nowy>=4)/*判断该格子是否到了可以显示的区域*/
floodfill(80+nowx*20+1,-20+nowy*20+1,color);
grid[nowx][nowy]=2;
}
}
x=x+1;
return;
}
/*****************************************************************************************/
void show_down ()
{

int i;/*计数器*/
int j;
int haveit;/*当前格子是否已经显示*/
int nowx;/*记录当前每个格子的位置*/
int nowy;
int key;
for (i=0;i<=3;i++)
{
if (grid[x+nowinfo->x[i]][y+nowinfo->y[i]+1]==1)/*判断方块是否能够下落*/
{
for (j=0;j<=3;j++)
{
grid[x+nowinfo->x[j]][y+nowinfo->y[j]]=1;
if (y+nowinfo->y[j]<=3)
{/*判断游戏是否已经玩完*/
install(oldtimer);
setfillstyle(SOLID_FILL,1);
bar(0,465,640,480);
outtextxy(5,469,"Do you want to restart (Y/N)...");
for (;
{
key=bioskey(0);
if (key==YES)
{
startset();
setfillstyle(SOLID_FILL,9);
bar(0,465,640,480);
return;
}
if (key==NO)
{
closegraph();
exit (0);}
}
}
}

delinfo(nowinfo);
scandel();/*扫描,删除*/
delay(2500);
while(bioskey(1)) bioskey(0);/*清除键盘缓冲区*/
/* clrkey();*/
nowinfo=nextinfo;/*得到新的方块*/
nextinfo=get_diamond();/*得到下一个方块*/
showsubwin(nextinfo);
x=nowinfo->start_x;/*重新设置方块位置*/
y=nowinfo->start_y;
return;
}
}

setfillstyle(SOLID_FILL,backcolor);/*设置背景色以消除不需要的格子*/

for (i=0;i<=3;i++)
{
haveit=0;
for (j=0;j<=3;j++)
{
if (nowinfo->x[i]==nowinfo->x[j]&&nowinfo->y[i]==nowinfo->y[j]+1) {haveit=1;break;}
}
......
详见:
http://topic.csdn.net/t/20030409/15/1638691.html
http://www.anyter.com/doc/doc.asp?doc_id=87

热点内容
别克s60和君威配置哪个好 发布:2024-11-27 00:36:03 浏览:722
数据库的文件名称 发布:2024-11-27 00:30:04 浏览:336
javaweb与android交互 发布:2024-11-27 00:28:26 浏览:918
华为手机方舟编译器emui91 发布:2024-11-27 00:10:46 浏览:948
高考时老妈解压 发布:2024-11-27 00:09:34 浏览:358
全振动算法 发布:2024-11-27 00:00:24 浏览:843
编译程序用锐龙好还是酷睿好 发布:2024-11-26 23:47:09 浏览:897
苹果缓存清理后会加速吗 发布:2024-11-26 23:28:11 浏览:139
我的世界服务器修改开放端口 发布:2024-11-26 23:22:51 浏览:52
qt5编译器 发布:2024-11-26 23:22:04 浏览:517