Ejemplo n.º 1
0
        //menghandle penekanan tombol pada mouse
        private void frmPentominos_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (player)
            {
                if (e.Button == MouseButtons.Right && draggedpentomino != null)
                {
                    sp2.Play();

                    draggedpentomino.klikkanan();
                    Invalidate(new Rectangle(draggedpentomino.GetX() - 2, draggedpentomino.GetY() - 2, 150, 150));
                }

                if (e.Button == MouseButtons.Left && draggedpentomino != null)
                {
                    if (!pentominoCollision(draggedpentomino, draggedpentomino.getUrutan()))
                    {
                        new System.Media.SoundPlayer(Properties.Resources.shoot).Play();
                        draggedpentomino = null;
                        isFinish();
                    }
                    return;
                }

                if (e.Button == MouseButtons.Left && draggedpentomino == null)
                {
                    int iPosX = e.X / 25;
                    int iPosY = e.Y / 25;

                    iPosX *= 25;
                    iPosY *= 25;
                    for (int i = 0; i < 12; i++)
                    {
                        if (pentomino[i].atPos(iPosX, iPosY))
                        {
                            draggedpentomino = pentomino[i];
                            new System.Media.SoundPlayer(Properties.Resources.shoot).Play();
                            break;
                        }
                    }
                }
            }
            else if (editorB)
            {
                if (e.Button == MouseButtons.Left)
                {
                    int iPosX = e.X / 25;
                    int iPosY = e.Y / 25;

                    iPosX *= 25;
                    iPosY *= 25;
                    set    = editor.getSel(iPosX, iPosY);
                    editor.atPos(iPosX, iPosY, set);
                    Invalidate();
                }
            }
        }
Ejemplo n.º 2
0
        //mengecek apakah terdapat pentomino yang bertumpukan
        public Boolean pentominoCollision(Pentominos p, int z)
        {
            for (int j = 0; j < 12; j++)
            {
                for (int a = 0; a < 5; a++)
                {
                    for (int b = 0; b < 5; b++)
                    {
                        if (p.getMatrix()[a, b] == 1)
                        {
                            for (int c = 0; c < 5; c++)
                            {
                                for (int d = 0; d < 5; d++)
                                {
                                    if (pentomino[j].getMatrix()[c, d] == 1)
                                    {
                                        if (p.GetX() + (a * 25) == pentomino[j].GetX() + (c * 25) &&
                                            p.GetY() + (b * 25) == pentomino[j].GetY() + (d * 25) && z != j)
                                        {
                                            return(true);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }