Example #1
0
        /// <summary>
        /// test si un grand rock est possible
        /// </summary>
        /// <param name="color"></param>
        /// <returns></returns>
        public bool IsSmallCastling(string color)
        {
            if (color == strColor1)
            {
                if (tabPiece[7][7] == null)
                {
                    return(false);
                }
                if (tabPiece[7][7].GetType() != typeof(Rook))
                {
                    return(false);
                }
                if (tabPiece[7][7].IsAlreadyMove)
                {
                    return(false);
                }

                if (tabPiece[7][6] != null || tabPiece[7][5] != null)
                {
                    return(false);
                }
                if (tabPiece[7][4] == null)
                {
                    return(false);
                }
                if (tabPiece[7][4].GetType() != typeof(King))
                {
                    return(false);
                }
                King k = (King)tabPiece[7][4].Clone();
                if (k.IsAlreadyMove)
                {
                    return(false);
                }
                k.PositionX = 5;
                if (k.IsCheck(this))
                {
                    return(false);
                }
                k.PositionX = 6;
                if (k.IsCheck(this))
                {
                    return(false);
                }
            }
            else
            {
                if (tabPiece[0][7] == null)
                {
                    return(false);
                }
                if (tabPiece[0][7].GetType() != typeof(Rook))
                {
                    return(false);
                }
                if (tabPiece[0][7].IsAlreadyMove)
                {
                    return(false);
                }
                if (tabPiece[0][6] != null || tabPiece[0][5] != null)
                {
                    return(false);
                }
                if (tabPiece[0][4] == null)
                {
                    return(false);
                }
                if (tabPiece[0][4].GetType() != typeof(King))
                {
                    return(false);
                }
                King k = (King)tabPiece[0][4].Clone();
                if (k.IsAlreadyMove)
                {
                    return(false);
                }
                k.PositionX = 5;
                if (k.IsCheck(this))
                {
                    return(false);
                }
                k.PositionX = 6;
                if (k.IsCheck(this))
                {
                    return(false);
                }
            }
            return(true);
        }
Example #2
0
        /// <summary>
        /// quand l'utilisateur clic sur une picture box si aucune pièce n'est dessus rien ne se passe, si il presse sur une pièce adverse rien ne se passe, si il pressque sur une de ses pièces les déplacements s'affichent
        /// si il presse sur une des picturebox afficher en vert la pièces séléctionner plus tôt se déplace
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void PictureBox_click(object sender, EventArgs e)
        {
            PictureBox pct = (PictureBox)sender;

            string s = pct.Tag.ToString();

            string[] t = s.Split('/');
            if (bIsGameTurned)
            {
                int[] Coup = new int[2];
                Coup[0] = Convert.ToInt32(t[0]);
                Coup[1] = Convert.ToInt32(t[1]);
                Coup[0] = DisplayBoardGame.Length - 1 - Coup[0];
                Coup[1] = DisplayBoardGame[Coup[0]].Length - 1 - Coup[1];

                t[0] = Convert.ToString(Coup[0]);
                t[1] = Convert.ToString(Coup[1]);
            }
            if (pct.BackColor == Color.Green)
            {
                bool bFlash = false;
                foreach (Game g in FlashGameForDraw)
                {
                    if (CompareGame(game, g))
                    {
                        bFlash = true;
                    }
                }
                if (bFlash)
                {
                    game.ConterEqualGame++;
                }
                else
                {
                    game.ConterEqualGame = 0;
                }
                FlashGameForDraw.Add(game.Clone());
                if (FlashGameForDraw.Count > 6)
                {
                    FlashGameForDraw.Remove(FlashGameForDraw[0]);
                }
                int[] move = new int[2];
                move[0] = Convert.ToInt32(t[0]);
                move[1] = Convert.ToInt32(t[1]);

                game.Players[0].LastPosition = move;

                Piece LastPiece = game.Players[0].LastPiece;
                if (bIsGameTurned)
                {
                    TurnGame();
                    PlayDisplayMove();
                }
                else
                {
                    PlayDisplayMove();
                    TurnGame();
                }
                game.Play();
                LoadColor();
                PlacementParts();
                if (LastPiece.GetType() == typeof(Pawn))
                {
                    if (game.isPawnLastLine((Pawn)LastPiece))
                    {
                        CustomMsgBox msg = new CustomMsgBox();
                        msg.ShowDialog();
                        Type Result = msg.Return;
                        game.ChangePawn(Result);

                        int[] MoveDisplay = new int[2];
                        MoveDisplay[0] = move[0];
                        MoveDisplay[1] = move[1];
                        if (bIsGameTurned)
                        {
                            MoveDisplay[0] = DisplayBoardGame.Length - 1 - MoveDisplay[0];
                            MoveDisplay[1] = DisplayBoardGame[move[0]].Length - 1 - MoveDisplay[1];
                        }
                        DisplayBoardGame[MoveDisplay[0]][MoveDisplay[1]] = game.TabPiece[move[0]][move[1]];
                        PlacementParts();
                    }
                }
                if (strActifColor == game.Color1)
                {
                    strActifColor = game.Color2;
                }
                else
                {
                    strActifColor = game.Color1;
                }
                if (game.IsCheckmat(strActifColor))
                {
                    if (strActifColor == game.Color1)
                    {
                        MessageBox.Show("échec et math " + strNamePlayer1 + " a gagné");
                    }
                    else
                    {
                        MessageBox.Show("échec et math " + strNamePlayer2 + " a gagné");
                    }
                    btnExit_Click(new object(), new EventArgs());
                }
                else if (game.IsDraw(strActifColor))
                {
                    MessageBox.Show("Match nul");
                    btnExit_Click(new object(), new EventArgs());
                }
                else if (game.IsKingCheck(strActifColor))
                {
                    MessageBox.Show("Echec");
                }
                game.NextPlayer();
                game.AskMovePlayer();
            }
            else if (pct.BackColor == Color.Orange)
            {
                int[] Coup = new int[2];
                Coup[0] = Convert.ToInt32(t[0]);
                Coup[1] = Convert.ToInt32(t[1]);
                game.Players[0].LastPosition = Coup;
                game.DoCastling(strActifColor);
                PlacementParts();
                LoadColor();
                game.NextPlayer();
                game.AskMovePlayer();
                if (strActifColor == game.Color1)
                {
                    strActifColor = game.Color2;
                }
                else
                {
                    strActifColor = game.Color1;
                }
            }
            else
            {
                LoadColor();
                Piece p = game.TabPiece[Convert.ToInt32(t[0])][Convert.ToInt32(t[1])];
                if (p != null)
                {
                    if (strActifColor == p.Color)
                    {
                        game.SetMovePiece(p);

                        List <String> Move        = p.Move;
                        List <String> specialMove = new List <string>();
                        if (p.GetType() == typeof(King))
                        {
                            King k = (King)p;
                            specialMove   = k.Specialmove;
                            k.Specialmove = new List <string>();
                        }
                        if (bIsGameTurned)
                        {
                            Move = TurnedList(Move);
                            if (p.GetType() == typeof(King))
                            {
                                specialMove = TurnedList(specialMove);
                            }
                        }
                        ShowTraveling(Move, Color.Green);

                        if (p.GetType() == typeof(King))
                        {
                            Game copiGame = game.Clone();
                            if (copiGame.IsSmallCastling(p.Color) || copiGame.IsBigCastling(p.Color))
                            {
                                King k = (King)p;
                                ShowTraveling(specialMove, Color.Orange);
                            }
                        }
                    }
                }
                else
                {
                    game.Players[0].LastPiece = null;
                }
            }
        }
Example #3
0
        /// <summary>
        /// test si un petit rock est possible
        /// </summary>
        /// <param name="color"></param>
        /// <returns></returns>
        public bool IsBigCastling(string color)
        {
            //implémente une série de test
            if (color == strColor1)
            {
                try
                {
                    Rook r = (Rook)tabPiece[7][0];
                }
                catch
                {
                    return(false);
                }
                if (tabPiece[7][1] != null || tabPiece[7][2] != null || tabPiece[7][3] != null)
                {
                    return(false);
                }
                try
                {
                    King k = (King)tabPiece[7][4].Clone();
                    if (k.IsAlreadyMove)
                    {
                        return(false);
                    }



                    k.PositionX = 3;
                    if (k.IsCheck(this))
                    {
                        return(false);
                    }
                    k.PositionX = 2;
                    if (k.IsCheck(this))
                    {
                        return(false);
                    }
                }
                catch
                {
                    return(false);
                }
            }
            else
            {
                try
                {
                    Rook r = (Rook)tabPiece[0][0];
                }
                catch
                {
                    return(false);
                }
                if (tabPiece[0][1] != null || tabPiece[0][2] != null || tabPiece[0][3] != null)
                {
                    return(false);
                }
                try
                {
                    King k = (King)tabPiece[0][4].Clone();
                    if (k.IsAlreadyMove)
                    {
                        return(false);
                    }


                    k.PositionX = 3;
                    if (k.IsCheck(this))
                    {
                        return(false);
                    }
                    k.PositionX = 2;
                    if (k.IsCheck(this))
                    {
                        return(false);
                    }
                }
                catch
                {
                    return(false);
                }
            }
            return(true);
        }