コード例 #1
0
        /// <summary>
        /// Constructeur qui permet de générer cette énigme
        /// </summary>
        /// <param name="size">Nombre de lampes par côté sur le carré généré</param>
        /// <param name="textAnswer">Réponse à afficher lors de la résolution de l'énigme</param>
        public SwitchesEnigmaPanel(int size, string textAnswer)
        {
            this.size = size;
            lights    = new Light[size][];
            for (int x = 0; x < size; x++)
            {
                lights[x] = new Light[size];
                for (int y = 0; y < size; y++)
                {
                    lights[x][y] = new Light(this);
                }
            }

            for (int x = 0; x < size; x++)
            {
                for (int y = 0; y < size; y++)
                {
                    Light light = lights[x][y];

                    if (x > 0)
                    {
                        light.AjouterVoisin(lights[x - 1][y]);
                    }

                    if (y > 0)
                    {
                        light.AjouterVoisin(lights[x][y - 1]);
                    }

                    if (x < size - 1)
                    {
                        light.AjouterVoisin(lights[x + 1][y]);
                    }

                    if (y < size - 1)
                    {
                        light.AjouterVoisin(lights[x][y + 1]);
                    }

                    light.Location = new Point(110 * x + 50, 110 * y + 50);
                    Controls.Add(light);
                }
            }

            Width  = 110 * size + 100;
            Height = 110 * size + 100;

            Font font = new Font("Arial", 30);

            this.answer = new Label()
            {
                Text = textAnswer, Visible = false, Font = font, Left = 0, Top = 0, Width = Width, Height = 50, TextAlign = ContentAlignment.MiddleCenter
            };
            this.answer.BringToFront();
            Controls.Add(this.answer);
        }