/// <summary> /// 将读取的json文本转成对象,并赋值给英雄和地图渲染 /// </summary> /// <param name="str"></param> private static void Deserialize(string str) { data = JsonConvert.DeserializeObject <DataLoad>(str); hero.properties = data.Properties; FloorFactory.GetInstance().SetFloorNum(data.FloorNum); DrawFloorAndHero(); }
/// <summary> /// 保存英雄属性 /// </summary> /// <returns></returns> private static string SaveHeroStatus() { Hero hero = Hero.GetInstance(); DataSave data = new DataSave { Properties = new HeroProperties() { hp = hero.properties.hp, atk = hero.properties.atk, def = hero.properties.def, res = hero.properties.res, level = hero.properties.level, gold = hero.properties.gold, exp = hero.properties.exp, yellowKey = hero.properties.yellowKey, blueKey = hero.properties.blueKey, redKey = hero.properties.redKey, x = hero.properties.x, y = hero.properties.y }, Map = MapUtility.GetAllFloorType(), FloorNum = FloorFactory.GetInstance().GetFloorNum() }; return(JsonConvert.SerializeObject(data)); }
/// <summary> /// Create floors using <c>FloorFactory</c> class. And assign to property named 'normalFloorLayouts' and 'entryexitFloorLayouts' list. /// 'normalFloorLayouts' and 'entryexitFloorLayouts' are <c>List<IFloor></c> type. /// </summary> void CreateFloors() { FloorFactory floorFactory = new FloorFactory(); floorFactory.CreateFloor(); this.normalFloorLayouts = floorFactory.NormalFloors; this.entryexitFloorLayouts = floorFactory.EntryExitFloors; }
/// <summary> /// 重新渲染地图和英雄 /// </summary> private static void DrawFloorAndHero() { // 更新英雄图片位置 FloorFactory.GetInstance().DrawHeroImage(data.Properties.y, data.Properties.x); // 重新初始化地图 MapUtility.UpdateFloor(data.Map); // 渲染地图 var floorFactory = FloorFactory.GetInstance(); hero.current_floor = floorFactory.CoreMap(data.FloorNum); }
void Start() { instance = this; }
private Hero(int hp = 1000, int atk = 10, int def = 10, int res = 0, int level = 1, int gold = 0, int exp = 0, int yellow = 0, int blue = 0, int red = 0) { floorFactory = FloorFactory.GetInstance(); current_floor = floorFactory.GetCurrentFloor(); }
/// <summary> /// 给窗口添加键盘事件,当楼层初始化后进行处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DirectionKeyDown(object sender, KeyEventArgs e) { if (!FloorFactory.GetInstance().IsInitialize()) { return; } //对话界面 if (hero.IsTalking) { if (e.Key == Key.Space || e.Key == Key.Enter) { hero.NPC.NextText(); } return; } // 游戏界面中 if (!isMenuOpened) { //英雄移动和菜单项开关 switch (e.Key) { case Key.Up: hero.MoveUp(); break; case Key.Down: hero.MoveDown(); break; case Key.Left: hero.MoveLeft(); break; case Key.Right: hero.MoveRight(); break; case Key.Escape: isMenuOpened = true; GlobalLeft.Navigate(MenuLeft.GetInstance()); GlobalRight.Navigate(MonsterData.GetInstance()); MonsterData.GetInstance().ShowContentItem(); break; } } else { //菜单栏监听 double itemTop = Canvas.GetTop(MenuLeft.ToggleCanvas); switch (e.Key) { case Key.Down: if (itemTop == 257) { Canvas.SetTop(MenuLeft.ToggleCanvas, 7); itemNum = 0; } else { Canvas.SetTop(MenuLeft.ToggleCanvas, Canvas.GetTop(MenuLeft.ToggleCanvas) + 50); itemNum++; } ShowRightWindow(itemNum); break; case Key.Up: if (itemTop == 7) { Canvas.SetTop(MenuLeft.ToggleCanvas, 257); itemNum = 5; } else { Canvas.SetTop(MenuLeft.ToggleCanvas, Canvas.GetTop(MenuLeft.ToggleCanvas) - 50); itemNum--; } ShowRightWindow(itemNum); break; case Key.Escape: isMenuOpened = false; GlobalLeft.Navigate(State.GetInstance()); GlobalRight.Navigate(FloorFactory.GetInstance()); Canvas.SetTop(MenuLeft.ToggleCanvas, 7); MonsterData.GetInstance().ContentItem.Children.Clear(); itemNum = 0; break; } } }
public void CreateFloor() { FloorFactory floorstruct = new FloorFactory(); floorstruct.TestCreateFloor(); }