Exemple #1
0
        private void setNextPlayer(Player player)
        {
            currentPlayer = player;

            flowLayoutPanel1.Controls.OfType <Control>().ToList().ForEach((item) =>
            {
                if (item is PencilColumn)
                {
                    ((PencilColumn)item).CurrentPlayer = currentPlayer;
                }
            });

            button1.BackColor = currentPlayer == Player.BLUE ? Color.Blue : Color.Red;

            if (currentPlayer == Player.RED && !isOpponentHuman)
            {
                button1.Image = Properties.Resources.Computer.ToBitmap();
            }
            else
            {
                button1.Image = null;
            }

            myNextActionControl = null;
            myNextActionCounter = 0;
        }
Exemple #2
0
        private void simulateNextStep()
        {
            PencilColumn removeColumn = null;
            int          removeCount  = 0;

            bool canWin = true;

            flowLayoutPanel1.Controls.OfType <Control>().ToList().ForEach((item) =>
            {
                if (item is PencilColumn)
                {
                    canWin = canWin != (((PencilColumn)item).remaining == 0);
                }
            });


            flowLayoutPanel1.Controls.OfType <Control>().ToList().ForEach((item) =>
            {
                if (item is PencilColumn)
                {
                    if (((PencilColumn)item).remaining != 0)
                    {
                        removeColumn = (PencilColumn)item;
                        removeCount  = ((PencilColumn)item).remaining;
                    }
                }
            });


            myNextActionControl = removeColumn;
            myNextActionCounter = removeCount;

            doUserStep();
        }
Exemple #3
0
        private void resetBoard()
        {
            flowLayoutPanel1.Controls.OfType <Control>().ToList().ForEach((item) => {
                if (item is PencilColumn)
                {
                    item.Dispose();
                    flowLayoutPanel1.Controls.Remove(item);
                }
            });

            Random rand = new Random();

            for (int i = 0; i < columns; i++)
            {
                int value = rand.Next(11) + 1;

                PencilColumn pencil = new PencilColumn()
                {
                    Counter = value
                };

                pencil.OnCounterSelectionChangedEvent += new PencilColumn.CounterSelectionChangedHandler(onCounterChanged);

                flowLayoutPanel1.Controls.Add(pencil);
            }

            button1.Enabled = true;
        }
Exemple #4
0
        private void onCounterChanged(object sender, CounterSelectionArgs e)
        {
            myNextActionCounter = e.Counter;
            myNextActionControl = (PencilColumn)sender;

            flowLayoutPanel1.Controls.OfType <Control>().ToList().ForEach((item) =>
            {
                if (item is PencilColumn)
                {
                    ((PencilColumn)item).IsEnabled = false;
                }
            });
        }