/// <summary>
        /// Sets the category of the current round to the given <paramref name="categoryId"/>.
        /// NOTE: It gets the category of the current <see cref="RunningGame.Round"/>, as this is called
        /// when the new round is played
        /// </summary>
        /// <param name="game">The game to be modified</param>
        /// <param name="categoryId">The category ID to be set for the current round</param>
        public static void SetCurrentCategory(this RunningGame game, int categoryId)
        {
            switch (game.Round)
            {
            case 1:
                game.R1Category = categoryId;
                break;

            case 2:
                game.R2Category = categoryId;
                break;

            case 3:
                game.R3Category = categoryId;
                break;

            case 4:
                game.R4Category = categoryId;
                break;

            case 5:
                game.R5Category = categoryId;
                break;

            case 6:
                game.R6Category = categoryId;
                break;
            }
        }
 public GameLaunchedEvent(RunningGame runningGame, Server server = null)
 {
     if (runningGame == null)
     {
         throw new ArgumentNullException(nameof(runningGame));
     }
     RunningGame = runningGame;
     Server      = server;
 }
Beispiel #3
0
        public void RegisterTermination()
        {
            var rg = Running;

            Running = null;
            if (rg != null)
            {
                rg.Dispose();
            }
        }
Beispiel #4
0
        public void RegisterRunning(Process p)
        {
            var current = Running;

            if (current != null)
            {
                current.Dispose();
            }
            Running = new RunningGame(this, p, CalculatedSettings.Collection, CalculatedSettings.Server);
        }
Beispiel #5
0
        /// <summary>
        /// Initialize this module.
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();

            // - Add the first service
            AddService(GetSettings(ModuleLoop));

            // - Load game
            RunningGame?.Load(this);
        }
 /// <summary>
 /// Gets the category of the current round.
 /// NOTE: It gets the category of the PREVIOUS <see cref="RunningGame.Round"/>, as this is called
 /// when the pending round is played
 /// </summary>
 /// <returns></returns>
 public static int GetCurrentCategory(this RunningGame game)
 {
     return(game.Round switch // I have never seen this kind of expression before
     {                        // Thanks, Visual Studio, I keep learning new stuff :D
         2 => game.R1Category,
         3 => game.R2Category,
         4 => game.R3Category,
         5 => game.R4Category,
         6 => game.R5Category,
         7 => game.R6Category,
         _ => - 1,
     });
 /// <summary>
 /// Get a list of all category IDs that were already played in the game <paramref name="g"/>.
 /// </summary>
 /// <param name="g">The game</param>
 /// <returns>A list of all category IDs that were already played in the game <paramref name="g"/></returns>
 public static List <int> GetPlayedCategories(this RunningGame g)
 {
     return(new List <int>
     {
         g.R1Category,
         g.R2Category,
         g.R3Category,
         g.R4Category,
         g.R5Category,
         g.R6Category
     }.Where(x => x != 0).ToList());
 }
Beispiel #8
0
        public static void RunningGame_Save(RunningGame game)
        {
            var g = DB.Table <RunningGame>().FirstOrDefault(x => x.Id == game.Id);

            if (g == null)
            {
                DB.Insert(game);
            }
            else
            {
                DB.Update(game);
            }
        }
Beispiel #9
0
        public void TestAskQuestion()
        {
            var quizQuestion = _questionRepository.List.First();

            var answerSpecification = new QuizAnswerSpecification(questionId: quizQuestion.QuestionId);
            var quizAnswers         = _answerRepository.Query(answerSpecification);

            quizQuestion.Answers = quizAnswers;

            var question = new GameQuestion(quizQuestion, 0, 0);

            var game = new RunningGame(0, new[] { 0 });

            game.AskQuestion(question);

            Assert.Equal(question, game.CurrentQuestion);
        }
Beispiel #10
0
        public void TestUseJoker()
        {
            var quizQuestion = _questionRepository.List.First();

            var answerSpecification = new QuizAnswerSpecification(questionId: quizQuestion.QuestionId);
            var quizAnswers         = _answerRepository.Query(answerSpecification);

            quizQuestion.Answers = quizAnswers;

            var question = new GameQuestion(quizQuestion, 0, 0);

            var game = new RunningGame(0, new[] { 0 });

            game.AskQuestion(question);

            game.UseJoker();

            Assert.True(game.JokerUsed);
        }
Beispiel #11
0
        public void TestAnswerQuestionIncorrect()
        {
            var quizQuestion = _questionRepository.List.First();

            var answerSpecification = new QuizAnswerSpecification(questionId: quizQuestion.QuestionId);
            var quizAnswers         = _answerRepository.Query(answerSpecification);

            quizQuestion.Answers = quizAnswers;

            var question = new GameQuestion(quizQuestion, 0, 0);

            var game = new RunningGame(0, new[] { 0 });

            game.AskQuestion(question);

            var answer = quizAnswers.First(a => !a.Correct);

            var result = game.AnswerQuestion(answer);

            Assert.True(!result.Correct);
        }
Beispiel #12
0
        /// <summary>
        /// Main update function; all game logic MUST be executed in this
        /// context, keep passing the clock on each update call.
        /// </summary>
        /// <param name="clock">Frame clock: gives all timing informations.</param>
        protected virtual void UpdateFunction(IFrameBasedClock clock)
        {
            // - Update the game tree state
            RunningGame.Update(clock);

            // - Gets the game tree resources
            var descriptor = RunningGame.GetDescriptor(UpdateGameLoop.Scheduler);

            // - Dispatch resource loading
            lock (ResourceStash)
            {
                foreach (var resource in descriptor.Resources)
                {
                    ResourceStash.Add(resource);
                }
            }

            // - Send the render assets to the graphic renderer
            using (var lk = GraphicRenderBuffer.Get(UsageType.Write))
                lk.Value = descriptor.Assets;
        }
Beispiel #13
0
        public void TestEndGame()
        {
            var quizQuestion = _questionRepository.List.First();

            var answerSpecification = new QuizAnswerSpecification(questionId: quizQuestion.QuestionId);
            var quizAnswers         = _answerRepository.Query(answerSpecification);

            quizQuestion.Answers = quizAnswers;

            var question = new GameQuestion(quizQuestion, 0, 0);

            var game = new RunningGame(0, new[] { 0 });

            game.AskQuestion(question);

            var answer       = quizAnswers.First(a => a.Correct);
            var answerResult = game.AnswerQuestion(answer);

            var result = game.End(answerResult.Correct && !answerResult.TimeOver, answerResult.TimeOver);

            Assert.Equal(30, result.Points);
        }
Beispiel #14
0
 public static void SaveDB(this RunningGame g)
 {
     Database.RunningGame_Save(g);
 }
Beispiel #15
0
 public static void DeleteDB(this RunningGame g)
 {
     Database.RunningGame_Delete(g);
 }
Beispiel #16
0
 public static void RunningGame_Delete(RunningGame game)
 {
     DB.Delete(game);
 }
Beispiel #17
0
 /// <summary>
 /// Initialize the game update modules and logic.
 /// </summary>
 protected virtual void UpdateInit()
 {
     // - Initialize the game
     RunningGame.Initialize(this);
 }
Beispiel #18
0
        /// <summary>
        /// 炸弹爆炸瞬间画图。type为动画的第几次
        /// </summary>
        /// <param name="type"></param>
        public void DrawExplode(Graphics g, int type, int time, Player player)
        {
            int leftlen  = Math.Max(ShowX - BombLen, 0);
            int rightlen = Math.Min(ShowX + BombLen, Configuration.MAP_WIDTH - 1);
            int uplen    = Math.Max(ShowY - BombLen, 0);
            int downlen  = Math.Min(ShowY + BombLen, Configuration.MAP_HEIGHT - 1);

            destRect.X      = ShowX * DrawWidth;
            destRect.Y      = ShowY * DrawHeight;
            destRect.Width  = DrawWidth;
            destRect.Height = DrawHeight;
            g.DrawImage(explodeImage[4, type], destRect, srcRect, GraphicsUnit.Pixel);
            player.checkDie(ShowX, ShowY);
            RunningGame.ReduceMonsterHp(ShowX, ShowY);

            // 上
            for (int i = ShowY - 1; i >= uplen; i--)
            {
                if (GameMap.gameMap[i, ShowX] == Plat.WALL)
                {
                    break;
                }
                if (!player.IsDie)
                {
                    player.checkDie(ShowX, i);
                }
                RunningGame.ReduceMonsterHp(ShowX, i);

                destRect.X      = ShowX * DrawWidth;
                destRect.Y      = i * DrawHeight;
                destRect.Width  = DrawWidth;
                destRect.Height = DrawHeight;

                // 如果碰到砖
                if (GameMap.gameMap[i, ShowX] == Plat.BRICK)
                {
                    GameMap.gameMap[i, ShowX] = Plat.BRICK_BREAK;
                    g.DrawImage(explodeImage[5, type], destRect, srcRect, GraphicsUnit.Pixel);
                    GameMap.explodeTime[i, ShowX] = Math.Max(time, GameMap.explodeTime[i, ShowX]);
                    break;
                }
                if (GameMap.gameMap[i, ShowX] == Plat.BRICK_BREAK ||
                    GameMap.gameMap[i, ShowX] == Plat.BIG_WALL_SHOW ||
                    GameMap.gameMap[i, ShowX] == Plat.BIG_WALL_HIDE)
                {
                    g.DrawImage(explodeImage[5, type], destRect, srcRect, GraphicsUnit.Pixel);
                    GameMap.explodeTime[i, ShowX] = Math.Max(time, GameMap.explodeTime[i, ShowX]);
                    break;
                }


                if (i - 1 >= 0 && GameMap.gameMap[i - 1, ShowX] == Plat.WALL)
                {
                    g.DrawImage(explodeImage[0, type], destRect, srcRect, GraphicsUnit.Pixel);
                    break;
                }
                if (i != uplen)
                {
                    g.DrawImage(explodeImage[0, 0], destRect, srcRect, GraphicsUnit.Pixel);
                }
                else
                {
                    g.DrawImage(explodeImage[0, type], destRect, srcRect, GraphicsUnit.Pixel);
                }
            }

            // 下
            for (int i = ShowY + 1; i <= downlen; i++)
            {
                if (GameMap.gameMap[i, ShowX] == Plat.WALL)
                {
                    break;
                }
                if (!player.IsDie)
                {
                    player.checkDie(ShowX, i);
                }
                RunningGame.ReduceMonsterHp(ShowX, i);
                destRect.X      = ShowX * DrawWidth;
                destRect.Y      = i * DrawHeight;
                destRect.Width  = DrawWidth;
                destRect.Height = DrawHeight;
                // 如果碰到砖
                if (GameMap.gameMap[i, ShowX] == Plat.BRICK)
                {
                    GameMap.gameMap[i, ShowX] = Plat.BRICK_BREAK;
                    g.DrawImage(explodeImage[5, type], destRect, srcRect, GraphicsUnit.Pixel);
                    GameMap.explodeTime[i, ShowX] = Math.Max(time, GameMap.explodeTime[i, ShowX]);
                    break;
                }
                if (GameMap.gameMap[i, ShowX] == Plat.BRICK_BREAK ||
                    GameMap.gameMap[i, ShowX] == Plat.BIG_WALL_SHOW ||
                    GameMap.gameMap[i, ShowX] == Plat.BIG_WALL_HIDE)
                {
                    g.DrawImage(explodeImage[5, type], destRect, srcRect, GraphicsUnit.Pixel);
                    GameMap.explodeTime[i, ShowX] = Math.Max(time, GameMap.explodeTime[i, ShowX]);
                    break;
                }

                // 如果下一格是墙
                if (i + 1 < Configuration.MAP_HEIGHT && GameMap.gameMap[i + 1, ShowX] == Plat.WALL)
                {
                    g.DrawImage(explodeImage[1, type], destRect, srcRect, GraphicsUnit.Pixel);
                    break;
                }
                if (i != downlen)
                {
                    g.DrawImage(explodeImage[1, 0], destRect, srcRect, GraphicsUnit.Pixel);
                }
                else
                {
                    g.DrawImage(explodeImage[1, type], destRect, srcRect, GraphicsUnit.Pixel);
                }
            }

            // 左
            for (int i = ShowX - 1; i >= leftlen; i--)
            {
                // 如果第一格是墙
                if (GameMap.gameMap[ShowY, i] == Plat.WALL)
                {
                    break;
                }
                if (!player.IsDie)
                {
                    player.checkDie(i, ShowY);
                }
                RunningGame.ReduceMonsterHp(i, ShowY);
                destRect.X      = i * DrawWidth;
                destRect.Y      = ShowY * DrawHeight;
                destRect.Width  = DrawWidth;
                destRect.Height = DrawHeight;
                // 如果碰到砖
                if (GameMap.gameMap[ShowY, i] == Plat.BRICK)
                {
                    GameMap.gameMap[ShowY, i] = Plat.BRICK_BREAK;
                    g.DrawImage(explodeImage[5, type], destRect, srcRect, GraphicsUnit.Pixel);
                    GameMap.explodeTime[ShowY, i] = Math.Max(time, GameMap.explodeTime[ShowY, i]);
                    break;
                }
                if (GameMap.gameMap[ShowY, i] == Plat.BRICK_BREAK ||
                    GameMap.gameMap[ShowY, i] == Plat.BIG_WALL_SHOW ||
                    GameMap.gameMap[ShowY, i] == Plat.BIG_WALL_HIDE)
                {
                    g.DrawImage(explodeImage[5, type], destRect, srcRect, GraphicsUnit.Pixel);
                    GameMap.explodeTime[ShowY, i] = Math.Max(time, GameMap.explodeTime[ShowY, i]);
                    break;
                }

                // 如果下一格是墙
                if (i - 1 >= 0 && GameMap.gameMap[ShowY, i - 1] == Plat.WALL)
                {
                    g.DrawImage(explodeImage[2, type], destRect, srcRect, GraphicsUnit.Pixel);
                    break;
                }

                // 判断是否到结束
                if (i != leftlen)
                {
                    g.DrawImage(explodeImage[2, 0], destRect, srcRect, GraphicsUnit.Pixel);
                }
                else
                {
                    g.DrawImage(explodeImage[2, type], destRect, srcRect, GraphicsUnit.Pixel);
                }
            }

            // 右
            for (int i = ShowX + 1; i <= rightlen; i++)
            {
                if (GameMap.gameMap[ShowY, i] == Plat.WALL)
                {
                    break;
                }
                if (player.IsDie)
                {
                    player.checkDie(i, ShowY);
                }
                RunningGame.ReduceMonsterHp(i, ShowY);
                destRect.X      = i * DrawWidth;
                destRect.Y      = ShowY * DrawHeight;
                destRect.Width  = DrawWidth;
                destRect.Height = DrawHeight;

                // 如果碰到砖
                if (GameMap.gameMap[ShowY, i] == Plat.BRICK)
                {
                    GameMap.gameMap[ShowY, i] = Plat.BRICK_BREAK;
                    g.DrawImage(explodeImage[5, type], destRect, srcRect, GraphicsUnit.Pixel);
                    GameMap.explodeTime[ShowY, i] = Math.Max(time, GameMap.explodeTime[ShowY, i]);
                    break;
                }
                if (GameMap.gameMap[ShowY, i] == Plat.BRICK_BREAK ||
                    GameMap.gameMap[ShowY, i] == Plat.BIG_WALL_SHOW ||
                    GameMap.gameMap[ShowY, i] == Plat.BIG_WALL_HIDE)
                {
                    g.DrawImage(explodeImage[5, type], destRect, srcRect, GraphicsUnit.Pixel);
                    GameMap.explodeTime[ShowY, i] = Math.Max(time, GameMap.explodeTime[ShowY, i]);
                    break;
                }

                // 下一格是墙
                if (i + 1 < Configuration.MAP_WIDTH && GameMap.gameMap[ShowY, i + 1] == Plat.WALL)
                {
                    g.DrawImage(explodeImage[3, type], destRect, srcRect, GraphicsUnit.Pixel);
                    break;
                }

                // 是否到结尾
                if (i != rightlen)
                {
                    g.DrawImage(explodeImage[3, 0], destRect, srcRect, GraphicsUnit.Pixel);
                }
                else
                {
                    g.DrawImage(explodeImage[3, type], destRect, srcRect, GraphicsUnit.Pixel);
                }
            }
        }
 public GameLaunchedEvent(RunningGame runningGame, Server server = null) {
     Contract.Requires<ArgumentNullException>(runningGame != null);
     RunningGame = runningGame;
     Server = server;
 }
Beispiel #20
0
 /// <summary>
 /// Sets the currently running game.
 /// </summary>
 /// <param name="game">The game that is currently running.</param>
 public void SetRunningGame(RunningGame game)
 {
     switch (game)
     {
         case RunningGame.BalloonPaintBucketGame:
             BalloonPaintBucketMainGame.GetInstance().Initialize(Game1.GetInstance());
             break;
         case RunningGame.SquatBugsGame:
             SquatBugsMainGame.GetInstance().Initialize(Game1.GetInstance());
             break;
         case RunningGame.MiniGameOverview:
             MiniGameOverviewMainGame.GetInstance().Initialize(Game1.GetInstance());
             // Remove first
             MiniGameOverviewMainGame.GetInstance().gameInfoPanel.onGameStartListeners -=
                 Game1.GetInstance().OnGameStart;
             MiniGameOverviewMainGame.GetInstance().gameInfoPanel.onGameStartListeners +=
                 Game1.GetInstance().OnGameStart;
             break;
         case RunningGame.DigGame:
             DiggingMainGame.GetInstance().Initialize(Game1.GetInstance());
             break;
         case RunningGame.BuzzBattleGame:
             BuzzBattleMainGame.GetInstance().Initialize(Game1.GetInstance());
             break;
     }
     this.game = game;
 }