Esempio n. 1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            bgc = Color.Black;
            bg  = new Bitmap(ClientSize.Width, ClientSize.Height);
            player.SoundLocation = "D://Cs//CS 232//Assignments//Minigame1//Sources//Melody.wav";
            player.Play();
            start = new Bitmap("D://Cs//CS 232//Assignments//Minigame1//Sources//Start.bmp");
            start.MakeTransparent(Color.White);
            options = new Bitmap("D://Cs//CS 232//Assignments//Minigame1//Sources//Options.bmp");
            options.MakeTransparent(Color.White);
            account = new Bitmap("D://Cs//CS 232//Assignments//Minigame1//Sources//Account.bmp");
            account.MakeTransparent(Color.White);
            highscores = new Bitmap("D://Cs//CS 232//Assignments//Minigame1//Sources//Highscores.bmp");
            highscores.MakeTransparent(Color.White);
            mon = new Bitmap("D://Cs//CS 232//Assignments//Minigame1//Sources//Ong.bmp");
            mon.MakeTransparent(Color.White);
            moff = new Bitmap("D://Cs//CS 232//Assignments//Minigame1//Sources//Off.bmp");
            moff.MakeTransparent(Color.White);
            back = new Bitmap("D://Cs//CS 232//Assignments//Minigame1//Sources//Back.bmp");
            back.MakeTransparent(Color.White);
            cbg = new Bitmap("D://Cs//CS 232//Assignments//Minigame1//Sources//Cbg.bmp");
            cbg.MakeTransparent(Color.White);
            music = new Bitmap("D://Cs//CS 232//Assignments//Minigame1//Sources//Music.bmp");
            music.MakeTransparent(Color.White);
            startst2 = new Bitmap("D://Cs//CS 232//Assignments//Minigame1//Sources//start stage 2.bmp");
            startst2.MakeTransparent(Color.White);
            arrow = new Bitmap("D://Cs//CS 232//Assignments//Minigame1//Sources//Arrow.bmp");
            arrow.MakeTransparent(Color.White);
            int[] s1posx = { -1, -1, -1, -1 };
            int[] s1posy = { -1, -1, -1, -1 };
            int   a, b;

            for (int z = 0; z < 4; z++)
            {
                for (; ;)
                {
                    a = r.Next(6);
                    b = r.Next(6);
                    if (!isExist(a, b, s1posx, s1posy))
                    {
                        s1posx[z] = a;
                        s1posy[z] = b;
                        break;
                    }
                }
            }
            bg    = new Bitmap(ClientSize.Width, ClientSize.Height);
            back2 = new Bitmap("back.bmp");
            ship  = new Bitmap("boat.bmp");
            ship.MakeTransparent(Color.White);
            enemy = new Bitmap("enemy.bmp");
            enemy.MakeTransparent(Color.White);
            person = new Bitmap("actor1.bmp");
            person.MakeTransparent(Color.White);
            person pnn = new person();

            pnn.x = 540;
            pnn.y = 640;
            pers.Add(pnn);
            pnn   = new person();
            pnn.x = 520;
            pnn.y = 640;
            pers.Add(pnn);
            pnn   = new person();
            pnn.x = 500;
            pnn.y = 640;
            pers.Add(pnn);
            enemy pnn2 = new enemy();

            pnn2.x = 460;
            pnn2.y = 640;
            enem.Add(pnn2);
            pnn2   = new enemy();
            pnn2.x = 440;
            pnn2.y = 640;
            enem.Add(pnn2);
            pnn2   = new enemy();
            pnn2.x = 420;
            pnn2.y = 640;
            enem.Add(pnn2);

            /*MessageBox.Show("--<st-->" + s1posx[0] + "<---->" + s1posy[0]);
            *  MessageBox.Show("--<st-->" + s1posx[1] + "<---->" + s1posy[1]);
            *  MessageBox.Show("--<st-->" + s1posx[2] + "<---->" + s1posy[2]);
            *  MessageBox.Show("--<st-->" + s1posx[3] + "<---->" + s1posy[3]);*/
            int k = 0;

            for (int i = 0; i < 4; i++)
            {
                stage1balls pnn4 = new stage1balls();
                pnn4.posx = s1posx[k] * 100 + s1t1 + 20;
                pnn4.posy = s1posy[k] * 70 + s1t2 + 10;
                if (i == 0)
                {
                    pnn4.iconnect = 2;
                }
                if (i == 1)
                {
                    pnn4.iconnect = 3;
                }
                if (i == 2)
                {
                    pnn4.iconnect = 0;
                }
                if (i == 3)
                {
                    pnn4.iconnect = 1;
                }
                st1b.Add(pnn4);
                k++;
            }
        }
Esempio n. 2
0
        void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            isup = 1;
            //stage 0
            //------------------------------------------------------------------
            if (stage == 0)
            {
                if (oah == 0)
                {
                    if (e.X >= 850 && e.Y >= 500 && e.X <= 850 + start.Width && e.Y <= 500 + start.Height / 2)
                    {
                        stage     = 2;
                        this.Text = "Level 1";
                    }
                    if (e.X >= 850 && e.Y >= 600 && e.X <= 850 + options.Width && e.Y <= 600 + options.Height)
                    {
                        oah = 1;
                    }

                    /*if (e.X >= 850 && e.Y >= 800 && e.X <= 850 + account.Width && e.Y <= 800 + account.Height)
                     * {
                     *  oah = 2;
                     * }
                     * if (e.X >= 850 && e.Y >= 700 && e.X <= 850 + highscores.Width && e.Y <= 700 + highscores.Height)
                     * {
                     *  oah = 3;
                     * }*/
                }
                if (oah == 1)
                {
                    if (e.X >= 600 && e.Y >= 500 && e.X <= 900 && e.Y <= 560)
                    {
                        if (mf == 0)
                        {
                            mon = new Bitmap("D://Cs//CS 232//Assignments//Minigame1//Sources//On.bmp");
                            mon.MakeTransparent(Color.White);
                            moff = new Bitmap("D://Cs//CS 232//Assignments//Minigame1//Sources//Offg.bmp");
                            moff.MakeTransparent(Color.White);
                            mf = 1;
                            player.Stop();
                        }
                        else if (mf == 1)
                        {
                            mon = new Bitmap("D://Cs//CS 232//Assignments//Minigame1//Sources//Ong.bmp");
                            mon.MakeTransparent(Color.White);
                            moff = new Bitmap("D://Cs//CS 232//Assignments//Minigame1//Sources//Off.bmp");
                            moff.MakeTransparent(Color.White);
                            mf = 0;
                            player.Play();
                        }
                    }
                    if (e.X >= 600 && e.Y >= 700 && e.X <= 700 && e.Y <= 760)
                    {
                        bgc = Color.White;
                    }
                    if (e.X >= 750 && e.Y >= 700 && e.X <= 850 && e.Y <= 760)
                    {
                        bgc = Color.Black;
                    }
                    if (e.X >= 900 && e.Y >= 700 && e.X <= 1000 && e.Y <= 760)
                    {
                        bgc = Color.Blue;
                    }
                    if (e.X >= 1050 && e.Y >= 700 && e.X <= 1150 && e.Y <= 760)
                    {
                        bgc = Color.Brown;
                    }
                    if (e.X >= 1100 && e.Y >= this.ClientSize.Height - 100 && e.X <= 1200 && e.Y <= this.ClientSize.Height - 40)
                    {
                        oah = 0;
                    }
                }
                //------------------------------------------------------------------
            }
            //Stage 1
            //----------------------------------------------------------------------
            if (stage == 1)
            {
                //Balls
                for (int i = 0; i < 4; i++)
                {
                    if (e.X >= st1b[i].posx && e.Y >= st1b[i].posy && e.X <= st1b[i].posx + 50 && e.Y <= st1b[i].posy + 50)
                    {
                        ex   = e.X;
                        ey   = e.Y;
                        bn   = i;
                        boxx = (st1b[bn].posx - 20 - s1t1) / 100;
                        boxy = (st1b[bn].posy - 10 - s1t2) / 70;
                        break;
                    }
                }
                //Back
                if (e.X >= 1100 && e.Y >= this.ClientSize.Height - 100 && e.X <= 1200 && e.Y <= this.ClientSize.Height - 40)
                {
                    string            message = "Do You Really Want To Exit And Remove All Progress";
                    string            caption = "You Will Lose";
                    MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                    DialogResult      result;
                    result = MessageBox.Show(message, caption, buttons);
                    if (result == System.Windows.Forms.DialogResult.Yes)
                    {
                        stage = 0;
                        oah   = 0;
                        for (int i = 0; i < st1b.Count; i++)
                        {
                            st1b.RemoveAt(i);
                        }
                        int[] s1posx = { -1, -1, -1, -1 };
                        int[] s1posy = { -1, -1, -1, -1 };
                        int   a, b;
                        for (int z = 0; z < 4; z++)
                        {
                            for (; ;)
                            {
                                a = r.Next(6);
                                b = r.Next(6);
                                if (!isExist(a, b, s1posx, s1posy))
                                {
                                    s1posx[z] = a;
                                    s1posy[z] = b;
                                    break;
                                }
                            }
                        }
                        int k = 0;
                        for (int i = 0; i < 4; i++)
                        {
                            stage1balls pnn = new stage1balls();
                            pnn.posx = s1posx[k] * 100 + s1t1 + 20;
                            pnn.posy = s1posy[k] * 70 + s1t2 + 10;
                            if (i == 0)
                            {
                                pnn.iconnect = 2;
                            }
                            if (i == 1)
                            {
                                pnn.iconnect = 3;
                            }
                            if (i == 2)
                            {
                                pnn.iconnect = 0;
                            }
                            if (i == 3)
                            {
                                pnn.iconnect = 1;
                            }
                            st1b.Add(pnn);
                            k++;
                        }
                    }
                }
                //next
                if (e.X >= 1300 && e.Y >= this.ClientSize.Height - 100 && e.X <= 1500 && e.Y <= this.ClientSize.Height - 40)
                {
                    stage = 2;
                }
            }
            //----------------------------------------------------------------------
            //Stage 2
            //----------------------------------------------------------------------
            //back
            if (stage == 2)
            {
                if (e.X >= 1100 && e.Y >= this.ClientSize.Height - 100 && e.X <= 1200 && e.Y <= this.ClientSize.Height - 40)
                {
                    string            message = "Do You Really Want To Exit And Remove All Progress";
                    string            caption = "You Will Lose";
                    MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                    DialogResult      result;
                    result = MessageBox.Show(message, caption, buttons);
                    if (result == System.Windows.Forms.DialogResult.Yes)
                    {
                        stage = 0;
                        oah   = 0;
                    }
                }
                if (e.X >= 600 && e.Y >= 250 && e.X <= 850 && e.Y <= 500)
                {
                    b = 1;
                    drawbuffer(this.CreateGraphics());
                    sndPlayer.SoundLocation = "D://Cs//CS 232//Assignments//Minigame1//Sources//1.wav";
                    sndPlayer.PlaySync();
                    if (fstart == 1)
                    {
                        for (int i = 0; i < 4; i++)
                        {
                            if (patternuser[i] == -1)
                            {
                                patternuser[i] = 0;
                                break;
                            }
                        }
                    }
                }
                if (e.X >= 860 && e.Y >= 250 && e.X <= 1110 && e.Y <= 500)
                {
                    re = 1;
                    drawbuffer(this.CreateGraphics());
                    sndPlayer.SoundLocation = "D://Cs//CS 232//Assignments//Minigame1//Sources//2.wav";
                    sndPlayer.PlaySync();
                    if (fstart == 1)
                    {
                        for (int i = 0; i < 4; i++)
                        {
                            if (patternuser[i] == -1)
                            {
                                patternuser[i] = 1;
                                break;
                            }
                        }
                    }
                }
                if (e.X >= 600 && e.Y >= 510 && e.X <= 850 && e.Y <= 760)
                {
                    gr = 1;
                    drawbuffer(this.CreateGraphics());
                    sndPlayer.SoundLocation = "D://Cs//CS 232//Assignments//Minigame1//Sources//3.wav";
                    sndPlayer.PlaySync();
                    if (fstart == 1)
                    {
                        for (int i = 0; i < 4; i++)
                        {
                            if (patternuser[i] == -1)
                            {
                                patternuser[i] = 2;
                                break;
                            }
                        }
                    }
                }
                if (e.X >= 860 && e.Y >= 510 && e.X <= 1110 && e.Y <= 760)
                {
                    y = 1;
                    drawbuffer(this.CreateGraphics());
                    sndPlayer.SoundLocation = "D://Cs//CS 232//Assignments//Minigame1//Sources//4.wav";
                    sndPlayer.PlaySync();
                    if (fstart == 1)
                    {
                        for (int i = 0; i < 4; i++)
                        {
                            if (patternuser[i] == -1)
                            {
                                patternuser[i] = 3;
                                break;
                            }
                        }
                    }
                }
                if (e.X >= 50 && e.Y >= 50 && e.X <= 150 && e.Y <= 150 && fstart == 0)
                {
                    stage2music();
                    fstart = 1;
                }
                if (win2 == 1)
                {
                    if (e.X >= 1300 && e.Y >= this.ClientSize.Height - 100 && e.X <= 1500 && e.Y <= this.ClientSize.Height - 40)
                    {
                        stage = 3;
                    }
                }
            }
            //-------------------------------------------------------------------------------------------
            //Stage 3
            //-------------------------------------------------------------------------------------------
            if (stage == 3)
            {
                if (e.X >= 1100 && e.Y >= this.ClientSize.Height - 100 && e.X <= 1200 && e.Y <= this.ClientSize.Height - 40)
                {
                    string            message = "Do You Really Want To Exit And Remove All Progress";
                    string            caption = "You Will Lose";
                    MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                    DialogResult      result;
                    result = MessageBox.Show(message, caption, buttons);
                    if (result == System.Windows.Forms.DialogResult.Yes)
                    {
                        stage = 0;
                        oah   = 0;
                    }
                }
                if (e.Button == MouseButtons.Left)
                {
                    for (int i = 0; i < pers.Count; i++)
                    {
                        if (ishit(e.X, e.Y, pers[i].x, pers[i].y))
                        {
                            if (pers[i].x > 700 && pers[i].y == 630)
                            {
                                pers[i].x = putx3;
                                pers[i].y = 640;
                                putx3    += 15;
                                nop--;
                                nopr++;
                                for (int k = 0; i < 2; i++)
                                {
                                    if (pn[k] == i)
                                    {
                                        pn[k] = -1;
                                    }
                                }
                                putx -= 15;
                            }
                            else if (nop < 2 && ((shipx < 700 && pers[i].x < 700) || (shipx > 700 && pers[i].x > 700)))
                            {
                                if (shipx > 700 && pers[i].x > 700)
                                {
                                    putx3 -= 15;
                                    nopr--;
                                }
                                else
                                {
                                    nopl--;
                                }
                                putx     += 15;
                                pers[i].x = putx;
                                pers[i].y = 630;
                                pn[nop]   = i;
                                nop++;
                            }
                            break;
                        }
                    }
                    for (int i = 0; i < enem.Count; i++)
                    {
                        if (ishit(e.X, e.Y, enem[i].x, enem[i].y))
                        {
                            if (enem[i].x > 700 && enem[i].y == 630)
                            {
                                enem[i].x = putx4;
                                enem[i].y = 640;
                                putx4    -= 30;
                                nop--;
                                noer++;
                                for (int k = 0; k < 2; k++)
                                {
                                    if (en[k] == i)
                                    {
                                        en[k] = -1;
                                    }
                                }
                                putx2 += 30;
                            }
                            else if (nop < 2 && ((enem[i].x < 700 && shipx < 700) || (enem[i].x > 700 && shipx > 700)))
                            {
                                if (shipx > 700 && enem[i].x > 700)
                                {
                                    putx4 += 30;
                                    noer--;
                                }
                                else
                                {
                                    noel--;
                                }
                                putx2    -= 30;
                                enem[i].x = putx2;
                                enem[i].y = 630;
                                en[nop]   = i;
                                nop++;
                            }
                            break;
                        }
                    }
                }
                if (e.Button == MouseButtons.Right)
                {
                    if (e.X >= 1250)
                    {
                        right = 1;
                    }
                    else if (e.X <= 630)
                    {
                        left = 1;
                    }
                }
            }
        }