Example #1
0
        /// <summary>
        /// 点击变色
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Main_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
            {
                return;
            }
            Postion pos = new Postion(e.X / 10, e.Y / 10);

            if (pos.x >= gameX || pos.y >= gameY)
            {
                return;
            }
            state[pos.x, pos.y] = !state[pos.x, pos.y];
            Graphics   g  = this.CreateGraphics();
            SolidBrush sb = new SolidBrush(state[pos.x, pos.y] ? Color.Black : Color.White);

            g.FillRectangle(sb, pos.rectangle);
            g.Dispose();
        }
Example #2
0
        /// <summary>
        /// 演化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Main_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar != 13)
            {
                return;
            }
            bool[,] s = new bool[gameX, gameY];
            for (int x = 0; x < gameX; x++)
            {
                for (int y = 0; y < gameY; y++)
                {
                    Postion p = new Postion(x, y);
                    s[x, y] = p.setNewState();

                    Graphics   g  = this.CreateGraphics();
                    SolidBrush sb = new SolidBrush(s[x, y] ? Color.Black : Color.White);
                    g.FillRectangle(sb, p.rectangle);
                    g.Dispose();
                }
            }

            state = s;
        }