Пример #1
0
        public ProductViewModel()
        {
            ProductsAPI        = new ProductsAPI();
            UnitAPI            = new UnitAPI();
            ProductCategoryAPI = new ProductCategoryAPI();
            var products         = ProductsAPI.GetAll();
            var productviewModel = products.Select(x => new Model.Product()
            {
                ProductId   = x.Id,
                Name        = x.Name,
                Description = x.Description,
                UnitId      = x.UnitId,
                Unit        = x.Unit,
                CategoryId  = x.ProductCategoryId,
                Category    = x.ProductCategory,
                Detail      = new Command(() =>
                {
                    DetailShow(x.Id);
                }
                                          ),
                Delete = new Command(() =>
                {
                    Detele(x.Id);
                }),
                Edit = new Command(() =>
                {
                    Edit(x.Id);
                })
            });

            Products = new ObservableCollection <Model.Product>(productviewModel);
        }
Пример #2
0
        public UnitViewModel()
        {
            unitApi = new UnitAPI();
            var units = unitApi.GetAll().Select(x => new Model.Unit()
            {
                Name   = x.Name,
                Symbol = x.Symbol,
                UnitId = x.Id,
                Delete = new Command(() =>
                {
                    Delete(x.Id);
                }),
                Edit = new Command(() =>
                {
                    Edit(x.Id);
                })
            });

            Units  = new ObservableCollection <Model.Unit>(units);
            Create = new Command((() =>
            {
                var view = new UnitCreateView();
                view.Show();
            }));
        }
Пример #3
0
        /*
         * Create a map using the C++ library
         */

        public int[] getMoves(MapStrategy strategy, UnitAPI unit, PlayerAPI p1, PlayerAPI p2, int curr_p, GameAPI game)
        {
            int[] curr_pos = { unit.x, unit.y };
            Race  race     = (curr_p == 1) ? p1.race : p2.race;

            int[]      moves = new int[strategy.size * strategy.size];
            TileType[] tiles = new TileType[strategy.size * strategy.size];
            int[]      pos   = new int[strategy.size * strategy.size];


            foreach (var tmpUnit in p1.units)
            {
                pos[tmpUnit.y * strategy.size + tmpUnit.x] = 1;
            }
            foreach (var tmpUnit in p1.units)
            {
                pos[tmpUnit.y * strategy.size + tmpUnit.x] = 2;
            }


            for (int i = 0; i < strategy.size; i++)
            {
                for (int j = 0; j < strategy.size; j++)
                {
                    tiles[i + strategy.size * j] = game.map.tiles[i, j].getType();
                }
            }

            Algo_getMoves(nativeAlgo, tiles, strategy.size, pos, curr_pos, curr_p, race, moves);
            return(moves);
        }
Пример #4
0
 public ProductCreateViewModel()
 {
     unitAPI            = new UnitAPI();
     productCategoryAPI = new ProductCategoryAPI();
     productsAPI        = new ProductsAPI();
     Units = unitAPI.GetAll().Select(x => new Model.Unit()
     {
         Name   = x.Symbol,
         UnitId = x.Id
     }).ToList();
     ProductCategories = productCategoryAPI.GetAll().Select(x => new ProductCategory()
     {
         Name = x.Name,
         Id   = x.Id
     }).ToList();
     Create = new Command(() =>
     {
         var model               = new ProductDTO();
         model.Name              = this.name;
         model.Description       = this.description;
         model.UnitId            = SelectedUnit.UnitId;
         model.ProductCategoryId = SelectProductCategory.Id;
         var resultFlag          = productsAPI.Create(model);
         if (resultFlag)
         {
             MessageBox.Show("Продукт успешно создан");
         }
         if (!resultFlag)
         {
             MessageBox.Show("Во время создания произошла ошибка");
         }
     });
 }
Пример #5
0
        public UnitAPI attack(UnitAPI unit)
        {
            if (!this.canAttack(unit))
            {
                return(null);
            }
            int currX = unit.x;
            int currY = unit.y;

            this.movePoints -= Game.INSTANCE.map.getTile(currX, currY).moveCost(this.getRace());

            double attackerHealth = (double)this.lifePoints / this.InitialLifePoints;
            double defenderHealth = (double)unit.lifePoints / unit.InitialLifePoints;

            double attackerPoints = attackerHealth * this.attackPoints;
            double defenderPoints = defenderHealth * this.defencePoints;

            double attackerRate = attackerPoints / (attackerPoints + defenderPoints) * 100;
            double defenderRate = defenderPoints / (attackerPoints + defenderPoints) * 100;

            int random = new Random().Next(1, 100);

            UnitAPI loser = null;

            if (random <= attackerRate) // attacker wins
            {
                loser = unit;
            }
            else             // defender wins
            {
                loser = this;
            }

            int randomDamages = new Random().Next(1, loser.lifePoints);

            loser.lifePoints -= randomDamages;

            if (unit.lifePoints <= 0)
            {
                unit.kill();
                //If Defender is killed and there's no enemy on the tile the unit shall move to the selected tile
                if (Game.INSTANCE.getUnits(currX, currY).Count() == 0)
                {
                    this.x = currX;
                    this.y = currY;
                    this.getPlayer().victoryPoints += Game.INSTANCE.map.getTile(x, y).getVictoryPoints(this.getRace());
                }
            }
            if (this.lifePoints <= 0)
            {
                this.kill();
            }

            return(loser);
        }
Пример #6
0
 /// <summary>
 /// signal que les tuiles ont pu changer d'état via la resource 'fer'
 /// </summary>
 internal void Refresh(List <UnitAPI> tileUnits, UnitAPI currentUnit)
 {
     this.tileUnits   = tileUnits;
     this.CurrentUnit = currentUnit;
     RaisePropertyChanged("HasElf");
     RaisePropertyChanged("HasOrc");
     RaisePropertyChanged("HasHuman");
     RaisePropertyChanged("tileNbUnits");
     RaisePropertyChanged("HasUnits");
     RaisePropertyChanged("HasUnitSelected");
 }
Пример #7
0
        public override bool canAttack(UnitAPI unit)
        {
            if (this.movePoints < 1 || unit.getRace() == this.getRace())
            {
                return(false);
            }

            if (Game.INSTANCE.map.getTile(this.x, this.y).getType() == TileType.Mountain)
            {
                return(Map.distance(unit.x, unit.y, this.x, this.y) <= 2);
            }
            else
            {
                return(Map.distance(unit.x, unit.y, this.x, this.y) <= 1);
            }
        }
Пример #8
0
        public UnitAPI getEnemy()
        {
            int     max            = 0;
            UnitAPI maxDefenceUnit = tileUnits.FirstOrDefault();

            if ((maxDefenceUnit == null) || (gameView.MemUnit.getUnit().getPlayer() == maxDefenceUnit.getPlayer()))
            {
                return(null);
            }
            tileUnits.ForEach(delegate(UnitAPI u) {
                if (u.defencePoints > max)
                {
                    maxDefenceUnit = u;
                }
            }
                              );
            return(maxDefenceUnit);
        }
Пример #9
0
 private void doActionAction()
 {
     if (MemUnit != null && (MemUnit.getUnit().getPlayer() == game.turn.currentPlayer))
     {
         UnitAPI currunit = memUnit.getUnit();
         if (SelectedTile.getEnemy() != null)
         {
             if (currunit.canAttack(SelectedTile.getEnemy()))
             {
                 UnitAPI loser = currunit.attack(SelectedTile.getEnemy());
                 MessageBox.Show(loser.getPlayer().name + " loses the battle!");
                 if (loser.lifePoints <= 0)
                 {
                     MessageBox.Show(loser.getPlayer().name + " is dead!");
                 }
             }
             else
             {
                 MessageBox.Show("Attack action not possible");
             }
         }
         else
         {
             if (currunit.canMove(SelectedTile.X, SelectedTile.Y))
             {
                 currunit.move(SelectedTile.X, SelectedTile.Y);
             }
             else
             {
                 MessageBox.Show("Move action not possible");
             }
         }
         //Global Refresh
         memUnit.Refresh();
         updateTiles();
         this.Refresh();
     }
     else
     {
         MessageBox.Show("No unit selected");
     }
     this.isFinished();
 }
Пример #10
0
        private void CreateUnit()
        {
            unitApi = new UnitAPI();
            var model = new UnitDTO()
            {
                Name   = this.name,
                Symbol = this.symbol
            };
            var resultFlag = unitApi.Create(model);

            if (resultFlag)
            {
                MessageBox.Show("Успешно создано.");
            }
            if (!resultFlag)
            {
                MessageBox.Show("Ошибка при создании.");
            }
        }
Пример #11
0
        private void EditUnit()
        {
            unitApi = new UnitAPI();
            var model = new UnitDTO()
            {
                Id     = this.id,
                Name   = this.name,
                Symbol = this.symbol
            };
            var resultFlag = unitApi.Update(model);

            if (resultFlag)
            {
                MessageBox.Show("Успешно сохранено.");
            }
            if (!resultFlag)
            {
                MessageBox.Show("Не удачно.");
            }
        }
Пример #12
0
 public ProductEditViewModel(Product product)
 {
     UnitAPI            = new UnitAPI();
     ProductCategoryAPI = new ProductCategoryAPI();
     this.id            = product.ProductId;
     this.name          = product.Name;
     this.description   = product.Description;
     this.Units         = UnitAPI.GetAll().Select(x => new Model.Unit()
     {
         UnitId = x.Id,
         Name   = x.Name
     }).ToList();
     this.SelectedUnit    = Units.Single(x => x.UnitId == product.UnitId);
     this.ProductCategory = ProductCategoryAPI.GetAll().Select(x => new ProductCategory()
     {
         Name = x.Name,
         Id   = x.Id
     }).ToList();
     this.SelectedCategory = ProductCategory.Single(x => x.Id == product.CategoryId);
     Update = new Command(() =>
     {
         ProductsAPI productAPI       = new ProductsAPI();
         var productDTO               = new ProductDTO();
         productDTO.Name              = Name;
         productDTO.Description       = Description;
         productDTO.Id                = id;
         productDTO.UnitId            = SelectedUnit.UnitId;
         productDTO.ProductCategoryId = SelectedCategory.Id;
         var resultFlag               = productAPI.Update(productDTO);
         if (resultFlag)
         {
             MessageBox.Show("Успешно сохранено.");
         }
         if (!resultFlag)
         {
             MessageBox.Show("Во время сохранения произошла ошибка.");
         }
     });
 }
 public SelectedUnitViewModel(UnitAPI unit)
 {
     this.unit = unit;
     this.Refresh();
 }
Пример #14
0
 private void updateSUnit()
 {
     this.selectedUnit = SelectedTile.CurrentUnit;
 }
Пример #15
0
 public override bool canAttack(UnitAPI unit)
 {
     return(unit.getRace() != this.getRace() && Map.distance(unit.x, unit.y, this.x, this.y) <= 2 && Map.inline(unit.x, unit.y, this.x, this.y) && this.movePoints >= 1);
 }
Пример #16
0
 /// <summary>
 /// Humans can only attack at a distance of 1
 /// </summary>
 /// <param name="unit"></param>
 /// <returns></returns>
 public override bool canAttack(UnitAPI unit)
 {
     return(this.canMove(unit.x, unit.y) && unit.getRace() != this.getRace() && Map.areAdjacent(unit.x, unit.y, this.x, this.y));
 }
Пример #17
0
 public abstract bool canAttack(UnitAPI unit);