コード例 #1
0
        public void GamePlay()//the event that occurs every timer tick, this is when the game is running
        {
            scoreLabel.Text = "Score: " + pacman.Score.ToString();
            maze.Draw();
            PacmanAnimation();
            pacman.Draw();
            ChasePacman();
            MoveGhouls();
            CheckNumberOfKibble();
            CheckForPacmanGhouls();
            DrawGhouls();

            foreach (Ghoul ghoul in ghouls)
            {
                if (ghoul.FoundPacman == true)
                {
                    pacmanDeath.Play();
                    pacman.Life--;

                    if (pacman.Life == 0)
                    {
                        gameEnd = true;
                    }
                    else if (pacman.Life > 0)
                    {
                        StartNewLife();
                    }
                }
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: Carthur-P/Pacman
        public Form1()//constructor
        {
            InitializeComponent();
            intro           = new SoundPlayer(Properties.Resources.Intro);
            win             = new SoundPlayer(Properties.Resources.Win);
            k               = Properties.Resources.Kibble;
            w               = Properties.Resources.Wall;
            b               = Properties.Resources.Blank;
            this.KeyPreview = true;
            maze            = new Maze(k, w, b);
            rand            = new Random();
            Controls.Add(maze);
            controller = new Controller(rand, maze, label1);
            maze.Draw();
            button2.Enabled = false;
            pfc             = new PrivateFontCollection();

            try
            {
                pfc.AddFontFile("..\\..\\..\\..\\Resources\\Font\\Arcade.ttf");
                button1.Font = new Font(pfc.Families[0], FONTSIZE1, FontStyle.Regular);
                button2.Font = new Font(pfc.Families[0], FONTSIZE1, FontStyle.Regular);
                button3.Font = new Font(pfc.Families[0], FONTSIZE1, FontStyle.Regular);
                label1.Font  = new Font(pfc.Families[0], FONTSIZE1, FontStyle.Regular);
                label2.Font  = new Font(pfc.Families[0], FONTSIZE1, FontStyle.Regular);
                label3.Font  = new Font(pfc.Families[0], FONTSIZE2, FontStyle.Regular);
            }

            catch (FileNotFoundException)//if font file cannot be found
            {
                MessageBox.Show("Font file is not found.\nStandard font will be use instead.");
            }
        }
コード例 #3
0
        //each timer interval tick of the timer it will call these methods that draw the maze and the sprites movement and functionality. Also calls in the points
        //accumulated to a label; showing off the score.
        private void timer1_Tick(object sender, EventArgs e)
        {
            maze.Draw();
            controller.PlayGame();

            label9.Text = controller.Points.ToString();
            if (controller.WinGame)
            {
                timer1.Enabled = false;
                MessageBox.Show("Well done you won! with a score of" + label9.Text);
                Application.Exit();
            }
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: Callum-Good/OPPacman
        private void timer1_Tick(object sender, EventArgs e)    //events that happen on a timer tick, or methods that constantly need checked
        {
            if (controller.EndGame() == true)
            {
                SoundPlayer audio = new SoundPlayer(Pacman.Properties.Resources.win);
                audio.Play();
                updatetext();
                timer1.Enabled = false;
                winMessage();
            }
            if (controller.Lives < 0)   //intentionally checking for when lives are < 0. this is so the label displays "0" lives left i.e.
            {                           //if you die with 0 lives left, you lose
                SoundPlayer audio = new SoundPlayer(Pacman.Properties.Resources.EndGame);
                audio.Play();
                timer1.Enabled = false;
                loseMessage();
            }

            controller.GhostMove();
            controller.PacEat();
            updatetext();
            maze.Draw();
            controller.StartGame();
        }
コード例 #5
0
ファイル: PacmanGame.cs プロジェクト: ianlee74/Gadgeteer
        public override void LoadContent()
        {
            _font = Resources.GetFont(Resources.FontResources.NinaB);

              var tempSheet = Resources.GetBitmap(Resources.BitmapResources.pacman);
              _spriteSheet = new Bitmap(tempSheet.Width, tempSheet.Height);
              _spriteSheet.DrawImage(0, 0, tempSheet, 0, 0, tempSheet.Width, tempSheet.Height);
              _spriteSheet.MakeTransparent(Microsoft.SPOT.Presentation.Media.Color.Black);

              _maze = new Maze();
              _maze.Draw(Surface, Host);

              _pacman = new Player(_spriteSheet, _maze);

              #region Initialize Bonus Point Sprites
              _bonus200 = new Sprite(new AnimationSequence(_spriteSheet, 0,
            new Rect[] { new Rect(80, 104, 16, 8) }));

              _bonus400 = new Sprite(new AnimationSequence(_spriteSheet, 0,
            new Rect[] { new Rect(96, 104, 16, 8) }));

              _bonus800 = new Sprite(new AnimationSequence(_spriteSheet, 0,
            new Rect[] { new Rect(112, 104, 16, 8) }));

              _bonus1600 = new Sprite(new AnimationSequence(_spriteSheet, 0,
            new Rect[] { new Rect(128, 104, 16, 8) }));

              _bonus100 = new Sprite(new AnimationSequence(_spriteSheet, 0,
            new Rect[] { new Rect(0, 112, 16, 8) }));

              _bonus300 = new Sprite(new AnimationSequence(_spriteSheet, 0,
            new Rect[] { new Rect(16, 112, 16, 8) }));

              _bonus500 = new Sprite(new AnimationSequence(_spriteSheet, 0,
            new Rect[] { new Rect(32, 112, 16, 8) }));

              _bonus700 = new Sprite(new AnimationSequence(_spriteSheet, 0,
            new Rect[] { new Rect(48, 112, 16, 8) }));

              _bonus1000 = new Sprite(new AnimationSequence(_spriteSheet, 0,
            new Rect[] { new Rect(64, 112, 20, 8) }));

              _bonus2000 = new Sprite(new AnimationSequence(_spriteSheet, 0,
            new Rect[] { new Rect(84, 112, 20, 8) }));

              _bonus3000 = new Sprite(new AnimationSequence(_spriteSheet, 0,
            new Rect[] { new Rect(106, 112, 20, 8) }));

              _bonus5000 = new Sprite(new AnimationSequence(_spriteSheet, 0,
            new Rect[] { new Rect(128, 112, 16, 8) }));
              #endregion

              #region Initialize Ghosts
              _blinky = new Ghost(_spriteSheet, _maze, _pacman, 16,
            new Personality()
            {
              ScatterX = 13 * 16,
              ScatterY = -2 * 16,
              TargetOffsetX = 0,
              TargetOffsetY = 0,
              HouseX = 7 * 16,
              HouseY = 7 * 16,
              StartX = 7 * 16,
              StartY = 5 * 16
            });
              _blinky.CurrentDirection = Direction.Left;

              _pinky = new Ghost(_spriteSheet, _maze, _pacman, 32,
            new Personality()
            {
              ScatterX = 1 * 16,
              ScatterY = -2 * 16,
              TargetOffsetX = 4 * 16,
              TargetOffsetY = 0,
              HouseX = 6 * 16,
              HouseY = 7 * 16,
              StartX = 6 * 16,
              StartY = 7 * 16
            });
              _pinky.CurrentDirection = Direction.Left;

              _inky = new Ghost(_spriteSheet, _maze, _pacman, 48,
            new Personality()
            {
              ScatterX = 14 * 16,
              ScatterY = 15 * 16,
              TargetOffsetX = -3 * 16,
              TargetOffsetY = 0,
              HouseX = 7 * 16,
              HouseY = 7 * 16,
              StartX = 7 * 16,
              StartY = 7 * 16
            });
              _inky.CurrentDirection = Direction.Left;

              _clyde = new Ghost(_spriteSheet, _maze, _pacman, 64,
            new Personality()
            {
              ScatterX = 0 * 16,
              ScatterY = 15 * 16,
              TargetOffsetX = 0,
              TargetOffsetY = -2 * 16,
              HouseX = 8 * 16,
              HouseY = 7 * 16,
              StartX = 8 * 16,
              StartY = 7 * 16
            });
              _clyde.CurrentDirection = Direction.Left;
              #endregion

              _pacman.Enemies = new Ghost[]
              {
            _blinky, _pinky, _inky, _clyde
              };

              #region Add objects to scene
              AddToScene(_showBonusCountDown);
              AddToScene(_showBonusScoreCountDown);
              AddToScene(_maze);
              AddToScene(_pacman);
              AddToScene(_blinky);
              AddToScene(_pinky);
              AddToScene(_inky);
              AddToScene(_clyde);
              #endregion

              _maze.LevelComplete += MazeLevelComplete;
              _showBonusCountDown.Expired += BonusCountDown_Expired;

              MessageService.Instance.Subscribe(typeof(Messages.PacmanDeadMessage), HandlePacmanDeadMessage);
              MessageService.Instance.Subscribe(typeof(Messages.PacmanAteGhostMessage), HandlePacmanAteGhostMessage);
              MessageService.Instance.Subscribe(typeof(Messages.AteBonusItemMessage), HandleAteBonusItem);

              base.LoadContent();

              Reset();
        }
コード例 #6
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     maze.Draw();
 }