Exemple #1
0
        /// <summary>
        /// Function that calls the selected chess piece control function.
        /// </summary>
        private void MovePiece()
        {
            List <int[, ]> locations = null;

            locations = ProtectKing.GetListFromDic(ChessList.GetList(white)[selectedChessPiece].GetID);
            if (locations == null)
            {
                locations = ProtectKing.GetListFromProtectingKingDic(ChessList.GetList(white)[selectedChessPiece].GetID);
            }
            if (locations != null)
            {
                ChessList.GetList(white)[selectedChessPiece].SetEndLocations = locations;
            }
            isActive = false;
            ChessList.GetList(white)[selectedChessPiece].Control();
            isActive = true;
        }
Exemple #2
0
 /// <summary>
 /// Function that calls functions needed for playing the game.
 /// </summary>
 public void Control()
 {
     isActive = true;
     do
     {
         bool didNotSurrender = HoverOver();
         if (didNotSurrender)
         {
             MovePiece();
             didMove = ChessList.GetList(white)[selectedChessPiece].CouldMove;
         }
         else
         {
             break;
         }
     } while (!didMove);
     isActive = false;
 }
Exemple #3
0
        /// <summary>
        /// Lets the player hover over a felt on the boardgame and gets the ID of that felt. If the ID is a chesspiece, it will be highlighted.
        /// </summary>
        private bool HoverOver()
        {
            string lastMapLocationID;
            int?   lastPiece = 0;

            ChessList.GetList(white)[(int)lastPiece].IsHoveredOn(true);
            bool hasSelected   = false;
            bool?friendlyPiece = true;

            location = ChessList.GetList(white)[0].GetMapLocation;
            SquareHighLight(true);
            do
            {
                bool?selected = FeltMove(location);
                if (lastPiece != null && !GameStates.GameEnded) //if a previous chess piece has been hovered over, remove the highlight.
                {
                    if (friendlyPiece == true)
                    {
                        ChessList.GetList(white)[(int)lastPiece].IsHoveredOn(false);
                    }
                    else if (friendlyPiece == false)
                    {
                        ChessList.GetList(!white)[(int)lastPiece].IsHoveredOn(false);
                    }
                    lastPiece         = null;
                    lastMapLocationID = null;
                    friendlyPiece     = null;
                }
                string squareID = MapMatrix.Map[location[0], location[1]];
                if (selected == null)
                {
                    if (GameStates.GameEnded)
                    {
                        hasSelected = true;
                        return(false);
                    }
                }
                else if (squareID != "")                //is there a chess piece on the location
                {
                    if (squareID.Split(':')[0] == team) //is it on the team
                    {
                        int posistion = 0;              //used for later finding the posistion in the List<ChessPiece> the chosen chesspiece got.
                        foreach (ChessPiece piece in ChessList.GetList(white))
                        {
                            if (piece.GetID == squareID)
                            { //correct chess piece and highlight it
                                piece.IsHoveredOn(true);
                                lastMapLocationID = piece.GetID;
                                lastPiece         = posistion;
                                friendlyPiece     = true;
                                if (selected == true)
                                {
                                    if (ProtectKing.Protect.Count != 0) //ensures only pieces that can protect the king can be moved
                                    {
                                        foreach (string id in ProtectKing.Protect)
                                        {
                                            if (piece.GetID == id)
                                            {
                                                hasSelected        = true;
                                                selectedChessPiece = posistion;
                                                ChessList.GetList(white)[(int)lastPiece].IsHoveredOn(false);
                                                break;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        hasSelected        = true;
                                        selectedChessPiece = posistion;
                                        ChessList.GetList(white)[(int)lastPiece].IsHoveredOn(false);
                                        break;
                                    }
                                }
                                break;
                            }
                            posistion++;
                        }
                    }
                    else
                    {
                        int posistion = 0;
                        if (!Settings.CanHighLight)
                        {
                            foreach (ChessPiece chePie in ChessList.GetList(!white))
                            {
                                if (chePie.GetID == squareID)
                                {
                                    friendlyPiece = false;
                                    chePie.IsHoveredOn(true, true);
                                    lastPiece = posistion;
                                    break;
                                }
                                posistion++;
                            }
                        }
                    }
                }
            } while (!hasSelected);
            SquareHighLight(false);
            return(true);
        }
Exemple #4
0
        /// <summary>
        /// Displays the stats of the game.
        /// </summary>
        private void GameStatsDisplay()
        {
            string mainColour      = Settings.CVTS.BrightWhiteForeground;
            string highLightColour = Settings.CVTS.BrightCyanForeground;
            string underscore      = Settings.CVTS.Underscore;
            string underscore_off  = Settings.CVTS.Underscore_Off;
            string reset           = Settings.CVTS.Reset;
            string enterColour     = Settings.CVTS.BrightRedForeground;

            Console.Clear();
            Console.CursorTop = Settings.MenuOffset[1];
            Console.WriteLine($"\x1b]2;Chess: Game Stats\x07" + //sets the title
                              $"{"".PadLeft(Settings.MenuTitleOffset[0])}{mainColour}{underscore}Stats:{reset}{Environment.NewLine}" +
                              $"{"".PadLeft(Settings.MenuOffset[0])}{mainColour}Amount of white pieces left: {highLightColour}{underscore}{ChessList.GetList(true).Count}{underscore_off}{mainColour}.{reset}{Environment.NewLine}" +
                              $"{"".PadLeft(Settings.MenuOffset[0])}{mainColour}Amount of black pieces left: {highLightColour}{underscore}{ChessList.GetList(false).Count}{underscore_off}{mainColour}.{reset}{Environment.NewLine}" +
                              $"{"".PadLeft(Settings.MenuOffset[0])}{mainColour}Amount of turns: {highLightColour}{underscore}{GameStates.TurnCounter}{underscore_off}{mainColour}.{reset}{Environment.NewLine}" +
                              $"{"".PadLeft(Settings.MenuOffset[0])}{mainColour}Turns since last capture or pawn move: {highLightColour}{underscore}{GameStates.TurnDrawCounter}{underscore_off}{mainColour}.{reset}{Environment.NewLine}" +
                              $"{"".PadLeft(Settings.MenuOffset[0])}{enterColour}Enter {mainColour}to return.{reset}");
            Console.ReadLine();
            Console.Clear();
        }