資源簡介
S2 北大青鳥C#課程中的 Monster 完整案例。一個簡單的Game 游戲,我使用簡單工廠,代碼 清晰,經調試暫無 bag ,總之感覺挺不錯,界面 美觀,功能齊全。

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
using?MyGame.Model;
using?System.Threading;
using?MyGame.DAL;
namespace?MyGame
{
????public?partial?class?levelForm?:?Form
????{
??????
????????public?levelForm(string?gt)
????????{
????????????InitializeComponent();
????????????gameType?=?gt;
????????}
????????private?string?gameType;
????????public?string?GameType
????????{
????????????get?{?return?gameType;?}
????????????set?{?gameType?=?value;?}
????????}
????????//怪獸集合
????????Dictionary?monsters?=?new?Dictionary();
????????//控件集合
????????Dictionary?UIMappings?=?new?Dictionary();
????????//創建一個GameManager?對象?gm?并創建關卡
????????GameManager?gm?=?new?GameManager();
????????PictureBox?picHero?=?new?PictureBox();
????????PictureBox?picMoster?=?null;
??
????????#region?加載
????????private?void?Form1_Load(object?sender?EventArgs?e)
????????{
????????????if?(gameType.Equals(Common.GameModes.New.ToString()))
????????????{
????????????????
????????????????gm.Game?=?new?Game();
????????????????gm.Game.Hero?=?new?Hero(“李小俠“?Image.FromFile(“../../image/hero.gif“)?new?Point(450?400)?new?Size(100?180)?Image.FromFile(“../../image/heroDead.gif“));
????????????
????????????????//使用簡單工廠模式創建關卡
????????????????gm.Game.CurrentLevel?=?LevelFactory.CreateLevel(1);???????????????????
???
????????????}
????????????else
????????????{
????????????????//接收加載過來的數據
????????????????gm.Game?=?gm.Load();
????????????????this.Refresh();
????????????}
????????????//付給當前的monsters
????????????monsters?=?gm.Game.CurrentLevel.Monsters;
????????????//調用初始化.
????????????InitUI();
????????????this.lblMessage.Text?=?““;
????????????this.BackgroundImage?=?gm.Game.CurrentLevel.StagePic;
????????????//必殺技不可用
????????????this.cmsAttack.Items[“tsmiSuper“].Enabled?=?false;
????????}?
????????#endregion
????????
????????
????????#region?初始化
????????///?
????????///?窗體中顯示關卡中的怪物和玩家的狀態控件
????????///?
????????private?void?InitUI()
????????{
???????????//默認窗體屬性
????????????this.WindowState?=?FormWindowState.Maximized;
??????????//怪獸攻擊
????????????this.btnMonster.Location?=?new?Point(900160);??????????????
????????????//保存
???????????//?this.btnSave.Location?=?new?Point(900400);
????????????//退出
????????????//this.btnExit.Location?=?new?Point(900480);
????????????//死亡信息
????????????this.lblDeadMessage.Location?=?new?Point(150450);
????????????this.lblDeadMessage.Text?=?““;
????????????//攻擊信息
????????????this.lblMessage.Location?=?new?Point(300650);
????????????this.lblMessage.Width?=?400;
????????????this.lblMessage.Height?=?50;
????????????//攻擊者頭像
????????????this.picHead.Location?=?new?Point(150?645);????????????
???????????this.picHead.Width?=?90;
??
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????1128448??2004-01-01?03:24??Game\bin\Debug\Game.exe
?????文件??????91648??2004-01-01?03:24??Game\bin\Debug\Game.pdb
?????文件??????14328??2004-01-01?03:24??Game\bin\Debug\Game.vshost.exe
?????目錄??????????0??2004-01-01?03:24??Game\bin\Debug
?????目錄??????????0??2004-01-01?03:15??Game\bin
?????文件????????745??2004-01-01?03:25??Game\Class\Common.cs
?????文件????????661??2004-01-01?00:10??Game\Class\Game.cs
?????文件???????8382??2004-01-01?02:48??Game\Class\GameManager.cs
?????文件???????5895??2004-01-01?05:57??Game\Class\Hero.cs
?????文件???????1221??2004-01-01?00:11??Game\Class\Level.cs
?????文件???????1736??2004-01-01?01:15??Game\Class\LevelFactory.cs
?????文件???????2765??2004-01-01?00:13??Game\Class\MonkeyMonster.cs
?????文件???????4874??2004-01-01?05:56??Game\Class\Monster.cs
?????文件???????2161??2004-01-01?00:13??Game\Class\TurtleMonster.cs
?????文件???????1018??2004-01-01?01:32??Game\Class\UIContainer.cs
?????目錄??????????0??2004-01-01?03:25??Game\Class
?????文件??????18791??2004-01-01?03:19??Game\Form1.cs
?????文件???????9574??2004-01-01?06:32??Game\Form1.Designer.cs
?????文件???????6011??2004-01-01?06:32??Game\Form1.resx
?????文件????????901??2004-01-01?00:26??Game\Game.sln
????..A..H.?????24576??2004-01-01?03:25??Game\Game.suo
?????文件??????10085??2004-01-01?04:43??Game\image\hero.gif
?????文件???????9789??2004-01-01?04:43??Game\image\heroDead.gif
?????文件?????507587??2004-01-01?04:43??Game\image\level1.jpg
?????文件???????8597??2004-01-01?04:43??Game\image\monkey.gif
?????文件???????8396??2004-01-01?04:43??Game\image\monkeyDead.gif
????....SH.?????25088??2004-01-01?04:43??Game\image\Thumbs.db
?????文件???????8756??2004-01-01?04:43??Game\image\turtle.gif
?????文件???????9160??2004-01-01?04:43??Game\image\turtleDead.gif
?????目錄??????????0??2004-01-01?04:43??Game\image
............此處省略30個文件信息
- 上一篇:最簡單快速地用c#批量化處理excel的方法
- 下一篇:c#繪等值線
評論
共有 條評論