Esempio n. 1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            // יש עוד לבנים                     יש עוד חיים
            if (boardGame.GetLife() > 0 && !(boardGame.Getlist().IsEmpty()))
            {
                gr = CreateGraphics();
                boardGame.GetKv().PainPaddle(gr);     //ציור הפדל
                Xkv = boardGame.GetKv().GetXpaddle(); //קבלת מקום הפדל

                bal.DrawBall(gr);
                x = bal.GetXball();
                y = bal.GetYball();
                //מחיקת הישן
                bal.DelBall(gr);
                bal.MoveBall();
                x = bal.GetXball();
                y = bal.GetYball();
                bal.DrawBall(gr);
                if (y >= 608 || x <= 50 || y <= 3 || x >= 780) //פה צריך להיות החלפת כיוון אם פגע הקצה
                {
                    bal.ChangeDir();
                    if (y >= 608)
                    {
                        timer1.Stop();
                        boardGame.GetLife();
                        life = boardGame.GetLife();
                        life--;//הורדת חיים אם פגע ברצפה
                        boardGame.SetLife(life);
                        label4.Text = "Life=" + boardGame.GetLife().ToString();
                        pdl.DelPafd(gr);
                        pdl.SetXpaddle(452);
                        pdl.SetYpaddle(607);
                        pdl.PainPaddle(gr);
                        bal.DelBall(gr);
                        bal.SetXball(485);
                        bal.SetYball(450);
                        bal.SetDir(4);
                        bal.DrawBall(gr);
                        timer1.Start();
                    }
                }
                if ((x >= Xkv) && (x < Xkv + 70) && (y + 30 >= Ykv) && (y + 30 <= Ykv + 4))
                {//החלפת כיוון אם נתפס בפדל
                    bal.ChangeDir();
                    if (bal.GetDir() == 7)
                    {
                        bal.ChangeDir();                   //למנוע מצב של זריקת הכדור למטה ופסילה
                    }
                    x = bal.GetXball();
                    y = bal.GetYball();
                }



                pos = boardGame.Getlist().GetFirst();
                bls = pos.GetInfo();

                while (pos != null)
                {
                    score = boardGame.GetScore();
                    bls   = pos.GetInfo();
                    //מעבר על הרשימה תוך חיפוש הלבנה
                    if (((bls.GetX() <= x) && (x <= bls.GetX() + 50)) && ((bls.GetY() <= y) && (y <= bls.GetY() + 30)))
                    {
                        //פגע בלבנה
                        bls = pos.GetInfo();
                        bls.DellBlock(gr);
                        if (bls.isbonus())
                        {
                            score += 50;//אם לבנה צהובה היעא שווה 50
                        }
                        else
                        {
                            //לבנה רגילה
                            bls.DellBlock(gr);                        //מחיקה גראפית מהמסך
                            pos    = boardGame.Getlist().Remove(pos); //מחיקת חוליה מהרשימה
                            score += 10;
                        }
                        boardGame.SetScore(score);
                        label3.Text = "Score=" + boardGame.GetScore().ToString();
                        bal.ChangeDir();
                        x = bal.GetXball();
                        y = bal.GetYball();
                    }
                    else
                    {
                        pos = pos.GetNext();
                    }
                }
            }
            else//נגמר המשחק
            {
            }
        }
Esempio n. 2
0
        public Board(Graphics g)  // פעולה בונה
        // בונה רשימת לבנים, מאתחלת משטח+כדור ומציירת את לוח המשחק
        {
            lb  = new List <Blocks>();
            pos = lb.GetFirst();
            Blocks box;
            int    x = 120; //אתחול גרפי של הלוח
            int    y = 200;

            Score = 0;
            Life  = 3;
            Color c = Color.Black;

            box = new Blocks(x, y, c);
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 20; j++)
                {
                    if (i == 0 || i == 6)
                    {
                        c = Color.Red;            //קביעת הצבע לשורה
                    }
                    if (i == 1 || i == 5 || i == 7)
                    {
                        c = Color.Magenta;
                    }

                    if (i == 2 || i == 4 || i == 8)
                    {
                        c = Color.Pink;
                    }

                    if (i == 3 || i == 9)
                    {
                        c = Color.Purple;
                    }
                    //לא מיצר לבנים בקצוות

                    if ((i == 0 || i == 9) && j > 4 && j < 15)
                    {
                        box = new Blocks(x, y, c);       //יוצר לבנה בגודל X,Y
                    }
                    if ((i == 1 || i == 8) && j > 1 && j < 18)
                    {
                        box = new Blocks(x, y, c);
                    }
                    if ((i == 2 || i == 7) && j > 0 && j < 19)
                    {
                        box = new Blocks(x, y, c);
                    }
                    if (i >= 3 && i < 7)
                    {
                        box = new Blocks(x, y, c);
                    }
                    if (((i + 1) + (j + 1)) % 5 == 2)
                    {
                        box.setColor(Color.Yellow);
                        if (i == 0 && j == 0)
                        {
                            box.setColor(Color.Black);
                        }
                    }

                    pos = lb.Insert(pos, box); // מצייר לבנה ומכניס אותה לרשימה
                    x  += 31;
                }
                x  = 120;
                y += 16;
            }


            Drawlist(g);
            bl = new Ball();   // יוצר עצם כדור
            bl.DrawBall(g);    // מצייר אותו
            kv = new Paddle(); // עצם פדל
            kv.PainPaddle(g);  // מצייר פדל
        }