public void moveUnit(Hex hex)
 {
     this.selectedUnit.unit.looseMovementPoints(hex.field);
     this.RemoveUnitOnMap(this.selectedUnit);
     this.selectedUnit.unit.coordinates = hex.coord;
     displayUnitOnMap(this.selectedUnit);
     deselectEverything();
     selectHex(this.selectedHex, PageGame.getUnitsOn(this.selectedHex.coord));
 }
Exemple #2
0
        /**
         * \brief show units on this hexagon
         */
        private void hex_down(object sender, MouseButtonEventArgs e)
        {
            List <UnitTexture> unitsHere = PageGame.getUnitsOn(this.coord);

            pg.selectHex(this, unitsHere);


            this.select();
        }
        /*
         * \brief  Move unit to Hex
         * */
        public void tryToMoveUnit(Hex hex)
        {
            List <UnitTexture> ListEnemies = PageGame.getUnitsOn(hex.coord);


            if (ListEnemies.Count > 0)
            {
                UnitTexture ennemie = ListEnemies.First <UnitTexture>();
                int         Atthp   = this.selectedUnit.unit.currentHP;
                int         Deffhp  = ennemie.unit.currentHP;
                if (!game.currentPlayer.belongTo(ennemie.unit))
                {
                    int res   = this.selectedUnit.unit.fightAgainst(ennemie.unit);
                    int idyou = 0;
                    if (game.currentPlayer == game.list_players[1])
                    {
                        idyou = 1;
                    }
                    int idEn = 1;
                    if (idyou == 1)
                    {
                        idEn = 0;
                    }

                    switch (res)
                    {
                    case 0:
                        if (ennemie.unit.faction == Faction.elf)
                        {
                            Random r = new Random();
                            int    b = r.Next(2);
                            b = b % 2;
                            if (b == 0)
                            {
                                MessageBox.Show("Enemy run away");
                                ennemie.unit.currentHP = 1;
                                return;
                            }
                        }
                        if (selectedUnit.unit.faction == Faction.human)
                        {
                            selectedUnit.unit.addKill();
                        }
                        MessageBox.Show("Your unit killed your unit's enemy !");
                        unitsInGame.Remove(ennemie);
                        game.list_players[idEn].remove(ennemie.unit);
                        this.RemoveUnitOnMap(ennemie);
                        unitsInGame.Remove(ennemie);
                        ListEnemies = PageGame.getUnitsOn(hex.coord);
                        if (ListEnemies.Count == 0)
                        {
                            this.moveUnit(hex);
                        }
                        else
                        {
                            this.selectedUnit.unit.movementPoints = 0;
                        }
                        break;

                    case 1:
                        if (selectedUnit.unit.faction == Faction.elf)
                        {
                            Random r = new Random();
                            int    b = r.Next(2);
                            b = b % 2;
                            if (b == 0)
                            {
                                MessageBox.Show("your unit run away !");
                                this.selectedUnit.unit.currentHP = 1;
                                return;
                            }
                        }
                        MessageBox.Show("your unit has been killed !");
                        unitsInGame.Remove(selectedUnit);
                        game.list_players[1].remove(selectedUnit.unit);
                        this.RemoveUnitOnMap(selectedUnit);
                        break;

                    default:
                        int    looseAttHp  = Atthp - this.selectedUnit.unit.currentHP;
                        int    looseDeffHp = Deffhp - ennemie.unit.currentHP;
                        string msg         = "RESULT OF THE BATTLE \n";
                        msg += "******************** \n";
                        msg += game.list_players[idyou].name + " looses " + looseAttHp + " HP \n";
                        msg += game.list_players[idEn].name + " looses " + looseDeffHp + " HP";
                        MessageBox.Show(msg);
                        this.selectedUnit.unit.movementPoints = 0;
                        break;
                    }
                }
                else
                {
                    moveUnit(hex);
                }
            }
            else
            {
                moveUnit(hex);
            }
        }