コード例 #1
0
        public Pacman(Form form, Pacman.Character chosen) : base(form)
        {
            main = form as Form1;
            // Score label.
            scoreLabel.ForeColor = Color.White;
            scoreLabel.Text      = "SCORE: 0";
            scoreLabel.Location  = new Point(12, 9);
            scoreLabel.BackColor = Color.DarkBlue;
            scoreLabel.Font      = new Font("Microsoft Sans Serif", 16);
            //scoreLabel.AutoSize = true;
            scoreLabel.Width = form.Width / 2;
            form.Controls.Add(scoreLabel);

            // Level label.
            levelLabel.Width     = form.Width / 2;
            levelLabel.ForeColor = Color.White;
            levelLabel.Text      = "LEVEL: 0";
            levelLabel.TextAlign = ContentAlignment.TopRight;
            levelLabel.BackColor = Color.DarkBlue;
            levelLabel.Font      = new Font("Microsoft Sans Serif", 16);
            //levelLabel.AutoSize = true;
            levelLabel.Width    = form.Width / 2;
            levelLabel.Location = new Point(form.Width - levelLabel.Width - 30, 9);
            form.Controls.Add(levelLabel);

            // Ovo treba odabrati u meniju.
            chosenCharacter = chosen;
            // Učitavanje slika za Pacmana.
            if (chosenCharacter == Character.MsPacman)
            {
                characterImages[0] = new Bitmap(Properties.Resources.MsPacmanLeft);
                characterImages.Add(new Bitmap(Properties.Resources.MsPacmanLeftEat));
                characterImages.Add(new Bitmap(Properties.Resources.MsPacmanUp));
                characterImages.Add(new Bitmap(Properties.Resources.MsPacmanUpEat));
                characterImages.Add(new Bitmap(Properties.Resources.MsPacmanRight));
                characterImages.Add(new Bitmap(Properties.Resources.MsPacmanRightEat));
                characterImages.Add(new Bitmap(Properties.Resources.MsPacmanDown));
                characterImages.Add(new Bitmap(Properties.Resources.MsPacmanDownEat));
                characterImages.Add(new Bitmap(Properties.Resources.MsPacmanNone));
            }
            else if (chosenCharacter == Character.ChristmasPacman)
            {
                characterImages[0] = new Bitmap(Properties.Resources.ChristmasPacmanLeft);
                characterImages.Add(new Bitmap(Properties.Resources.ChristmasPacmanLeftEat));
                characterImages.Add(new Bitmap(Properties.Resources.ChristmasPacmanUp));
                characterImages.Add(new Bitmap(Properties.Resources.ChristmasPacmanUpEat));
                characterImages.Add(new Bitmap(Properties.Resources.ChristmasPacmanRight));
                characterImages.Add(new Bitmap(Properties.Resources.ChristmasPacmanRightEat));
                characterImages.Add(new Bitmap(Properties.Resources.ChristmasPacmanDown));
                characterImages.Add(new Bitmap(Properties.Resources.ChristmasPacmanDownEat));
                characterImages.Add(new Bitmap(Properties.Resources.ChristmasPacmanNone));
            }
            else
            {
                characterImages[0] = new Bitmap(Properties.Resources.PacmanLeft);
                characterImages.Add(new Bitmap(Properties.Resources.PacmanLeftEat));
                characterImages.Add(new Bitmap(Properties.Resources.PacmanUp));
                characterImages.Add(new Bitmap(Properties.Resources.PacmanUpEat));
                characterImages.Add(new Bitmap(Properties.Resources.PacmanRight));
                characterImages.Add(new Bitmap(Properties.Resources.PacmanRightEat));
                characterImages.Add(new Bitmap(Properties.Resources.PacmanDown));
                characterImages.Add(new Bitmap(Properties.Resources.PacmanDownEat));
                characterImages.Add(new Bitmap(Properties.Resources.PacmanNone));
            }
            currentImage = characterImages.Count - 1;

            // Inicijaliziraj svih 10 PictureBoxeva, a slike postavi samo na
            // prvih lives sličica.
            for (int i = 0; i < 10; i++)
            {
                PictureBox life = new PictureBox();
                if (i < lives)
                {
                    life.Image = characterImages[0];
                }
                life.SizeMode        = PictureBoxSizeMode.StretchImage;
                life.Location        = new Point(Form1.squareSize.X * (i + 2), Form1.squareSize.Y * 33);
                life.Size            = new Size(Form1.squareSize.X, Form1.squareSize.Y);
                life.BackColor       = Color.DarkBlue;
                livesPictureBoxes[i] = life;
                form.Controls.Add(livesPictureBoxes[i]);
                livesPictureBoxes[i].BringToFront();
            }
        }