Esempio n. 1
0
 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));
 }
Esempio n. 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();
        }
Esempio n. 3
0
        private void LunchGame(object sender, RoutedEventArgs e)
        {
            if (RacePlayer1.Text == RacePlayer2.Text)
            {
                MessageBoxResult msg = MessageBox.Show("Players must have different races");
                return;
            }
            GameCreator gc = new GameCreator();

            gc.setPeopleJ1(RacePlayer1.Text);
            gc.setPeopleJ2(RacePlayer2.Text);
            GameBuilder gb;

            switch (TypeOfGame.Text)
            {
            case "Demo Game":
                gb = new DemoGameBuilder();
                break;

            case "Small Game":
                gb = new SmallGameBuilder();
                break;

            case "Classic Game":
                gb = new ClassicGameBuilder();
                break;

            default:
                gb = new DemoGameBuilder();
                break;
            }

            gc.gameBuilder = gb;
            gc.createGame();
            parent.game = gc.getGame();

            parent.game.list_players[0].name = NamePlayer1.Text;
            parent.game.list_players[1].name = NamePlayer2.Text;

            PageGame pg   = new PageGame();
            score    scJ1 = new score(parent.game.list_players[0]);
            score    scJ2 = new score(parent.game.list_players[1]);

            parent.center.Navigate(pg);
            parent.ScoreJ1.Navigate(scJ1);
            parent.ScoreJ2.Navigate(scJ2);
            parent.ScoreJ1.Visibility = Visibility.Visible;
            parent.ScoreJ2.Visibility = Visibility.Visible;
            parent.listScore.Add(scJ1);
            parent.listScore.Add(scJ2);
        }
Esempio n. 4
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);
            }
        }