Example #1
0
        // -- Change current player -- //
        private void Change_current_player()
        {
            CurrentPlayer = (CurrentPlayer == Type_Player.One) ? Type_Player.Two
                                                               : Type_Player.One;

            if (CurrentPlayer == Type_Player.Two)
            {
                Player_2_Play();
            }
        }
Example #2
0
        // -- Generate victory
        private void Generate_Victory(Type_Player player)
        {
            if (isNotFirstplay && YoteClass.IsVictory(Board, player))
            {
                MessageBox.Show(
                    $"Félicitation, le joueur{((player == Type_Player.One) ? "1 (" + Player_2.name + ")" : "2 (" + Player_1.name + ")")} a gagné!",
                    "Information",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information
                    );

                // -- Event new gae
                nouvellePartieToolStripMenuItem1.PerformClick();
            }
        }
Example #3
0
        public static Boolean IsVictory(State_Space[,] board, Type_Player type_player)
        {
            State_Space opponent = (type_player == Type_Player.One) ? State_Space.One
                                                                     : State_Space.Two;

            for (int _x = 0; _x < Program.row_board_count; _x++)
            {
                for (int _y = 0; _y < Program.column_board_count; _y++)
                {
                    if (board[_x, _y] == opponent)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Example #4
0
        public Form_Main(string name_1, string name_2) : this()
        {
            // -- Create players -- //
            Player_1 = new Player(name_1, true);
            Player_2 = new Player(name_2, false);
            // -- Update event -- //
            Player_1.PropertyChanged += Event_Property_Player_Change;
            Player_2.PropertyChanged += Event_Property_Player_Change;

            // -- Initialise var -- //
            Moves          = new List <Space>();
            MoveStack      = new List <Space>();
            Board          = new State_Space[RowCount, ColumnCount];
            isNotFirstplay = false;

            // -- Initialisation form -- //
            InitalisationForm();

            // -- Initialise current player -- //
            _currentPlayer = Type_Player.One;
        }
Example #5
0
        public static List <Space> Enable_Space(State_Space[,] Board, Space space, Type_Player type_player)
        {
            List <Space> list     = new List <Space>();
            State_Space  my_state = (type_player == Type_Player.One) ? State_Space.One
                                                                    : State_Space.Two;
            Boolean have_opponent = false;

            for (int passage = 1; passage <= 4; passage++)
            {
                // -- Var
                int row = space.Row, row_second = space.Row,
                    column = space.Column, column_second = space.Column;

                // -- Update var with passage
                switch (passage)
                {
                case 1:
                    row        = space.Row - 1;
                    row_second = space.Row - 2;
                    break;

                case 2:
                    row        = space.Row + 1;
                    row_second = space.Row + 2;
                    break;

                case 3:
                    column        = space.Column - 1;
                    column_second = space.Column - 2;
                    break;

                default:
                    column        = space.Column + 1;
                    column_second = space.Column + 2;
                    break;
                }

                // x-1, x+1, y-1, y+1
                try
                {
                    if (Board[row, column] != my_state)
                    {
                        // -- Space to mive -- //
                        if (Board[row, column] == State_Space.None)
                        {
                            // -- Add
                            list.Add(new Space(row, column, Board[row, column]));
                        }
                        // -- Space to win -- //
                        else if (Board[row_second, column_second] == State_Space.None)
                        {
                            // -- Add
                            list.Add(new Space(row, column, Board[row, column]));
                            // -- Add second
                            list.Add(new Space(row_second, column_second, Board[row_second, column_second]));
                            // -- Update opponent -- //
                            have_opponent = true;
                        }
                    }
                }
                catch { }
            }

            if (have_opponent)
            {
                // -- remove -- //
                list.RemoveAll(l => (Math.Abs(l.Row - space.Row) == 1 || Math.Abs(l.Column - space.Column) == 1) &&
                               l.State == State_Space.None);
            }

            return(list);
        }