亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 編程 > C++ > 正文

基于c++ ege圖形庫實現五子棋游戲

2020-05-23 13:23:07
字體:
來源:轉載
供稿:網友

本文分享的五子棋實例,制作基于ege圖像庫, 首先需要安裝配置ege環境 就可以編寫小游戲了. 用到的ege庫函數不多 , 主要是基于c++的.

先看界面效果:

c++,ege,圖形庫,五子棋游戲

輸入界面:(就是控制臺)

c++,ege,圖形庫,五子棋游戲

游戲勝利界面:

c++,ege,圖形庫,五子棋游戲

c++,ege,圖形庫,五子棋游戲

文檔如下:

關于五子棋的構思:

實現人人對戰的五子棋游戲.使用面向對象的c++ 和 ege庫實現.
ege的安裝過程不在說明 , 在添加編譯鏈接時去掉 -mwindows 選項.
dev c++ 的運行環境設置為 TDM-GCC 4.8.1.32-bit Debug
為保險起見,編譯時選擇菜單欄里的  運行-全部重新編譯(F12) 

需要3個對象 : 

1:棋盤對象
2:黑方棋手對象
3:白方棋手對象       

需要說明,對五子棋的實現來說,棋子的數據結構和游戲使用界面相互分離.對棋子的操作基于二維數組,棋盤和棋子的顯示用單獨的方法實現.       

棋盤對象名: chessboard  

屬性:

1:所有棋子-allchessman  二維數組,用來存放整個棋盤上棋子的分布和選手信息   
數組元素值為0 表示該位置無子   值為1表示該位置為白方落子  值為-1表示該位置為黑方落子
二維數組元素以結構體來表示 , 存X, Y坐標和身份標識.要注意的是 ,標識值為2標識是棋盤邊界.不能落子           

方法:

 1:添加棋子 - bool  addchessman(int , int , int message)   //message指示落子黑白方身份識別
 2:畫棋盤 - void  drawchessboard() 
 3:判勝  - int bunko(int , int , int message) 
 4:void  playchess()  運行代碼的總程序          

黑方對象:

屬性: 
 1: 棋子橫向位置  int chessman_X  
 2: 棋子縱向位置  int chessman_Y
 3: 落子總個數    black_chessman_count
 4: 身份標識      int black_chessplayer 
方法:
 1: 提交棋子  submit_chessman(int , int)                   

白方對象:

屬性:
1:棋子橫向位置  int chessman_X
2:棋子縱向位置  int chessman_Y
3:落子總個數    white_chessman_count 
4:身份標識      int white_chessplayer 
方法:
1: 提交棋子     submit_chessman(int ,int )

三個頭文件對應三個對象:

黑棋選手:

#include<iostream>using namespace std; class black { int chessman_X; //橫向位置 int chessman_Y; //縱向位置  int black_chessman_count ; //落子總數 int black_chessmanplayer ;  public:   black() { black_chessman_count=0; black_chessmanplayer=-1; }   bool submit_chessman(int chessman_X , int chessman_Y ) { if(chessman_X>15 || chessman_X<1 || chessman_Y>15 ||chessman_Y<1) { return false; } else { this->chessman_X = chessman_X; this->chessman_Y = chessman_Y; black_chessman_count++; return true; } }   int getIdentity() { return black_chessmanplayer;  } int getChessman_X() { return chessman_X-1; //這里設置減一是因為畫圖從0位置開始  }  int getChessman_Y() { return chessman_Y-1; }  int getChessmanCount() { return black_chessman_count ; }};

白棋選手:

#include<iostream>using namespace std; class white{ int chessman_X; //橫向位置 int chessman_Y; //縱向位置  int white_chessman_count; //落子總數 int white_chessmanplayer;  public:  white() { white_chessman_count=0; white_chessmanplayer=1; }  bool submit_chessman(int chessman_X , int chessman_Y ) { if(chessman_X>15 || chessman_X<1 || chessman_Y>15 || chessman_Y<1) { return false; } else  {  this->chessman_X = chessman_X; this->chessman_Y = chessman_Y; white_chessman_count++; return true; } }   int getIdentity() { return white_chessmanplayer;  }  int getChessman_X() { return chessman_X-1; }  int getChessman_Y() { return chessman_Y-1; }  int getChessmanCount() { return white_chessman_count ; }};

棋盤對象:

#include<iostream>#include "graphics.h"#include"black.h"#include"white.h"#include <process.h>#define singleGirdSize 40#define girdLength 15 using namespace std;class chessboard{ //int allchessman[girdLength][girdLength] = {{0 ,0}}; struct allchessman { int point_X; //記錄棋子X軸位置  int point_Y; //記錄棋子Y軸位置 int message; //識別棋子身份 (黑方? 白方 ? 空子? )  }allchessman[girdLength][girdLength];  public : bool win =false; //玩家輸贏的標記  black b; //定義黑方對象  white w; //定義白方對象  //這里b , w 是全局的 ,局部的話會對black_chessman_count這種屬性的變化有影響   public:  //在構造方法中初始化所有棋子 chessboard() { int x=100 , y=100; //棋盤左上端點100 ,100  for(int i=0 ; i<15 ; i++ , y+=singleGirdSize) { for(int u=0; u<15 ; u++ , x+=singleGirdSize) {  allchessman[i][u].point_X = x;  allchessman[i][u].point_Y = y;  if(allchessman[i][u].point_X == 100 || allchessman[i][u].point_X == 660 || allchessman[i][u].point_Y == 100 || allchessman[i][u].point_Y == 660)  {  allchessman[i][u].message =2; //棋盤邊界標識記為2 , 不能落子   }  else  {  allchessman[i][u].message =0; //初始化為空子   } } x=100; //讓X重新回到端點位置  } }     //添加棋子  bool addchessman(int chessman_X , int chessman_Y , int message) { if(message == -1) //黑方落子  { if(allchessman[chessman_X][chessman_Y].message== 0) //預落子位置無子 { allchessman[chessman_X][chessman_Y].message = -1; //落子  setfillcolor(RED); fillellipse(allchessman[chessman_X][chessman_Y].point_X , allchessman[chessman_X][chessman_Y].point_Y , 20 , 20); //界面上顯示落子 .半徑20  if(is_run()) delay_fps(10); return true; //落子成功  }  else return false; //添加棋子失敗 重復落子的處理  } else  {  if (message == 1) { if(allchessman[chessman_X][chessman_Y].message == 0 )  {  allchessman[chessman_X][chessman_Y].message =1;  setfillcolor(WHITE);  fillellipse(allchessman[chessman_X][chessman_Y].point_X , allchessman[chessman_X][chessman_Y].point_Y , 20 , 20); //界面上顯示落子 .半徑20   if(is_run()) delay_fps(10);  return true; //落子成功  } else return false; } else { return false; //應對意外情況 --message身份出錯時  } } } //addchessman     void drawchessboard() { setinitmode(INIT_WITHLOGO, CW_USEDEFAULT, CW_USEDEFAULT); //畫布大小暫定800 ,800 initgraph(800 , 800);  setfont(50 ,0 ,"宋體"); outtextxy(250 , 0 , "簡易五子棋"); setfont(20 , 0 , "宋體"); //畫出棋盤  //預定棋盤左上端點是100 ,100 像素點 int startpoint_X =100 , startpoint_Y =100 ; char str[10]; for(int i=0; i<15 ; i++) { sprintf(str , "%d" , i+1); outtextxy(startpoint_X-20 , startpoint_Y-7, str); line(startpoint_X , startpoint_Y , startpoint_X+( girdLength*singleGirdSize-singleGirdSize) , startpoint_Y); //線段畫出屏幕會出錯:什么也畫不出來  startpoint_Y+=singleGirdSize; }   startpoint_Y = 100; //重置起始點Y  for(int i=0 ; i<15 ; i++) { sprintf(str , "%d" , i+1); outtextxy(startpoint_X-7, startpoint_Y-20 , str); line(startpoint_X , startpoint_Y , startpoint_X , startpoint_Y+(girdLength*singleGirdSize-singleGirdSize) ); startpoint_X+=singleGirdSize; }    /*  for(int i=0 ; i<15 ; i++) { for(int u=0 ; u<15 ; u++) { if(allchessman[i][u].message == 2) {} else {  circle(allchessman[i][u].point_X , allchessman[i][u].point_Y , 20); } } } */   }//drawchessboard      void playchess() { if(is_run()) delay_fps(10); int x ,y ; //接收落子的位置  int identity=1; // 標識黑方 白方身份 identity取余不為0 則是黑方  do { cout<<"       *************先輸入豎列 再輸入橫列*************** "<<endl; black_entry(x ,y); if(is_run()) delay_fps(10); if(!win) {  white_entry(x ,y); } system("cls"); } while(!win); getch(); }  void black_entry(int &x , int &y) { //bool addchessman(int chessman_X , int chessman_Y , int message); cout<<"       請黑方落子(您的棋子顏色是紅色):"<<endl; cout<<"       請輸入橫向位置:"<<endl; cout<<"       "; cin>>x; cout<<"       請輸入縱向位置:"<<endl; cout<<"       "; cin>>y;   if( ! b.submit_chessman(x ,y) ) { cout<<"      輸入位置超出棋盤大小或不合法,請重新輸入"<<endl; black_entry(x ,y); }  if( !addchessman(b.getChessman_X(), b.getChessman_Y() , b.getIdentity()) ) { cout<<"      落子失敗! 該位置已有棋子或棋盤邊界不能落子! 請重新輸入~~~"<<endl;  black_entry( x ,y); } else { if(bunko( b.getChessman_X(), b.getChessman_Y() , b.getIdentity()) )  {  setfont(50 , 0 ,"宋體");  setfontbkcolor(GREEN);  outtextxy(300 ,300 ,"黑方勝!");  setfont(20 ,0 ,"宋體"); outtextxy(300 ,750 ,"按任意鍵退出!");   win = true; } } cout<<"       當前黑方落子總數:"<<b.getChessmanCount()<<endl; cout<<"       當前白方落子總數:"<<w.getChessmanCount()<<endl;  }   void white_entry(int &x , int &y) { // bool addchessman(int chessman_X , int chessman_Y , int message); cout<<endl<<endl<<endl; cout<<"       請白方落子(您的棋子顏色是白色):"<<endl; cout<<"       請輸入橫向位置:"<<endl; cout<<"       "; cin>>x; cout<<"       請輸入縱向位置:"<<endl; cout<<"       "; cin>>y;   if( ! w.submit_chessman(x ,y) ) { cout<<"      輸入位置超出棋盤大小或不合法,請重新輸入"<<endl; black_entry(x ,y); }  if( !addchessman(w.getChessman_X() ,w.getChessman_Y() ,w.getIdentity()) ) { cout<<"      落子失敗! 該位置已有棋子或棋盤邊界不能落子! 請重新輸入~~~"<<endl; white_entry(x ,y); } else { if(bunko( w.getChessman_X(), w.getChessman_Y() , w.getIdentity()) )  {  setfont(50 , 0 ,"宋體");  setfontbkcolor(LIGHTGRAY);  outtextxy(300 ,300 ,"白方勝!");  setfont(20 ,0 ,"宋體"); outtextxy(300 ,720 ,"按任意鍵退出!");   win = true; } }  }  bool bunko(int x, int y , int message) //判勝  {  int xReturnZero =x;  int yReturnZero =y;   int accumulative=0; //用來記錄黑方或白方累計連在一起的 棋子個數     //先以該子位置為基點,向上(X軸不動 ,Y軸反方向) 逐一判斷  while(allchessman[--x][y].message == message)  {   accumulative++;    //cout<<"累計的:"<<accumulative<<endl;  }   /*   if(accumulative == 5)   {   accumulative=0; //重置計數為0    return true;  }  else  {   return false;  }  */   x = xReturnZero;  y = yReturnZero;  //先以該子位置為基點 , 向下( X軸不動 , Y軸正方向) 逐一判斷   while(allchessman[++x][y].message == message)  {   accumulative++;    //cout<<"累計的:"<<accumulative<<endl;  }     if(accumulative == 5)   {   accumulative=0; //重置計數為0    return true;  }  else  {  // return false;  }    x = xReturnZero;  y = yReturnZero;  //先以該子位置為基點 , 向左(Y軸不動 , X軸反方向) 逐一判斷  while(allchessman[x][--y].message == message)  {   accumulative++;    //cout<<"累計的:"<<accumulative<<endl;  }     /*  if(accumulative == 5)   {   accumulative=0; //重置計數為0    return true;  }  else  {   return false;  }  */  x = xReturnZero;  y = yReturnZero;  //先以該子位置為基點, 向右(Y軸不動 , X軸正方向) 逐一判斷  while(allchessman[x][++y].message == message)  {   accumulative++;    //cout<<"累計的:"<<accumulative<<endl;  }     if(accumulative == 5)   {   accumulative=0; //重置計數為0    return true;  }  else  {  // return false;  }    x = xReturnZero;  y = yReturnZero;  //右下方  while(allchessman[++x][++y].message == message)  {   accumulative++;    //cout<<"累計的:"<<accumulative<<endl;  }   /*   if(accumulative == 5)   {   accumulative=0; //重置計數為0    return true;  }  else  {   return false;  } */     x = xReturnZero;  y = yReturnZero;  //左上方  while(allchessman[--x][--y].message == message)  {   accumulative++;    //cout<<"累計的:"<<accumulative<<endl;  }     if(accumulative == 5)   {   accumulative=0; //重置計數為0    return true;  }  else  {   //return false;  }     x = xReturnZero;  y = yReturnZero;  //右上方  while(allchessman[--x][++y].message == message)  {   accumulative++;    //cout<<"累計的:"<<accumulative<<endl;  }   /*   if(accumulative == 5)   {   accumulative=0; //重置計數為0    return true;  }  else  {   return false;  } */   x = xReturnZero;  y = yReturnZero;  //左下方  while(allchessman[++x][--y].message == message)  {   accumulative++;    //cout<<"累計的:"<<accumulative<<endl;  }     if(accumulative == 5)   {   accumulative=0; //重置計數為0    return true;  }  else  {   return false;  }  }     //要在界面上顯示黑方已下棋子個數  //這個方法目前沒有實現 , 實際運行有bug , 棋子數一直為初始值沒有改變 , 所以沒有用這個方法  char* showBlackChessmanCount(black b) {  char str[50];  sprintf(str , "black role chessman count:%d" , b.getChessmanCount());  return str; }  };

主函數運行:

#include<iostream>#include"chessboard.h"using namespace std;int main(){ chessboard chman; chman.drawchessboard(); chman.playchess();}

用時兩天,希望大家喜歡!

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
中文字幕在线看视频国产欧美| 欧美视频13p| 亚洲另类激情图| 精品福利在线观看| 国产亚洲精品久久久久久| 自拍视频国产精品| 成人久久一区二区| 欧美一区深夜视频| 日韩成人中文字幕在线观看| 精品av在线播放| 久久国产精品久久精品| 国产欧美日韩中文| 欧美性猛交xxxxx免费看| 国产精品亚洲片夜色在线| 国产乱人伦真实精品视频| 亚洲综合在线播放| 日韩综合视频在线观看| 亚洲视频欧洲视频| 日韩免费av片在线观看| 国产精品精品久久久久久| 欧美色道久久88综合亚洲精品| 日韩在线小视频| 日韩av三级在线观看| 国产日本欧美一区| 亚洲国产精品久久精品怡红院| 一区二区三区久久精品| 国产精品视频一区二区高潮| 精品成人在线视频| 黄色精品在线看| 久久精品国产清自在天天线| 日韩中文字幕第一页| 亚洲午夜精品久久久久久久久久久久| 久久久久国产一区二区三区| 色偷偷噜噜噜亚洲男人的天堂| 亚洲欧美日韩一区二区在线| 久久国产一区二区三区| 日韩美女在线看| 国产伦精品一区二区三区精品视频| **欧美日韩vr在线| 色综合导航网站| 久久艳片www.17c.com| 亚洲小视频在线| 欧美超级乱淫片喷水| 91精品久久久久久久久中文字幕| 久久久久久中文| 亚洲欧美日韩另类| 91夜夜未满十八勿入爽爽影院| 尤物99国产成人精品视频| 视频在线一区二区| 88国产精品欧美一区二区三区| 亚洲精品自拍视频| 亚洲精品97久久| 久久精品成人欧美大片古装| 久久久久久伊人| 欧美xxxx18性欧美| 国产美女久久精品| 欧美性xxxxxxxxx| 九九久久精品一区| 欧美性高潮在线| 少妇高潮久久久久久潘金莲| 成人av在线亚洲| 国产婷婷97碰碰久久人人蜜臀| 国产亚洲美女久久| 亚洲色图15p| 国产欧美日韩精品专区| 国产精品99蜜臀久久不卡二区| 国产亚洲在线播放| 亚洲大尺度美女在线| 91在线观看免费高清| 亚洲影视中文字幕| 欧美激情一区二区三级高清视频| 精品一区二区三区四区| 亚洲美女av在线播放| 精品高清一区二区三区| 超碰日本道色综合久久综合| 欧美成人sm免费视频| 色噜噜亚洲精品中文字幕| 欧美超级免费视 在线| 8x海外华人永久免费日韩内陆视频| 美女撒尿一区二区三区| 日韩成人在线视频网站| 成人观看高清在线观看免费| 91精品国产亚洲| 亚洲变态欧美另类捆绑| 欧美色图在线视频| 亚洲91精品在线| 青青草精品毛片| 国产美女久久精品香蕉69| 高清欧美性猛交xxxx黑人猛交| 亚洲欧美在线一区二区| 日本久久精品视频| 7m第一福利500精品视频| 精品日本美女福利在线观看| 国产成人自拍视频在线观看| 久久999免费视频| 久久久亚洲欧洲日产国码aⅴ| 98精品在线视频| 日韩精品视频中文在线观看| 日韩欧美有码在线| 欧美日韩免费区域视频在线观看| 91高清视频在线免费观看| 久久乐国产精品| 日本精品久久久| 欧美精品www在线观看| 国产在线拍揄自揄视频不卡99| 毛片精品免费在线观看| 色妞欧美日韩在线| 中文字幕成人在线| 亚洲精品国产成人| 久久香蕉国产线看观看网| 深夜福利91大全| 欧美另类99xxxxx| 欧美韩国理论所午夜片917电影| 亚洲97在线观看| 久久中国妇女中文字幕| 日韩va亚洲va欧洲va国产| 国产va免费精品高清在线观看| 九色成人免费视频| 亚洲人成网7777777国产| 国产在线精品自拍| 国产又爽又黄的激情精品视频| 中文字幕欧美精品日韩中文字幕| 国产精品中文久久久久久久| 国产美女搞久久| 精品亚洲一区二区| 555www成人网| 性色av一区二区咪爱| 欧美三级xxx| 久久久噜噜噜久久中文字免| 亚洲第一页在线| 国产午夜精品麻豆| 亚洲第一国产精品| 欧美大片在线免费观看| 一本色道久久88综合日韩精品| 日韩经典中文字幕在线观看| 日韩中文字幕国产精品| 91久久久久久久| 成人在线精品视频| 欧美电影免费观看大全| 456国产精品| 91视频88av| 亚洲性线免费观看视频成熟| 在线播放国产一区中文字幕剧情欧美| 欧美亚洲视频在线看网址| 91天堂在线观看| 精品亚洲精品福利线在观看| 国外色69视频在线观看| 欧美激情第一页xxx| 欧美性猛交xxxx免费看漫画| 在线亚洲国产精品网| 欧美激情视频一区二区三区不卡| 97婷婷大伊香蕉精品视频| 欧美日韩高清在线观看| 久久国产色av| 久久精品视频播放| 久久国产精品首页| 久久影院在线观看| 亚洲香蕉伊综合在人在线视看| 亚洲色在线视频| 孩xxxx性bbbb欧美| 亚洲电影免费观看高清| 国产精品伦子伦免费视频| 亚洲自拍偷拍网址| 精品久久久久久国产91|