Android Open Source - SeniorDesign Hint Provider






From Project

Back to project page SeniorDesign.

License

The source code is released under:

GNU General Public License

If you think the Android project SeniorDesign listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package fakesetgame.seniordesign.model;
/*from w  w  w  . ja  va2 s .co  m*/
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * A class to provide hints about the game to the player.
 */
public class HintProvider {
    private final Game game;

    public HintProvider(Game game) {
        this.game = game;
    }

    private Set<Set<Tile>> hintedSets = new HashSet<Set<Tile>>();
    private List<Tile> hintTiles = null;
    private Set<Tile> providedHints = null;

    public boolean wasHintProvided(Set<Tile> tileSet) {
        return hintedSets.contains(tileSet);
    }

    public Set<Tile> getHint() {
        if (game.isGameOver())
            return null;

        // If the hint we're working on has already been found,
        // clear it from memory
        if (hintTiles != null && game.isFound(hintTiles)) {
            hintTiles = null;
            providedHints = null;
        }

        // If we're not working on a hint, pick a set of tiles
        // that hasn't been found
        if (hintTiles == null) {
            // need to find a new set to make hints for
            for (Set<Tile> set : game.board.getSets()) {
                if (!game.isFound(set)) {
                    hintedSets.add(set);
                    hintTiles = new ArrayList<Tile>(set);
                    providedHints = new HashSet<Tile>();
                    break;
                }
            }

            if (hintTiles == null)
                throw new RuntimeException("We haven't found all the sets, but still couldn't find a set to make a hint for. This shouldn't happen.");
        }

        if (providedHints.size() < hintTiles.size() - 1)
            providedHints.add(hintTiles.get(providedHints.size()));

        game.setHintUsed();
        return providedHints;
    }
}




Java Source Code List

fakesetgame.seniordesign.BoardTest.java
fakesetgame.seniordesign.GameScreen.java
fakesetgame.seniordesign.GameTest.java
fakesetgame.seniordesign.HomeScreen.java
fakesetgame.seniordesign.OptionsScreen.java
fakesetgame.seniordesign.SettingsTest.java
fakesetgame.seniordesign.SplashScreen.java
fakesetgame.seniordesign.SummaryScreen.java
fakesetgame.seniordesign.TileSetTest.java
fakesetgame.seniordesign.data.FoundSetRecord.java
fakesetgame.seniordesign.data.GameOutcome.java
fakesetgame.seniordesign.data.GameSummaryListItemCursorAdapter.java
fakesetgame.seniordesign.data.OptionsHelper.java
fakesetgame.seniordesign.data.PlayerDataDbHelper.java
fakesetgame.seniordesign.data.Setting.java
fakesetgame.seniordesign.data.package-info.java
fakesetgame.seniordesign.model.BoardSize.java
fakesetgame.seniordesign.model.Board.java
fakesetgame.seniordesign.model.Color.java
fakesetgame.seniordesign.model.GameOverEvent.java
fakesetgame.seniordesign.model.GameOverListener.java
fakesetgame.seniordesign.model.Game.java
fakesetgame.seniordesign.model.HintProvider.java
fakesetgame.seniordesign.model.Modifier.java
fakesetgame.seniordesign.model.Shading.java
fakesetgame.seniordesign.model.Shape.java
fakesetgame.seniordesign.model.TileSet.java
fakesetgame.seniordesign.model.Tile.java
fakesetgame.seniordesign.model.package-info.java
fakesetgame.seniordesign.view.GameSummaryListItemView.java
fakesetgame.seniordesign.view.ShadedImageView.java
fakesetgame.seniordesign.view.package-info.java
fakesetgame.seniordesign.package-info.java