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(); } } }
void _NotifyEvent(INotifyObserver observer, string eventName, INotifyData data) { if (_observers.Contains(observer)) { observer.onNotify(eventName, data); } }
//暂停游戏 private void stopGame(INotifyData obj) { if (_stoneBallObj != null) { Destroy(_stoneBallObj); _stoneBallObj = null; } }
private void handleGamePrepareOk(INotifyData obj) { //初始化数据 GameModel gameModel = GameModel.getInstance(); gameModel.level = 1; gameModel.score = 0; startRound(); }
private void playButonPressedSound(INotifyData obj) { int soundIndex = (int)E_SOUND_ID.E_BUTTON_PRESSED_SOUND; if (_audioResources.Count > soundIndex) { _audioResources[soundIndex].Play(); } }
private void showStopMenu(INotifyData obj) { GameObject menu = showScene(1, SceneLayerType.E_MENU_LAYER_TYPE); StopMenu logic = menu.GetComponent <StopMenu>(); if (logic != null) { logic.setGameEndDisplay(obj.id == (int)NotifyId.NOTIFY_SHOW_GAME_END); } }
public void onNotify(string eventName, INotifyData data) { EmitterData info = data as EmitterData; Console.WriteLine(_name + "::onNotify : " + eventName + " / " + info._data); // The default behavior of this test transmitter would be // to propagate the event to observers who are looking at you. NotifyEvent(eventName, data); }
public void NotifyEvent(string eventName, INotifyData data) { var info = data as EmitterData; if (_emitter.HasObserver()) { Console.WriteLine("NotifyEvent : " + eventName + " / " + info._data); _emitter.NotifyEvent(eventName, data); } }
private void startRound(INotifyData obj) { NotifyData <NotifyRoundStartMsg> msg = obj as NotifyData <NotifyRoundStartMsg>; //创建一个石球 resetStoneBall(msg.data.result); cannon.clearNumber(); //刷新按键数字 numberBtnArea.refreshNumbers(msg.data.numbers); }
public void NotifyEvent(string eventName, INotifyData data) { Queue <INotifyObserver> queue = new Queue <INotifyObserver>(); _observers.ForEach((observer) => { queue.Enqueue(observer); }); while (queue.Count > 0) { _NotifyEvent(queue.Dequeue(), eventName, data); } }
private void onOpNumberChanged(INotifyData obj) { NotifyData <int> msg = obj as NotifyData <int>; if (msg.data <= 0) { numberText.text = ""; } else { numberText.text = msg.data.ToString(); } }
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(); }
private void showOpResult(INotifyData obj) { NotifyData <bool> notifyData = obj as NotifyData <bool>; //算对了 if (notifyData.data == true) { //将炮移到数字的位置 if (_stoneBallObj != null) { float x = _stoneBallObj.transform.localPosition.x; cannon.moveToX(x); } else { Debug.LogError("GameScene.showOpResult: _stoneBallObj is null"); } } else { cannon.shake(); } }
private void handleStopGame(INotifyData obj) { GameNotifier.getInstance().notifyStateChange((int)NotifyId.NOTIFY_SHOW_STOP_MENU); }
private void onLevelUpdate(INotifyData obj) { NotifyData <int> data = obj as NotifyData <int>; levelText.text = "LVL:" + data.data.ToString(); }
private void onScroeUpdate(INotifyData obj) { NotifyData <int> data = obj as NotifyData <int>; scoreText.text = data.data.ToString(); }
private void onGameStop(INotifyData obj) { throw new NotImplementedException(); }
//球落到地上了,游戏结束 public void handleStoneFallingEnd(INotifyData obj) { GameNotifier.getInstance().notifyStateChange((int)NotifyId.NOTIFY_SHOW_GAME_END); }
private void handleRestartGame(INotifyData obj) { handleGamePrepareOk(obj); }
private void handleContinuGame(INotifyData obj) { startRound(); }