/// <summary> /// Lógica del programa. /// </summary> /// <returns>Si se sale del programa o no</returns> public Boolean update() { this.currentScreenState = this.nextScreenState; this.currentPlayState = this.nextPlayState; switch (this.currentScreenState) { case screenState.INIT: // algo en inicio? this.nextScreenState = screenState.MENU; break; case screenState.MENU: updateButtonsState(this.menuButtons); if (this.menuButtons[(int)GameButtonList.menuButton.PLAY].justPushed()) { this.nextScreenState = screenState.PLAY; this.nextPlayState = playState.INIT; } else if (this.menuButtons[(int)GameButtonList.menuButton.EXIT].justPushed()) { // termina el juego return false; } break; case screenState.PLAY: switch (this.currentPlayState) { case playState.INIT: // algo en inicio? this.gamePostures = null; this.gameScores.Clear(); this.nextPlayState = playState.SELECT_POSTURE; break; case playState.SELECT_POSTURE: // actualiza la postura objetivo if (updateCurrentGamePosture()) { /// @FIX001: this.drawPostureTimeOut = Stopwatch.StartNew(); this.nextPlayState = playState.DRAW_POSTURE; } // si no quedan mas posturas va a la puntuacion final else { this.nextPlayState = playState.FINAL_SCORE; } break; case playState.DRAW_POSTURE: // Esta fase es para presentarle al usuario la postura objetivo // TIMEOUT de 10 segundos o pulsar CONTINUE /// @FIX001: Estaba a null el this.drawPostureTimeOut, asique le he puesto valor en SELECT_POSTURE (Margen de error: 1frame). updateButtonsState(this.pauseButtons); if (this.pauseButtons[(int)GameButtonList.pauseButton.CONTINUE].justPushed() || isTimedOut(this.drawPostureTimeOut, DRAW_POSTURE_TIME)) { this.drawPostureTimeOut.Reset(); this.nextPlayState = playState.DETECT_POSTURE; } break; case playState.DETECT_POSTURE: updateButtonsState(this.gameButtons); if (this.gameButtons[(int)GameButtonList.gameButton.PAUSE].justPushed()) this.nextPlayState = playState.PAUSE; else { if (playerSkeleton != null) { Posture.Posture p = new Posture.Posture(playerSkeleton); score = p.compareTo(gamePostures[gamePosturesIndex], ref jointScore, averageTolerance, puntualTolerance); if (score < 1.0) { this.holdPostureTimeOut = Stopwatch.StartNew(); this.nextPlayState = playState.HOLD_POSTURE; } } } break; case playState.HOLD_POSTURE: updateButtonsState(this.gameButtons); if (this.gameButtons[(int)GameButtonList.gameButton.PAUSE].justPushed()) this.nextPlayState = playState.PAUSE; else { if (playerSkeleton != null) { Posture.Posture p = new Posture.Posture(playerSkeleton); score = p.compareTo(gamePostures[gamePosturesIndex], ref jointScore, averageTolerance, puntualTolerance); if (score < 1.0) { // La postura hay que mantenerla 2 segundos (HOLD_POSTURE_TIME) if (isTimedOut(this.holdPostureTimeOut, HOLD_POSTURE_TIME)) { gameScores.Add(gamePostures[gamePosturesIndex], score); this.holdPostureTimeOut.Reset(); this.scoreTimeOut = Stopwatch.StartNew(); this.nextPlayState = playState.SCORE; } } else { this.holdPostureTimeOut.Reset(); this.nextPlayState = playState.DETECT_POSTURE; } } } break; case playState.PAUSE: updateButtonsState(this.pauseButtons); if (this.pauseButtons[(int)GameButtonList.pauseButton.CONTINUE].justPushed()) this.nextPlayState = playState.DETECT_POSTURE; else if (this.pauseButtons[(int)GameButtonList.pauseButton.REPLAY].justPushed()) this.nextPlayState = playState.INIT; else if (this.pauseButtons[(int)GameButtonList.pauseButton.EXIT].justPushed()) this.nextPlayState = playState.END; break; case playState.SCORE: updateButtonsState(this.scoreButtons); // TIMEOUT de 10 segundos a la siguiente postura o se pulsa alguna opcion if (this.scoreButtons[(int)GameButtonList.scoreButton.NEXT].justPushed() || isTimedOut(this.scoreTimeOut, SCORE_TIME)) { this.scoreTimeOut.Reset(); this.nextPlayState = playState.SELECT_POSTURE; } else if (this.scoreButtons[(int)GameButtonList.scoreButton.MENU].justPushed()) { this.scoreTimeOut.Reset(); this.nextPlayState = playState.END; } else if (this.scoreButtons[(int)GameButtonList.scoreButton.REPLAY].justPushed()) { this.scoreTimeOut.Reset(); this.nextPlayState = playState.INIT; } break; case playState.FINAL_SCORE: updateButtonsState(this.scoreButtons); if (this.scoreButtons[(int)GameButtonList.scoreButton.MENU].justPushed()) this.nextPlayState = playState.END; else if (this.scoreButtons[(int)GameButtonList.scoreButton.REPLAY].justPushed()) this.nextPlayState = playState.INIT; break; default: case playState.END: this.nextScreenState = screenState.MENU; break; } break; default: case screenState.END: return false; // Se avisa de que el programa dejara de actualizarse } return true; // Si no esta en estado de END se continua con la ejecucion }
/// <summary> /// Lógica del programa. /// </summary> /// <returns>Si se sale del programa o no</returns> public Boolean update() { this.currentScreenState = this.nextScreenState; this.currentPlayState = this.nextPlayState; switch (this.currentScreenState) { case screenState.INIT: // algo en inicio? this.nextScreenState = screenState.MENU; break; case screenState.MENU: updateButtonsState(this.menuButtons); if (this.menuButtons[(int)GameButtonList.menuButton.PLAY].justPushed()) { this.nextScreenState = screenState.PLAY; this.nextPlayState = playState.INIT; } else if (this.menuButtons[(int)GameButtonList.menuButton.EXIT].justPushed()) { // termina el juego return(false); } break; case screenState.PLAY: switch (this.currentPlayState) { case playState.INIT: // algo en inicio? this.gamePostures = null; this.gameScores.Clear(); this.nextPlayState = playState.SELECT_POSTURE; break; case playState.SELECT_POSTURE: // actualiza la postura objetivo if (updateCurrentGamePosture()) { /// @FIX001: this.drawPostureTimeOut = Stopwatch.StartNew(); this.nextPlayState = playState.DRAW_POSTURE; } // si no quedan mas posturas va a la puntuacion final else { this.nextPlayState = playState.FINAL_SCORE; } break; case playState.DRAW_POSTURE: // Esta fase es para presentarle al usuario la postura objetivo // TIMEOUT de 10 segundos o pulsar CONTINUE /// @FIX001: Estaba a null el this.drawPostureTimeOut, asique le he puesto valor en SELECT_POSTURE (Margen de error: 1frame). updateButtonsState(this.pauseButtons); if (this.pauseButtons[(int)GameButtonList.pauseButton.CONTINUE].justPushed() || isTimedOut(this.drawPostureTimeOut, DRAW_POSTURE_TIME)) { this.drawPostureTimeOut.Reset(); this.nextPlayState = playState.DETECT_POSTURE; } break; case playState.DETECT_POSTURE: updateButtonsState(this.gameButtons); if (this.gameButtons[(int)GameButtonList.gameButton.PAUSE].justPushed()) { this.nextPlayState = playState.PAUSE; } else { if (playerSkeleton != null) { Posture.Posture p = new Posture.Posture(playerSkeleton); score = p.compareTo(gamePostures[gamePosturesIndex], ref jointScore, averageTolerance, puntualTolerance); if (score < 1.0) { this.holdPostureTimeOut = Stopwatch.StartNew(); this.nextPlayState = playState.HOLD_POSTURE; } } } break; case playState.HOLD_POSTURE: updateButtonsState(this.gameButtons); if (this.gameButtons[(int)GameButtonList.gameButton.PAUSE].justPushed()) { this.nextPlayState = playState.PAUSE; } else { if (playerSkeleton != null) { Posture.Posture p = new Posture.Posture(playerSkeleton); score = p.compareTo(gamePostures[gamePosturesIndex], ref jointScore, averageTolerance, puntualTolerance); if (score < 1.0) { // La postura hay que mantenerla 2 segundos (HOLD_POSTURE_TIME) if (isTimedOut(this.holdPostureTimeOut, HOLD_POSTURE_TIME)) { gameScores.Add(gamePostures[gamePosturesIndex], score); this.holdPostureTimeOut.Reset(); this.scoreTimeOut = Stopwatch.StartNew(); this.nextPlayState = playState.SCORE; } } else { this.holdPostureTimeOut.Reset(); this.nextPlayState = playState.DETECT_POSTURE; } } } break; case playState.PAUSE: updateButtonsState(this.pauseButtons); if (this.pauseButtons[(int)GameButtonList.pauseButton.CONTINUE].justPushed()) { this.nextPlayState = playState.DETECT_POSTURE; } else if (this.pauseButtons[(int)GameButtonList.pauseButton.REPLAY].justPushed()) { this.nextPlayState = playState.INIT; } else if (this.pauseButtons[(int)GameButtonList.pauseButton.EXIT].justPushed()) { this.nextPlayState = playState.END; } break; case playState.SCORE: updateButtonsState(this.scoreButtons); // TIMEOUT de 10 segundos a la siguiente postura o se pulsa alguna opcion if (this.scoreButtons[(int)GameButtonList.scoreButton.NEXT].justPushed() || isTimedOut(this.scoreTimeOut, SCORE_TIME)) { this.scoreTimeOut.Reset(); this.nextPlayState = playState.SELECT_POSTURE; } else if (this.scoreButtons[(int)GameButtonList.scoreButton.MENU].justPushed()) { this.scoreTimeOut.Reset(); this.nextPlayState = playState.END; } else if (this.scoreButtons[(int)GameButtonList.scoreButton.REPLAY].justPushed()) { this.scoreTimeOut.Reset(); this.nextPlayState = playState.INIT; } break; case playState.FINAL_SCORE: updateButtonsState(this.scoreButtons); if (this.scoreButtons[(int)GameButtonList.scoreButton.MENU].justPushed()) { this.nextPlayState = playState.END; } else if (this.scoreButtons[(int)GameButtonList.scoreButton.REPLAY].justPushed()) { this.nextPlayState = playState.INIT; } break; default: case playState.END: this.nextScreenState = screenState.MENU; break; } break; default: case screenState.END: return(false); // Se avisa de que el programa dejara de actualizarse } return(true); // Si no esta en estado de END se continua con la ejecucion }
public void TestPostureCompareTo_ClosePosture() { Posture.Posture p1 = PostureLibrary.loadPosture("./postures/T_JOSE"); Posture.Posture p2 = PostureLibrary.loadPosture("./postures/T_JOSE2"); Assert.Less(p1.compareTo(p2, ref jointScore, puntualTolerance, averageTolerance), 1); }