void OnCollisionEnter2D(Collision2D coll) { //炮弹发生碰撞,表明击中了 GameObject.Destroy(this.gameObject); GameNotifier.getInstance().notifyStateChange((int)NotifyId.NOTIFY_BULLET_HIT); }
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(); } } }
private void onContinueBtnClick() { //析构本界面 Destroy(this.gameObject); //重新开始游戏 GameNotifier.getInstance().notifyStateChange((int)NotifyId.CONTINUE_GAME); }
private void onRestartBtnClick() { //析构本界面 Destroy(this.gameObject); //重新开始游戏 GameNotifier.getInstance().notifyStateChange((int)NotifyId.RESTART_GAME); }
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); }
void OnCollisionEnter2D(Collision2D coll) { //如果不是子弹打的, 游戏结束 if (!coll.gameObject.name.StartsWith("Bullet")) { GameNotifier.getInstance().notifyStateChange((int)NotifyId.ON_STONE_BALL_FALLING_END); } }
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); }
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; }
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(); }
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; }
private void onStopBtnClick() { GameNotifier.getInstance().notifyStateChange((int)NotifyId.STOP_GAME); }
//球落到地上了,游戏结束 public void handleStoneFallingEnd(INotifyData obj) { GameNotifier.getInstance().notifyStateChange((int)NotifyId.NOTIFY_SHOW_GAME_END); }
private void handleStopGame(INotifyData obj) { GameNotifier.getInstance().notifyStateChange((int)NotifyId.NOTIFY_SHOW_STOP_MENU); }