Exemplo n.º 1
0
        // Survol sur une case

        private void survolCase(object sender, MouseEventArgs e)
        {
            // Supprimer ancienne case survolee
            if (this.selectedTile != null)
            {
                this.mapGrid.Children.Remove(this.selectedTile);
            }

            // Ajoute une bordure auround de la case survolee
            var    selection = sender as Border;
            Border bordure   = new Border();

            bordure.Background           = FabriqueImage.getInstance().getSelection(false);
            bordure.Width                = tailleCase;
            bordure.Height               = tailleCase;
            bordure.Cursor               = Cursors.Hand;
            bordure.MouseLeftButtonDown += new MouseButtonEventHandler(this.clicGaucheCase);
            Canvas.SetLeft(bordure, Canvas.GetLeft(selection));
            Canvas.SetTop(bordure, Canvas.GetTop(selection));
            this.mapGrid.Children.Add(bordure);
            this.selectedTile = bordure;


            if (this.game.getMap().getTile(this.getY(Canvas.GetTop(selection)), this.getX(Canvas.GetLeft(selection))).getUnit().Count() > 0)
            {
                afficherUniteCase(this.game.getMap().getTile(this.getY(Canvas.GetTop(selection)), this.getX(Canvas.GetLeft(selection))).getUnit());
            }
            else if (this.game.getMap().getTile(this.selectX, this.selectY).getUnit().Count() > 0)
            {
                afficherUniteCase(this.game.getMap().getTile(this.selectX, this.selectY).getUnit());
            }
        }
Exemplo n.º 2
0
        /// Remplissage de la map

        private void creerCarte(object sender, RoutedEventArgs e)
        {
            int t = 0;
            int l = 0;

            for (int x = 0; x < this.game.getMap().getSize(); x++)
            {
                if ((x % 2) != 0)
                {
                    l = 50;
                }
                else
                {
                    l = 0;
                }

                for (int y = 0; y < this.game.getMap().getSize(); y++)
                {
                    // Creation et positionnement de la case
                    Border hexagone = new Border();
                    hexagone.Background = FabriqueImage.getInstance().getBrushCase(this.game.getMap().getTile(x, y));
                    Canvas.SetLeft(hexagone, l);
                    Canvas.SetTop(hexagone, t);
                    hexagone.Width  = tailleCase;
                    hexagone.Height = tailleCase;
                    hexagone.Cursor = Cursors.Hand;
                    hexagone.MouseLeftButtonDown += new MouseButtonEventHandler(this.clicGaucheCase);
                    hexagone.MouseEnter          += new MouseEventHandler(this.survolCase);
                    this.mapGrid.Children.Add(hexagone);
                    l = l + 100;
                }
                t = t + 75;
            }

            // Determine la taille du canvas
            this.mapGrid.Width  = this.game.getMap().getSize() * 100;
            this.mapGrid.Height = this.game.getMap().getSize() * 75;
            this.mapGrid.HorizontalAlignment = HorizontalAlignment.Center;
            this.mapGrid.VerticalAlignment   = VerticalAlignment.Center;

            // Ajoute les unites sur la map
            ajoutUnite();

            // Selectionne la premiere case cliquee
            if (this.game.getMap().getTile(0, 0).isTile(this.player))
            {
                this.selectX = 0;
                this.selectY = 0;
            }
            else
            {
                this.selectX = this.game.getMap().getSize() - 1;
                this.selectY = this.game.getMap().getSize() - 1;
            }
            selectionCase();
        }
Exemplo n.º 3
0
        /// Placement des unités sur la map

        private void ajoutUnite()
        {
            int t = 0;
            int l = 10;

            // Supprime les anciennes unites
            for (int x = 0; x < this.unitBoard.GetLength(0); x++)
            {
                for (int y = 0; y < this.unitBoard.GetLength(1); y++)
                {
                    this.mapGrid.Children.Remove(this.unitBoard[x, y]);
                }
            }


            for (int x = 0; x < this.unitBoard.GetLength(0); x++)
            {
                if ((x % 2) != 0)
                {
                    l = 50;
                }
                else
                {
                    l = 0;
                }

                for (int y = 0; y < this.unitBoard.GetLength(1); y++)
                {
                    List <IUnit> units = this.game.getMap().getTile(x, y).getUnit();

                    if (units.Count() > 0)
                    {
                        // Ajout image unit
                        Border hexagoneUnite = new Border();
                        hexagoneUnite.Background = FabriqueImage.getInstance().getBrushUnite(units[0]);
                        TextBlock unitText = new TextBlock();
                        hexagoneUnite.Width  = tailleCase;
                        hexagoneUnite.Height = tailleCase;

                        hexagoneUnite.MouseLeftButtonDown += new MouseButtonEventHandler(this.clicGaucheCase);
                        hexagoneUnite.MouseEnter          += new MouseEventHandler(this.survolCase);
                        this.unitBoard[x, y] = hexagoneUnite;
                        this.mapGrid.Children.Add(hexagoneUnite);
                    }
                    l = l + 100;
                }
                t = t + 75;
            }
        }
Exemplo n.º 4
0
        // Selection d'une case

        private void selectionCase()
        {
            // Supprime bordure de l'ancienne case selectionnee
            if (this.clicTile != null)
            {
                this.mapGrid.Children.Remove(this.clicTile);
            }

            // Ajoute bordure sur la nouvelle case selectionnee
            Border bordure = new Border();

            bordure.Background           = FabriqueImage.getInstance().getSelection(true);
            bordure.Width                = tailleCase;
            bordure.Height               = tailleCase;
            bordure.Cursor               = Cursors.Hand;
            bordure.MouseLeftButtonDown += new MouseButtonEventHandler(this.clicGaucheCase);
            bordure.MouseEnter          += new MouseEventHandler(this.survolCase);
            int ligne1 = 0;

            if (this.selectY % 2 != 0)
            {
                ligne1 = (this.selectX * 100) + 50;
            }
            else
            {
                ligne1 = this.selectX * 100;
            }

            Canvas.SetLeft(bordure, ligne1);
            Canvas.SetTop(bordure, this.selectY * 75);
            this.mapGrid.Children.Add(bordure);
            this.clicTile = bordure;

            // Affiche les unites de la case selectionnee
            afficherUniteCase(this.game.getMap().getTile(this.selectY, this.selectX).getUnit());
        }
Exemplo n.º 5
0
        // Affichage des unités

        private void afficherUniteCase(List <IUnit> lunite)
        {
            //effacerSelection();
            string vie       = "";
            string attaque   = "";
            string defense   = "";
            string mouvement = "";
            int    i         = 0;
            int    j         = 0;
            int    cpt       = 0;

            effacementGrilleUnite();

            //On vérifie que la case contient bien des unités
            if (lunite.Count() > 0)
            {
                //Création de la grille qui va contenir les unités dans la barre d'information
                unitGrid = new Grid();
                for (i = 0; i < 3; i++)
                {
                    unitGrid.RowDefinitions.Add(new RowDefinition()
                    {
                        Height = new GridLength(3, GridUnitType.Star)
                    });
                    unitGrid.ColumnDefinitions.Add(new ColumnDefinition()
                    {
                        Width = new GridLength(3, GridUnitType.Star)
                    });
                }
                Grid.SetRow(unitGrid, 0);
                Grid.SetColumn(unitGrid, 1);
                this.barreInfo.Children.Add(unitGrid);
                this.unitGrid.Focus();

                for (i = 0; i < 5; i++)
                {
                    for (j = 0; j < 2; j++)
                    {
                        if (cpt < lunite.Count())
                        {
                            //Mise en place de la grille interne
                            Grid grille = new Grid();
                            //grille.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });
                            grille.RowDefinitions.Add(new RowDefinition()
                            {
                                Height = new GridLength(3, GridUnitType.Star)
                            });
                            Grid.SetRow(grille, i);
                            Grid.SetColumn(grille, j);
                            grille.Cursor = Cursors.Hand;
                            unitGrid.Children.Add(grille);

                            //Ajout de l'image de l'unité à la grille interne
                            Rectangle image = new Rectangle();
                            image.Fill   = FabriqueImage.getInstance().getBrushUnite(lunite[cpt]);
                            image.Width  = tailleCase;
                            image.Height = tailleCase;
                            image.HorizontalAlignment = HorizontalAlignment.Center;
                            Grid.SetRow(image, 0);
                            Grid.SetColumn(image, 0);
                            grille.Children.Add(image);

                            //Ajout des caractéristiques de l'unité à la grille interne
                            TextBlock texte = new TextBlock();
                            texte.TextAlignment = TextAlignment.Left;
                            vie        = "Vie : " + lunite[cpt].getHealthPts();
                            mouvement  = "Mouvement : " + lunite[cpt].getMovePts();
                            attaque    = "Attaque : " + lunite[cpt].getAttackPts();
                            defense    = "Defense : " + lunite[cpt].getDefensePts();
                            texte.Text = vie + "\n" + mouvement + "\n" + attaque + "\n" + defense;
                            Grid.SetRow(texte, 1);
                            Grid.SetColumn(texte, 0);
                            grille.Children.Add(texte);

                            // Enregistre les unites
                            this.selectUnit[i, j] = (Unit)lunite[cpt];
                            cpt++;
                        }
                    }
                }
            }
        }