Exemplo n.º 1
0
        /// <summary>
        /// 显伤脚本
        /// </summary>
        /// <param name="monster">对应的怪物</param>
        public void ShowDamage(int left, int top)
        {
            if (textBlock != null)
            {
                HideDamage();
            }
            Run run = new Run()
            {
                Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 150, 0)),
                FontWeight = FontWeight.FromOpenTypeWeight(999)
            };
            int damage = CalculationUtility.CalculateDamage(this);

            // -1代表不可战斗显示问号
            if (damage == -1)
            {
                run.Text = "???";
            }
            else
            {
                run.Text = damage + "";
            }
            textBlock = new TextBlock(run)
            {
                Height   = 20,
                FontSize = 13
            };
            Canvas.SetLeft(textBlock, left);
            Canvas.SetTop(textBlock, top);
            Panel.SetZIndex(textBlock, 9);
            FloorFactory.canvas.Children.Add(textBlock);
        }
Exemplo n.º 2
0
 public void MoveRight()
 {
     if (properties.y + 1 > 10)
     {
         return;
     }
     properties.y++;
     if (IsTouch(current_floor[properties.x, properties.y]) == false)
     {
         properties.y--;
         return;
     }
     else
     {
         CalculationUtility.RefreshStatus();
         Canvas.SetLeft(floorFactory.GetHeroImage(), Canvas.GetLeft(floorFactory.GetHeroImage()) + 50);
         floorFactory.GetHeroImage().Source = new BitmapImage(new Uri("/res/icons/characters/hero11.png", UriKind.Relative));
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// 向Panel添加显示怪物资料的Canvas
        /// </summary>
        private void AddChildCanvas(MonsterImage monster)
        {
            Canvas parennt = new Canvas();

            #region 添加怪物图片
            Image image = new Image
            {
                Source = new BitmapImage(new Uri(MonsterImage.GetImagePaths((MonsterType)monster.GetFineType())[0], UriKind.Relative)),
                Height = 50,
                Width  = 50,
                Margin = new Thickness(10)
            };
            parennt.Children.Add(image);
            #endregion

            #region 添加怪物名称
            TextBox name = CreateTextBox(monster.GetFineType().ToString(), new SolidColorBrush(Color.FromRgb(255, 255, 255)), 80, 10);
            parennt.Children.Add(name);
            #endregion

            #region 添加怪物特殊能力
            TextBox ability = CreateTextBox(monster.Ability.ToString(), new SolidColorBrush(Color.FromRgb(255, 255, 255)), 80, 35);
            parennt.Children.Add(ability);
            #endregion

            #region 添加怪物血量
            TextBox hp = CreateTextBox("血量:" + monster.Hp, new SolidColorBrush(Color.FromRgb(209, 133, 42)), 200, 10);
            parennt.Children.Add(hp);
            #endregion

            #region 添加怪物攻击
            TextBox atk = CreateTextBox("攻击:" + monster.Atk, new SolidColorBrush(Color.FromRgb(209, 133, 42)), 310, 10);
            parennt.Children.Add(atk);
            #endregion

            #region 添加怪物防御
            TextBox def = CreateTextBox("防御:" + monster.Def, new SolidColorBrush(Color.FromRgb(209, 133, 42)), 420, 10);
            parennt.Children.Add(def);
            #endregion

            #region 添加获得的金币
            TextBox gold = CreateTextBox("金币:" + monster.Gold, new SolidColorBrush(Color.FromRgb(185, 185, 40)), 200, 35);
            parennt.Children.Add(gold);
            #endregion

            #region 添加获得的经验
            TextBox exp = CreateTextBox("经验:" + monster.Exp, new SolidColorBrush(Color.FromRgb(185, 185, 40)), 310, 35);
            parennt.Children.Add(exp);
            #endregion

            #region 添加打怪的损失
            string damage = CalculationUtility.CalculateDamage(monster) + "";
            if ("-1".Equals(damage))
            {
                damage = "???";
            }
            TextBox damageText = CreateTextBox("伤害:" + damage, new SolidColorBrush(Color.FromRgb(180, 45, 45)), 420, 35);
            parennt.Children.Add(damageText);
            #endregion

            #region 添加分割线
            Canvas canvas = new Canvas
            {
                Height     = 3,
                Width      = 550,
                Background = new SolidColorBrush(Color.FromRgb(200, 200, 200))
            };
            parennt.Children.Add(canvas);
            #endregion
            ContentItem.Children.Add(parennt);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 判别碰到的类型
        /// </summary>
        /// <param name="a"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        private bool IsTouch(IBaseImage image)
        {
            // 细分类
            Enum e = image.GetFineType();

            switch (image.GetCoarseType())
            {
            case Atype.地板:
                switch (e)
                {
                case FloorType.地板:
                    image.PlayMusic(image.GetPlayer(), "../../res/se/走路.MP3");
                    return(true);

                case FloorType.楼梯上:
                    image.PlayMusic(image.GetPlayer(), "../../res/se/上下楼.MP3");
                    current_floor = floorFactory.CoreMap(floorFactory.GetFloorNum() + 1);
                    return(true);

                case FloorType.楼梯下:
                    image.PlayMusic(image.GetPlayer(), "../../res/se/上下楼.MP3");
                    current_floor = floorFactory.CoreMap(floorFactory.GetFloorNum() - 1);
                    return(true);
                }
                return(false);

            case Atype.门:
                if (image.isImageExist())
                {
                    switch (e)
                    {
                    case DoorType.黄门:
                        if (properties.yellowKey > 0)
                        {
                            MapUtility.ChangeToImage(floorFactory.GetFloorNum(), properties.x, properties.y, new FloorImage(FloorType.地板));
                            image.HideImage();
                            properties.yellowKey--;
                        }
                        else
                        {
                            image.PlayMusic(image.GetPlayer(), "../../res/se/开门失败.MP3");
                        }
                        break;

                    case DoorType.蓝门:
                        if (properties.blueKey > 0)
                        {
                            MapUtility.ChangeToImage(floorFactory.GetFloorNum(), properties.x, properties.y, new FloorImage(FloorType.地板));
                            image.HideImage();
                            properties.blueKey--;
                        }
                        else
                        {
                            image.PlayMusic(image.GetPlayer(), "../../res/se/开门失败.MP3");
                        }
                        break;

                    case DoorType.红门:
                        if (properties.redKey > 0)
                        {
                            MapUtility.ChangeToImage(floorFactory.GetFloorNum(), properties.x, properties.y, new FloorImage(FloorType.地板));
                            image.HideImage();
                            properties.redKey--;
                        }
                        else
                        {
                            image.PlayMusic(image.GetPlayer(), "../../res/se/开门失败.MP3");
                        }
                        break;

                    case DoorType.铁门:
                        MapUtility.ChangeToImage(floorFactory.GetFloorNum(), properties.x, properties.y, new FloorImage(FloorType.地板));
                        image.HideImage();
                        break;
                    }
                }
                return(false);

            case Atype.宝石:
                switch (e)
                {
                case GemstoneType.红宝石:
                    properties.atk += 3;
                    break;

                case GemstoneType.蓝宝石:
                    properties.def += 3;
                    break;

                case GemstoneType.绿宝石:
                    properties.res += 3;
                    break;

                case GemstoneType.红血瓶:
                    properties.hp += 100;
                    break;

                case GemstoneType.蓝血瓶:
                    properties.hp += 300;
                    break;

                case GemstoneType.黄血瓶:
                    properties.hp += 500;
                    break;

                case GemstoneType.绿血瓶:
                    properties.hp += 1000;
                    break;

                case GemstoneType.铁剑:
                    properties.atk += 10;
                    weapon          = CommonString.WEAPON_SWORD;
                    break;

                case GemstoneType.铁盾:
                    properties.def += 10;
                    break;

                case GemstoneType.银剑:
                    properties.atk += 30;
                    break;

                case GemstoneType.银盾:
                    properties.def += 30;
                    break;

                case GemstoneType.骑士剑:
                    properties.atk += 70;
                    break;

                case GemstoneType.骑士盾:
                    properties.def += 70;
                    break;

                case GemstoneType.圣剑:
                    properties.atk += 100;
                    break;

                case GemstoneType.圣盾:
                    properties.def += 100;
                    break;
                }
                image.PlayMusic(image.GetPlayer(), "../../res/se/吃物品.MP3");
                MapUtility.ChangeToImage(floorFactory.GetFloorNum(), properties.x, properties.y, new FloorImage(FloorType.地板));
                image.HideImage();
                //更新显伤脚本
                MapUtility.UpdateDamage();
                return(true);

            case Atype.特殊物品:
                MapUtility.ChangeToImage(floorFactory.GetFloorNum(), properties.x, properties.y, new FloorImage(FloorType.地板));
                image.PlayMusic(image.GetPlayer(), "../../res/se/吃物品.MP3");
                return(true);

            case Atype.钥匙:
                switch ((KeyType)e)
                {
                case KeyType.黄钥匙:
                    properties.yellowKey++;
                    image.HideImage();
                    break;

                case KeyType.蓝钥匙:
                    properties.blueKey++;
                    image.HideImage();
                    break;

                case KeyType.红钥匙:
                    properties.redKey++;
                    image.HideImage();
                    break;
                }
                MapUtility.ChangeToImage(floorFactory.GetFloorNum(), properties.x, properties.y, new FloorImage(FloorType.地板));
                image.PlayMusic(image.GetPlayer(), "../../res/se/吃物品.MP3");
                return(true);

            case Atype.怪物:
                MonsterImage monster = new MonsterImage((MonsterType)e);
                if (CalculationUtility.Battle(monster))
                {
                    image.PlayMusic(image.GetPlayer(), "../../res/se/" + weapon + ".MP3");

                    //删除怪物图片和显伤脚本
                    image.HideImage();
                    ((MonsterImage)image).HideDamage();

                    //删除怪物,更改为地板
                    MapUtility.ChangeToImage(floorFactory.GetFloorNum(), properties.x, properties.y, new FloorImage(FloorType.地板));

                    //从怪物列表中删除怪物和位置
                    MapUtility.MonsterList.Remove(image);
                    foreach (KeyValuePair <int, int> pair in MapUtility.MonsterPosition)
                    {
                        if (pair.Key == properties.x && pair.Value == properties.y)
                        {
                            MapUtility.MonsterPosition.Remove(pair);
                            break;
                        }
                    }
                }
                return(false);

            case Atype.NPC:
                IsTalking = true;
                NPC       = (NPCImage)image;
                NPC.ShowDialog();
                break;
            }
            return(false);
        }