Ejemplo n.º 1
0
 public UnitScore(UnitTexture u)
 {
     InitializeComponent();
     unitTex         = u;
     Race.Content    = u.unit.faction.ToString();
     HP.Content      = u.unit.currentHP;
     this.MP.Content = u.unit.movementPoints;
 }
Ejemplo n.º 2
0
 /**
  * \brief display all units on the map
  */
 private void displayUnits()
 {
     foreach (Player player in game.list_players)
     {
         foreach (Unit unit in player.faction.troops)
         {
             UnitTexture unitTexture = new UnitTexture(unit);
             unitsInGame.Add(unitTexture);
             displayUnitOnMap(unitTexture);
         }
     }
 }
Ejemplo n.º 3
0
        private void RemoveUnitOnMap(UnitTexture unitTexture)
        {
            int x = unitTexture.unit.coordinates.x;
            int y = unitTexture.unit.coordinates.y;

            // if odd row
            if (y % 2 != 0)
            {
                x++;
            }

            Grid SelectedRow = (Grid)VisualTreeHelper.GetChild(this.map, y);

            SelectedRow.Children.Remove(unitTexture);
            // VisualTreeHelper.GetChild(SelectedRow, x).
        }
Ejemplo n.º 4
0
        /**
         * \brief display a unit on the map
         */
        private void displayUnitOnMap(UnitTexture unitTexture)
        {
            int x = unitTexture.unit.coordinates.x;
            int y = unitTexture.unit.coordinates.y;

            // if odd row
            if (y % 2 != 0)
            {
                x++;
            }

            Grid SelectedRow = (Grid)VisualTreeHelper.GetChild(this.map, y);

            Grid.SetColumn(unitTexture, x);

            SelectedRow.Children.Add(unitTexture);
        }
Ejemplo n.º 5
0
        /*
         * \brief highlight the accessible hexagons for the specified unit
         * */
        private void highlightAccessibleHexagons(UnitTexture unitTex)
        {
            // highlight accessible hexagons
            List <Coordinates> adjacent = unitTex.unit.coordinates.getAdjacent();

            //string res = " x " + adjacent.First<Coordinates>().x + "y : " +  adjacent.First<Coordinates>().y;
            //MessageBoxResult mg = MessageBox.Show(res);

            deselectEverything();

            foreach (Coordinates coord in adjacent)
            {
                // if korrigan, highlight mountains too
                if (unitTex.unit.faction == Faction.korrigan && this.selectedHex.field == Field.Mountain)
                {
                    foreach (Hex hex in hexagons)
                    {
                        if ((hex.coord.x == coord.x && hex.coord.y == coord.y) || hex.field == Field.Mountain)
                        {
                            if (unitTex.unit.canMove(hex.field))
                            {
                                hex.highlight();
                            }
                        }
                    }
                }

                // else just highlight accessible hexagons
                else
                {
                    foreach (Hex hex in hexagons)
                    {
                        if (hex.coord.x == coord.x && hex.coord.y == coord.y)
                        {
                            if (unitTex.unit.canMove(hex.field))
                            {
                                hex.highlight();
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        /*
         * \brief show unit statistics and highlight accessible hexagons
         * */
        internal void selectUnit(UnitTexture unitTex)
        {
            highlightAccessibleHexagons(unitTex);
            this.selectedUnit = unitTex;

            foreach (UnitScore unitScore in parent.infoUnit.Children)
            {
                unitScore.unselect();
            }

            // update the control panel
            unitTex.unitscore.select();
            //parent.unitIcon.Source = new BitmapImage(new Uri("pack://application:,,,/textures/" + unitTex.unit.faction + ".png", UriKind.RelativeOrAbsolute));
            //parent.unitIcon.Visibility = Visibility.Visible;
            //parent.unitName.Content = "Beautiful unit";
            //parent.movementPoints.Content = unitTex.unit.movementPoints;
            UnitInformation info = new UnitInformation(unitTex.unit);

            parent.info.Navigate(info);
            info.Visibility = Visibility.Visible;
        }
Ejemplo n.º 7
0
        /*
         * \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);
            }
        }