請問要怎樣用class寫踩地雷? |
尚未結案
|
moveurbody
一般會員 發表:1 回覆:2 積分:0 註冊:2009-01-07 發送簡訊給我 |
我現在只會用dev寫出最基本的建立出地雷陣列
[code cpp] #include #include using namespace std; int main(int argc, char *argv[]) { int bomb[12][12]={0};//設邊寬大1 srand(time(0)); for(int i=0;i<10;i )//設定炸彈數,並隨機成立 { bomb[(rand()) 1][(rand()) 1]=9;//炸彈設9 } //判斷旁邊的數字 for(int i=0;i<12;i ) { for(int j=0;j<12;j ) { if(bomb[i][j]==9) { if(bomb[i-1][j-1]!=9) bomb[i-1][j-1] ; if(bomb[i-1][j]!=9) bomb[i-1][j] ; if(bomb[i-1][j 1]!=9) bomb[i-1][j 1] ; if(bomb[i][j-1]!=9) bomb[i][j-1] ; if(bomb[i][j 1]!=9) bomb[i][j 1] ; if(bomb[i 1][j-1]!=9) bomb[i 1][j-1] ; if(bomb[i 1][j]!=9) bomb[i 1][j] ; if(bomb[i 1][j 1]!=9) bomb[i 1][j 1] ; } } } //顯示 ,取中間10X10矩陣 for(int i=1;i<11;i ) { for(int j=1;j<11;j ) { cout< cout< cout< return EXIT_SUCCESS; } [/code] 請問怎麼將整個踩地雷寫成class並且用bcb寫出來? 編輯記錄
moveurbody 重新編輯於 2009-01-07 22:19:35, 註解 無‧
|
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
|
moveurbody
一般會員 發表:1 回覆:2 積分:0 註冊:2009-01-07 發送簡訊給我 |
|
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
把您嘗試寫的程式碼PO出來,讓前輩們幫您看看問題在哪邊^_^
===================引 用 moveurbody 文 章=================== 而且我嘗試寫class可是失敗了 所以才會想再問一次
編輯記錄
taishyang 重新編輯於 2009-01-08 18:48:45, 註解 無‧
|
moveurbody
一般會員 發表:1 回覆:2 積分:0 註冊:2009-01-07 發送簡訊給我 |
這是我一開始測試他基本的class去寫的
因為習慣用dev對BCB不熟 [code cpp] #include #include using namespace std; class Bomb { public: int create_map(int width,int height); private: int width; int height; }; int Bomb::create_map(int width,int height) { int bomb[width][height]; srand(time(0)); rand(); for(int i=0;i for(int j=0;j bomb[i][j]=0; cout< cout< cout< int main(int argc, char *argv[]) { Bomb bomb; int Height,Width; cout<<"高:"< cout<<"寬:"< bomb.create_map(Width,Height); system("PAUSE"); return EXIT_SUCCESS; } [/code] 我又參考了http://delphi.ktop.com.tw/board.php?cid=31&fid=79&tid=26676這篇的原始碼 [code cpp] class Bomb{ public: int create_map(int width,int height);//建立地圖 private: int width,height; static int bnum;//設定炸彈數量 TPanel *box1[10][10]; }; int Bomb::bnum=0; //--------------------------------------------------------------------------- int Bomb::create_map(int width,int height) { int bomb[width][height];//這邊就錯誤了 for(int i=0;i for(int j=0;j bomb[i][j]=0; box1[i][j]->Caption=""; box1[i][j]->Color=clGrayText; } } } [/code] int bomb[width][height]; 可是到了這邊就錯誤了... 我的想法是 [code cpp] class bomb { public: create_map(int width,int height,int bomb_number);//可以透過輸入產生地雷 bool box1Click;//點選後的處理; private: int width; int height; int bomb_number; bool isBomb; //以布林記錄是否為炸彈 }; [/code] 可是同學說這樣有問題 不知道可不可以給點正確的方向
編輯記錄
moveurbody 重新編輯於 2009-01-11 13:49:03, 註解 無‧
|
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |