Android Open Source - Tetris-Evolution Logic Scheme






From Project

Back to project page Tetris-Evolution.

License

The source code is released under:

GNU General Public License

If you think the Android project Tetris-Evolution 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 com.mygdx.blocks;
/*from   w ww .  j a v  a 2s . c  o m*/
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.Array;
import com.mygdx.tools.Resources;

public class LogicScheme {
  
  private Array<Connect> connects;
  private Map<Integer, Block> blocks;
  private Map<Integer, Level> levels;

  public LogicScheme(){
    connects = new Array<Connect>();
    blocks = new HashMap<Integer, Block>();
    levels = new HashMap<Integer, Level>();
  }
  
  public void checkConnects(BlocksBox blocksBox, float x, float y){
    
    int activeBlockIndex = blocksBox.getBlockIndex(x, y);
    
    if (activeBlockIndex != -1){
      Block activeBlock = blocksBox.getBlocks().get(activeBlockIndex);
      
      Array<Integer> finalIdexBlocks = new Array<Integer>();
      
      for (Connect connect : connects) {
        int value = 0;
        finalIdexBlocks.clear();
        
        for (int dirIndex = 0; dirIndex < connect.getDirections().length; dirIndex++) {
          int[] direction = connect.getDirections()[dirIndex];
          int condition = connect.getConditions()[dirIndex];
          
          int blockIndex = blocksBox.getBlockIndex(x + direction[0] * activeBlock.getWidth(), y + direction[1] * activeBlock.getHeight());
          
          if (blockIndex == -1){
            finalIdexBlocks.clear();
            break;
          } else {
            
            Block block = blocksBox.getBlocks().get(blockIndex);
            
            if (block.getBlockId() != condition){
              finalIdexBlocks.clear();
              break;
            } else {
              value += 1;
              finalIdexBlocks.add(blockIndex);
              
              if (value == connect.getDirections().length){
                Array<Block> toRemove = new Array<Block>();
                
                for (int index = 0; index < finalIdexBlocks.size; index++) {
                  int actualBlockIndex = finalIdexBlocks.get(index);
                  Block actualBlock = blocksBox.getBlocks().get(actualBlockIndex);
                  
                  int substitution = connect.getSubstitution()[index];
                  
                  if (substitution == -1) toRemove.add(actualBlock);
                  else {
                    activeBlock.setImageId(substitution);
                  }
                }
                
                blocksBox.getBlocks().removeAll(toRemove, false);
                
                return;
              }
            }
          }
        }
      }
    }
  }
  
  public void addConnect(Connect connect){
    connects.add(connect);
  }
  
  public void addBlock(int id, Block block){
    blocks.put(id, block);
  }
  
  public void addLevel(int id, Level level){
    levels.put(id, level);
  }
  
  public Map<Integer, Block> getBlocks() {
    return blocks;
  }
  
  public Map<Integer, Level> getLevels() {
    return levels;
  }
  
  public Array<Connect> getConnects() {
    return connects;
  }


}




Java Source Code List

com.mygdx.TetrisEvolution.android.AndroidLauncher.java
com.mygdx.TetrisEvolution.client.HtmlLauncher.java
com.mygdx.TetrisEvolution.desktop.DesktopLauncher.java
com.mygdx.blocks.Block.java
com.mygdx.blocks.BlocksBox.java
com.mygdx.blocks.Connect.java
com.mygdx.blocks.Level.java
com.mygdx.blocks.LogicScheme.java
com.mygdx.game.Game.java
com.mygdx.main.TetrisEvolution.java
com.mygdx.modes.DarwinMode.java
com.mygdx.modes.Mode.java
com.mygdx.renderer.ModeRenderer.java
com.mygdx.states.Info.java
com.mygdx.states.MainMenu.java
com.mygdx.states.ModeMenu.java
com.mygdx.states.Play.java
com.mygdx.states.Splash.java
com.mygdx.tools.GifDecoder.java
com.mygdx.tools.InvertXY.java
com.mygdx.tools.Resources.java
com.mygdx.util.Collision.java