Esempio n. 1
0
        public static BaseGame StartPVPGame(List <IGamePlayer> red, List <IGamePlayer> blue, int mapIndex, eRoomType roomType, eGameType gameType, int timeType)
        {
            try
            {
                int index = MapMgr.GetMapIndex(mapIndex, (byte)roomType, m_serverId);
                Map map   = MapMgr.CloneMap(index);

                if (map != null)
                {
                    PVPGame game = new PVPGame(m_gameId++, 0, red, blue, map, roomType, gameType, timeType);

                    lock (m_games)
                    {
                        m_games.Add(game.Id, game);
                    }

                    game.Prepare();
                    return(game);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                log.Error("Create game error:", e);
                return(null);
            }
        }
Esempio n. 2
0
        private void OnGameEnd()
        {
            m_game = null;

            MsgBoxAPI.ShowMsgBox("game over", "your score for this game is: " + cur_score, "OK", (arg) =>
            {
                UIManager.Instance.GoBackPage();
            });
        }
Esempio n. 3
0
        private void OnGameEnd()
        {
            m_game = null;

            UIAPI.ShowMsgBox("游戏结束", "显示游戏积分...", "确定", (arg) =>
            {
                UIManager.Instance.GoBackPage();
            });
        }
Esempio n. 4
0
    //==============================================
    void OnGameStart(PVPStartParam startParam)
    {
        pvpGame = new PVPGame();
        pvpGame.Start(startParam);

        EventManager.Instance.SendEvent(EventDef.OnEnterBattle);

        CreateBattleView();
    }
Esempio n. 5
0
    //=========================================
    void OnLeaveBattle()
    {
        if (pvpGame != null)
        {
            pvpGame.Stop();
            pvpGame = null;
        }

        ClearBattleView();

        ModuleManager.Instance.OpenModule(ModuleDef.LobbyModule);
    }
Esempio n. 6
0
        protected override void OnOpen(object arg)
        {
            base.OnOpen(arg);

            PVPModule module = ModuleManager.Instance.GetModule(ModuleDef.PVPModule) as PVPModule;

            m_game = module.GetGame();
            m_game.onMainPlayerDie += OnMainPlayerDie;
            m_game.onGameEnd       += OnGameEnd;

            txtUserInfo.text = UserManager.Instance.MainUserData.name;
            txtTimeInfo.text = "";
        }
Esempio n. 7
0
        public static BaseGame StartPVPGame(int roomId, List <IGamePlayer> red, List <IGamePlayer> blue, int mapIndex, eRoomType roomType, eGameType gameType, int timeType)
        {
            BaseGame result;

            try
            {
                int totalLevel = 0;
                foreach (IGamePlayer player in red)
                {
                    totalLevel += player.PlayerCharacter.Grade;
                }
                foreach (IGamePlayer player in blue)
                {
                    totalLevel += player.PlayerCharacter.Grade;
                }
                int averageLevel = totalLevel / (red.Count + blue.Count);
                int mapId        = MapMgr.GetMapIndex(averageLevel, GameMgr.m_serverId);
                if (mapIndex == 0)
                {
                    mapIndex = mapId;
                }
                Map map = MapMgr.AllocateMapInstance(mapIndex);
                if (map != null)
                {
                    PVPGame game = new PVPGame(GameMgr.m_gameId++, roomId, red, blue, map, roomType, gameType, timeType, 0);
                    //game.GameOverLog += new BaseGame.GameOverLogEventHandle(LogMgr.LogFightAdd);
                    List <BaseGame> games;
                    Monitor.Enter(games = GameMgr.m_games);
                    try
                    {
                        GameMgr.m_games.Add(game);
                    }
                    finally
                    {
                        Monitor.Exit(games);
                    }
                    game.Prepare();
                    result = game;
                }
                else
                {
                    result = null;
                }
            }
            catch (Exception e)
            {
                GameMgr.log.Error("Create game error:", e);
                result = null;
            }
            return(result);
        }
Esempio n. 8
0
        public void Execute(BaseGame game, long tick)
        {
            if (this.m_tick <= tick)
            {
                PVPGame pvp = game as PVPGame;
                if (pvp != null)
                {
                    switch (game.GameState)
                    {
                    case eGameState.Inited:
                        pvp.Prepare();
                        break;

                    case eGameState.Prepared:
                        pvp.StartLoading();
                        break;

                    case eGameState.Loading:
                        if (pvp.IsAllComplete())
                        {
                            pvp.StartGame();
                        }
                        break;

                    case eGameState.Playing:
                        if ((pvp.CurrentPlayer == null || !pvp.CurrentPlayer.IsAttacking) && pvp.CurrentActionCount == 1)
                        {
                            if (pvp.CanGameOver())
                            {
                                pvp.GameOver();
                            }
                            else
                            {
                                pvp.NextTurn();
                            }
                        }
                        break;

                    case eGameState.GameOver:
                        if (pvp.CurrentActionCount == 1)
                        {
                            pvp.Stop();
                        }
                        break;
                    }
                }
                this.m_isFinished = true;
            }
        }
Esempio n. 9
0
        /// <summary>
        /// 停止游戏
        /// </summary>
        private void StopGame()
        {
            if (m_game != null)
            {
                m_game.Stop();
                m_game = null;
            }

            if (m_room != null)
            {
                m_room.CancelReady();
            }

            ModuleManager.Instance.SendMessage(ModuleDef.HostModule, "ReStart");
        }
Esempio n. 10
0
        //----------------------------------------------------------------------
        /// <summary>
        /// 开始游戏
        /// </summary>
        /// <param name="param"></param>
        private void StartGame(PVPStartParam param)
        {
            //创建游戏逻辑
            m_game = new PVPGame();
            m_game.Start(param);

            //当游戏结束时
            m_game.onGameEnd += () =>
            {
                StopGame();
            };

            //显示战斗UI
            UIManager.Instance.OpenPage(UIDef.UIPVPGamePage);
        }
Esempio n. 11
0
        //----------------------------------------------------------------------
        /// <summary>
        /// start the game
        /// </summary>
        /// <param name="param"></param>
        private void StartGame(PVPStartParam param)
        {
            //create PVP game
            m_game = new PVPGame();
            m_game.Start(param);

            //when game ends
            m_game.onGameEnd += () =>
            {
                StopGame();
            };

            //show PVP game UI
            UIManager.Instance.OpenPage(UIConst.UIPVPGamePage);
        }
Esempio n. 12
0
        public static BaseGame StartPVPGame(int roomId, List <IGamePlayer> red, List <IGamePlayer> blue, int mapIndex, eRoomType roomType, eGameType gameType, int timeType)
        {
            BaseGame result;

            try
            {
                int mapIndex2 = MapMgr.GetMapIndex(mapIndex, (byte)roomType, GameMgr.m_serverId);
                Map map       = MapMgr.CloneMap(mapIndex2);
                List <PetSkillElementInfo> gameNeedPetSkillInfoList = PetMgr.GameNeedPetSkill();
                if (map != null)
                {
                    PVPGame pVPGame = new PVPGame(GameMgr.m_gameId++, roomId, red, blue, map, roomType, gameType, timeType, gameNeedPetSkillInfoList);
                    pVPGame.GameOverLog += new BaseGame.GameOverLogEventHandle(LogMgr.LogFightAdd);
                    List <BaseGame> games;
                    Monitor.Enter(games = GameMgr.m_games);
                    try
                    {
                        GameMgr.m_games.Add(pVPGame);
                    }
                    finally
                    {
                        Monitor.Exit(games);
                    }
                    pVPGame.Prepare();
                    result = pVPGame;
                }
                else
                {
                    result = null;
                }
            }
            catch (Exception exception)
            {
                GameMgr.log.Error("Create game error:", exception);
                result = null;
            }
            return(result);
        }
Esempio n. 13
0
 protected override void OnClose(object arg)
 {
     m_game = null;
     base.OnClose(arg);
 }
Esempio n. 14
0
 protected override void startButton_Click(object sender, EventArgs e)
 {
     game      = new PVPGame(this);      //make a new game
     base.game = game;                   //give the base class the new game as well
     game.runGame(maxTurns, codeLength); //run the game with appropriate params
 }