Exemple #1
0
 /// <summary>
 /// Switches the indicator to the player whose turn it is.
 /// </summary>
 /// <param name="currentPlayer">The player whose turn it is</param>
 public void SwitchVisualIndicators(Player currentPlayer)
 {
     if (currentPlayer.GetPosition() == Player.Position.South)
     {
         _visualIndicatorSouth.SwitchOn();
         _visualIndicatorNorth.SwitchOff();
         PlayerNameFieldSouth.Foreground = Application.Current.Resources["GamePageTextOn"] as SolidColorBrush;
         PlayerNameFieldNorth.Foreground = Application.Current.Resources["GamePageTextOff"] as SolidColorBrush;
     }
     else
     {
         _visualIndicatorSouth.SwitchOff();
         _visualIndicatorNorth.SwitchOn();
         PlayerNameFieldSouth.Foreground = Application.Current.Resources["GamePageTextOff"] as SolidColorBrush;
         PlayerNameFieldNorth.Foreground = Application.Current.Resources["GamePageTextOn"] as SolidColorBrush;
     }
 }
Exemple #2
0
        /// <summary>Logs the board contents for debug purposes.</summary>
        public void LogBoard(Player firstPlayer, Player secondPlayer, Logging.LogLevel logLevel)
        {
            if ((Logging.I.GetLogLevel() & logLevel) == Logging.LogLevel.Off)
            {
                // Small optimization to leave as soon as possible if logging is not active anyway.
                return;
            }

            if (firstPlayer == secondPlayer)
            {
                Logging.I.LogMessage("LogBoard: first and second player are the same: " + firstPlayer + ".\n");
                return;
            }

            // We find out who of the players is south and who is north;
            Player south = null;
            Player north = null;
            if (firstPlayer.GetPosition() == Player.Position.South)
            {
                south = firstPlayer;
                north = secondPlayer;
            }
            else
            {
                south = secondPlayer;
                north = firstPlayer;
            }

            // Now we start building up the log string:
            string logString = ("Game board:\n                ");

            for (int pitIndex = _numHousesPerPlayer - 1; pitIndex >= 0; --pitIndex)
            {
                int numberOfSeeds = GetPitOfPlayer(north, pitIndex).GetNumberofSeeds();
                if (numberOfSeeds < 10) {
                    logString += " ";
                }
                logString += numberOfSeeds + " ";
            }

            logString += "\n              " + GetKalahOfPlayer(north).GetNumberofSeeds();
            for (int index = 0; index < ((3*_numHousesPerPlayer)+3); ++index)
            {
                logString += " ";
            }
            logString += (GetKalahOfPlayer(south).GetNumberofSeeds() + "\n                ");

            for (int pitIndex = 0; pitIndex < _numHousesPerPlayer; ++pitIndex)
            {
                int numberOfSeeds = GetPitOfPlayer(south, pitIndex).GetNumberofSeeds();
                if (numberOfSeeds < 10) {
                    logString += " ";
                }
                logString += numberOfSeeds + " ";
            }

            Logging.I.LogMessage(logString + "\n", logLevel);
        }
Exemple #3
0
        /// <summary>
        /// Prints a message to the screen at the center position, using a globalized string taken from the corresponding resource file.
        /// This message automatically vanishes after a few seconds.
        /// </summary>
        /// <param name="messageKey">The resource key to be used</param>
        /// <param name="relevantPlayer">The player whose turn it is currently</param>
        /// <param name="args">0 or more parameters for the resource key</param>
        public async void PrintFadingMsg(String messageKey, Player relevantPlayer, params object[] args)
        {
            string message = KalahaResources.I.GetMsg(messageKey, args);
            MessageFieldCenter.Text = message;

            // Define the angle of the visual indicator:
            MessageFieldCenter.RenderTransformOrigin = new Point(0.5, 0.5);         // Rotate around the center
            RotateTransform myRotateTransform = new RotateTransform();

            if ((relevantPlayer.GetPosition() == Player.Position.North) && Presenter.I.TabletModeIsActive())
            {
                // Put the name upside down if we are told to do so:
                myRotateTransform.Angle = 180;
            }
            else
            {
                // Leave the name in the "usual" angle:
                myRotateTransform.Angle = 0;
            }

            MessageFieldCenter.RenderTransform = myRotateTransform;

            // Print the actual message to the screen by fading in:
            await MessageFieldCenter.FadeIn(TimeSpan.FromMilliseconds(1500));   // The parameter defines the time that the message is visible

            // ... and out:
            await MessageFieldCenter.FadeOut(TimeSpan.FromMilliseconds(200));
        }
Exemple #4
0
        /// <summary>
        /// Prints a message to the screen at the center position, using a globalized string taken from the corresponding resource file.
        /// This message does not vanish.
        /// </summary>
        /// <param name="messageKey">The resource key to be used</param>
        /// <param name="relevantPlayer">The player whose turn it is currently</param>
        /// <param name="args">0 or more parameters for the resource key</param>
        public void PrintFixedMsg(String messageKey, Player relevantPlayer, params object[] args)
        {
            string message = KalahaResources.I.GetMsg(messageKey, args);
            FixedMessageFieldCenter.Text = message;

            if ((relevantPlayer.GetPosition() == Player.Position.North) && Presenter.I.TabletModeIsActive())
            {
                // Put the words upside down in order for the current player to be easily readable:

                // Define the angle of the visual indicator:
                FixedMessageFieldCenter.RenderTransformOrigin = new Point(0.5, 0.5);         // Rotate around the center
                RotateTransform myRotateTransform = new RotateTransform();
                // Put the name upside down if we are told to do so:
                myRotateTransform.Angle = 180;
                FixedMessageFieldCenter.RenderTransform = myRotateTransform;
            }
        }
Exemple #5
0
        /// <summary>
        /// Sets the pit with the given index to state "selected" by making visible the according image.
        /// Sets all other pits unselected. Sets all pits unhighlighted.
        /// </summary>
        /// <param name="pitIndexSelected"></param>
        public void SetSelected(int pitIndexSelected, Player currentPlayer)
        {
            int numHouses = GetNumOfHousesPerPlayer();

            if (currentPlayer.GetPosition() == Player.Position.North)
            {
                pitIndexSelected += numHouses + 1;
            }

            for (int pitIndex = 0; pitIndex < numHouses*2+1; ++pitIndex)
            {
                if (pitIndex == numHouses)
                {
                    // Skip the Kalah:
                    continue;
                }

                // Unhighlight the pits in any case:
                UnHighlight(pitIndex);

                if (pitIndex == pitIndexSelected)
                {
                    _pit[pitIndex].SetSelected();
                }
                else
                {
                    _pit[pitIndex].SetUnSelected();
                }
            }
        }
Exemple #6
0
        /// <param name="player">The player whose pit coordinates are requested</param>
        /// <param name="pitIndex">The index of the pit. May be between 0 and the number of pits-1.</param>
        /// <returns>The center coordinate on the "1000-page" of the given pit</returns>
        public Point GetTopLeftCornerOfPit(Player player, int pitIndex)
        {
            // Take over the numer of pits in order not to call the method each time:
            int numPits = GetNumOfHousesPerPlayer();

            if (pitIndex >= numPits)
            {
                throw new PSTException("GetCenterOfPit: Unknown pitIndex: " + pitIndex);
            }

            // Set the internal index of the first pit in the row:
            int internalStartIndex = ((player.GetPosition() == Player.Position.South) ? 0 : (numPits + 1));

            return (_pit[internalStartIndex + pitIndex].GetTopLeftCorner());
        }
Exemple #7
0
        /// <param name="player">The player whose Kalah coordinates are requested</param>
        /// <returns>The center coordinate on the "1000-page" of the given player</returns>
        public Point GetTopLeftCornerOfKalah(Player player)
        {
            // Take over the numer of pits in order not to call the method each time:
            int numPits = _gameBoard.GetNumOfHousesPerPlayer();

            // Set the internal index of the first pit in the row:
            int internalStartIndex = ((player.GetPosition() == Player.Position.South) ? 0 : (numPits + 1));

            return (_pit[internalStartIndex + numPits].GetTopLeftCorner());
        }
Exemple #8
0
        /// <summary>Enables the non-empty houses of the given player and disables all of his opponent.</summary>
        /// <param name="player">The player whose turn it is</param>
        public void EnableHousesOfPlayer(Player player)
        {
            int numPits = GetNumOfHousesPerPlayer();
            int startIndexOfPlayer = ((player.GetPosition() == Player.Position.South) ? 0 : numPits + 1);
            int startIndexOfOpponent = ((player.GetPosition() == Player.Position.South) ? numPits + 1 : 0);

            for (int pitIndex = 0; pitIndex < numPits; ++pitIndex)
            {
                if (_pit[pitIndex + startIndexOfPlayer].GetNumberOfSeeds() > 0)
                {
                    _pit[pitIndex + startIndexOfPlayer].EnableTouchField();
                }
                else
                {
                    _pit[pitIndex + startIndexOfPlayer].DisableTouchField();
                }
                _pit[pitIndex + startIndexOfOpponent].DisableTouchField();
            }
        }
Exemple #9
0
 /// <returns>The opponent of the given player</returns>
 /// <param name="player">The player whose opponent is to be returned</param>
 /// <returns></returns>
 private Player Opponent(Player player)
 {
     if (player.GetPosition() == Player.Position.South)
     {
         return _northPlayer;
     }
     else
     {
         return _southPlayer;
     }
 }