示例#1
0
        public void Dispose()
        {
            try
            {
                BlinkyTimer.Dispose();
                PinkyTimer.Dispose();
                ClydeTimer.Dispose();
                InkyTimer.Dispose();
                PacmanTimer.Dispose();

                blinky.PersecutionOrRunawayTimer.Dispose();
                blinky.FrightenedTimer.Dispose();
                blinky.PersecutionOrRunawayWatch.Stop();
                blinky.IsFrightenedWatch.Stop();

                pinky.PersecutionOrRunawayTimer.Dispose();
                pinky.FrightenedTimer.Dispose();
                pinky.PersecutionOrRunawayWatch.Stop();
                pinky.IsFrightenedWatch.Stop();

                inky.PersecutionOrRunawayTimer.Dispose();
                inky.FrightenedTimer.Dispose();
                inky.PersecutionOrRunawayWatch.Stop();
                inky.IsFrightenedWatch.Stop();

                clyde.PersecutionOrRunawayTimer.Dispose();
                clyde.FrightenedTimer.Dispose();
                clyde.PersecutionOrRunawayWatch.Stop();
                clyde.IsFrightenedWatch.Stop();
            }
            catch
            { }
        }
示例#2
0
        internal Task StartNewGame()
        {
            blinky = new GhostBlinky();
            pinky  = new GhostPinky();
            clyde  = new GhostClyde();
            inky   = new GhostInky();

            _pacman.isMoving   = false;
            _pacman.position_x = 1;
            _pacman.position_y = 1;
            _pacman.move_X     = 0;
            _pacman.move_Y     = 1;

            level                = 1;
            _pacman.lifes        = 3;
            score.coin_sum       = 0;
            score.game_finish    = 0;
            score.sum_bonus_coin = 0;

            CountDown();

            eated_coin.Clear();
            eated_energizer.Clear();

            _pacman.isMoving = true;
            PacmanTimer.Change(0, 100);
            InkyTimer.Change(0, 120);
            ClydeTimer.Change(0, 120);
            PinkyTimer.Change(0, 120);
            BlinkyTimer.Change(0, 120);

            blinky.StartMoving();


            _gameMap.RestorMap();


            return(Task.CompletedTask);
        }
示例#3
0
        private void NextLevel()
        {
            blinky = new GhostBlinky();
            pinky  = new GhostPinky();
            clyde  = new GhostClyde();
            inky   = new GhostInky();

            _pacman.isMoving   = false;
            _pacman.position_x = 1;
            _pacman.position_y = 1;
            _pacman.move_X     = 0;
            _pacman.move_Y     = 1;

            _pacman.lifes++;
            level++;
            score.game_finish = 0;

            CountDown();

            eated_coin.Clear();
            eated_energizer.Clear();

            _pacman.isMoving = true;
            PacmanTimer.Change(0, 100);
            InkyTimer.Change(0, 120);
            ClydeTimer.Change(0, 120);
            PinkyTimer.Change(0, 120);
            BlinkyTimer.Change(0, 120);

            blinky.StartMoving();

            score.ghost_start = 0;


            _gameMap.RestorMap();
        }
示例#4
0
        public void UpdateInky(object state)
        {
            //inky_logic
            if (inky.IsMoving)
            {
                if (inky.MovingToHome)
                {
                    inky.IsFrightened = false;

                    InkyTimer.Change(50, 50);
                    var qwerty = new Init().Inite(11, 14, inky.position_x, inky.position_y);

                    inky.move_X = qwerty.Item1;
                    inky.move_Y = qwerty.Item2;

                    if ((inky.position_x == 11) && (inky.position_y == 14))
                    {
                        inky.MovingToHome = false;
                        InkyTimer.Change(120, 120);
                    }
                }
                else if (!inky.IsFrightened)
                {
                    if (inky.PersecutionOrRunaway)
                    {
                        inky.finish_point_x = inky.run_point_x;
                        inky.finish_point_y = inky.run_point_y;
                    }
                    else if (!inky.PersecutionOrRunaway)
                    {
                        int x = 0;
                        int y = 0;

                        if (_gameMap.map[_pacman.position_x + _pacman.move_X, _pacman.position_y + _pacman.move_Y] != 'w')
                        {
                            inky.pacman_position_plus_two_x = _pacman.position_x + _pacman.move_X;
                            inky.pacman_position_plus_two_y = _pacman.position_y + _pacman.move_Y;
                        }
                        try
                        {
                            if (_gameMap.map[_pacman.position_x + _pacman.move_X + _pacman.move_X, _pacman.position_y + _pacman.move_Y + _pacman.move_Y] != 'w')
                            {
                                inky.pacman_position_plus_two_x = _pacman.position_x + _pacman.move_X + _pacman.move_X;
                                inky.pacman_position_plus_two_y = _pacman.position_y + _pacman.move_Y + _pacman.move_Y;
                            }
                        }
                        catch
                        {
                            if (_gameMap.map[_pacman.position_x + _pacman.move_X, _pacman.position_y + _pacman.move_Y] != 'w')
                            {
                                inky.pacman_position_plus_two_x = _pacman.position_x + _pacman.move_X;
                                inky.pacman_position_plus_two_y = _pacman.position_y + _pacman.move_Y;
                            }
                            else
                            {
                                inky.pacman_position_plus_two_x = _pacman.position_x;
                                inky.pacman_position_plus_two_y = _pacman.position_y;
                            }
                        }

                        if (inky.pacman_position_plus_two_x <= blinky.position_x)
                        {
                            x = blinky.position_x - inky.pacman_position_plus_two_x;

                            if (inky.pacman_position_plus_two_y <= blinky.position_y)
                            {
                                y = blinky.position_y - inky.pacman_position_plus_two_y;

                                if (x == y)
                                {
                                    inky.finish_point_x = inky.pacman_position_plus_two_x;

                                    inky.finish_point_y = inky.pacman_position_plus_two_y;
                                }
                                else if (x > y)
                                {
                                    int step = 0;
                                    while (step != x + 1)
                                    {
                                        double kof  = (((step) * 100) / x);
                                        double newy = kof / 100 * y;

                                        try
                                        {
                                            if (_gameMap.map[(inky.pacman_position_plus_two_x - step), Convert.ToInt32(inky.pacman_position_plus_two_y - newy)] != 'w')
                                            {
                                                inky.finish_point_x = inky.pacman_position_plus_two_x - step;

                                                inky.finish_point_y = Convert.ToInt32(inky.pacman_position_plus_two_y - newy);
                                            }
                                        }
                                        catch
                                        {
                                            step = x;
                                        }
                                        step++;
                                    }
                                }
                                else if (x < y)
                                {
                                    int step = 0;
                                    while (step != y + 1)
                                    {
                                        double kof  = (((step) * 100) / y);
                                        double newx = kof / 100 * x;

                                        try
                                        {
                                            if (_gameMap.map[Convert.ToInt32(inky.pacman_position_plus_two_x - newx), inky.pacman_position_plus_two_y - step] != 'w')
                                            {
                                                inky.finish_point_x = Convert.ToInt32(inky.pacman_position_plus_two_x - newx);

                                                inky.finish_point_y = inky.pacman_position_plus_two_y - step;
                                            }
                                        }
                                        catch
                                        {
                                            step = y;
                                        }
                                        step++;
                                    }
                                }
                            }
                            else if (inky.pacman_position_plus_two_y > blinky.position_y)
                            {
                                y = inky.pacman_position_plus_two_y - blinky.position_y;

                                if (x >= y)
                                {
                                    int step = 0;
                                    while (step != x + 1)
                                    {
                                        double kof  = (((step) * 100) / x);
                                        double newy = kof / 100 * y;

                                        try
                                        {
                                            if (_gameMap.map[(inky.pacman_position_plus_two_x - step), Convert.ToInt32(inky.pacman_position_plus_two_y + newy)] != 'w')
                                            {
                                                inky.finish_point_x = inky.pacman_position_plus_two_x - step;

                                                inky.finish_point_y = Convert.ToInt32(inky.pacman_position_plus_two_y + newy);
                                            }
                                        }
                                        catch
                                        {
                                            step = x;
                                        }
                                        step++;
                                    }
                                }
                                else if (x < y)
                                {
                                    int step = 0;
                                    while (step != y + 1)
                                    {
                                        double kof  = (((step) * 100) / y);
                                        double newx = kof / 100 * x;

                                        try
                                        {
                                            if (_gameMap.map[Convert.ToInt32(inky.pacman_position_plus_two_x - newx), inky.pacman_position_plus_two_y + step] != 'w')
                                            {
                                                inky.finish_point_x = Convert.ToInt32(inky.pacman_position_plus_two_x - newx);

                                                inky.finish_point_y = inky.pacman_position_plus_two_y + step;
                                            }
                                        }
                                        catch
                                        {
                                            step = y;
                                        }
                                        step++;
                                    }
                                }
                            }
                        }
                        else if (inky.pacman_position_plus_two_x > blinky.position_x)
                        {
                            x = inky.pacman_position_plus_two_x - blinky.position_x;

                            if (inky.pacman_position_plus_two_y <= blinky.position_y)
                            {
                                y = blinky.position_y - inky.pacman_position_plus_two_y;

                                if (x >= y)
                                {
                                    int step = 0;
                                    while (step != x + 1)
                                    {
                                        double kof  = (((step) * 100) / x);
                                        double newy = kof / 100 * y;

                                        try
                                        {
                                            if (_gameMap.map[(inky.pacman_position_plus_two_x + step), Convert.ToInt32(inky.pacman_position_plus_two_y - newy)] != 'w')
                                            {
                                                inky.finish_point_x = inky.pacman_position_plus_two_x + step;

                                                inky.finish_point_y = Convert.ToInt32(inky.pacman_position_plus_two_y - newy);
                                            }
                                        }
                                        catch
                                        {
                                            step = x;
                                        }
                                        step++;
                                    }
                                }
                                else if (x < y)
                                {
                                    int step = 0;
                                    while (step != y + 1)
                                    {
                                        double kof  = (((step) * 100) / y);
                                        double newx = kof / 100 * x;

                                        try
                                        {
                                            if (_gameMap.map[Convert.ToInt32(inky.pacman_position_plus_two_x + newx), inky.pacman_position_plus_two_y - step] != 'w')
                                            {
                                                inky.finish_point_x = Convert.ToInt32(inky.pacman_position_plus_two_x + newx);

                                                inky.finish_point_y = inky.pacman_position_plus_two_y - step;
                                            }
                                        }
                                        catch
                                        {
                                            step = y;
                                        }
                                        step++;
                                    }
                                }
                            }
                            else if (inky.pacman_position_plus_two_y > blinky.position_y)
                            {
                                y = inky.pacman_position_plus_two_y - blinky.position_y;

                                if (x >= y)
                                {
                                    int step = 0;
                                    while (step != x + 1)
                                    {
                                        double kof  = (((step) * 100) / x);
                                        double newy = kof / 100 * y;

                                        try
                                        {
                                            if (_gameMap.map[(inky.pacman_position_plus_two_x + step), Convert.ToInt32(inky.pacman_position_plus_two_y + newy)] != 'w')
                                            {
                                                inky.finish_point_x = inky.pacman_position_plus_two_x + step;

                                                inky.finish_point_y = Convert.ToInt32(inky.pacman_position_plus_two_y + newy);
                                            }
                                        }
                                        catch
                                        {
                                            step = x;
                                        }
                                        step++;
                                    }
                                }
                                else if (x < y)
                                {
                                    int step = 0;
                                    while (step != y + 1)
                                    {
                                        double kof  = (((step) * 100) / y);
                                        double newx = kof / 100 * x;

                                        try
                                        {
                                            if (_gameMap.map[Convert.ToInt32(inky.pacman_position_plus_two_x + newx), inky.pacman_position_plus_two_y + step] != 'w')
                                            {
                                                inky.finish_point_x = Convert.ToInt32(inky.pacman_position_plus_two_x + newx);

                                                inky.finish_point_y = inky.pacman_position_plus_two_y + step;
                                            }
                                        }
                                        catch
                                        {
                                            step = y;
                                        }
                                        step++;
                                    }
                                }
                            }
                        }
                    }

                    if (inky.TimerType)
                    {
                        InkyTimer.Change(120, 120);
                        inky.TimerType = false;
                    }

                    // визначення напрямку через граф
                    if (_gameMap.map[inky.position_x, inky.position_y] == 'c')
                    {
                        try
                        {
                            var qwerty = new Init().Inite2(inky.finish_point_x, inky.finish_point_y, inky.position_x, inky.position_y, inky.move_X, inky.move_Y);
                            inky.move_X = qwerty.Item1;
                            inky.move_Y = qwerty.Item2;
                        }
                        catch { }
                    }
                }
                else
                {
                    // блінкі переходить у режим страху: зменшення швидкості, миттєво змінює напрямок, випадково визначає напрямок руху
                    if (_gameMap.map[inky.position_x, inky.position_y] == 'c')
                    {
                        inky.RandomMove();
                        inky.TimerType = true;
                    }
                }


                if (_gameMap.map[inky.position_x + inky.move_X, inky.position_y + inky.move_Y] != 'w')
                {
                    inky.position_x += inky.move_X;
                    inky.position_y += inky.move_Y;
                }

                // перевірка чи гост не зловив пакмена
                CheckPacmanTouchGhost(inky);


                hub.Clients.Clients(clients).SendAsync("ChangeInkyPosition", inky.position_x, inky.position_y, inky.IsFrightened, inky.MovingToHome);
            }
        }