Example #1
0
    void OnCollisionEnter2D(Collision2D coll)
    {
        //炮弹发生碰撞,表明击中了
        GameObject.Destroy(this.gameObject);

        GameNotifier.getInstance().notifyStateChange((int)NotifyId.NOTIFY_BULLET_HIT);
    }
Example #2
0
    public void handleBtnClick(INotifyData obj)
    {
        NotifyData <int> msg = obj as NotifyData <int>;

        if (msg != null)
        {
            GameModel    gameModel    = GameModel.getInstance();
            GameNotifier gameNotifier = GameNotifier.getInstance();

            bool needResult = false;

            //如果现在已经有数字, 加上去
            if (gameModel.opNumber > 0)
            {
                gameModel.opNumber += msg.data;
                needResult          = true;
            }
            else
            {
                gameModel.opNumber = msg.data;
            }

            //通知炮上的数字发生改变
            gameNotifier.notifydata((int)NotifyId.CANNON_NUMBER_CHANGE, gameModel.opNumber);

            //如果需要结算
            if (needResult)
            {
                handleOpResult();
            }
        }
    }
Example #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime appLifetime)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            //app.UseCookiePolicy();

            app.UseSignalR(routes =>
            {
                routes.MapHub <SpaceHub>("/spaceHub");
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            appLifetime.ApplicationStarted.Register(() =>
            {
                GameNotifier = app.ApplicationServices.GetService <GameNotifier>();
                GameNotifier.UpdateGameState(null);
            });
        }
Example #4
0
 private void onContinueBtnClick()
 {
     //析构本界面
     Destroy(this.gameObject);
     //重新开始游戏
     GameNotifier.getInstance().notifyStateChange((int)NotifyId.CONTINUE_GAME);
 }
Example #5
0
 private void onRestartBtnClick()
 {
     //析构本界面
     Destroy(this.gameObject);
     //重新开始游戏
     GameNotifier.getInstance().notifyStateChange((int)NotifyId.RESTART_GAME);
 }
Example #6
0
        public void SubscribeToEvents(string gameId, int fromSequenceNumber)
        {
            var movesSubscriber        = new MovesNotifier(gameId, fromSequenceNumber, serviceBus, movesRepository, client);
            var gameFinishedSubscriber = new GameNotifier(gameId, serviceBus, client);

            HandleNewNotifier(movesSubscriber);
            HandleNewNotifier(gameFinishedSubscriber);
        }
Example #7
0
    void Start()
    {
        _recipient.addNotify(NotifyId.START_A_ROUND, startRound);
        _recipient.addNotify(NotifyId.NOTIFY_OP_RESULT, showOpResult);
        _recipient.addNotify(NotifyId.NOTIFY_SHOW_STOP_MENU, stopGame);

        GameNotifier.getInstance().notifyStateChange((int)NotifyId.NOTIFY_GAME_PREPARE_OK);
    }
Example #8
0
 void OnCollisionEnter2D(Collision2D coll)
 {
     //如果不是子弹打的, 游戏结束
     if (!coll.gameObject.name.StartsWith("Bullet"))
     {
         GameNotifier.getInstance().notifyStateChange((int)NotifyId.ON_STONE_BALL_FALLING_END);
     }
 }
Example #9
0
    private void onBtnClick()
    {
        GameNotifier.getInstance().notifydata((int)NotifyId.ON_NUMBER_BTN_CLICK, int.Parse(numberText.text));

        //播放按键音
        GameNotifier.getInstance().notifyStateChange((int)NotifyId.NOTIFY_PLAY_BUTTON_PRESSED_SOUND);

        //处于按下状态,不能再点击
        setBtnEnable(false);
    }
Example #10
0
    public void handleOpResult()
    {
        GameNotifier gameNotifier = GameNotifier.getInstance();
        GameModel    gameModel    = GameModel.getInstance();

        //通知结果
        bool isCorrect = (gameModel.resultNumber == gameModel.opNumber);

        gameNotifier.notifydata((int)NotifyId.NOTIFY_OP_RESULT, isCorrect);

        //重置记录的数字
        gameModel.opNumber = -1;
    }
Example #11
0
    private void handleBulletHit(INotifyData obj)
    {
        GameModel    gameModel    = GameModel.getInstance();
        GameNotifier gameNotifier = GameNotifier.getInstance();

        gameModel.score += 1;
        gameNotifier.notifydata((int)NotifyId.NOTIFY_SOCRE_UPDATE, gameModel.score);

        //每5分升一级
        if (gameModel.score > 0 && gameModel.score % 5 == 0)
        {
            gameModel.level += 1;
            gameNotifier.notifydata((int)NotifyId.NOTIFY_LEVEL_UPDATE, gameModel.level);
        }

        startRound();
    }
Example #12
0
    public void startRound()
    {
        int       numberCount = 8;
        GameModel gameModel   = GameModel.getInstance();

        //最大数字
        int maxNumber = gameModel.level * 10;

        //生成8个随机数
        List <int> randomNumbers = new List <int>();

        while (randomNumbers.Count < numberCount)
        {
            int number = gameModel.getRandomNumber(1, maxNumber);
            if (randomNumbers.IndexOf(number) != -1)
            {
                continue;
            }
            randomNumbers.Add(number);
        }

        //挑选2个座位结果
        int index1 = gameModel.getRandomNumber(0, numberCount - 1);
        int index2 = gameModel.getRandomNumber(0, numberCount - 1);

        while (index1 == index2)
        {
            index2 = gameModel.getRandomNumber(0, numberCount - 1);
        }

        //消息体
        NotifyData <NotifyRoundStartMsg> msg = new NotifyData <NotifyRoundStartMsg>();

        msg.data = new NotifyRoundStartMsg();

        msg.id           = (int)NotifyId.START_A_ROUND;
        msg.data.result  = randomNumbers[index1] + randomNumbers[index2];
        msg.data.numbers = randomNumbers;
        GameNotifier.getInstance().notify(msg);

        gameModel.resultNumber = msg.data.result;
    }
Example #13
0
 private void onStopBtnClick()
 {
     GameNotifier.getInstance().notifyStateChange((int)NotifyId.STOP_GAME);
 }
Example #14
0
 //球落到地上了,游戏结束
 public void handleStoneFallingEnd(INotifyData obj)
 {
     GameNotifier.getInstance().notifyStateChange((int)NotifyId.NOTIFY_SHOW_GAME_END);
 }
Example #15
0
 private void handleStopGame(INotifyData obj)
 {
     GameNotifier.getInstance().notifyStateChange((int)NotifyId.NOTIFY_SHOW_STOP_MENU);
 }