1 / 23

Mud 小遊戲程式

Mud 小遊戲程式. 物件導向觀念. 物件程式. 先定義遊戲中的類別: (1) 玩家 (2) 怪物 (3) 地點場景. 物件的關係. 玩家. 玩家處在某一地點. 玩家會和怪物戰鬥. 地點場景. 怪物. 每個地點都有一個怪物. 定義類別. (1) 先定義類別的靜態特性,也就是物件的屬 性 (Attribute) (2) 再定義該類別的動作,也就是物件的動態 特性,也就是物件的方法 (Method). “ 玩家 ” 類別的特性 (Attribute). (1) 姓名 (2) 職業

Download Presentation

Mud 小遊戲程式

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Mud小遊戲程式

  2. 物件導向觀念

  3. 物件程式 • 先定義遊戲中的類別: • (1)玩家 • (2)怪物 • (3)地點場景

  4. 物件的關係 玩家 玩家處在某一地點 玩家會和怪物戰鬥 地點場景 怪物 每個地點都有一個怪物

  5. 定義類別 (1)先定義類別的靜態特性,也就是物件的屬 性(Attribute) (2)再定義該類別的動作,也就是物件的動態 特性,也就是物件的方法(Method)

  6. “玩家” 類別的特性(Attribute) (1)姓名 (2)職業 (3)HP(生命值) (4)Max_HP(最大生命值) (5)錢 (6)經驗值 (7)等級 (8)攻擊力 (9)防禦力 (10)敏銳度 (11) X方位的坐標 (12)Y方位的坐標 促使地點以及玩家之間產生關連

  7. “玩家” 類別的動作(Method) (1)建構子 (2)顯示玩家的基本資料 (3)戰鬥(和怪獸戰鬥)與怪獸類別之間的互動 (4)行動(包括移動,觀察) 與地點場景之間的關係 類別的基本功能 ( get_...(),set_...() ) (1)獲得姓名、職業、 HP、經驗值等等的值 (2)更改姓名、職業、 HP、經驗值等等的值

  8. 訊息關係 • 訊息相當於真實世界人說的話,藉由訊息的傳遞,觸動物件的方法,然後產生動作。 = =

  9. 玩家和怪物的關係__戰鬥 • 物件:玩家 • 成員函數:戰鬥 • 引數:怪物資訊 • 戰鬥動作:戰鬥模式,包括攻擊力的運算、生命值的運算、勝利的動作

  10. 玩家和地點場景的關係__行動 • 物件:玩家 • 成員函數:行動 • 引數:行動選擇 以及 場景資訊 • 行動內容:選擇要移動,還是要觀察四週,移動包括四個方位的移動

  11. “怪物” 類別的特性(Attribute) (1)怪獸名 (2)HP(生命值) (3)可獲得的金錢 (4)可獲得的經驗值 (5)攻擊力 (6)防禦力 (7)敏銳度

  12. “怪物” 類別的動作(Method) 類別的基本功能 ( get_...(),set_...() ) (1)獲得怪獸名字、 HP、經驗值等等的值 (2)更改怪獸名字、 HP、經驗值等等的值

  13. “地點” 類別的特性(Attribute) (1) X方位的坐標 (2)Y方位的坐標 (3)東方是否可行走 (4)西方是否可行走 (5)南方是否可行走 (6)北方是否可行走 (7)敘述 (8)擁有的怪物

  14. “地點” 類別的動作(Method) 類別的基本功能 ( get_...(),set_...() ) (1)獲得地點坐標、 地點方向等等的值 (2)更改地點坐標、 地點方向等等的值

  15. 結合關係 • 用於描述各物件間相互連接的結構關係。物件導向觀念透過結合概念,將可描述現實世界中的結構關係 • 例如一間公司可以由許多人組合— 公司與人之間存在者公司由許多人組成的關係。

  16. 地點場景 vs. 區域空間 • 許多的地點場景組合成一個區域空間 • 區域空間是由地點場景組合而成 • 程式設計為4*4的區域空間,所以遊戲的空間是由16個地點場景組成 區域空間由這4*4個地點組成 (x,y)括弧代表著x和y的坐標

  17. 地點場景 vs. 區域空間 利vector用<Land> 來表示地點場景的物件組合 • class Space{ • public: • vector<Land> space; • …… • };

  18. 玩家類別 • class Player{ • private: • string name; • string career; • double attack; • double defense; • double quick; • int hp; • int max_hp; • int exp; • int money; • int classes; • int x; • int y; • public: • Player(string _name,char _career); • void Show_Information(); • void Fight(Monster _monster); • void set_HP(int _hp){hp=_hp;} • void action(char choice,Space _action); • int get_HP(); • };

  19. 怪物類別 • class Monster{ • private: • string name; • int hp; • int exp; • int money; • double attack; • double defense; • double quick; • public: • int get_HP(); • int get_EXP(){return exp;} • int get_Money(){return money;} • double get_Defense(){return defense;} • double get_Attack(){return attack;} • double get_Quick(){return quick;} • string get_Name(){return name;} • void set_HP(int _HP){hp=_HP;} • Monster(string _name,int _hp,int _money,int _exp,double _attack,double _defense,double _quick); • };

  20. 地點類別 • class Land{ • private: • int x; • int y; • bool n; • bool w; • bool s; • bool e; • string land_script; • Monster monster; • public: • Land(int _x,int _y,bool _e,bool _w,bool _s,bool _n,string _land_script,Monster _monster); • int get_X(){return x;} • int get_Y(){return y;} • bool get_N(){return n;} • bool get_E(){return e;} • bool get_S(){return s;} • bool get_W(){return w;} • string get_Script(){return land_script;} • Monster get_Monster(){return monster;} • };

  21. 區域空間類別 • class Space{ • private: • public: • vector<Land> space; • Land Find_Space(int _x,int _y); • void Add_Space(int _x,int _y,bool _e,bool _w,bool _s,bool _n,string _land_script,Monster _monster); • };

  22. 主程式上宣告怪物物件 • Monster Devil("邪惡劍士",600,300,300,150,240,90); • Monster Mouse("兇惡的老鼠",40,20,20,20,20,20); • Monster Ghost("鬼魂",150,20,75,30,125,100); • Monster Killer("殺手",400,200,500,200,300,300); • Monster Bird("老鷹",800,500,1000,350,100,600); • Monster Fish("鯊魚",800,100,600,400,600,400); • Monster Little_Fish("小魚",600,100,200,300,200,500); • Monster Bear("熊",800,100,700,250,1000,50); • Monster God_1("山神",1200,500,1500,600,1000,600); • Monster God_2("河神",1500,550,1600,750,750,1000); • Monster Sea_Bird("海鳥",800,300,800,300,200,700); • Monster Final_Monster("邪惡的魔王",2000,800,2500,1000,1000,1000);

  23. 主程式上宣告地點物件 • space.Add_Space(0,0,true,false,false,false,"好漂亮的房間,你目前看到東邊有一條通道",Ghost); • space.Add_Space(1,0,false,true,false,true,"北方有光線,好像可以通到室外",Devil); • space.Add_Space(1,1,true,true,true,true,"光線好亮呀,原來這是出口呀,四處都是通道",Killer); • space.Add_Space(2,1,true,true,true,true,"很寬廣的草原,一望無際",Bird); • space.Add_Space(0,1,true,false,false,true,"前面有河流檔住了,死路一條",Fish); • space.Add_Space(3,1,false,true,true,true,"前面有一座山檔住路了",Bear); • space.Add_Space(2,0,true,false,false,true,"眼前皆是山壁,只能往東走了",Bear); • space.Add_Space(3,0,false,true,false,true,"完全是死路,只能往原路走回去了",God_1); • space.Add_Space(0,2,true,false,true,false,"眼前是一個湖,西邊是一條大溪,只能往東走了",God_2); • space.Add_Space(1,2,true,true,true,false,"北邊是一個大湖,只有東西方有路可以通",Little_Fish); • space.Add_Space(2,2,true,true,true,false,"出海口了,北方沒有路了",Sea_Bird); • space.Add_Space(3,2,false,true,true,false,"眼前就是最終的魔王,他正等待你來跟他挑戰",Final_Monster);

More Related