Exemplo n.º 1
0
        public void RetrieveScores()
        {
            gwRef = GameWindow.ReturnGameWindowInstance();

            Dictionary <string, int> unsortedPlayerStats = new Dictionary <string, int>();
            Dictionary <string, int> sortedPlayerStats   = new Dictionary <string, int>();

            // Random value used solely for testing
            //Random r = new Random();

            foreach (PlayerController player in gwRef.playerControllers)
            {
                //int test = r.Next(-200, 200);

                unsortedPlayerStats.Add(player.playerName, player.myLivesAndScore.currentScore);
                Console.WriteLine(string.Format("Player result: {0}, score: {1}", player.playerName, player.myLivesAndScore.currentScore));
            }

            // Use OrderBy method to sort dictionary by value, then add the sorted values to the second dictionary.
            foreach (var item in unsortedPlayerStats.OrderBy(i => i.Value))
            {
                //MessageBox.Show(string.Format("Dictionary key/value: {0}", item));
                Console.WriteLine(item);
                sortedPlayerStats.Add(item.Key, item.Value);
            }

            // The sorted dictionary should have the top-scoring player as the last entry.
            topPlayer = sortedPlayerStats.Keys.Last();
            Console.WriteLine("{0} is the winner!", topPlayer);
            Winner.Content = topPlayer;

            player1Score.Content = unsortedPlayerStats.Values.ElementAt(0);
            player2Score.Content = unsortedPlayerStats.Values.ElementAt(1);
            player3Score.Content = unsortedPlayerStats.Values.ElementAt(2);
            player4Score.Content = unsortedPlayerStats.Values.ElementAt(3);

            // If there are only 4 players, empty the last two groups of labels
            if (GameWindow.ReturnNumberOfPlayer() <= 4)
            {
                player5Score.Content = "";
                player5Label.Content = "";
                player6Score.Content = "";
                player6Label.Content = "";
            }

            else
            {
                player5Score.Content = unsortedPlayerStats.Values.ElementAt(4);
                player6Score.Content = unsortedPlayerStats.Values.ElementAt(5);
            }
        }
Exemplo n.º 2
0
        private void setPlayerPos(int gridStartPos)
        {
            playerTileAnimOverlay = new PlayerUserControl();
            playerTileAnimOverlay.UpdateDirection(true);
            playerTile        = new Rectangle();
            playerTile.Height = tileSize;
            playerTile.Width  = tileSize;
            Grid.SetColumn(playerTile, 0);
            Grid.SetRow(playerTile, 0);

            Grid.SetZIndex(playerTile, 10); //set the layering position of the playerTile - can use Grid.SetZIndex or Canvas.SetZIndex(object,int layer)
            Grid.SetZIndex(playerTileAnimOverlay, 11);


            //------------------------------------------------------------------------------------------------
            //-------------------------------|           PLAYER 1             |-------------------------------
            //------------------------------------------------------------------------------------------------
            if (gridStartPos == 0)
            {
                relativePosition = new Point(64, 64);

                playerColour = Colors.Silver;
                playerImage  = "PlayerRight1.png";
                Debug.WriteLine("%%% Player {0}: player X: {1}, player Y: {2} /n", gridStartPos + 1, playerX, playerY);
            }
            //------------------------------------------------------------------------------------------------
            //-------------------------------|           PLAYER 2             |-------------------------------
            //------------------------------------------------------------------------------------------------
            else if (gridStartPos == 1)
            {
                if (GameWindow.ReturnNumberOfPlayer() == 6)
                {
                    // Become PLAYER 3
                    relativePosition = new Point(1344, 384);

                    playerImage = "PlayerRight1.png";
                    playerTileAnimOverlay.UpdateDirection(false);
                }
                else
                {
                    // Stay as PLAYER 2
                    relativePosition = new Point(1344, 64);

                    playerImage = "PlayerRight1.png";
                }
                playerColour = Colors.Red;
                Debug.WriteLine("%%% Player {0}: player X: {1}, player Y: {2} /n", gridStartPos + 1, playerX, playerY);
            }
            //------------------------------------------------------------------------------------------------
            //-------------------------------|           PLAYER 3             |-------------------------------
            //------------------------------------------------------------------------------------------------
            else if (gridStartPos == 2)
            {
                if (GameWindow.ReturnNumberOfPlayer() == 6)
                {
                    // Becomes PLAYER 5
                    relativePosition = new Point(64, 704);

                    playerImage = "PlayerRight1.png";
                }
                else
                {
                    // Stay as PLAYER 3
                    relativePosition = new Point(1344, 704);

                    playerImage = "PlayerRight1.png";
                }
                playerColour = Colors.Blue;
                Debug.WriteLine("%%% Player {0}: player X: {1}, player Y: {2} /n", gridStartPos + 1, playerX, playerY);
            }
            //------------------------------------------------------------------------------------------------
            //-------------------------------|           PLAYER 4             |-------------------------------
            //------------------------------------------------------------------------------------------------
            else if (gridStartPos == 3)
            {
                if (GameWindow.ReturnNumberOfPlayer() == 6)
                {
                    // BECOMES PLAYER 6
                    relativePosition = new Point(64, 384);
                    playerImage      = "PlayerRight1.png";
                }
                else
                {
                    // Stay as PLAYER 4
                    relativePosition = new Point(64, 704);

                    playerImage = "PlayerRight1.png";
                }
                Debug.WriteLine("%%% Player {0}: player X: {1}, player Y: {2} /n", gridStartPos + 1, playerX, playerY);
                playerColour = Colors.Yellow;
            }
            //------------------------------------------------------------------------------------------------
            //-------------------------------|           PLAYER 5             |-------------------------------
            //------------------------------------------------------------------------------------------------
            else if (gridStartPos == 4)
            {
                relativePosition = new Point(1344, 64);

                playerColour = (Color)ColorConverter.ConvertFromString("#FFAC02FB");
                playerImage  = "PlayerRight1.png";
                Debug.WriteLine("%%% Player {0}: player X: {1}, player Y: {2} /n", gridStartPos + 1, playerX, playerY);
            }
            //------------------------------------------------------------------------------------------------
            //-------------------------------|           PLAYER 6             |-------------------------------
            //------------------------------------------------------------------------------------------------
            else if (gridStartPos == 5)
            {
                relativePosition = new Point(1344, 704);

                playerColour = Colors.Green;
                playerImage  = "PlayerRight1.png";
                //Debug.WriteLine("%%% Player {0}: player X: {1}, player Y: {2} /n", gridStartPos + 1, playerX, playerY);
            }

            else
            {
                return;
            }


            // Update the player's position in the list
            for (int i = 0; i < GameWindow.ReturnPlayerList().Count; i++)
            {
                if (GameWindow.ReturnPlayerList()[i].playerName == playerName)
                {
                    GameWindow.ReturnPlayerList()[i].playerPosition = relativePosition;
                    MessageBox.Show(string.Format("{0} found at position: {1}.", playerName, relativePosition));
                }
            }

            //playerTile.Fill = new ImageBrush(new BitmapImage(new Uri(@"./Resources/" + playerImage, UriKind.Relative)));
            playerX         = (int)relativePosition.X / tileSize;
            playerY         = (int)relativePosition.Y / tileSize;
            playerTile.Fill = new SolidColorBrush(Colors.Transparent);
            localGameGrid.Children.Add(playerTileAnimOverlay);
            localGameGrid.Children.Add(playerTile);
        }