教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 资格考试 >

数据结构课程设计(C++)_八皇后动态演示原代码

来源:网络收集 时间:2026-09-27
导读: 论文!课程设计! //运行环境TC3.0 #includemath.h //调用数学函数库 #includestdio.h //调用标准输入输出函数库 #includeconio.h #includegraphics.h //调用图形函数库 #includestdlib.h #define MAX 8 //定义棋盘格数(特别是横轴方向上) int board[MAX]; /

论文!课程设计!

//运行环境TC3.0

#include<math.h> //调用数学函数库

#include<stdio.h> //调用标准输入输出函数库 #include<conio.h>

#include<graphics.h> //调用图形函数库

#include<stdlib.h>

#define MAX 8 //定义棋盘格数(特别是横轴方向上) int board[MAX]; //纵轴方向格数

void Drow() //画棋盘

{

int i;

int Driver=VGA,Mode=VGAHI; //初始化显示器

initgraph(&Driver,&Mode,"d:\\tc\\bgi");

setfillstyle(SOLID_FILL,BLUE); //棋盘底色模式

bar(5,15,600,500); //棋盘外框(二维)

setcolor(YELLOW); //棋盘边框颜色

for(i=0;i<=9;i++)

{

line(10,20+50*i,460,20+50*i); //画行

}

for(i=0;i<=9;i++)

{

line(10+50*i,20,10+50*i,470); //画列

}

line(460,20,560,20);

line(10,470,560,470);

line(560,470,560,20);

setcolor(RED);

outtextxy(465,30,"WuShangjie"); //版权注释

outtextxy(465,45,"Eight Queue");

outtextxy(465,60,"CopyRight2.0");

outtextxy(415,440,"Start"); //屏幕输出文本 坐标标记 outtextxy(385,440,"0");

outtextxy(335,440,"1");

outtextxy(285,440,"2");

outtextxy(235,440,"3");

outtextxy(185,440,"4");

outtextxy(135,440,"5");

outtextxy(85,440,"6");

outtextxy(35,440,"7");

outtextxy(415,455,"Point");

论文!课程设计!

outtextxy(435,390,"0");

outtextxy(435,340,"1");

outtextxy(435,290,"2");

outtextxy(435,240,"3");

outtextxy(435,190,"4");

outtextxy(435,140,"5");

outtextxy(435,90,"6");

outtextxy(435,40,"7");

}

void DrowCircle(int i,int j) //

{

char text[80];

setfillstyle(SOLID_FILL,YELLOW);

setcolor(YELLOW);

circle(385-50*i,395-50*j,15);

floodfill(385-50*i,395-50*j,YELLOW); //

setcolor(RED);

sprintf(text,"%d,%d",i,j); //

outtextxy(385-50*i-14,395-50*j,text);

}

void GiveDrowIn(int i,int j) //

{

setfillstyle(SOLID_FILL,BLUE); //

同

setcolor(BLUE); //

同

circle(385-50*i,395-50*j,15);

floodfill(385-50*i,395-50*j,BLUE); //

outtextxy(385-50*i-14,395-50*j," ");

}

void show_result() //

{

int j=0;

while(j<MAX)

{

DrowCircle(j,board[j]);

getch();

j++;

}

getch();

for(j=0;j<MAX;j++)

{

GiveDrowIn(j,board[j]); //话棋子 圆内颜色填充 棋子上坐标标记 过去显示棋子清除 将填充颜色设置与底色相将画笔颜色设置与底色相一定区域内填充 调度相关算法求出所有结果 释放上回显示棋子区域

论文!课程设计!

}

getch();

}

int check_cross(int n) //判断棋子是否冲突函数

{

int k;

for(k=0;k<n;k++){

if(board[k]==board[n]||(n-k)==abs(board[k]-board[n])) //是否同行,是否同对角线

return 1;

}

return 0;

}

void put_chess(int n) //

显示函数

{

for(int l=0;l<MAX;l++){

board[n]=l;

if(!check_cross(n)){

if(n==MAX-1) {

getch();

show_result();

}

else put_chess(n+1);

}

}

}

void main() //

{

Drow();

put_chess(0);

//to the end of the program

getch();

exit(1);

}

八皇后摆列方式逐个主函数

论文!课程设计!

免责声明:文档在线网(文档中国)中所有的文档资料均由文档在线网会员提供。文档在线网会对会员提供的文档资料进行筛选和编辑,但是并不声明或保证其内容的合法性、正确性或可靠性。该文档资料的版权属于提供者所有,有关版权的问题请直接与提供者联系。

…… 此处隐藏:475字,全部文档内容请下载后查看。喜欢就下载吧 ……
数据结构课程设计(C++)_八皇后动态演示原代码.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/92300.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150份
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150份
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)