Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factor out game enum/states/logic? #74

Open
samreid opened this issue Jun 15, 2018 · 5 comments
Open

Factor out game enum/states/logic? #74

samreid opened this issue Jun 15, 2018 · 5 comments

Comments

@samreid
Copy link
Member

samreid commented Jun 15, 2018

From phetsims/area-model-common#99

// Copyright 2017-2018, University of Colorado Boulder

/**
 * Enumeration for all states that the game can be in.
 *
 * @author Jonathan Olson <[email protected]>
 * REVIEW: These states and corresponding logic are duplicated across many games.  Do we have the potential to factor something out?
 * REVIEW*: Probably not easily, as showing a "correct" solution, giving two attempts, and having a "level complete"
 * REVIEW*: state are not-at-all universal for game sims.
 */
define( function( require ) {
  'use strict';

  // modules
  var areaModelCommon = require( 'AREA_MODEL_COMMON/areaModelCommon' );

  var GameState = {
    // "check" button, editable
    FIRST_ATTEMPT: 'FIRST_ATTEMPT',
    SECOND_ATTEMPT: 'SECOND_ATTEMPT',

    // "next" button, happy face with +1 or +2 depending on score. NOT editable
    CORRECT_ANSWER: 'CORRECT_ANSWER',

    // "try again" button, sad face (editable?) - triggers next state on edit?
    WRONG_FIRST_ANSWER: 'WRONG_FIRST_ANSWER',

    // "show solution" button, sad face (editable?) - no trigger on edit?
    WRONG_SECOND_ANSWER: 'WRONG_SECOND_ANSWER',

    // "next" button, NOT editable, replaced with a solution
    SHOW_SOLUTION: 'SHOW_SOLUTION',

    LEVEL_COMPLETE: 'LEVEL_COMPLETE'
  };

  areaModelCommon.register( 'GameState', GameState );

  // @public {Array.<GameState>} - All values the enumeration can take.
  GameState.VALUES = [
    GameState.FIRST_ATTEMPT,
    GameState.SECOND_ATTEMPT,
    GameState.CORRECT_ANSWER,
    GameState.WRONG_FIRST_ANSWER,
    GameState.WRONG_SECOND_ANSWER,
    GameState.SHOW_SOLUTION,
    GameState.LEVEL_COMPLETE
  ];

  // verify that enum is immutable, without the runtime penalty in production code
  if ( assert ) { Object.freeze( GameState ); }

  return GameState;
} );

I've seen several games that use these states, should this or corresponding logic be factored out? I'll run this past @jbphet first, since he has familiarity with vegas and some games.

@jbphet
Copy link
Contributor

jbphet commented Jun 15, 2018

I had this same thought a while back and tried it in Area Builder, please see the file QuizGameModel.js. It was an attempt to do - I think - exactly what you're describing here, i.e. extract the logic for the basic flow of the game into a reusable object or set of objects. In the end, I found what I'd implemented a little awkward because there was some sim-specific logic that needed to be hooked up somehow, and I did that, and it worked, but I didn't feel like it worked well enough that I wanted to move it into the vegas repo. Please take a look and, if you think it would be worth the effort, we could potentially use this as a starting point and go from there. It does seem like it would be a cost savings if there was a grab-and-go object for this that wasn't too hard to use.

@jonathanolson
Copy link
Contributor

@samreid is there something I should do here? It's the last blocking common non-a11y issue for area-model.

@samreid
Copy link
Member Author

samreid commented Jun 29, 2018

At some point we should move code like this and supporting logic into vegas. That will help us develop new games, factor out code from other games and will simplify PhET-iO development and API. It's really up to Ariel when we do that.

@samreid samreid assigned ariel-phet and unassigned samreid Jun 29, 2018
@ariel-phet
Copy link

@samreid I agree we should do this at some point. @jbphet next sim after EFAC is quite likely to be a new math sim....and math sims often seem to have games. I am going to mark this as deferred and perhaps we can consider this improvement with our next sim with a game.

@ariel-phet
Copy link

Marked as deferred but assigned to @jbphet to be revisited when we look at next math sim.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants