Beispiel #1
0
        private void UpdatePacman(object state)
        {
            if (_pacman.isMoving)
            {
                if (pause == false)
                {
                    if (_gameMap.CoinMap[_pacman.position_x, _pacman.position_y] == 'c')
                    {
                        _gameMap.CoinMap[_pacman.position_x, _pacman.position_y] = ' ';
                        score.coin_sum += 10;
                        score.ghost_start++;
                        score.game_finish++;
                        //if (ghost_start_score == blinky.initial_score_limit)
                        //{
                        //    blinky.StartMoving();
                        //}
                        if ((score.ghost_start == pinky.initial_score_limit) && (pinky.IsMoving == false))
                        {
                            pinky.StartMoving();
                        }
                        if ((score.ghost_start == clyde.initial_score_limit) && (clyde.IsMoving == false))
                        {
                            clyde.StartMoving();
                        }
                        if ((score.ghost_start == inky.initial_score_limit) && (inky.IsMoving == false))
                        {
                            inky.StartMoving();
                        }
                        if (score.game_finish == 96)
                        {
                            Random random = new Random();
                            var    t      = random.Next(eated_coin.Count);
                            fruit_pos = eated_coin[t];

                            int first;
                            int second;

                            if (fruit_pos[1] == 'o')
                            {
                                first = Convert.ToInt32(fruit_pos[0].ToString());
                            }
                            else
                            {
                                first = Convert.ToInt32(((fruit_pos[0].ToString() + fruit_pos[1].ToString())).ToString());
                            }

                            if (fruit_pos[fruit_pos.Length - 2] == 'o')
                            {
                                second = Convert.ToInt32((fruit_pos[fruit_pos.Length - 1]).ToString());
                            }
                            else
                            {
                                second = Convert.ToInt32(((fruit_pos[fruit_pos.Length - 2].ToString() + fruit_pos[fruit_pos.Length - 1].ToString())).ToString());
                            }


                            _gameMap.CoinMap[first, second] = 'f';
                            hub.Clients.Clients(clients).SendAsync("CreateFruit", fruit_pos);
                        }
                        if (score.game_finish == 200)
                        {
                            Random random = new Random();
                            var    t      = random.Next(eated_coin.Count);
                            fruit_pos = eated_coin[t];

                            int first;
                            int second;

                            if (fruit_pos[1] == 'o')
                            {
                                first = Convert.ToInt32(fruit_pos[0].ToString());
                            }
                            else
                            {
                                first = Convert.ToInt32(((fruit_pos[0].ToString() + fruit_pos[1].ToString())).ToString());
                            }

                            if (fruit_pos[fruit_pos.Length - 2] == 'o')
                            {
                                second = Convert.ToInt32((fruit_pos[fruit_pos.Length - 1]).ToString());
                            }
                            else
                            {
                                second = Convert.ToInt32(((fruit_pos[fruit_pos.Length - 2].ToString() + fruit_pos[fruit_pos.Length - 1].ToString())).ToString());
                            }


                            _gameMap.CoinMap[first, second] = 'f';
                            hub.Clients.Clients(clients).SendAsync("CreateFruit", fruit_pos);
                        }
                        if (score.game_finish == 284)
                        {
                            NextLevel();
                        }

                        eated_coin.Add((_pacman.position_x).ToString() + "o" + (_pacman.position_y).ToString());
                    }
                    else if (_gameMap.CoinMap[_pacman.position_x, _pacman.position_y] == 'k')
                    {
                        eated_energizer.Add((_pacman.position_x).ToString() + "o" + (_pacman.position_y).ToString());

                        //score = score + 10;
                        score.bonus_coin = 100;

                        MakeGhostFrightened(blinky, BlinkyTimer);

                        MakeGhostFrightened(pinky, PinkyTimer);

                        MakeGhostFrightened(clyde, ClydeTimer);

                        MakeGhostFrightened(inky, InkyTimer);

                        _gameMap.CoinMap[_pacman.position_x, _pacman.position_y] = ' ';
                    }
                    else if (_gameMap.CoinMap[_pacman.position_x, _pacman.position_y] == 'f')
                    {
                        score.sum_bonus_coin = score.sum_bonus_coin + 500;
                        hub.Clients.Clients(clients).SendAsync("DestroyFruit", fruit_pos);
                        _gameMap.CoinMap[_pacman.position_x, _pacman.position_y] = ' ';
                    }

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

                    // перевірка чи пакмен не натрапив на блінкі
                    CheckPacmanTouchGhost(blinky);

                    // перевірка чи пакмен не натрапив на пінкі
                    CheckPacmanTouchGhost(pinky);

                    // перевірка чи пакмен не натрапив на клуді
                    CheckPacmanTouchGhost(clyde);

                    // перевірка чи пакмен не натрапив на інкі
                    CheckPacmanTouchGhost(inky);


                    hub.Clients.Clients(clients).SendAsync("ChangePacmanPosition", _pacman.position_x, _pacman.position_y, score.coin_sum + score.sum_bonus_coin);
                }
            }
        }