Exemplo n.º 1
0
        public void HexClickedColor(object sender, MouseEventArgs e)
        {
            HexagonButton sender_Button = sender as HexagonButton;

            //sender_Button.BackColor = Color.FromArgb(255, 105, 180);
            hexClickedRound += 1;
        }
Exemplo n.º 2
0
        public void HexClicked(object sender, MouseEventArgs e)
        {
            //Console.WriteLine($"You pressed on tile: ({XCoordinate}, {YCoordinate}) {IsEdgeTile}");
            HexagonButton sender_Button = sender as HexagonButton;

            sender_Button.Enabled  = false;
            sender_Button.Passable = false;
            //PrintNeighbours();
        }
Exemplo n.º 3
0
 /// <summary>
 /// Finds the cost of a route.
 /// </summary>
 /// <param name="count"></param>
 /// <param name="hexToCheck"></param>
 /// <returns></returns>
 private int CheckParent(int count, HexagonButton hexToCheck)
 {
     if (hexToCheck.parent == null)
     {
         return(count);
     }
     else
     {
         return(CheckParent(count + 1, hexToCheck.parent));
     }
 }
Exemplo n.º 4
0
        public void PlaceHexagonButton(HexagonButton button)
        {
            //For at farve midten før man har klikket på skærmen.
            if (button.XCoordinate == MapTest.TotalHexagonColumns / 2 && button.YCoordinate == MapTest.TotalHexagonRows / 2)
            {
                button.BackColor = System.Drawing.Color.Aqua;
                button.Enabled   = false;
            }

            button.Left = CalculateButtonWidthOffset(button.XCoordinate, button.YCoordinate);
            button.Top  = CalculateButtonHeightOffset(button.YCoordinate);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Initialises and draws a hexagon button,
 /// and adds a click event calculates a new route when an HexButton is clicked.
 /// </summary>
 /// <param name="button"></param>
 /// <param name="map"></param>
 public void DrawButton(HexagonButton button, MapTest map)
 {
     button.Size      = new Size((int)(ConvertPointToPixel(formatting.ButtonHeight)), (int)(ConvertPointToPixel(formatting.ButtonWidth)));
     button.TabStop   = false;
     button.FlatStyle = FlatStyle.Flat;
     button.FlatAppearance.BorderSize = 0;
     button.BackColor   = Color.LightGray;
     button.Paint      += ButtonPainter;
     button.MouseClick += button.HexClicked;
     button.MouseClick += HexClickedColor;
     button.MouseClick += map.MousePositioner;
     gamePanel.Controls.Add(button);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Takes a HexagonButton grid, and the posistion to start from.
        /// </summary>
        /// <param name="hexMap"></param>
        /// <param name="startingHex"></param>
        public HexagonButton CalculateRoutes(HexagonButton[,] hexMap, HexagonButton startingHex)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            ResetAllButtons(hexMap);
            _pathsToEdge.Clear();
            _reachableHexList.Clear();
            _queue.Add(startingHex);

            while (_queue.Any())
            {
                HexagonButton currentHex = _queue.First();
                _queue.Remove(_queue.First());
                currentHex.Visited = true;
                if (currentHex.IsEdgeTile == false)
                {
                    foreach (HexagonButton hex in currentHex.neighbourList)
                    {
                        if (hex.Visited == false && hex.Passable == true)
                        {
                            hex.parent = currentHex;
                            _queue.Add(hex);
                            hex.Visited = true;
                            _reachableHexList.Add(hex);
                        }
                    }
                }

                else
                {
                    _pathsToEdge.Add(currentHex);
                }
            }

            //FirstButtonInPath = FindTheRoute(_pathsToEdge, _reachableHexList);

            stopWatch.Stop();
            // Get the elapsed time as a TimeSpan value.
            TimeSpan ts = stopWatch.Elapsed;

            // Format and display the TimeSpan value.
            string elapsedTime = ts.TotalMilliseconds.ToString();

            Console.WriteLine("RunTime " + elapsedTime);

            return(FindTheRoute(_pathsToEdge, _reachableHexList));
        }
Exemplo n.º 7
0
 /// <summary>
 /// Initialises the HexagonButton grid. Flags edge buttons.
 /// </summary>
 /// <param name="game"></param>
 public void CreateMap(GameForm game)
 {
     game.CalculateButtonDimension();
     for (int i = 0; i < _totalHexagonColumns; i++)
     {
         for (int j = 0; j < _totalHexagonRows; j++)
         {
             bool isEdge = false;
             if (i == 0 || i == _totalHexagonColumns - 1 || j == 0 || j == _totalHexagonRows - 1)
             {
                 isEdge = true;
             }
             hexMap[i, j] = new HexagonButton(i, j, isEdge);
             game.DrawButton(hexMap[i, j], this);
             game.PlaceHexagonButton(hexMap[i, j]);
         }
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// If there is multiple routes with the same cost, choose a random one.
        /// </summary>
        /// <param name="routes"></param>
        /// <returns></returns>
        private List <HexagonButton> ChooseRouteByRand(List <HexagonButton> routes)
        {
            var routeByRand   = new List <HexagonButton>();
            int routeToChoose = rnd.Next(0, routes.Count);

            HexagonButton edgeHex    = routes.ElementAt(routeToChoose);
            HexagonButton currentHex = edgeHex;

            do
            {
                routeByRand.Add(currentHex);
                currentHex.BackColor = System.Drawing.Color.FromArgb(50, 205, 50);
                currentHex           = currentHex.parent;
            } while (currentHex.parent != null);

            routeByRand.Reverse();

            return(routeByRand);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Calculates new route when HexagonButton is clicked.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void MousePositioner(object sender, MouseEventArgs e)
 {
     //Når der bliver klikket bliver tidligere punkt farvet gråt, så bliver der beregnet ny vej og koordinaterne til næste knap bliver assignet til xValue og yValue og knappen med disse koordinater farves Aqua.
     //næste to linjer er det som skal ske for den knap musen stop på i det tidligere trin.
     if (newGame)
     {
         hexMap[StartMouseXCoordinate, StartMouseYCoordinate].BackColor = System.Drawing.Color.LightGray;
         hexMap[StartMouseXCoordinate, StartMouseYCoordinate].Enabled   = true;
         _firstButtonInPath = path.CalculateRoutes(hexMap, hexMap[StartMouseXCoordinate, StartMouseYCoordinate]);
         newGame            = false;
     }
     else if (!newGame)
     {
         hexMap[MouseXCoordinate, MouseYCoordinate].BackColor = System.Drawing.Color.LightGray;
         hexMap[MouseXCoordinate, MouseYCoordinate].Enabled   = true;
         _firstButtonInPath = path.CalculateRoutes(hexMap, hexMap[MouseXCoordinate, MouseYCoordinate]);
     }
     //Nye position.
     MouseXCoordinate = _firstButtonInPath.XCoordinate;
     MouseYCoordinate = _firstButtonInPath.YCoordinate;
     hexMap[MouseXCoordinate, MouseYCoordinate].BackColor = System.Drawing.Color.Aqua;
     hexMap[MouseXCoordinate, MouseYCoordinate].Enabled   = false;
 }