Exemplo n.º 1
1
        public Form1()
        {
            InitializeComponent();
            rand = new Random();
            dataGrid = new Grid("TileMap.csv");
            Controls.Add(dataGrid);
            sound = new System.Windows.Media.MediaPlayer();
            sound.Open(new Uri("pacmanDubHeavy.mp3", UriKind.Relative));
            sound.Play();

            gameEngine = new GameEngine(dataGrid, rand, timer1.Interval);

            //pacman font
            PrivateFontCollection fontCollection = new PrivateFontCollection();
            fontCollection.AddFontFile("crackman.ttf");

            FontFamily ff = fontCollection.Families[0];
            int fontsize = 12;
            Font pacmanFont = new Font(ff, fontsize, FontStyle.Bold);

            label2.Font = pacmanFont;
            label3.Font = pacmanFont;
            label4.Font = pacmanFont;

            lifeCounter = new PictureBox[3];
            lifeCounter[0] = pictureBox1;
            lifeCounter[1] = pictureBox2;
            lifeCounter[2] = pictureBox3;
        }
Exemplo n.º 2
0
        private void Draw(Graphics g)
        {
            //draw layers
            backLayer.Draw(g);
            foodLayer.Draw(g);

            //draw pacman
            pacMan.Draw(g);

            //draw ghosts
            for (int i = 0; i < GameObjects.Count; i++)
            {
                GameObjects[i].Draw(g);
            }

            //draw score
            g.DrawString("Score: " + totalScore, new Font("Arial", 12f, FontStyle.Bold), new SolidBrush(Color.Yellow), new Point(0, 0));

            //draw
            StringFormat stringFormat = new StringFormat();

            stringFormat.Alignment     = StringAlignment.Center;
            stringFormat.LineAlignment = StringAlignment.Center;

            //is game over
            if (this.isGameOver && this.isGameWon == false)
            {
                g.DrawString("GAME OVER", new Font("Arial", 32f, FontStyle.Bold), new SolidBrush(Color.Yellow), GameEngine.GameFieldSize().Width / 2, GameEngine.GameFieldSize().Height / 3, stringFormat);
                g.DrawString("Press ENTER for new game", new Font("Arial", 18f, FontStyle.Bold), new SolidBrush(Color.Yellow), GameEngine.GameFieldSize().Width / 2, GameEngine.GameFieldSize().Height / 2, stringFormat);
            }
            //is game won
            if (this.isGameOver && this.isGameWon)
            {
                g.DrawString("WINNER!", new Font("Arial", 32f, FontStyle.Bold), new SolidBrush(Color.Yellow), GameEngine.GameFieldSize().Width / 2, GameEngine.GameFieldSize().Height / 3, stringFormat);
                g.DrawString("Press ENTER for new game", new Font("Arial", 18f, FontStyle.Bold), new SolidBrush(Color.Yellow), GameEngine.GameFieldSize().Width / 2, GameEngine.GameFieldSize().Height / 2, stringFormat);
            }
            //is power up active
            if (this.isGameOver == false && pacMan.HasPower)
            {
                g.DrawString("POWER UP ACTIVATED!", new Font("Arial", 24f, FontStyle.Bold), new SolidBrush(Color.Yellow), GameEngine.GameFieldSize().Width / 2, GameEngine.GameFieldSize().Height / 4, stringFormat);
            }
            //if game is paused
            if (this.isPaused)
            {
                g.DrawString("GAME PAUSED", new Font("Arial", 24f, FontStyle.Bold), new SolidBrush(Color.Yellow), GameEngine.GameFieldSize().Width / 2, GameEngine.GameFieldSize().Height / 2, stringFormat);
            }
        }