C語言用Easyx繪制圍棋和象棋的棋盤
更新時(shí)間:2022年05月12日 15:42:45 作者:輝小歌
這篇文章主要為大家詳細(xì)介紹了C語言用Easyx繪制圍棋和象棋的棋盤,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了C語言繪制圍棋和象棋棋盤的具體代碼,供大家參考,具體內(nèi)容如下
一、繪制圍棋棋盤
代碼如下:
#include<graphics.h> #include<conio.h> int main() { ?? ?int step=30; ?? ?//初始化繪圖窗口 ?? ?initgraph(600,600); ?? ?//設(shè)置背景色為黃色 ?? ?setbkcolor(YELLOW); ?? ?//用背景色清空屏幕 ?? ?cleardevice(); ?? ?setlinestyle(PS_SOLID,2);//畫實(shí)線,寬度為兩個(gè)像素 ?? ?setcolor(RGB(0,0,0));//設(shè)置為黑色 ?? ?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); ?? ?//設(shè)置背景色為黃色 ?? ?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; }
效果圖如下:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
VC++獲得當(dāng)前進(jìn)程運(yùn)行目錄的方法
這篇文章主要介紹了VC++獲得當(dāng)前進(jìn)程運(yùn)行目錄的方法,可通過系統(tǒng)函數(shù)實(shí)現(xiàn)該功能,是非常實(shí)用的技巧,需要的朋友可以參考下2014-10-10C++實(shí)現(xiàn)保存數(shù)據(jù)至EXCEL
這篇文章主要介紹了C++實(shí)現(xiàn)保存數(shù)據(jù)至EXCEL,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-11-11