Android Open Source - minecraft-connect-4 Game Rules






From Project

Back to project page minecraft-connect-4.

License

The source code is released under:

MIT License

If you think the Android project minecraft-connect-4 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

/* COPYRIGHT (C) 2014 Aleksandr Belkin. All Rights Reserved. */
package sq.squ1rr.mcc4.rules;
// w  ww.  j a va 2 s  . c  om
import android.os.Bundle;
import sq.squ1rr.mcc4.R;

/**
 * Provides interface to manipulate and access game rules.
 * Provides functionality to save and load game rules.
 * @author Aleksandr Belkin
 */
public class GameRules {
    /**
     * Difficulty settings
     */
    public class Difficulty extends Rule {
        public static final int PEACEFUL    = R.string.difficulty_0;
        public static final int EASY        = R.string.difficulty_1;
        public static final int NORMAL      = R.string.difficulty_2;
        public static final int HARD        = R.string.difficulty_3;
        

        Difficulty() {
            super(new int[] { PEACEFUL, EASY, NORMAL, HARD });
        }
    }

    /**
     * First Turn settings
     */
    public class FirstTurn extends Rule {
        public static final int PLAYER1        = Player.PLAYER1;
        public static final int PLAYER2        = Player.PLAYER2;
        

        FirstTurn() {
            super(new int[] { PLAYER1, PLAYER2});
        }
    }

    /**
     * Game Type settings
     */
    public class GameType extends Rule {
        public static final int QUICK    = 1;
        

        GameType() {
            super(new int[] { QUICK });
        }
    }

    /**
     * Opponent settings
     */
    public class Opponent extends Rule {
        public static final int PLAYER    = R.string.quick_game_opponent_player;
        public static final int AI        = R.string.quick_game_opponent_ai;
        

        Opponent() {
            super(new int[] { PLAYER, AI });
        }
    }

    /**
     * Token settings
     */
    public class Token extends Rule {
        public static final int DIAMOND     = R.drawable.diamond;
        public static final int REDSTONE    = R.drawable.redstone;
        public static final int MAGMA       = R.drawable.magma;
        

        Token() {
            super(new int[] { DIAMOND, REDSTONE, MAGMA });
        }
    }
    
    /**
     * Count FPS
     */
    public class Fps extends Rule {
        public static final int NO       = R.string.fps_hide;
        public static final int COUNT    = R.string.fps_show;
        
        Fps() {
            super(new int[] { NO, COUNT });
        }
    }

    /*
     * All possible rules
     */
    public static final int DIFFICULTY  = 0;
    public static final int FIRST_TURN  = 1;
    public static final int GAME_TYPE   = 2;
    public static final int OPPONENT    = 3;
    public static final int TOKEN       = 4;
    public static final int TOKEN2      = 5; // 2nd player token
    public static final int FPS         = 6;
    
    /** rules storage */
    private final Rule[] rules;
    
    /**
     * Creates Game rules
     */
    public GameRules() {
        rules = new Rule[] {
                new Difficulty(),
                new FirstTurn(),
                new GameType(),
                new Opponent(),
                new Token(),
                new Token(),
                new Fps()
        };
    }
    
    /**
     * Returns current rule state
     * @param rule
     * @return
     */
    public int getRule(int rule) {
        return rules[rule].getId();
    }
    
    /**
     * Sets new rule state
     * @param rule
     * @param value
     */
    public void setRule(int rule, int value) {
        rules[rule].setId(value);
    }
    
    /**
     * Returns all possible IDs for the rule
     * @param rule
     * @return
     */
    public int[] getIds(int rule) {
        return rules[rule].getIds();
    }
    
    public Bundle exportTo(Bundle bundle) {
        int[] bundleRules = new int[rules.length];
        for(int i = 0; i < rules.length; ++i) {
            bundleRules[i] = rules[i].getId();
        }
        
        bundle.putIntArray("rules", bundleRules);
        return bundle;
    }
    
    public void importFrom(Bundle bundle) {
        int[] bundleRules = bundle.getIntArray("rules");
        for(int i = 0; i < bundleRules.length; ++i) {
            rules[i].setId(bundleRules[i]);
        }
    }
}




Java Source Code List

sq.squ1rr.mcc4.AboutMenu.java
sq.squ1rr.mcc4.BaseActivity.java
sq.squ1rr.mcc4.GameActivity.java
sq.squ1rr.mcc4.MainMenuActivity.java
sq.squ1rr.mcc4.MainMenu.java
sq.squ1rr.mcc4.MenuLayout.java
sq.squ1rr.mcc4.OptionsMenu.java
sq.squ1rr.mcc4.QuickGameMenu.java
sq.squ1rr.mcc4.StatsMenu.java
sq.squ1rr.mcc4.Stats.java
sq.squ1rr.mcc4.ai.Ai.java
sq.squ1rr.mcc4.ai.EasyAi.java
sq.squ1rr.mcc4.ai.HardAi.java
sq.squ1rr.mcc4.ai.NormalAi.java
sq.squ1rr.mcc4.ai.PeacefulAi.java
sq.squ1rr.mcc4.board.BoardDialogue.java
sq.squ1rr.mcc4.board.BoardLogic.java
sq.squ1rr.mcc4.board.BoardRenderer.java
sq.squ1rr.mcc4.board.BoardView.java
sq.squ1rr.mcc4.board.GameBoard.java
sq.squ1rr.mcc4.board.Texture.java
sq.squ1rr.mcc4.gl.Rectangle.java
sq.squ1rr.mcc4.gl.SpriteBatch.java
sq.squ1rr.mcc4.gl.SpriteString.java
sq.squ1rr.mcc4.gl.Sprite.java
sq.squ1rr.mcc4.layout.LayoutManager.java
sq.squ1rr.mcc4.layout.McButton.java
sq.squ1rr.mcc4.layout.McGroup.java
sq.squ1rr.mcc4.layout.McSelector.java
sq.squ1rr.mcc4.layout.McStyle.java
sq.squ1rr.mcc4.layout.McText.java
sq.squ1rr.mcc4.layout.McToggler.java
sq.squ1rr.mcc4.layout.McToken.java
sq.squ1rr.mcc4.rules.GameRules.java
sq.squ1rr.mcc4.rules.Player.java
sq.squ1rr.mcc4.rules.Rule.java
sq.squ1rr.mcc4.util.GlobalConstants.java