日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

C語言用Easyx繪制圍棋和象棋的棋盤_C 語言

作者:輝小歌 ? 更新時間: 2022-07-07 編程語言

本文實例為大家分享了C語言繪制圍棋和象棋棋盤的具體代碼,供大家參考,具體內容如下

一、繪制圍棋棋盤

代碼如下:

#include<graphics.h>
#include<conio.h>
int main()
{
?? ?int step=30;
?? ?//初始化繪圖窗口
?? ?initgraph(600,600);
?? ?//設置背景色為黃色
?? ?setbkcolor(YELLOW);
?? ?//用背景色清空屏幕
?? ?cleardevice();

?? ?setlinestyle(PS_SOLID,2);//畫實線,寬度為兩個像素
?? ?setcolor(RGB(0,0,0));//設置為黑色

?? ?int i;
?? ?for(i=1;i<=19;i++)//畫橫線和豎線
?? ?{
?? ??? ?line(i*step,1*step,i*step,19*step);
?? ??? ?line(1*step,i*step,19*step,i*step);
?? ?}
?? ?getch();
?? ?closegraph();
?? ?return 0;
}

效果圖如下:

二、繪制象棋棋盤

代碼如下:

#include<graphics.h>
#include<conio.h>
int main(void)
{
?? ?int step=50;
?? ?//初始化繪圖窗口
?? ?initgraph(500,500);
?? ?//設置背景色為黃色
?? ?setbkcolor(YELLOW);
?? ?//用背景色清空屏幕
?? ?cleardevice();

?? ?int i,j;
?? ?for(i=1;i<=8;i++)
?? ?{
?? ??? ?for(j=1;j<=8;j++)
?? ??? ?{
?? ??? ??? ?if((i+j)%2==1)
?? ??? ??? ?{
?? ??? ??? ??? ?setfillcolor(BLACK);
?? ??? ??? ??? ?solidrectangle(i*step,j*step,(i+1)*step,(j+1)*step);
?? ??? ??? ??? ?//繪制黑色磚塊
?? ??? ??? ?}
?? ??? ??? ?else
?? ??? ??? ?{
?? ??? ??? ??? ?setfillcolor(WHITE);
?? ??? ??? ??? ?solidrectangle(i*step,j*step,(i+1)*step,(j+1)*step);
?? ??? ??? ??? ?//繪制白色磚塊
?? ??? ??? ?}
?? ??? ?}
?? ?}
?? ?getch();
?? ?closegraph();
?? ?return 0;
}

效果圖如下:

原文鏈接:https://huixiaoge.blog.csdn.net/article/details/107767499

欄目分類
最近更新