コード例 #1
0
ファイル: Form1.cs プロジェクト: MalykhS/Personal
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            Graphics g = CreateGraphics();

            ApplyTransform(g);
            PointF[] p = { new Point(e.X, e.Y) };
            g.TransformPoints(CoordinateSpace.World, CoordinateSpace.Device, p);

            if (ai.numSpacesLeft() > 0 && !ai.gameOver())
            {
                if (p[0].X < 0 || p[0].Y < 0)
                {
                    return;
                }
                int i = (int)(p[0].X / block);
                int j = (int)(p[0].Y / block);
                if (i > 2 || j > 2)
                {
                    return;
                }

                if (ai.spaceIsEmpty(i, j))
                {
                    if (e.Button == MouseButtons.Left)
                    {
                        ai.playerMoveAt(i, j);
                        this.Invalidate();
                        alertWinner();
                        if (!ai.gameOver())
                        {
                            ai.takeTurn();
                            this.Invalidate();
                            alertWinner();
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Bad move!");
                }
            }
        }