예제 #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!");
                }
            }
        }