Exemple #1
0
 public void CheckCaptures(Pawn sourcePawn)
 {
     if (sourcePawn.isKing)
     {
         if (currentGameRules.kingMovesDiagonally)
         {
             CheckDiagonalCapture(sourcePawn, 1, 1);
             CheckDiagonalCapture(sourcePawn, 1, -1);
             CheckDiagonalCapture(sourcePawn, -1, 1);
             CheckDiagonalCapture(sourcePawn, -1, -1);
         }
         else
         {
             if (sourcePawn.vertical > 1)
             {
                 if (sourcePawn.horizontal > 1)
                 {
                     CheckRegularCapture(sourcePawn, -1, -1);
                 }
                 if (sourcePawn.horizontal < currentGameRules.horizontalSize - 2)
                 {
                     CheckRegularCapture(sourcePawn, 1, -1);
                 }
             }
             if (sourcePawn.vertical < currentGameRules.verticalSize - 2)
             {
                 if (sourcePawn.horizontal > 1)
                 {
                     CheckRegularCapture(sourcePawn, -1, 1);
                 }
                 if (sourcePawn.horizontal < currentGameRules.horizontalSize - 2)
                 {
                     CheckRegularCapture(sourcePawn, 1, 1);
                 }
             }
         }
     }
     else if (currentGameRules.pawnCapturesBackwards)
     {
         if (sourcePawn.vertical > 1)
         {
             if (sourcePawn.horizontal > 1)
             {
                 CheckRegularCapture(sourcePawn, -1, -1);
             }
             if (sourcePawn.horizontal < currentGameRules.horizontalSize - 2)
             {
                 CheckRegularCapture(sourcePawn, 1, -1);
             }
         }
         if (sourcePawn.vertical < currentGameRules.verticalSize - 2)
         {
             if (sourcePawn.horizontal > 1)
             {
                 CheckRegularCapture(sourcePawn, -1, 1);
             }
             if (sourcePawn.horizontal < currentGameRules.horizontalSize - 2)
             {
                 CheckRegularCapture(sourcePawn, 1, 1);
             }
         }
     }
     else
     {
         if (sourcePawn.isWhite)
         {
             if (sourcePawn.vertical < currentGameRules.verticalSize - 2)
             {
                 if (sourcePawn.horizontal > 1)
                 {
                     CheckRegularCapture(sourcePawn, -1, 1);
                 }
                 if (sourcePawn.horizontal < currentGameRules.horizontalSize - 2)
                 {
                     CheckRegularCapture(sourcePawn, 1, 1);
                 }
             }
             else
             {
             }
         }
         else if (sourcePawn.vertical > 1)
         {
             if (sourcePawn.horizontal > 1)
             {
                 CheckRegularCapture(sourcePawn, -1, -1);
             }
             if (sourcePawn.horizontal < currentGameRules.horizontalSize - 2)
             {
                 CheckRegularCapture(sourcePawn, 1, -1);
             }
         }
     }
 }
Exemple #2
0
        public void LoadGame(String path)
        {
            GameState gs = null;

            try
            {
                IFormatter formatter = new BinaryFormatter();
                Stream     stream    = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
                gs = (GameState)formatter.Deserialize(stream);
                stream.Close();
            }
            catch {
                MessageBox.Show(Properties.Resources.LoadErrorBody, Properties.Resources.LoadErrorHeader);
            }
            if (gs != null)
            {
                currentGameRules = gs.gameRules;

                //resetting game-state parameters
                activePawn         = null;
                isWhiteTurn        = gs.isWhiteTurn;
                isCaptureAvailable = false;
                isMultiCapture     = gs.isMultiCapture;

                //populating board with pawns

                moveList.Clear();
                foreach (Target t in targetList)
                {
                    t.Dispose();
                }
                targetList.Clear();
                //made that way so panels from board wouldn't flicker when new game is created

                //create new board with new pawns
                List <Pawn> newPawns = new List <Pawn>();
                Panel[,] newPanels = InitializeBoard();

                Size size = new Size(this.tileSize, this.tileSize);
                for (int i = 0; i < gs.rawPawnList.Count; i++)
                {
                    newPawns.Add(new Pawn(gs.rawPawnList[i], newPanels, size, pawnClick));
                    if (i == gs.activePawnIndex)
                    {
                        activePawn = newPawns[i];
                    }
                }

                foreach (Pawn p in newPawns)
                {
                    p.ResetPawnGraphics();
                }
                if (boardPanels != null)
                {
                    for (int i = 0; i < boardPanels.GetLength(0); i++)
                    {
                        for (int j = 0; j < boardPanels.GetLength(1); j++)
                        {
                            boardPanels[i, j].Dispose();
                        }
                    }
                    for (int i = 0; i < pawnList.Count; i++)
                    {
                        pawnList[i].Dispose();
                    }
                    pawnList.Clear();
                }
                boardPanels = newPanels;
                pawnList    = newPawns;
                SwitchLabel();
                StartMoveState(isMultiCapture);
            }
        }