コード例 #1
0
ファイル: Units.cs プロジェクト: DenisEA81/TheGame
 public BackgroundSprite(IImageUnitTemplate template)
 {
     TemplateImage = template;
     SetItem();
 }
コード例 #2
0
ファイル: Units.cs プロジェクト: DenisEA81/TheGame
 public UnitSprite(IImageUnitTemplate template) : base(template)
 {
     PhysicalCenter = ((IPhysicalUnit)template).PhysicalCenter;
     BlockingSize   = ((IPhysicalUnit)template).BlockingSize;
 }
コード例 #3
0
ファイル: Controller.cs プロジェクト: DenisEA81/TheGame
        public override void Start()
        {
            #region Загрузка словаря Images
            XMLImageInformation[] ImageInfoList = XMLImageInformation.LoadFromXML($@"{AppPath}{ApplicationSubDirectory}Images\Images.xml");
            UnitTemplate = new Dictionary <string, Dictionary <string, IImageUnitTemplate> >();
            IImageMatrixListLoader ImageMatrixLoader = new FileImageMatrixLoader($@"{AppPath}{ApplicationSubDirectory}Images\");
            for (int i = 0; i < ImageInfoList.Length; i++)
            {
                IImageUnitTemplate temp = ImageUnitBuilder.Build(ImageInfoList[i], ImageMatrixLoader);

                if (!UnitTemplate.ContainsKey(ImageInfoList[i].ClassName.ToUpper()))
                {
                    UnitTemplate.Add(ImageInfoList[i].ClassName.ToUpper(), new Dictionary <string, IImageUnitTemplate>());
                }

                UnitTemplate[ImageInfoList[i].ClassName.ToUpper()].Add(ImageInfoList[i].UnitName.ToUpper(), temp);
            }
            #endregion

            #region Создание TestUnit
            TestUnit = new List <IUnit2D>()
            {
                new Unit2D("Villy",
                           new FloatPoint2D(350, 50),
                           new Point3D(20, 20, 50),
                           new Point3D(0, 0, 0),
                           new Orientation(64),
                           null)
            };

            Dictionary <string, IUnit2DActions> ActionDic = new Dictionary <string, IUnit2DActions>();
            ActionDic.Add("turn0", new ActionTurnUnit2D(null, 0, null));
            ActionDic.Add("turn90", new ActionTurnUnit2D(null, 90, null));
            ActionDic.Add("turn180", new ActionTurnUnit2D(null, 180, null));
            ActionDic.Add("turn270", new ActionTurnUnit2D(null, 270, null));

            for (int i = 0; i < TestUnit.Count; i++)
            {
                TestUnit[i].Actions =
                    new List <IActions>()
                {
                    new ActionWaitForTime(2000,
                                          new ActionInTimeSteps(ActionDic["turn180"].Copy(TestUnit[i]), 5,
                                                                new ActionWaitForTime(2000,
                                                                                      new ActionInTimeSteps(ActionDic["turn0"].Copy(TestUnit[i]), 50,
                                                                                                            new ActionWaitForTime(2000,
                                                                                                                                  new ActionInTimeSteps(ActionDic["turn90"].Copy(TestUnit[i]), 20,
                                                                                                                                                        new ActionWaitForTime(2000,
                                                                                                                                                                              new ActionInTimeSteps(ActionDic["turn0"].Copy(TestUnit[i]), 1,
                                                                                                                                                                                                    new ActionInTimeSteps(ActionDic["turn270"].Copy(TestUnit[i]), 0,
                                                                                                                                                                                                                          new ActionInTimeSteps(ActionDic["turn180"].Copy(TestUnit[i]), 0,
                                                                                                                                                                                                                                                new ActionWaitForTime(1000,
                                                                                                                                                                                                                                                                      new ActionInTimeSteps(ActionDic["turn0"].Copy(TestUnit[i]), 10
                                                                                                                                                                                                                                                                                            ))))))))))))
                };
            }
            #endregion

            #region Загрузка текущей сцены
            FullScenePictureList = new List <List <IPositionedBitmap> >()
            {
                new List <IPositionedBitmap>(), new List <IPositionedBitmap>()
            };
            int YYY = 125;
            int XXX = 135;

            foreach (Dictionary <string, IImageUnitTemplate> dc in UnitTemplate.Values)
            {
                foreach (IImageUnitTemplate item in dc.Values)
                {
                    switch (item.ClassName.ToUpper())
                    {
                    case "BACKGROUND":
                        FullScenePictureList[0].Add(new BackgroundSprite(item));
                        break;

                    case "IMAGEUNIT":
                        UnitSprite temp = new UnitSprite(item);
                        temp.Position = new Point(XXX, YYY);
                        YYY           = 0;
                        XXX           = 0;
                        FullScenePictureList[1].Add(temp);
                        break;

                    default:
                        throw new Exception($"Неизвестный класс <{item.ClassName}>");
                    }
                }
            }
            // добавление дополнительной фоновой клетки
            {
                IPositionedBitmap itm = new BackgroundSprite(UnitTemplate["BACKGROUND"].ToList()[0].Value);
                itm.Position = new Point(itm.Item.Width, 0);
                FullScenePictureList[0].Add(itm);
                //добавление юнита
                IPositionedBitmap itmU = new UnitSprite(UnitTemplate["IMAGEUNIT"].ToList()[0].Value);
                itmU.Position = new Point(3 * itm.Item.Width / 2 - itmU.Item.Width / 2, (itm.Item.Height - itmU.Item.Height) / 2);
                FullScenePictureList[1].Add(itmU);
            }
            #endregion

            base.Start();
        }