Beispiel #1
0
        //Pac-Man eats food. Пакмен поглинає "їжу"
        public void Eat(Point coord)
        {
            DateTime now = DateTime.Now;

            elapsed = (float)(now - EnergizedStateStartedTime).TotalMilliseconds;
            if (elapsed > form.levels.get_frightTime() +
                (form.levels.blinkTimerInterval * form.levels.get_nFlashes() * 2) && form.pacman.energized)
            {
                form.pacman.energized = false;
                //at the end of frightened period, resume the usual chase-scatter timers
                if (Ghost.scatter)
                {
                    Ghost.scatterTimer.Interval = form.levels.get_chaseScatter(Ghost.scatterCounter * 2) - (int)chaseScatterInterruptedAt;
                    Ghost.scatterTimer.Start();
                    Ghost.scatterStopwatch.Start();
                }
                else if (Ghost.chaseCounter < 3)
                {
                    Ghost.chaseTimer.Interval = form.levels.get_chaseScatter(Ghost.chaseCounter * 2 + 1) - (int)chaseScatterInterruptedAt;
                    Ghost.chaseTimer.Start();
                    Ghost.chaseStopwatch.Start();
                }
            }

            if (itemsMap[coord.Y, coord.X] > 1 && itemsMap[coord.Y, coord.X] < 5)
            {
                //regular dot
                if (itemsMap[coord.Y, coord.X] == 2)
                {
                    if (playedEatingSound)
                    {
                        wmp_munch_3.Stop();
                        wmp_munch_3.Open(new Uri("Sounds/munch_3.wav", UriKind.Relative));
                        //wmp_munch_3.Position = new TimeSpan(0);
                        wmp_munch_3.Play();
                        playedEatingSound = false;
                    }
                    //eatingSoundTimer.Start();

                    dotStopwatch.Start();
                    form.player.adjustScore(10);
                    itemsMap[coord.Y, coord.X] = 1;
                    form.pacman.sleepAfterLunch++;

                    //Dot counters for ghosts exit

                    //Scenario after life has been lost
                    if (alternativeExitCounterAfterPacManDies)
                    {
                        globalDotCounter++;
                    }
                    //Scenario at the start of the game and after ghosts are eaten
                    else
                    {
                        for (int i = 0; i < Ghost.canExit.Length; i++)
                        {
                            if (!Ghost.canExit[i])
                            {
                                ghostDotCounter[i]++;
                                break;
                            }
                        }
                    }
                }

                //super dot
                if (itemsMap[coord.Y, coord.X] == 3)
                {
                    wmp_power_pellet.Stop();
                    wmp_power_pellet.Open(new Uri("Sounds/power_pellet.wav", UriKind.Relative));
                    //wmp_power_pellet.Position = new TimeSpan(0);
                    wmp_power_pellet.Play();
                    EnergizedStateStartedTime = DateTime.Now;
                    form.player.adjustScore(50);
                    if (!form.pacman.energized)
                    {
                        form.blinky.reverseDirection = true;
                        form.inky.reverseDirection   = true;
                        form.pinky.reverseDirection  = true;
                        form.clyde.reverseDirection  = true;

                        //pause chase-scatter timer for the time being frightened
                        if (Ghost.scatter)
                        {
                            Ghost.scatterTimer.Stop();
                            Ghost.scatterStopwatch.Stop();
                            chaseScatterInterruptedAt = Ghost.scatterStopwatch.Elapsed.TotalMilliseconds;
                        }
                        else if (Ghost.chaseCounter < 3)
                        {
                            Ghost.chaseTimer.Stop();
                            Ghost.chaseStopwatch.Stop();
                            chaseScatterInterruptedAt = Ghost.chaseStopwatch.Elapsed.TotalMilliseconds;
                        }
                    }
                    itemsMap[coord.Y, coord.X]   = 1;
                    form.pacman.sleepAfterLunch += 3;
                    form.pacman.energized        = true;
                }
            }
            if (fruitTime && itemsMap[coord.Y, coord.X] == 4)
            {
                wmp_eat_fruit.Stop();
                wmp_eat_fruit.Open(new Uri("Sounds/eat_fruit.wav", UriKind.Relative));
                //wmp_eat_fruit.Position = new TimeSpan(0);
                wmp_eat_fruit.Play();
                showScore = true;
                hideScoreTimer.Start();
                fruitTimer.Stop();
                fruitTime = false;
                form.player.adjustScore(form.levels.get_bonusPoints());
            }
            if (dots == 0)//0-240
            {
                form.StartLevelTransition();
            }
            if (dots == 70 && !firstItemAppeared)
            {
                fruitTime         = true;
                firstItemAppeared = true;
                fruitTimer.Start();
            }
            if (dots == 170 && !secondItemAppeared)
            {
                fruitTime          = true;
                secondItemAppeared = true;
                fruitTimer.Start();
            }
            if (dots <= form.levels.get_elroy1DotsLeft())
            {
                elroy1 = true;
            }
            if (dots <= form.levels.get_elroy2DotsLeft())
            {
                elroy2 = true;
            }
        }