c语言画函数图像用自定义函数画棋盘

用c语言画棋盘
[问题点数:50分]
本版专家分:0
结帖率 50%
CSDN今日推荐
本版专家分:0
结帖率 50%
本版专家分:44246
2018年6月 C/C++大版内专家分月排行榜第二2018年1月 C/C++大版内专家分月排行榜第二2017年12月 C/C++大版内专家分月排行榜第二2017年8月 C/C++大版内专家分月排行榜第二
2018年5月 C/C++大版内专家分月排行榜第三2018年4月 C/C++大版内专家分月排行榜第三2018年3月 C/C++大版内专家分月排行榜第三2018年2月 C/C++大版内专家分月排行榜第三2017年11月 C/C++大版内专家分月排行榜第三2017年10月 C/C++大版内专家分月排行榜第三2017年9月 C/C++大版内专家分月排行榜第三2017年6月 C/C++大版内专家分月排行榜第三2017年5月 C/C++大版内专家分月排行榜第三2017年4月 C/C++大版内专家分月排行榜第三2017年3月 C/C++大版内专家分月排行榜第三
本版专家分:8423
2017年12月 C++ Builder大版内专家分月排行榜第一2016年12月 C++ Builder大版内专家分月排行榜第一2016年11月 C++ Builder大版内专家分月排行榜第一2016年9月 C++ Builder大版内专家分月排行榜第一2016年8月 C++ Builder大版内专家分月排行榜第一
本版专家分:8423
2017年12月 C++ Builder大版内专家分月排行榜第一2016年12月 C++ Builder大版内专家分月排行榜第一2016年11月 C++ Builder大版内专家分月排行榜第一2016年9月 C++ Builder大版内专家分月排行榜第一2016年8月 C++ Builder大版内专家分月排行榜第一
本版专家分:368362
2017年 总版技术专家分年内排行榜第一
2014年 总版技术专家分年内排行榜第二
2013年 总版技术专家分年内排行榜第三
2012年 总版技术专家分年内排行榜第七
本版专家分:40
本版专家分:39
匿名用户不能发表回复!|
CSDN今日推荐凡事预则立,不预则废
笔记:C语言图形基本函数及实例五子棋游戏
初始化图形界面
gdriver = DETECT;
initgraph(&gdriver,&gmode,”” );
cleardevice ();
退出图形化界面
closegraph ();
画图之前未设定调用颜色,则背景色默认为黑色,前景色默认为白色
setbkcolor (WHITE) //背景色
setcolor (4);//前景色
前景,背景
前景,背景
前景,背景
前景,背景
前景,背景
前景,背景
前景,背景
LIGHTGREEN
LIGHTMAGENTA
——-图形化界面函数
//自己测试的时候下面四个得到的值都是0
int far getmaxx (void)
int far getmaxy (void)
int far getx (void)
int far gety (void)
//自己测试的时候下面两个没看到效果
void far moveto (int x, int y) 光标移动到 (x,y)点,在移动过程中画点
void far moverel (int dx, int dy); 光标从 (x,y)移动到 (x+dx, y+dy)的位置,移动中不画店
//以下的有看到效果
void far line (int x1, int y1, int x2, int y2) 画线
void far setlinestyle (int linestyle, unsigned upattern, int thickness);
linestyle 设置线的形状,
4 用户定义线
thickness 设置线的宽度
1 一个像素宽(默认值)
3 三个像素宽
当linestyle取值为 4时,还必须设置upattern参数。此时upattern的16位二进制数
每一位代表一个像素,该位为1则画像素点,为0则不画。
#include "stdio.h"
#include "conio.h"
#include "graphics.h"
void main ()
int arw[16] = {200, 102,
200, 102};
gdriver = DETECT;
initgraph(&gdriver,&gmode,"" );
setbkcolor (WHITE);
cleardevice ();
setcolor (BLUE);
circle (320, 240, 98);
setlinestyle (0, 0, 3);
setcolor (GREEN);
rectangle (220, 140, 420, 340);
setcolor (GREEN);
setlinestyle (4,0xaaaa, 3);
line (220, 240, 420, 240);
line (320, 140, 320, 340);
closegraph ();
void far circle (int x, int y, int radius); 画圆圈
void far rectangle (int x1, int y1, int x2, int y2); 画矩形
void far putpixel (int x, int y, int color)画点
void far linerel (int dx, int dy); 从当前光标 (x,y)画线到点 (x +dx , y + dy)
void far arc (int x, int y, int stangle, int endangle, int radius); 画弧线
void far ellipse(int x, int y, int stangle, int endangle, int xradius, int yradius) 画椭型
void far drawpoly (int numpoints , int far * polypoints) 画多边形
各顶点坐标由
polypoints 给出
———–填充函数
void far setfillstyle (int pattern, int
设置填充模式以及颜色。
以背景色颜色填充
以实线填充
以直线填充
以斜线填充(阴影线)
以粗斜线填充(粗阴影线)
以粗反斜线填充(~)
以反斜线填充(~)
以直方网格填充
以斜网格填充
以间隔点填充
以大间隔点填充
以小间隔点填充
以用户自定义样图填充
做五子棋的时候, 我这样设置红方的棋子。
setfillstyle(1,RED);
floodfill(XiaoYuanX1+10,XiaoYuanY1+10,7);
void far floodfill (int x, int y, int border);
————————-图形方式下文本输出
void far outtext (char far *textstring);
当前位置输出字符串
void far outtext (int x, int y, far *textstring )
在 (x,y) 位置输出字符串
outtextxy(230,30,”player
chess!”);
int sprintf (char * str, char *format, 变量列表)
char s[30];
int i = 400;
sprintf (s, “your score is %d”, i );
void far settextjustify (int horiz, int vert);
定位输出字符串时的对齐方式,
CENTER_TEXT 1
RIGHT_TEXT
void far settextstyle (int font, int direction, int charsize);
direction 输出方向
charsize 字符大小
DEFAULT_FONT
8*8点阵字(默认)
TRIPLEX_FONT
三重笔画字体
SMALL_FONT
小号画笔字体
SANSSERIF_FONT
无衬线画笔字体
GOTHIC_FONT 4
黑体笔画笔
USER_CHAR_SIZE=0
用户定义字符大小
当初课程设计做的一个五子棋游戏。
#include "stdio.h"
#include "conio.h"
#include "graphics.h"
#include &bios.h&
#define Esc 0x11b
#define Player1_up 18432
#define Player1_down 20480
#define Player1_left 19200
#define Player1_right 19712
#define Player1_do 7181
#define Player2_up 4471
#define Player2_down 8051
#define Player2_left 7777
#define Player2_right 8292
#define Player2_do 14624
int AllChessNumber = 0;
int Chess[15][15] = {0};
int CountN
int JudgeX;
int JudgeY;
int LineX1;
int LineX2;
int LineY1;
int LineY2;
int XiaoQiPanX1 = 230;
int XiaoQiPanX2 = 380;
int XiaoQiPanY1 = 230;
int XiaoQiPanY2 = 380;
int XiaoYuanX1 = 100;
int XiaoYuanY1 = 335;
int XiaoYuanX2 = 520;
int XiaoYuanY2 = 335;
int YuanR = 20;
int DaQiPanX1 = 170;
int DaQiPanX2 = 450;
int DaQiPanY1 = 100;
int DaQiPanY2 = 380;
int ChessRedLocalX = 170;
int ChessRedLocalY = 100;
int ChessWhiteLocalX = 170;
int ChessWhiteLocalY = 100;
int ChessLocalBoxX;
int ChessLocalBoxY;
void Welcome(void);
void ModeChoose(void);
void DrawChessBox(void);
void ChooseFirst_Or_Second(void);
void DrawChessR_W(int x,int y,int color);
void DrawStandForRed();
void DrawStandForWhite();
void Player1_vs_Player2(void);
void Player_vs_Computer(void);
void ChessNowLocal(int x,int y);
void ChessActionRed(int key);
void ChessActionWhite(int key);
void RedWin(void);
void WhiteWin(void);
void PrintfChess(void);
void JudgeHeng(int x,int y,int R_or_W);
void JudgeShu(int x,int y,int R_or_W);
void JudgeZuoXie(int x,int y,int R_or_W);
void JudgeYouXie(int x,int y,int R_or_W);
int ComputeYouXie(int x,int y,int R_or_W);
int ComputeShu(int x,int y,int R_or_W);
int ComputeZuoXie(int x,int y,int R_or_W);
int ComputeHeng(int x,int y,int R_or_W);
int ScoreReturn(int CountLeft,int CountRight,int LeftLive,int RightLive,int R_or_W);
void PCChessActionWhite();
void Exit();
gdriver = DETECT;
initgraph(&gdriver,&gmode,"" );
Welcome();
outtextxy(230,120,"player1 vs player2");
outtextxy(230,160,"player vs computer");
DrawChessR_W(200,120,BLUE);
ModeChoose();
DrawChessBox();
ChooseFirst_Or_Second();
DrawChessBox();
if(PlayMode == 1)
Player1_vs_Player2();
Player_vs_Computer();
void Player1_vs_Player2(void)
if (RedXianhou == 1)
setcolor(GREEN);
outtextxy(220,40,"Red,please put your chess! ");
outtextxy(400,400,"press Esc to exit!");
DrawChessR_W(ChessRedLocalX,ChessRedLocalY,RED);
ChessNowLocal(ChessRedLocalX,ChessRedLocalY);
DrawStandForRed();
while(bioskey(1) == 0);
key = bioskey(0);
if(key != Esc)
ChessActionRed(key);
setcolor(GREEN);
outtextxy(220,40,"White,please put your chess! ");
outtextxy(400,400,"press Esc to exit!");
DrawChessR_W(ChessWhiteLocalX,ChessWhiteLocalY,WHITE);
ChessNowLocal(ChessWhiteLocalX,ChessWhiteLocalY);
DrawStandForWhite();
while(bioskey(1) == 0);
key = bioskey(0);
if(key != Esc)
ChessActionWhite(key);
void Player_vs_Computer(void)
if (RedXianhou == 1)
setcolor(GREEN);
outtextxy(220,40,"White,please put your chess! ");
outtextxy(400,400,"press Esc to exit!");
DrawChessR_W(ChessRedLocalX,ChessRedLocalY,RED);
ChessNowLocal(ChessRedLocalX,ChessRedLocalY);
DrawStandForRed();
while(bioskey(1) == 0);
key = bioskey(0);
if(key != Esc)
ChessActionRed(key);
Chess[9][9] = 2;
PrintfChess();
setcolor(GREEN);
outtextxy(220,40,"Red,please put your chess! ");
outtextxy(400,400,"press Esc to exit!");
DrawChessR_W(ChessRedLocalX,ChessRedLocalY,RED);
ChessNowLocal(ChessRedLocalX,ChessRedLocalY);
DrawStandForRed();
while(bioskey(1) == 0);
key = bioskey(0);
if(key != Esc)
ChessActionRed(key);
void ChessActionRed(int key)
setcolor(GREEN);
outtextxy(220,40,"Red,please put your chess!");
DrawChessR_W(ChessRedLocalX,ChessRedLocalY,RED);
ChessNowLocal(ChessRedLocalX,ChessRedLocalY);
ChessLocalBoxX = (ChessRedLocalX - 170) / 20;
ChessLocalBoxY = (ChessRedLocalY - 100) / 20;
switch(key)
case Player1_up
: ChessRedLocalY = ChessRedLocalY - 20;break;
case Player1_down : ChessRedLocalY = ChessRedLocalY + 20;break;
case Player1_left : ChessRedLocalX = ChessRedLocalX - 20;break;
case Player1_right: ChessRedLocalX = ChessRedLocalX + 20;break;
case Player1_do
if (Chess[ChessLocalBoxX][ChessLocalBoxY] != 0)
setcolor(GREEN);
outtextxy(180,60,"Red,you can not put your chess here! ");
Chess[ChessLocalBoxX][ChessLocalBoxY] = 1;
JudgeHeng(ChessLocalBoxX,ChessLocalBoxY,1);
cleardevice();
DrawChessBox();
PrintfChess();
DrawStandForWhite();
setcolor(GREEN);
outtextxy(220,40,"White,please put your chess! ");
if (PlayMode == 1)
DrawChessR_W(ChessWhiteLocalX,ChessWhiteLocalY,WHITE);
ChessNowLocal(ChessWhiteLocalX,ChessWhiteLocalY);
setcolor(BLACK);
line(ChessRedLocalX-5,ChessRedLocalY,ChessRedLocalX+5,ChessRedLocalY);
line(ChessRedLocalX,ChessRedLocalY-5,ChessRedLocalX,ChessRedLocalY+5);
while(bioskey(1) == 0);
key = bioskey(0);
if (key != Esc)
ChessActionWhite(key);
PCChessActionWhite();
default : break;
if (ChessRedLocalX &= 170 && ChessRedLocalX &= 450 && ChessRedLocalY &= 100 && ChessRedLocalY &= 380 && key != Player1_do)
cleardevice();
DrawChessBox();
PrintfChess();
DrawChessR_W(ChessRedLocalX,ChessRedLocalY,RED);
ChessNowLocal(ChessRedLocalX,ChessRedLocalY);
DrawStandForRed();
setcolor(BLACK);
line(ChessWhiteLocalX-5,ChessWhiteLocalY,ChessWhiteLocalX+5,ChessWhiteLocalY);
line(ChessWhiteLocalX,ChessWhiteLocalY-5,ChessWhiteLocalX,ChessWhiteLocalY+5);
setcolor(GREEN);
outtextxy(220,40,"Red,please put your chess! ");
outtextxy(400,400,"press Esc to exit!");
switch (key)
case Player1_up
: ChessRedLocalY = ChessRedLocalY + 20;break;
case Player1_down : ChessRedLocalY = ChessRedLocalY - 20;break;
case Player1_left : ChessRedLocalX = ChessRedLocalX + 20;break;
case Player1_right: ChessRedLocalX = ChessRedLocalX - 20;break;
while(bioskey(1) == 0);
key = bioskey(0);
if (key == Esc)
}while(1);
void PCChessActionWhite()
int PCChessScore[15][15] = {0};
int PlayerChessScore[15][15] = {0};
for(i = 0;i & 15;i++)
for (j = 0;j & 15;j++)
if (Chess[i][j] == 0)
PlayerChessScore[i][j] = ComputeHeng (i,j,1) + ComputeShu(i,j,1) + ComputeZuoXie(i,j,1) + ComputeYouXie(i,j,1);
PCChessScore[i][j] = ComputeHeng (i,j,2) + ComputeShu(i,j,2) + ComputeZuoXie(i,j,2) + ComputeYouXie(i,j,2);
max = PlayerChessScore[0][0];
remberx = 0;
rembery = 0;
for (i = 0; i & 15;i++)
for (j = 0;j & 15;j++)
if (max & PlayerChessScore[i][j])
max = PlayerChessScore[i][j];
if (max & PCChessScore[i][j])
max = PCChessScore[i][j];
Chess[remberx][rembery] = 2;
cleardevice();
DrawChessBox();
PrintfChess();
JudgeHeng(remberx,rembery,2);
ChessWhiteLocalX = remberx * 20 + 170;
ChessWhiteLocalY = rembery * 20 + 100;
setcolor(BLACK);
line(ChessWhiteLocalX-5,ChessWhiteLocalY,ChessWhiteLocalX+5,ChessWhiteLocalY);
line(ChessWhiteLocalX,ChessWhiteLocalY-5,ChessWhiteLocalX,ChessWhiteLocalY+5);
DrawChessR_W(ChessRedLocalX,ChessRedLocalY,RED);
ChessNowLocal(ChessRedLocalX,ChessRedLocalY);
DrawStandForRed();
while(bioskey(1) == 0);
key = bioskey(0);
if (key != Esc)
ChessActionRed(key);
int ScoreReturn(int CountLeft,int CountRight,int LeftLive,int RightLive,int R_or_W)
int Score = CountLeft + CountR
if(R_or_W == 1)
switch(Score)
if (LeftLive == 1 && RightLive == 1)
return 50;
if(LeftLive == 0 && RightLive == 0)
return 10;
return 35;
if (LeftLive == 1 && RightLive == 1)
return 700;
if (LeftLive == 0 && RightLive == 0)
return 100;
return 650;
if (LeftLive == 1 && RightLive == 1)
return 3500;
if (LeftLive == 0 && RightLive == 0)
return 800;
return 3000;
if (LeftLive == 1 && RightLive == 1)
return 15000;
if (LeftLive == 0 && RightLive == 0)
return 15000;
return 15000;
switch(Score)
if (LeftLive == 1 && RightLive == 1)
return 60;
if (LeftLive == 0 && RightLive == 0)
return 10;
return 40;
if (LeftLive == 1 && RightLive == 1)
return 950;
if (LeftLive == 0 && RightLive == 0)
return 100;
return 900;
if (LeftLive == 1 && RightLive == 1)
return 6000;
if (LeftLive == 0 && RightLive == 0)
return 3600;
return 5000;
if (LeftLive == 1 && RightLive == 1)
return 20000;
if (LeftLive == 0 && RightLive == 0)
return 20000;
return 20000;
int RightL
int CountL
int CountR
int ComputeHeng(int x,int y,int R_or_W)
LeftLive = 1;
RightLive = 1;
CountLeft = 0;
CountRight = 0;
while(Chess[xx][yy] == R_or_W && xx &= 0)
CountLeft++;
xx = xx-1;
if (Chess[xx][yy] == 0)
LeftLive = 1;
LeftLive = 0;
while(Chess[xx][yy] == R_or_W && xx &=14)
CountRight++;
xx = xx+1;
if (Chess[xx][yy] == 0)
RightLive = 1;
RightLive = 0;
return ScoreReturn(CountLeft,CountRight,LeftLive,RightLive,R_or_W);
int ComputeShu(int x,int y,int R_or_W)
LeftLive = 1;
RightLive = 1;
CountLeft = 0;
CountRight = 0;
yy = y - 1;
while(Chess[xx][yy] == R_or_W && yy &= 0)
CountLeft++;
if (Chess[xx][yy] == 0)
LeftLive = 1;
LeftLive = 0;
yy = y + 1;
while(Chess[xx][yy] == R_or_W && yy &= 14)
CountRight++;
if (Chess[xx][yy] == 0)
RightLive = 1;
RightLive = 0;
return ScoreReturn(CountLeft,CountRight,LeftLive,RightLive,R_or_W);
int ComputeZuoXie(int x,int y,int R_or_W)
LeftLive = 1;
RightLive = 1;
CountLeft = 0;
CountRight = 0;
while(Chess[xx][yy] == R_or_W && xx &= 0 && yy &= 0)
CountLeft++;
xx = xx-1;
yy = yy-1;
if (Chess[xx][yy] == 0)
LeftLive = 1;
LeftLive = 0;
yy = y+ 1;
while(Chess[xx][yy] == R_or_W && xx &= 14 && yy &= 14)
CountRight++;
xx = xx+1;
yy = yy+ 1;
if (Chess[xx][yy] == 0)
RightLive = 1;
RightLive = 0;
return ScoreReturn(CountLeft,CountRight,LeftLive,RightLive,R_or_W);
int ComputeYouXie(int x,int y,int R_or_W)
LeftLive = 1;
RightLive = 1;
CountLeft = 0;
CountRight = 0;
while(Chess[xx][yy] == R_or_W && xx &= 14 && yy &= 0)
CountLeft++;
xx = xx+1;
yy = yy-1;
if (Chess[xx][yy] == 0)
LeftLive = 1;
LeftLive = 0;
yy = y+ 1;
while(Chess[xx][yy] == R_or_W && xx &= 0 && yy &= 14)
CountRight++;
xx = xx-1;
yy = yy+ 1;
if (Chess[xx][yy] == 0)
RightLive = 1;
RightLive = 0;
return ScoreReturn(CountLeft,CountRight,LeftLive,RightLive,R_or_W);
void ChessActionWhite(int key)
setcolor(BLACK);
line(ChessRedLocalX-5,ChessRedLocalY,ChessRedLocalX+5,ChessRedLocalY);
line(ChessRedLocalX,ChessRedLocalY-5,ChessRedLocalX,ChessRedLocalY+5);
setcolor(GREEN);
outtextxy(220,40,"White,please put your chess! ");
DrawChessR_W(ChessWhiteLocalX,ChessWhiteLocalY,WHITE);
ChessNowLocal(ChessWhiteLocalX,ChessWhiteLocalY);
ChessLocalBoxX = (ChessWhiteLocalX - 170) / 20;
ChessLocalBoxY = (ChessWhiteLocalY - 100) / 20;
switch(key)
case Player2_up
: ChessWhiteLocalY = ChessWhiteLocalY - 20;break;
case Player2_down
: ChessWhiteLocalY = ChessWhiteLocalY + 20;break;
case Player2_left
: ChessWhiteLocalX = ChessWhiteLocalX - 20;break;
case Player2_right
: ChessWhiteLocalX = ChessWhiteLocalX + 20;break;
case Player2_do
if (Chess[ChessLocalBoxX][ChessLocalBoxY] != 0)
setcolor(GREEN);
outtextxy(180,60,"White,you can not put your chess here! ");
Chess[ChessLocalBoxX][ChessLocalBoxY] = 2;
JudgeHeng(ChessLocalBoxX,ChessLocalBoxY,2);
cleardevice();
DrawChessBox();
PrintfChess();
DrawStandForRed();
setcolor(GREEN);
outtextxy(220,40,"Red,please put your chess!");
DrawChessR_W(ChessRedLocalX,ChessRedLocalY,RED);
ChessNowLocal(ChessRedLocalX,ChessRedLocalY);
setcolor(BLACK);
line(ChessWhiteLocalX-5,ChessWhiteLocalY,ChessWhiteLocalX+5,ChessWhiteLocalY);
line(ChessWhiteLocalX,ChessWhiteLocalY-5,ChessWhiteLocalX,ChessWhiteLocalY+5);
while(bioskey(1) == 0);
key = bioskey(0);
if (key != Esc)
ChessActionRed(key);
default : break;
if (ChessWhiteLocalX &= 170 && ChessWhiteLocalX &= 450 && ChessWhiteLocalY &= 100 && ChessWhiteLocalY &= 380 && key != Player2_do)
cleardevice();
DrawChessBox();
PrintfChess();
DrawChessR_W(ChessWhiteLocalX,ChessWhiteLocalY,WHITE);
ChessNowLocal(ChessWhiteLocalX,ChessWhiteLocalY);
DrawStandForWhite();
setcolor(BLACK);
line(ChessRedLocalX-5,ChessRedLocalY,ChessRedLocalX+5,ChessRedLocalY);
line(ChessRedLocalX,ChessRedLocalY-5,ChessRedLocalX,ChessRedLocalY+5);
setcolor(GREEN);
outtextxy(220,40,"White,please put your chess! ");
outtextxy(400,400,"press Esc to exit!");
switch(key)
case Player2_up
: ChessWhiteLocalY = ChessWhiteLocalY + 20;break;
case Player2_down
: ChessWhiteLocalY = ChessWhiteLocalY - 20;break;
case Player2_left
: ChessWhiteLocalX = ChessWhiteLocalX + 20;break;
case Player2_right
: ChessWhiteLocalX = ChessWhiteLocalX - 20;break;
while(bioskey(1) == 0);
key = bioskey(0);
if (key == Esc)
}while(1);
void PrintfChess(void)
for (i = 0;i & 15;i++)
for (j = 0;j & 15;j++)
if (Chess[i][j] == 1)
DrawChessR_W(170 + 20 * i,100 + 20 * j,RED);
if (Chess[i][j] == 2)
DrawChessR_W(170 + 20 * i,100 + 20 * j,WHITE);
void JudgeHeng(int x,int y,int R_or_W)
CountNumber = 1;
JudgeX = x - 1;
while (Chess[JudgeX][JudgeY] == R_or_W && JudgeX &= 0)
LineX1 = JudgeX;
LineY1 = JudgeY;
CountNumber++;
JudgeX = x + 1;
while (Chess[JudgeX][JudgeY] == R_or_W && JudgeX &= 14)
LineX2 = JudgeX;
LineY2 = JudgeY;
CountNumber++;
if (CountNumber &= 5 && R_or_W == 1)
setcolor(WHITE);
line (LineX1 * 20 + 170,LineY1 * 20 + 100,LineX2 * 20 + 170,LineY2 * 20 + 100);
if (CountNumber &= 5 && R_or_W == 2)
setcolor(RED);
line (LineX1 * 20 + 170,LineY1 * 20 + 100,LineX2 * 20 + 170,LineY2 * 20 + 100);
WhiteWin();
JudgeShu(x,y,R_or_W);
void JudgeShu(int x,int y,int R_or_W)
CountNumber = 1;
JudgeY = y - 1;
while (Chess[JudgeX][JudgeY] == R_or_W && JudgeY &= 0)
LineX1 = JudgeX;
LineY1 = JudgeY;
CountNumber++;
JudgeY = y + 1;
while (Chess[JudgeX][JudgeY] == R_or_W && JudgeY &= 14)
LineX2 = JudgeX;
LineY2 = JudgeY;
CountNumber++;
if (CountNumber &= 5 && R_or_W == 1)
setcolor(WHITE);
line (LineX1 * 20 + 170,LineY1 * 20 + 100,LineX2 * 20 + 170,LineY2 * 20 + 100);
if (CountNumber &= 5 && R_or_W == 2)
setcolor(RED);
line (LineX1 * 20 + 170,LineY1 * 20 + 100,LineX2 * 20 + 170,LineY2 * 20 + 100);
WhiteWin();
JudgeZuoXie(x,y,R_or_W);
void JudgeZuoXie(int x,int y,int R_or_W)
CountNumber = 1;
JudgeX = x - 1;
JudgeY = y - 1;
while (Chess[JudgeX][JudgeY] == R_or_W && JudgeY &= 0 && JudgeX &= 0)
LineX1 = JudgeX;
LineY1 = JudgeY;
CountNumber++;
JudgeX = x + 1;
JudgeY = y + 1;
while (Chess[JudgeX][JudgeY] == R_or_W && JudgeY &= 14 && JudgeX &= 14)
LineX2 = JudgeX;
LineY2 = JudgeY;
CountNumber++;
if (CountNumber &= 5 && R_or_W == 1)
setcolor(WHITE);
line (LineX1 * 20 + 170,LineY1 * 20 + 100,LineX2 * 20 + 170,LineY2 * 20 + 100);
if (CountNumber &= 5 && R_or_W == 2)
setcolor(RED);
line (LineX1 * 20 + 170,LineY1 * 20 + 100,LineX2 * 20 + 170,LineY2 * 20 + 100);
WhiteWin();
JudgeYouXie(x,y,R_or_W);
void JudgeYouXie(int x,int y,int R_or_W)
CountNumber = 1;
JudgeX = x + 1;
JudgeY = y - 1;
while (Chess[JudgeX][JudgeY] == R_or_W && JudgeY &= 0 && JudgeX &= 0)
LineX1 = JudgeX;
LineY1 = JudgeY;
CountNumber++;
JudgeX = x - 1;
JudgeY = y + 1;
while (Chess[JudgeX][JudgeY] == R_or_W && JudgeY &= 14 && JudgeX &= 14)
LineX2 = JudgeX;
LineY2 = JudgeY;
CountNumber++;
if (CountNumber &= 5 && R_or_W == 1)
setcolor(WHITE);
line (LineX1 * 20 + 170,LineY1 * 20 + 100,LineX2 * 20 + 170,LineY2 * 20 + 100);
if (CountNumber &= 5 && R_or_W == 2)
setcolor(RED);
line (LineX1 * 20 + 170,LineY1 * 20 + 100,LineX2 * 20 + 170,LineY2 * 20 + 100);
WhiteWin();
void RedWin(void)
setcolor(RED);
outtextxy(470,160,"******************");
outtextxy(470,170,"*
outtextxy(470,180,"*
outtextxy(470,190,"
Player:RED
outtextxy(470,200,"
outtextxy(470,210,"*
outtextxy(470,220,"*
outtextxy(470,230,"******************");
void WhiteWin(void)
setcolor(WHITE);
outtextxy(10,160,"******************");
outtextxy(10,170,"*
outtextxy(10,180,"*
outtextxy(10,190,"
Player:White
outtextxy(10,200,"
outtextxy(10,210,"*
outtextxy(10,220,"*
outtextxy(10,230,"******************");
void ChessNowLocal(int x,int y)
setcolor(BLACK);
outtextxy (x-20,y-3,"&");
outtextxy (x+15,y-3,"&");
outtextxy (x-3,y-20,"v");
outtextxy (x-3,y+15,"^");
void Welcome(void)
setbkcolor(YELLOW);
setcolor(1);
outtextxy(230,30,"welcome to Wuziqi Game!");
setcolor(2);
outtextxy(250,100,"Mode Choose:");
setcolor(3);
rectangle(XiaoQiPanX1,XiaoQiPanY1,XiaoQiPanX2,XiaoQiPanY2);
for (i = 1;i & 15;i++)
line(XiaoQiPanX1 + i * 10,XiaoQiPanY1,XiaoQiPanX1 + i * 10,XiaoQiPanY2);
line(XiaoQiPanX1,XiaoQiPanY1 + i * 10,XiaoQiPanX2,XiaoQiPanY1 + i * 10);
DrawStandForRed();
DrawStandForWhite();
setcolor(GREEN);
rectangle(50,245,150,375);
outtextxy(60,235,"Player:Red ");
outtextxy(55,255,"UP----up");
outtextxy(55,265,"DOWN--down");
outtextxy(55,275,"LEFT--left");
outtextxy(55,285,"RIGHT-right");
outtextxy(55,295,"DO----enter");
rectangle(460,245,550,375);
outtextxy(470,235,"Plyaer:White");
outtextxy(465,255,"UP----w");
outtextxy(465,265,"DOWN--s");
outtextxy(465,275,"LEFT--a");
outtextxy(465,285,"RIGHT-d");
outtextxy(465,295,"DO----space");
void ModeChoose(void)
PlayMode = 1;
while(bioskey(1) == 0);
key = bioskey(0);
if (key == Player1_up)
cleardevice();
Welcome();
outtextxy(230,120,"player1 vs player2");
outtextxy(230,160,"player vs computer");
DrawChessR_W(200,120,BLUE);
PlayMode = 1;
if (key == Player1_down)
cleardevice();
Welcome();
outtextxy(230,120,"player1 vs player2");
outtextxy(230,160,"player vs computer");
DrawChessR_W(200,160,BLUE);
PlayMode = 2;
}while (key != Player1_do);
void DrawChessBox(void)
cleardevice();
setbkcolor(BLUE);
setcolor(DARKGRAY);
rectangle(DaQiPanX1 - 20,DaQiPanY1 - 20,DaQiPanX2 + 20,DaQiPanY2 + 20);
setfillstyle(1,CYAN);
floodfill(DaQiPanX1 - 10,DaQiPanY1 - 10,DARKGRAY);
setcolor(CYAN);
rectangle(DaQiPanX1,DaQiPanY1,DaQiPanX2,DaQiPanY2);
setfillstyle(1,CYAN);
floodfill(DaQiPanX1 + 10,DaQiPanY1 + 10,DARKGRAY);
setcolor(BLACK);
rectangle(DaQiPanX1,DaQiPanY1,DaQiPanX2,DaQiPanY2);
for (i = 1;i & 15;i++)
line(DaQiPanX1 + i * 20,DaQiPanY1,DaQiPanX1 + i * 20,DaQiPanY2);
line(DaQiPanX1,DaQiPanY1 + i * 20,DaQiPanX2,DaQiPanY1 + i * 20);
circle(230,160,3);
circle(390,160,3);
circle(230,320,3);
circle(390,320,3);
circle(310,240,3);
outtextxy(DaQiPanX1 + 0
,DaQiPanY1 - 10,"A");
outtextxy(DaQiPanX1 + 20 ,DaQiPanY1 - 10,"B");
outtextxy(DaQiPanX1 + 40 ,DaQiPanY1 - 10,"C");
outtextxy(DaQiPanX1 + 60 ,DaQiPanY1 - 10,"D");
outtextxy(DaQiPanX1 + 80 ,DaQiPanY1 - 10,"E");
outtextxy(DaQiPanX1 + 100,DaQiPanY1 - 10,"F");
outtextxy(DaQiPanX1 + 120,DaQiPanY1 - 10,"G");
outtextxy(DaQiPanX1 + 140,DaQiPanY1 - 10,"H");
outtextxy(DaQiPanX1 + 160,DaQiPanY1 - 10,"I");
outtextxy(DaQiPanX1 + 180,DaQiPanY1 - 10,"J");
outtextxy(DaQiPanX1 + 200,DaQiPanY1 - 10,"K");
outtextxy(DaQiPanX1 + 220,DaQiPanY1 - 10,"L");
outtextxy(DaQiPanX1 + 240,DaQiPanY1 - 10,"M");
outtextxy(DaQiPanX1 + 260,DaQiPanY1 - 10,"N");
outtextxy(DaQiPanX1 + 280,DaQiPanY1 - 10,"O");
outtextxy(DaQiPanX1 - 15 ,DaQiPanY1 - 0 ,"1");
outtextxy(DaQiPanX1 - 15 ,DaQiPanY1 + 20,"2");
outtextxy(DaQiPanX1 - 15 ,DaQiPanY1 + 40,"3");
outtextxy(DaQiPanX1 - 15 ,DaQiPanY1 + 60,"4");
outtextxy(DaQiPanX1 - 15 ,DaQiPanY1 + 80,"5");
outtextxy(DaQiPanX1 - 15 ,DaQiPanY1 + 100,"6");
outtextxy(DaQiPanX1 - 15 ,DaQiPanY1 + 120,"7");
outtextxy(DaQiPanX1 - 15 ,DaQiPanY1 + 140,"8");
outtextxy(DaQiPanX1 - 15 ,DaQiPanY1 + 160,"9");
outtextxy(DaQiPanX1 - 15 ,DaQiPanY1 + 180,"10");
outtextxy(DaQiPanX1 - 15 ,DaQiPanY1 + 200,"11");
outtextxy(DaQiPanX1 - 15 ,DaQiPanY1 + 220,"12");
outtextxy(DaQiPanX1 - 15 ,DaQiPanY1 + 240,"13");
outtextxy(DaQiPanX1 - 15 ,DaQiPanY1 + 260,"14");
outtextxy(DaQiPanX1 - 15 ,DaQiPanY1 + 280,"15");
setcolor(GREEN);
rectangle(80,20,540,70);
outtextxy(260,10,"MessageBox");
void ChooseFirst_Or_Second(void)
RedXianhou = 1;
setcolor(GREEN);
if (PlayMode == 1)
outtextxy(230,30,"player1 use Red
outtextxy(230,40,"player2 use White chess!");
outtextxy(230,30,"player
outtextxy(230,40,"computer use White chess!");
outtextxy(100,50,"Red first? (letf/right) to change,(enter)to make sure");
DrawStandForRed();
while(bioskey(1) == 0);
key = bioskey(0);
if (key == Player1_left)
cleardevice();
DrawChessBox();
outtextxy(100,50,"Red first? (letf/right) to change,(enter)to make sure");
DrawStandForRed();
RedXianhou = 1;
if (key == Player1_right)
cleardevice();
DrawChessBox();
outtextxy(100,50,"White first? (letf/right) to change,(enter)to make sure");
DrawStandForWhite();
RedXianhou = 2;
setcolor(GREEN);
if (PlayMode == 1)
outtextxy(230,30,"player1 use Red
outtextxy(230,40,"player2 use White chess!");
outtextxy(230,30,"player
outtextxy(230,40,"computer use White chess!");
}while(Player1_do != key);
cleardevice();
void DrawChessR_W(int x,int y,int color)
setcolor(color);
circle(x,y,10);
setfillstyle(1,color);
floodfill(x+5,y+5,color);
void DrawStandForRed()
setcolor(7);
circle(XiaoYuanX1,XiaoYuanY1,YuanR);
setfillstyle(1,RED);
floodfill(XiaoYuanX1+10,XiaoYuanY1+10,7);
void DrawStandForWhite()
setcolor(15);
circle(XiaoYuanX2,XiaoYuanY2,YuanR);
setfillstyle(1,WHITE);
floodfill(XiaoYuanX2+10,XiaoYuanY2+10,15);
void Exit()
cleardevice();
setbkcolor(BLACK);
setcolor(GREEN);
outtextxy(280,350,"goodbye!");
closegraph();
没有更多推荐了,

我要回帖

更多关于 c语言自定义函数题目 的文章

 

随机推荐