Advertisement
Guest User

Game.cs

a guest
Oct 23rd, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 142.55 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. //using AssemblyCSharp;
  6.  
  7. public class Game : MonoBehaviour {
  8.        
  9.     public enum GAME_PROPERTIES
  10.     {
  11.          rowLength      = 6
  12.         ,columnLength   = 6    
  13.        
  14.     };
  15.    
  16.     //de (int)PIECE_TYPE.java
  17.     public enum PIECE_TYPE
  18.     {
  19.          OUT_OF_BOUNDS = -1
  20.         ,NOT_USED = 0
  21.         ,ROAD
  22.         ,BUSH
  23.         ,TREE
  24.         ,RUCA
  25.         ,HOME
  26.         ,CASTLE
  27.         ,BUILDING
  28.         ,FUTURE_HOME
  29.         ,FUTURE_HOME_HOVERING
  30.         ,FUTURE_CITY
  31.         ,ALIEN_BASIC
  32.         ,ALIEN_TELEPORTER
  33.         ,MOAI
  34.         ,MOAIS
  35.         ,STONEHENGE
  36.         ,ROCK// = 18
  37.         ,CAVE
  38.         ,DIAMOND
  39.         ,RUBY
  40.         ,MAGIC_CRISTAL_PURPLE// = 22
  41.         ,MAGIC_CRISTAL_GREEN
  42.         ,BLACK_HOLE
  43.     };
  44.     //fin (int)PIECE_TYPE.java
  45.        
  46.    
  47.     public enum BG_TYPE {
  48.         NOT_USED
  49.         ,ROAD
  50.         ,LEFT_DOWN_RIGHT
  51.         ,TOP_DOWN_RIGHT
  52.         ,TOP_LEFT_RIGHT
  53.         ,TOP_LEFT_DOWN
  54.         ,TOP_LEFT
  55.         ,LEFT_DOWN
  56.         ,DOWN_RIGHT
  57.         ,TOP_RIGHT
  58.         ,TOP_LEFT_CORNER_4
  59.         ,LEFT_DOWN_CORNER_1
  60.         ,DOWN_RIGHT_CORNER_2
  61.         ,TOP_RIGHT_CORNER_3
  62.         ,TOP
  63.         ,TOP_CORNER_3
  64.         ,TOP_CORNER_4
  65.         ,TOP_CORNER_3_4
  66.         ,LEFT
  67.         ,LEFT_CORNER_1
  68.         ,LEFT_CORNER_4
  69.         ,LEFT_CORNER_1_4
  70.         ,DOWN
  71.         ,DOWN_CORNER_1
  72.         ,DOWN_CORNER_2
  73.         ,DOWN_CORNER_1_2
  74.         ,RIGHT
  75.         ,RIGHT_CORNER_2
  76.         ,RIGHT_CORNER_3
  77.         ,RIGHT_CORNER_2_3
  78.         ,CORNER_1
  79.         ,CORNER_2
  80.         ,CORNER_3
  81.         ,CORNER_4
  82.         ,CORNER_1_2
  83.         ,CORNER_1_3
  84.         ,CORNER_1_4
  85.         ,CORNER_2_3
  86.         ,CORNER_2_4
  87.         ,CORNER_3_4
  88.         ,CORNER_1_2_3
  89.         ,CORNER_2_3_4
  90.         ,CORNER_1_3_4
  91.         ,CORNER_1_2_4
  92.         ,CORNER_1_2_3_4
  93.         ,HORIZONTAL_GRASS = (49 - 4)
  94.         ,VERTICAL_GRASS = (49 - 3)
  95.         ,GRASS = (49-2)
  96.         ,ISLE = (49-1)
  97.         //original
  98. //      ,HORIZONTAL_GRASS = vbackgroundGraphic.Length-4
  99. //      ,VERTICAL_GRASS = backgroundGraphic.Length-3
  100. //      ,GRASS = backgroundGraphic.Length-2
  101. //      ,ISLE = backgroundGraphic.Length-1
  102.     }            
  103.            
  104.     public List<PIECE_TYPE> pieceChance;       
  105.    
  106.     public enum Estados {
  107. //      DEAD = -99
  108. //      ,RETRY = -1
  109.         INITIALIZE = 0
  110.         ,WAITING_FOR_CLICK
  111.         ,COLLAPSING
  112.         ,WAIT_END_ANIMATION
  113.         ,BUYING
  114.         ,PAUSE
  115.         ,GAME_OVER
  116. //      ,START_NEW_GAME = 97
  117. //      ,EXIT_GAME
  118.     };
  119.    
  120.     public delegate void OnUpdateStateDelegate();
  121.    
  122.     OnUpdateStateDelegate[] onUpdateDelegate = null;
  123.    
  124.    
  125.     public Estados STATE;
  126. //  private Estados PreviousState;
  127.    
  128.    
  129.     //bg_type.java
  130.     public static string[] backgroundGraphic =
  131.     {
  132.         "Road"
  133.         ,"Road"
  134.         ,"LeftDownRight"
  135.         ,"TopDownRight"
  136.         ,"TopLeftRight"
  137.         ,"TopLeftDown"
  138.         ,"TopLeft"
  139.         ,"LeftDown"
  140.         ,"DownRight"
  141.         ,"TopRight"
  142.         ,"TopLeftCorner4"
  143.         ,"LeftDownCorner1"
  144.         ,"DownRightCorner2"
  145.         ,"TopRightCorner3"
  146.         ,"Top"
  147.         ,"TopCorner3"
  148.         ,"TopCorner4"
  149.         ,"TopCorner3_4"
  150.         ,"Left"
  151.         ,"LeftCorner1"
  152.         ,"LeftCorner4"
  153.         ,"LeftCorner1_4"
  154.         ,"Down"
  155.         ,"DownCorner1"
  156.         ,"DownCorner2"
  157.         ,"DownCorner1_2"
  158.         ,"Right"
  159.         ,"RightCorner2"
  160.         ,"RightCorner3"
  161.         ,"RightCorner2_3"
  162.         ,"Corner1"
  163.         ,"Corner2"
  164.         ,"Corner3"
  165.         ,"Corner4"
  166.         ,"Corner1_2"
  167.         ,"Corner1_3"
  168.         ,"Corner1_4"
  169.         ,"Corner2_3"
  170.         ,"Corner2_4"
  171.         ,"Corner3_4"
  172.         ,"Corner1_2_3"
  173.         ,"Corner2_3_4"
  174.         ,"Corner1_3_4"
  175.         ,"Corner1_2_4"
  176.         ,"Corner1_2_3_4"
  177.         ,"HorizontalGrass"
  178.         ,"VerticalGrass"
  179.         ,"Grass"
  180.         ,"Isle"
  181.     };
  182.    
  183.        
  184.     [HideInInspector]
  185.     public int[] connections = new int[300];
  186.     //fin BG_TYPE ^
  187.    
  188.    
  189.    
  190.    
  191.     public Hashtable tablaAllAnimations;                   
  192.            
  193.     public int[] buyValue =
  194.     {
  195.         0
  196.         ,10
  197.         ,30
  198.         ,45
  199.         ,70
  200.         ,100
  201.         ,150
  202.         ,225
  203.         ,350
  204.         ,530
  205.         ,800
  206.         ,12
  207.         ,18
  208.         ,2700
  209.         ,4000
  210.         ,6000
  211.         ,9000
  212.         ,15000
  213.         ,4000
  214.         ,6000
  215.         ,9000
  216.         ,15000
  217.         ,2000
  218.         ,1100
  219.         ,2500
  220.     };
  221.    
  222.     public Hashtable tablaBuyForCoinsValue;
  223.     public Hashtable tablaSellForCoinsValue;               
  224.        
  225. //  public static bool soundEnabled = false;
  226.  
  227.  
  228. //  public static int initGold;
  229. //  public static int initCurrentScore;
  230. //  public static int initRecordScore;
  231.    
  232.     public tk2dSprite guiCoin;
  233.    
  234.    
  235.     private float angleRadians;
  236.  
  237.    
  238. //  public tk2dSpriteAnimation animCollectionUpgrade;
  239. //  public tk2dSpriteAnimation animCollectionBasic;
  240.     private string scoreString;    
  241.     private string highScoreString;
  242.     private string coinsString;
  243. //  private string debugTextGridClick;         
  244.    
  245.     //coordenadas que hacen referencia al gameGrid[,]
  246.     public int touchX;
  247.     public int touchY;
  248.    
  249.     private List<int> indexesToCollapseList = new List<int>();
  250.    
  251.     public int lastAlienToMoaiX;
  252.     public int lastAlienToMoaiY;
  253.    
  254.     public GameObject selector;
  255.     private tk2dAnimatedSprite selectorAnimation;
  256.     public tk2dAnimatedSprite selectorNextPiece;
  257.    
  258.     public readonly Color32 SELECTOR_COLOR_RED = new Color32(255, 0, 0, 255);//168
  259.     public readonly Color32 SELECTOR_COLOR_NORMAL = new Color32(255, 255, 255, 255);//200
  260.    
  261.     public tk2dAnimatedSprite ufoNextPiece;
  262.     private Vector3 ufoNextPieceOriginPos;
  263.     public tk2dAnimatedSprite wildCardStoragePiece;
  264.    
  265.    
  266.     public tk2dTextMesh txtCoins;
  267.     public tk2dTextMesh txtScore;
  268.     public tk2dTextMesh txtHiScore;
  269.     public tk2dTextMesh txtGameOver;
  270.     public int bonusMultiplier = 0;
  271.    
  272.     public tk2dSprite[] gameGridSprites;// fondo
  273.     public tk2dAnimatedSprite[] gamePiecesAnimations; //animaciones de foreground
  274.     public GameObject[] lightCells; //grilla highlight
  275.    
  276.     public tk2dSprite btnBuy;
  277.     public tk2dSprite btnHelp;
  278.     public tk2dSprite btnPause;
  279.     public tk2dSprite btnMute;
  280.     private SoundController btnMuteSoundScript;
  281.    
  282. //  public GameObject btnSoundPrefab;
  283.     public GameObject comboStarAnimationPrefab;
  284. //  private GameObject btnSound = null;
  285.    
  286.     public GameObject txtAddScorePrefab;
  287.    
  288.            
  289.     public int[,] gameGrid;
  290. //  public int[,] compareGrid;
  291. //  public bool[,] usedGrid;
  292. //  public bool[,] usedGridCopy;
  293.    
  294.     public bool initializing = false;
  295.     public bool firstClick = false;
  296.     public bool animateNeigbors = false;
  297.     public bool collapsing = true;
  298.     public bool upgradedGraphic = false;
  299. //  public bool enabledSound = true;
  300. //  public bool magicCrystalToRock = false;
  301.     public bool alreadyMovedAliens = false;
  302.     public bool gameOver = false;
  303.    
  304.     public int nextPiece;
  305. //  public PIECE_TYPE lastPieceUsed;
  306. //  public int pieceBought = -1;
  307. //  public bool boughtPiece = false;
  308.     public int neighborToFind;
  309.     public int transitionPiece;
  310.     public int wildCard = -1;
  311.            
  312.     public enum TipoJuego {NEW_GAME, CONTINUE_GAME, DEMO};
  313.     public static TipoJuego LOAD_GAME_TYPE = TipoJuego.NEW_GAME;
  314.     //public final int NEW_GAME = 0;
  315.     //public final int CONTINUE_GAME = 1;                  
  316.        
  317.  
  318. //  public bool[,] movingPiece = new bool[(int)GAME_PROPERTIES.rowLength,(int)GAME_PROPERTIES.columnLength];
  319. //  public bool[,] toMoai = new bool[(int)GAME_PROPERTIES.rowLength,(int)GAME_PROPERTIES.columnLength];
  320. //  public bool[,] pieceChecked = new bool[(int)GAME_PROPERTIES.rowLength,(int)GAME_PROPERTIES.columnLength];
  321. //  public bool[,] destAvailable = new bool[(int)GAME_PROPERTIES.rowLength,(int)GAME_PROPERTIES.columnLength];
  322. //  public bool[,] roadSearched = new bool[(int)GAME_PROPERTIES.rowLength,(int)GAME_PROPERTIES.columnLength];
  323. //  public bool[,] alienTranformedAt = new bool[(int)GAME_PROPERTIES.rowLength,(int)GAME_PROPERTIES.columnLength];
  324. //  public float[,] originalX = new float[(int)GAME_PROPERTIES.rowLength,(int)GAME_PROPERTIES.columnLength];
  325. //  public float[,] originalY = new float[(int)GAME_PROPERTIES.rowLength,(int)GAME_PROPERTIES.columnLength];
  326. //  public float[,] destPieceX = new float[(int)GAME_PROPERTIES.rowLength,(int)GAME_PROPERTIES.columnLength];
  327. //  public float[,] destPieceY = new float[(int)GAME_PROPERTIES.rowLength,(int)GAME_PROPERTIES.columnLength];
  328. //  public float[,] destPieceMidpointX = new float[(int)GAME_PROPERTIES.rowLength,(int)GAME_PROPERTIES.columnLength];
  329. //  public float[,] destPieceMidpointY = new float[(int)GAME_PROPERTIES.rowLength,(int)GAME_PROPERTIES.columnLength];
  330.  
  331.     public int prevClickX = -1;
  332.     public int prevClickY = -1;
  333.                        
  334.     public int currentGold = 0;
  335.     public int currentScore = 0;
  336.     public int highScore = 0;  
  337.    
  338.    
  339.     public static float anchoEnTransformUnitsSquareSprite;
  340.     public static float altoEnTransformUnitsSquareSprite;
  341.    
  342.    
  343.    
  344.     public Hashtable tablaScorePerPiece;
  345.    
  346.     public float currentTime = 0;
  347.     public float maxTime = 0;
  348.                
  349.     delegate void onPieceClick(int clickCount);
  350.     Dictionary<PIECE_TYPE,onPieceClick> piecesClick = null;
  351.    
  352.     GameObject buyScreen = null;
  353.     GameObject helpScreen = null;
  354.     GameObject pauseScreen = null;
  355. //  GameObject gameChangeScreen = null;
  356.     GameObject popUpConfirmWindow = null;
  357.     GameObject popUpSaveGameWindow = null;
  358.     GameObject popUpPurchaseFeedbackWindow = null;
  359.     GameObject popUpFreeCoinsWindow = null;
  360.    
  361.     public GameObject popUpSaveGameWindowPrefab = null;
  362.     public GameObject buyScreenPrefab = null;
  363.     public GameObject helpScreenPrefab = null;
  364.     public GameObject pauseScreenPrefab = null;
  365.     public GameObject gameChangeScreenPrefab = null;
  366.     public GameObject popUpConfirmWindowPrefab = null;
  367.     public GameObject popUpPurchaseFeedbackPrefab = null;
  368.     public GameObject popUpFreeCoinsPrefab = null;
  369.    
  370.     private GameObject sound;
  371.    
  372.     public GameObject sndPutPiecePrefab = null;
  373.     public GameObject sndCombinePiecePrefab = null;
  374.     public GameObject sndCavernicolaMPrefab = null;
  375.     public GameObject sndCavernicolaFPrefab = null;
  376.     public GameObject sndVillagerPrefab = null;
  377.     public GameObject sndAlienTeleportPrefab = null;
  378.     public GameObject sndCashSound1Prefab = null;
  379.     public GameObject sndCashSound2Prefab = null;
  380. //  public tk2dSprite spriteBtnSound;
  381.     private List<AudioSource> listCashSounds = new List<AudioSource>();
  382.     //public List<GameObject> cashSoundsListPrefab = new List<GameObject>();
  383.    
  384. //  GameObject copperCoin = null;
  385. //  GameObject silverCoin = null;
  386. //  GameObject goldCoin = null;
  387.     public GameObject copperCoinPrefab = null;
  388.     public GameObject silverCoinPrefab = null;
  389.     public GameObject goldCoinPrefab = null;
  390.    
  391.    
  392.     public GameObject villagerPrefab;
  393.    
  394.    
  395.     private tk2dTextMesh txtPopUpQuestion;
  396.     private string popUpQuestionString;
  397.         // Use this for initialization
  398.    
  399.     public int numberOfPlays;
  400.     public System.DateTime lastDateFreeCoins;
  401.    
  402.     private struct DemoMoves {
  403.         public PIECE_TYPE demoNextPiece;
  404.         public int toqueGridX;
  405.         public int toqueGridY;
  406.     }
  407.    
  408.     void Start ()
  409.     {
  410.         onUpdateDelegate = new OnUpdateStateDelegate[]
  411.         {
  412.              onUpdateInitialize
  413.             ,onWaitForClick        
  414.             ,onCollapsingCells
  415.             ,onWaitEndOfAnimation
  416.             ,onBuyScreen
  417.             ,onPause
  418.             ,onGameOver
  419.            
  420.            
  421.         };
  422.    
  423.         piecesClick = new Dictionary<PIECE_TYPE, onPieceClick>()
  424.         {
  425.              {PIECE_TYPE.BLACK_HOLE,onBlackHoleClick}
  426.             ,{PIECE_TYPE.MAGIC_CRISTAL_GREEN,onMagicCrystalGreenClick}
  427.             ,{PIECE_TYPE.MAGIC_CRISTAL_PURPLE, onMagicCrystalPurpleClick}
  428.         };
  429.                                    
  430.        
  431.         touchX = -1;
  432.         touchY = -1;
  433.         lastAlienToMoaiX = -1;
  434.         lastAlienToMoaiY = -1;
  435.        
  436.        
  437.         btnMuteSoundScript = btnMute.GetComponent<SoundController>();
  438. //     
  439. //      BoxCollider newCollider = btnMute.gameObject.AddComponent<BoxCollider>();
  440. //      Vector3 colliderExtents = newCollider.extents;
  441. //      colliderExtents.z = 0.2f;
  442. //      newCollider.extents = colliderExtents;
  443.        
  444. //      btnMute.boxCollider = new BoxCollider();
  445.        
  446.         initializeArrayConnections();              
  447.         initializeTablaAllAnimations();    
  448.         initializeArrayPieceChance();      
  449.         initializeTablaScorePerPiece();
  450.         initializeTablaBuyForCoinsValue();
  451.         initializeTablaSellForCoinsValue();
  452.                            
  453.        
  454. //      compareGrid = new int[(int)GAME_PROPERTIES.rowLength,(int)GAME_PROPERTIES.columnLength];
  455. //      usedGrid = new bool[(int)GAME_PROPERTIES.rowLength,(int)GAME_PROPERTIES.columnLength];
  456. //      usedGridCopy = new bool[(int)GAME_PROPERTIES.rowLength,(int)GAME_PROPERTIES.columnLength];
  457.                        
  458.        
  459.         initializeMouseColliderHelper();
  460.        
  461. //      Instantiate(btnSoundPrefab);// as GameObject;
  462.  
  463.         currentGold = MainMenu.gold;
  464.         highScore = MainMenu.highScore;
  465.         ufoNextPieceOriginPos = ufoNextPiece.transform.position;
  466.         selectorAnimation = selector.GetComponent<tk2dAnimatedSprite>();
  467.        
  468.         numberOfPlays = 0;
  469. #if UNITY_EDITOR       
  470.         lastDateFreeCoins = System.DateTime.Today.AddDays(-1);
  471. #else  
  472.         DataGame.loadOnlyFreeCoinsDate();      
  473. #endif
  474.    
  475.    
  476.         STATE = Estados.INITIALIZE;
  477.     }
  478.    
  479. //  static bool show = false;
  480.    
  481.     public bool printDebugGameGrid = false;
  482.     void Update()
  483.     {
  484.         int state = (int)STATE;
  485.        
  486. //      if (STATE != PreviousState) {
  487. //          if (STATE == Estados.WAITING_FOR_CLICK || STATE == Estados.COLLAPSING || STATE == Estados.WAIT_END_ANIMATION) {
  488. //              iTween.Resume();
  489. //          } else {               
  490. //              iTween.Pause();
  491. //          }
  492. //      }
  493.        
  494.         if (STATE != Estados.WAITING_FOR_CLICK) {
  495.  
  496.             if (btnBuy.enabled) {              
  497.                 btnBuy.enabled = false;
  498.             }
  499.            
  500.             if (btnMuteSoundScript.isSpriteClickeable) {               
  501.                 btnMuteSoundScript.isSpriteClickeable = false;
  502.             }
  503.            
  504.             if (btnHelp.enabled) {             
  505.                 btnHelp.enabled = false;
  506.             }
  507.            
  508.             if (btnPause.enabled) {            
  509.                 btnPause.enabled = false;
  510.             }
  511.            
  512.            
  513.         } else {
  514.            
  515.             if (!btnBuy.enabled) {
  516.                 btnBuy.enabled = true;
  517.             }
  518.            
  519.             if (!btnMuteSoundScript.isSpriteClickeable) {
  520.                 btnMuteSoundScript.isSpriteClickeable = true;
  521.             }
  522.            
  523.             if (!btnHelp.enabled) {
  524.                 btnHelp.enabled = true;
  525.             }
  526.            
  527.             if (!btnPause.enabled) {
  528.                 btnPause.enabled = true;
  529.             }          
  530.            
  531.            
  532.         }
  533.        
  534.         if(state >=0 && state< onUpdateDelegate.Length && onUpdateDelegate[state]!=null)
  535.         {
  536.             onUpdateDelegate[state]();
  537.         }
  538.        
  539.         if (currentScore < 0) {
  540.             currentScore = 0;
  541.         }
  542.         updateHud();
  543.        
  544.        
  545.         if (printDebugGameGrid) {
  546.             printGameGrid();
  547.             printDebugGameGrid = false;
  548.         }
  549.        
  550.         if (Input.GetKeyDown(KeyCode.Escape)) {
  551.             switch(STATE) {
  552.             case Estados.WAITING_FOR_CLICK:
  553.                 openPauseScreen();
  554.                 break;
  555.             case Estados.PAUSE:
  556.                 if (pauseScreen != null && !gameOver) {
  557.                     closePauseScreen();
  558.                 }
  559.                 break;
  560.             }
  561.                
  562.            
  563.         }
  564.        
  565.        
  566.        
  567. //      PreviousState = STATE;
  568.     }
  569.  
  570.     public PIECE_TYPE nextPieceReadable;
  571.     public void updateHud()
  572.     {
  573.         scoreString = "Score "+currentScore.ToString();
  574.         highScoreString = "Top "+highScore.ToString();
  575.         coinsString = currentGold.ToString();
  576.         nextPieceReadable = (PIECE_TYPE)nextPiece;
  577.        
  578.         if (txtScore.text != scoreString) {
  579.             txtScore.text = scoreString;
  580.             txtScore.maxChars = txtScore.text.Length+1;
  581.             txtScore.Commit();
  582.         }
  583.        
  584.         if (currentScore > highScore) {
  585.             highScore = currentScore;
  586.             highScoreString = "Top "+highScore.ToString();
  587.                
  588.         }
  589.        
  590.         if (highScoreString != txtHiScore.text) {          
  591.            
  592.             txtHiScore.text = highScoreString;
  593.             txtHiScore.maxChars = txtHiScore.text.Length+1;
  594.             txtHiScore.Commit();           
  595.         }
  596.        
  597.         if (txtCoins.text != coinsString) {
  598.             txtCoins.text = coinsString;
  599.             txtCoins.maxChars = txtCoins.text.Length+1;
  600.             txtCoins.Commit();
  601.         }              
  602.        
  603.     }
  604.    
  605.    
  606.    
  607.     public void rebuildForeground ()
  608.     {
  609.         for(int i=0; i < (int)GAME_PROPERTIES.rowLength; i++)
  610.         {
  611.             for(int j=0; j < (int)GAME_PROPERTIES.columnLength; j++)
  612.             {                      
  613.                 replaceGraphicGridAt(i, j);
  614.                 if (gameGrid[i,j] == (int)PIECE_TYPE.RUCA || gameGrid[i,j] == (int)PIECE_TYPE.CAVE) {
  615.                     addVillager(Villager.TIPOS_VILLAGER.CAVERNICOLA, gameGridSprites[j*6+i].transform.position);
  616.                 }
  617.                
  618.                 if (gameGrid[i,j] == (int)PIECE_TYPE.HOME || gameGrid[i,j] == (int)PIECE_TYPE.CASTLE) {
  619.                     addVillager(Villager.TIPOS_VILLAGER.CIUDADANO, gameGridSprites[j*6+i].transform.position);
  620.                 }
  621.             }
  622.         }
  623.     }  
  624.    
  625.     public void rebuildBackground ()
  626.     {
  627.         replaceNotUsed();  
  628.        
  629.         for(int i=0; i < (int)GAME_PROPERTIES.rowLength; i++)
  630.         {
  631.             for(int j=0; j < (int)GAME_PROPERTIES.columnLength; j++)
  632.             {                      
  633.                 updateBackgroundGridAt(i, j);
  634.                 updateBackgroundGridAroundAt(i, j);
  635.             }
  636.         }
  637.     }
  638.    
  639.    
  640.     private DemoMoves[] demoMoves = new DemoMoves[10];
  641.     public void onUpdateInitialize ()
  642.     {
  643.         initializing = true;
  644.         gameGrid = new int[(int)GAME_PROPERTIES.rowLength,(int)GAME_PROPERTIES.columnLength];
  645.         gameGrid[0,(int)GAME_PROPERTIES.columnLength-1] = -1;
  646.         wildCard = -1;
  647.         wildCardStoragePiece.Play("RoadT");
  648.         gameOver = false;
  649.                 //currentGold = 0;
  650.         currentScore = 0;
  651.        
  652.         switch(LOAD_GAME_TYPE)
  653.         {
  654.             case TipoJuego.NEW_GAME:
  655.             {              
  656.                 if (listAldeanos.Count > 0) {
  657.                     for (int i = 0; i < listAldeanos.Count; i++) {
  658.                         Destroy(listAldeanos[i]);
  659.                     }
  660.                
  661.                     listAldeanos.Clear();
  662.                 }
  663.                
  664.                 getNextPiece();
  665. //              nextPiece = (int)PIECE_TYPE.BLACK_HOLE;
  666. //              nextPiece = (int)PIECE_TYPE.ALIEN_BASIC;
  667. //              showNextPieceInSelectorAndGui(nextPiece);      
  668.                
  669.            
  670.            
  671.                 populate(Random.Range(5, 10 + 1), (int)PIECE_TYPE.BUSH              , (int)PIECE_TYPE.NOT_USED);
  672.                 populate(Random.Range(1, 2  + 1), (int)PIECE_TYPE.TREE              , (int)PIECE_TYPE.NOT_USED);
  673.                 populate(Random.Range(0, 1  + 1), (int)PIECE_TYPE.RUCA              , (int)PIECE_TYPE.NOT_USED);
  674.                 populate(Random.Range(1, 3  + 1), (int)PIECE_TYPE.ROCK              , (int)PIECE_TYPE.NOT_USED);
  675.                 populate(Random.Range(0, 2  + 1), (int)PIECE_TYPE.ALIEN_BASIC       , (int)PIECE_TYPE.NOT_USED);
  676. //              populate(Random.Range(0, 2  + 1), (int)PIECE_TYPE.ALIEN_TELEPORTER  , (int)PIECE_TYPE.NOT_USED);
  677.                 populate(Random.Range(1, 2  + 1), (int)PIECE_TYPE.MOAI              , (int)PIECE_TYPE.NOT_USED);
  678.            
  679.                         //caso full of moais
  680. //                      for (int i = 0; i < 6; i++) {
  681. //                          for (int j  = 0; j  < 6; j++) {
  682. //                              if ((i == 0 && j == 5) || (i== 2 && j == 2) || (i == 3 && j == 2) ) {
  683. //                                  continue;
  684. //                              } else {
  685. //                                  gameGrid[i,j] = (int)PIECE_TYPE.MOAI;
  686. //                              }                                                  
  687. //                          }
  688. //                      }
  689. //                      gameGrid[2,2] = (int)PIECE_TYPE.ALIEN_TELEPORTER;
  690. //                      gameGrid[3,2] = (int)PIECE_TYPE.ALIEN_TELEPORTER;
  691.                        
  692.                         //caso full of aliens
  693. //                      for (int i = 0; i < 6; i++) {
  694. //                          for (int j  = 0; j  < 6; j++) {
  695. //                              if ((i == 0 && j == 5) || (i== 2 && j == 2) || (i == 3 && j == 2) ) {
  696. //                                  continue;
  697. //                              } else {
  698. //                                  gameGrid[i,j] = (int)PIECE_TYPE.ALIEN_TELEPORTER;
  699. //                              }                                                  
  700. //                          }
  701. //                      }
  702. //                      gameGrid[2,2] = (int)PIECE_TYPE.ALIEN_TELEPORTER;
  703. //                      gameGrid[3,2] = (int)PIECE_TYPE.ALIEN_TELEPORTER;
  704.            
  705.            
  706. //                      caso 2 cadenas diferentes
  707. //                      gameGrid[5,5] = (int)PIECE_TYPE.ALIEN_BASIC;
  708. //                      gameGrid[4,5] = (int)PIECE_TYPE.ALIEN_TELEPORTER;
  709. //                      gameGrid[2,2] = (int)PIECE_TYPE.BUSH;
  710. //                      gameGrid[2,3] = (int)PIECE_TYPE.BUSH;
  711. //                      gameGrid[0,1] = (int)PIECE_TYPE.RUCA;
  712. //                      gameGrid[1,1] = (int)PIECE_TYPE.RUCA;
  713. //                      gameGrid[3,1] = (int)PIECE_TYPE.RUCA;
  714. //                      gameGrid[4,1] = (int)PIECE_TYPE.BUSH;
  715. //                      gameGrid[5,2] = (int)PIECE_TYPE.BUSH;
  716. //                      gameGrid[5,1] = (int)PIECE_TYPE.MOAI;
  717. //                      gameGrid[0,0] = (int)PIECE_TYPE.MOAIS;
  718. //                      gameGrid[1,0] = (int)PIECE_TYPE.ALIEN_BASIC;
  719. //                      gameGrid[2,0] = (int)PIECE_TYPE.ALIEN_BASIC;
  720. //                      gameGrid[3,0] = (int)PIECE_TYPE.ALIEN_BASIC;
  721. //                      gameGrid[4,0] = (int)PIECE_TYPE.MOAIS;
  722. //                      gameGrid[5,0] = (int)PIECE_TYPE.MOAIS;
  723.            
  724. //                      caso 2 grupos de aliens
  725. //                      nextPiece = (int)PIECE_TYPE.ROCK;
  726. //                      gameGrid[5,5] = (int)PIECE_TYPE.ALIEN_BASIC;
  727. //                      gameGrid[0,1] = (int)PIECE_TYPE.BUSH;
  728. //                      gameGrid[1,1] = (int)PIECE_TYPE.BUSH;
  729. //                      gameGrid[2,1] = (int)PIECE_TYPE.BUSH;
  730. //                      gameGrid[3,1] = (int)PIECE_TYPE.BUSH;
  731. //                      gameGrid[4,1] = (int)PIECE_TYPE.BUSH;
  732. //                      gameGrid[5,2] = (int)PIECE_TYPE.BUSH;
  733. //                      gameGrid[5,1] = (int)PIECE_TYPE.ALIEN_BASIC;
  734. //                      gameGrid[0,0] = (int)PIECE_TYPE.ALIEN_BASIC;
  735. //                      gameGrid[1,0] = (int)PIECE_TYPE.ALIEN_BASIC;
  736. //                      gameGrid[2,0] = (int)PIECE_TYPE.ALIEN_BASIC;
  737. ////                        gameGrid[3,0] = (int)PIECE_TYPE.ALIEN_BASIC;
  738. //                      gameGrid[4,0] = (int)PIECE_TYPE.ALIEN_BASIC;
  739. //                      gameGrid[5,0] = (int)PIECE_TYPE.ALIEN_BASIC;
  740.            
  741.                        
  742.                 initializeMoaiIndexes();
  743.                 rebuildBackground();
  744.                 rebuildForeground();
  745.            
  746.                 anchoEnTransformUnitsSquareSprite = Mathf.Abs(gameGridSprites[0].transform.position.x - gameGridSprites[1].transform.position.x);
  747.                 altoEnTransformUnitsSquareSprite = Mathf.Abs(gameGridSprites[0].transform.position.y - gameGridSprites[0+6].transform.position.y);
  748.                            
  749.                 //gamePiecesAnimations[0].CurrentClip.fps = 99f;
  750.                 STATE = Estados.WAITING_FOR_CLICK;
  751.             }
  752.             break;
  753.            
  754.             case TipoJuego.CONTINUE_GAME:
  755.             {
  756.                 DataGame.loadSaveGame();
  757.                
  758.                 initializeMoaiIndexes();
  759.                 rebuildBackground();
  760.                 rebuildForeground();
  761.                 checkForChancesOnLoadSavedGame();
  762.                 anchoEnTransformUnitsSquareSprite = Mathf.Abs(gameGridSprites[0].transform.position.x - gameGridSprites[1].transform.position.x);
  763.                 altoEnTransformUnitsSquareSprite = Mathf.Abs(gameGridSprites[0].transform.position.y - gameGridSprites[0+6].transform.position.y);             
  764.                 showNextPieceInSelectorAndGui(nextPiece);
  765.                 if (wildCard != (int)PIECE_TYPE.OUT_OF_BOUNDS) {
  766.                     wildCardStoragePiece.Play((string)tablaAllAnimations[wildCard]);
  767.                 }
  768.                 LOAD_GAME_TYPE = TipoJuego.NEW_GAME;
  769.                 STATE = Estados.WAITING_FOR_CLICK;
  770.             }
  771.             break;
  772.            
  773.             case TipoJuego.DEMO:
  774.                 //inicializar gamegrid para demo
  775.                 if (listAldeanos.Count > 0) {
  776.                         for (int i = 0; i < listAldeanos.Count; i++) {
  777.                             Destroy(listAldeanos[i]);
  778.                         }
  779.                    
  780.                         listAldeanos.Clear();
  781.                 }
  782.                
  783.                 gameGrid = new int[(int)GAME_PROPERTIES.rowLength, (int)GAME_PROPERTIES.columnLength]; 
  784.                 rebuildBackground();
  785.                 rebuildForeground();
  786.            
  787.                
  788.                 demoMoves[0].demoNextPiece = PIECE_TYPE.BUSH;
  789.                 demoMoves[0].toqueGridX = -1;
  790.                 demoMoves[0].toqueGridY = -1;
  791.            
  792.                 demoMoves[1].demoNextPiece = PIECE_TYPE.BUSH;
  793.                 demoMoves[1].toqueGridX = 2;
  794.                 demoMoves[1].toqueGridY = 2;
  795.            
  796.                 anchoEnTransformUnitsSquareSprite = Mathf.Abs(gameGridSprites[0].transform.position.x - gameGridSprites[1].transform.position.x);
  797.                 altoEnTransformUnitsSquareSprite = Mathf.Abs(gameGridSprites[0].transform.position.y - gameGridSprites[0+6].transform.position.y);
  798.                
  799.                 break;
  800.            
  801.             default:
  802.             break;
  803.         }
  804.     }
  805.  
  806.    
  807.     private List<int> neighborsList = new List<int>();
  808.    
  809.     void onBlackHoleClick(int clickCount)
  810.     {
  811.         if (touchX < 0 && touchY < 0) {
  812.             return;
  813.         }
  814.        
  815.         if (gameGrid[touchX, touchY] == (int)PIECE_TYPE.ROAD) {
  816. //          changeSelectorAnimationColor(SELECTOR_COLOR_RED);
  817.             changeSelectorAnimation(false);
  818.             return;
  819.         } else {
  820. //          changeSelectorAnimationColor(SELECTOR_COLOR_NORMAL);
  821.             changeSelectorAnimation(true);
  822.         }
  823.        
  824.         if (clickCount == 1) {
  825.             if (gameGrid[touchX,touchY] == (int)PIECE_TYPE.ALIEN_BASIC || gameGrid[touchX,touchY] == (int)PIECE_TYPE.ALIEN_TELEPORTER) {
  826.                 startNeighborsSearch(PIECE_TYPE.MOAI, touchX, touchY);
  827.                 animateNeigbors = (this.neighborsList.Count >= 2);
  828.                 turnOnOffHighLightGrid(animateNeigbors);
  829.             }
  830.            
  831.         } else {
  832.            
  833.             createBlackHole((PIECE_TYPE) gameGrid[touchX, touchY]);
  834. //          lastPieceUsed = PIECE_TYPE.BLACK_HOLE;
  835.            
  836.         }
  837.                
  838.     }
  839.    
  840.     void onMagicCrystalGreenClick(int clickCount)
  841.     {
  842.         if (touchX < 0 && touchY < 0) {
  843.             return;
  844.         }
  845.        
  846.         PIECE_TYPE pieceToSell = (PIECE_TYPE)gameGrid[touchX, touchY];
  847.        
  848.         if (pieceToSell == PIECE_TYPE.ALIEN_BASIC || pieceToSell == PIECE_TYPE.ALIEN_TELEPORTER) {
  849. //              changeSelectorAnimationColor(SELECTOR_COLOR_RED);
  850.             changeSelectorAnimation(false);
  851.                 return;
  852.         } else {
  853. //          changeSelectorAnimationColor(SELECTOR_COLOR_NORMAL);
  854.             changeSelectorAnimation(true);
  855.         }
  856.        
  857.         if (clickCount == 2) {
  858.            
  859. //          lastPieceUsed = PIECE_TYPE.MAGIC_CRISTAL_GREEN;
  860.                        
  861.            
  862.             if (pieceToSell == PIECE_TYPE.ROAD) {
  863.             addCoins(1, touchX, touchY);
  864.                            
  865.                
  866.             } else {
  867.                 addCoins((int)tablaSellForCoinsValue[pieceToSell], touchX, touchY);
  868.                 int scoreAmountToAdd = -((int)tablaScorePerPiece[pieceToSell]);
  869.                 currentScore += scoreAmountToAdd;
  870.                 createScoreText(scoreAmountToAdd, touchX, touchY, bonusMultiplier, false);
  871.                 gameGrid[touchX, touchY] = (int)PIECE_TYPE.ROAD;
  872.                 gamePiecesAnimations[touchY*6 + touchX].Play((string)tablaAllAnimations[(int)PIECE_TYPE.ROAD]);            
  873.                 updateBackgroundGridAt(touchX, touchY);
  874.                 updateBackgroundGridAroundAt(touchX, touchY);              
  875.             }
  876.            
  877.             getNextPiece();
  878.             moveAliens();
  879.             hideSelector();
  880. //          selector.transform.position
  881. //          if(piecesClick.ContainsKey((PIECE_TYPE)nextPiece))
  882. //          {
  883. //              piecesClick[(PIECE_TYPE)nextPiece](1);
  884. //          }
  885. //          else
  886. //          {
  887. //              onPieceClickDefault(1);
  888. //          }
  889.            
  890.            
  891.            
  892.         }
  893.        
  894.     }  
  895.    
  896.     public PIECE_TYPE jokerPiece;
  897.     void onMagicCrystalPurpleClick(int clickCount)
  898.     {              
  899.         if (touchX < 0 && touchY < 0) {
  900.             return;
  901.         }
  902.        
  903.         if(clickCount==1)
  904.         {
  905.             if (gameGrid[touchX,touchY] == (int)PIECE_TYPE.ROAD)
  906.             {
  907.                 //inicia busqueda y animacion
  908. //              changeSelectorAnimationColor(SELECTOR_COLOR_NORMAL);
  909.                 changeSelectorAnimation(true);
  910.                 jokerPiece = jokerSearch(PIECE_TYPE.ROCK);//siempre se busca rock primero                                                                          
  911.                 animateNeigbors = (this.neighborsList.Count >= 2);
  912.                 turnOnOffHighLightGrid(animateNeigbors);
  913.             } else {
  914. //              changeSelectorAnimationColor(SELECTOR_COLOR_RED);
  915.                 changeSelectorAnimation(false);
  916.             }
  917.         }
  918.         else
  919.         {
  920.             if (gameGrid[touchX,touchY] == (int)PIECE_TYPE.ROAD)
  921.             {
  922.                 //poner piezas o colapsarlas
  923.                 putOrCollapsePieces(jokerPiece);                                   
  924.             }  
  925.         }
  926.     }
  927.    
  928.     void onPieceClickDefault(int clickCount)
  929.     {
  930.         if (touchX < 0 && touchY < 0) {
  931.             return;
  932.         }
  933.         if(clickCount==1)
  934.         {
  935.             if (gameGrid[touchX,touchY] == (int)PIECE_TYPE.ROAD)
  936.             {
  937.                 //inicia busqueda y animacion              
  938. //              changeSelectorAnimationColor(SELECTOR_COLOR_NORMAL);
  939.                 changeSelectorAnimation(true);
  940.                
  941.                
  942.                 if (nextPiece == (int)PIECE_TYPE.ALIEN_BASIC || nextPiece == (int)PIECE_TYPE.ALIEN_TELEPORTER) {
  943.                     neighborsList.Clear();
  944.                     return;
  945.                 }
  946.                 startNeighborsSearch((PIECE_TYPE)nextPiece, touchX, touchY);
  947.                 animateNeigbors = (this.neighborsList.Count >= 2);
  948.                 turnOnOffHighLightGrid(animateNeigbors);
  949.             } else {
  950. //              changeSelectorAnimationColor(SELECTOR_COLOR_RED);
  951.                 changeSelectorAnimation(false);
  952.             }
  953.         }
  954.         else
  955.         {
  956.             if (gameGrid[touchX,touchY] == (int)PIECE_TYPE.ROAD)
  957.             {
  958.                 //poner piezas o colapsarlas
  959.                 putOrCollapsePieces((PIECE_TYPE)nextPiece);            
  960.             }  
  961.         }          
  962.     }
  963.  
  964.     /// <summary>
  965.     /// Starts the neighbors search.
  966.     /// </summary>
  967.  
  968.     public void startNeighborsSearch(PIECE_TYPE pieceToFind, int x, int y)
  969.     {
  970.         neighborsList.Clear();     
  971.         getNeighBorsListAt(ref neighborsList,x,y,x,y, pieceToFind);
  972.     }
  973.  
  974.     public PIECE_TYPE jokerSearch (PIECE_TYPE pieceToSearch)
  975.     {      
  976.                        
  977.         if ( (getPieceTypeAt(touchX, touchY + 1) == PIECE_TYPE.ROAD || getPieceTypeAt(touchX, touchY + 1) == PIECE_TYPE.OUT_OF_BOUNDS)
  978.                 && (getPieceTypeAt(touchX + 1, touchY) == PIECE_TYPE.ROAD || getPieceTypeAt(touchX + 1, touchY) == PIECE_TYPE.OUT_OF_BOUNDS)
  979.                 && (getPieceTypeAt(touchX, touchY - 1) == PIECE_TYPE.ROAD || getPieceTypeAt(touchX, touchY - 1) == PIECE_TYPE.OUT_OF_BOUNDS)
  980.                 && (getPieceTypeAt(touchX - 1, touchY) == PIECE_TYPE.ROAD || getPieceTypeAt(touchX - 1, touchY) == PIECE_TYPE.OUT_OF_BOUNDS)) {
  981.             if (neighborsList.Count > 0) {
  982.                 neighborsList.Clear();
  983.             }
  984.             return PIECE_TYPE.ROCK;
  985.         }
  986.         PIECE_TYPE pieceToReturn;
  987.         startNeighborsSearch(pieceToSearch, touchX, touchY);
  988.         switch(pieceToSearch) {
  989.             case PIECE_TYPE.ROCK:
  990.                
  991.                 if (neighborsList.Count >= 2) {
  992.                     return PIECE_TYPE.ROCK;
  993.                 } else {                   
  994.                     pieceToReturn = jokerSearch(PIECE_TYPE.CAVE);                  
  995.                 }
  996.             break;
  997.            
  998.             case PIECE_TYPE.CAVE:              
  999.                 if (neighborsList.Count >= 2) {
  1000.                     return PIECE_TYPE.CAVE;
  1001.                 } else {                   
  1002.                     pieceToReturn = jokerSearch(PIECE_TYPE.DIAMOND);                   
  1003.                 }
  1004.             break;
  1005.            
  1006.             case PIECE_TYPE.DIAMOND:               
  1007.                 if (neighborsList.Count >= 2) {
  1008.                     return PIECE_TYPE.DIAMOND;
  1009.                 } else {                   
  1010.                     pieceToReturn = jokerSearch(PIECE_TYPE.MOAI);                  
  1011.                 }
  1012.             break;
  1013.            
  1014.             case PIECE_TYPE.MOAI:              
  1015.                 if (neighborsList.Count >= 2) {
  1016.                     return PIECE_TYPE.MOAI;
  1017.                 } else {                   
  1018.                     pieceToReturn = jokerSearch(PIECE_TYPE.MOAIS);                 
  1019.                 }
  1020.             break;
  1021.            
  1022.             case PIECE_TYPE.MOAIS:             
  1023.                 if (neighborsList.Count >= 2) {
  1024.                     return PIECE_TYPE.MOAIS;
  1025.                 } else {                   
  1026.                     pieceToReturn = jokerSearch(PIECE_TYPE.STONEHENGE);                
  1027.                 }
  1028.             break;
  1029.            
  1030.             case PIECE_TYPE.STONEHENGE:            
  1031.                 if (neighborsList.Count >= 2) {                
  1032.                     return PIECE_TYPE.STONEHENGE;
  1033.                 } else {                   
  1034.                     pieceToReturn = jokerSearch(PIECE_TYPE.BUSH);                  
  1035.                 }
  1036.             break;
  1037.            
  1038.             case PIECE_TYPE.BUSH:              
  1039.                 if (neighborsList.Count >= 2) {
  1040.                     return PIECE_TYPE.BUSH;
  1041.                 } else {                   
  1042.                     pieceToReturn = jokerSearch(PIECE_TYPE.TREE);                  
  1043.                 }
  1044.             break;
  1045.            
  1046.             case PIECE_TYPE.TREE:              
  1047.                 if (neighborsList.Count >= 2) {
  1048.                     return PIECE_TYPE.TREE;
  1049.                 } else {                   
  1050.                     pieceToReturn = jokerSearch(PIECE_TYPE.RUCA);                  
  1051.                 }
  1052.             break;
  1053.            
  1054.             case PIECE_TYPE.RUCA:              
  1055.                 if (neighborsList.Count >= 2) {
  1056.                     return PIECE_TYPE.RUCA;
  1057.                 } else {                   
  1058.                     pieceToReturn = jokerSearch(PIECE_TYPE.HOME);                  
  1059.                 }
  1060.             break;
  1061.            
  1062.             case PIECE_TYPE.HOME:              
  1063.                 if (neighborsList.Count >= 2) {
  1064.                     return PIECE_TYPE.HOME;
  1065.                 } else {                   
  1066.                     pieceToReturn = jokerSearch(PIECE_TYPE.CASTLE);                
  1067.                 }
  1068.             break;
  1069.            
  1070.             case PIECE_TYPE.CASTLE:            
  1071.                 if (neighborsList.Count >= 2) {
  1072.                     return PIECE_TYPE.CASTLE;
  1073.                 } else {                   
  1074.                     pieceToReturn = jokerSearch(PIECE_TYPE.BUILDING);                  
  1075.                 }
  1076.             break;
  1077.            
  1078.             case PIECE_TYPE.BUILDING:              
  1079.                 if (neighborsList.Count >= 2) {
  1080.                     return PIECE_TYPE.BUILDING;
  1081.                 } else {                   
  1082.                     pieceToReturn = jokerSearch(PIECE_TYPE.FUTURE_HOME);                   
  1083.                 }
  1084.             break;
  1085.            
  1086.             case PIECE_TYPE.FUTURE_HOME:               
  1087.                 if (neighborsList.Count >= 2) {
  1088.                     return PIECE_TYPE.FUTURE_HOME;
  1089.                 } else {                   
  1090.                     pieceToReturn = jokerSearch(PIECE_TYPE.FUTURE_HOME_HOVERING);                  
  1091.                 }
  1092.             break;
  1093.            
  1094.             case PIECE_TYPE.FUTURE_HOME_HOVERING:              
  1095.                 if (neighborsList.Count >= 2) {
  1096.                     return PIECE_TYPE.FUTURE_HOME_HOVERING;
  1097.                 } else {               
  1098.                     return PIECE_TYPE.ROCK;                
  1099.                 }
  1100. //          break;
  1101.            
  1102.             default:
  1103.                 return PIECE_TYPE.ROCK;
  1104. //          break;                                 
  1105.                    
  1106.         }
  1107.         return pieceToReturn;
  1108.        
  1109.     }
  1110.  
  1111.     /// <summary>
  1112.     /// Puts the or collapse pieces.
  1113.     /// </summary>
  1114.    
  1115.     bool collapsingHasStarted = false;
  1116.     bool collapsingPieces = false;
  1117.     bool collapsingHasEnded = false;
  1118.    
  1119.     public void onCollapsingCells() {
  1120.        
  1121.            
  1122.             int indexesToCollapseOriginalCount = indexesToCollapseList.Count;
  1123.             enableOrDisableUFOGuiButtons(false);
  1124.             for(int i = 0; i < indexesToCollapseList.Count; i++) {
  1125.                 //just in case
  1126.                
  1127.                 int targetX = indexesToCollapseList[i]%6;
  1128.                 int targetY = indexesToCollapseList[i]/6;
  1129.                
  1130.                 if(!collapsingHasStarted)
  1131.                 {
  1132.                     turnOnOffHighLightGrid(false);
  1133.                     collapsingHasStarted = true;
  1134.                    
  1135. //                  if (i == 0) {
  1136. //                      selector.transform.Translate(Vector3.forward*-10f);//ocultar selector
  1137. //                  }
  1138.                 }
  1139.                
  1140.                
  1141.                
  1142.                 if(!collapsingPieces)
  1143.                 {          
  1144.                     collapseNeighBors(targetX,targetY);
  1145.                 }
  1146.                
  1147.                
  1148.                 if(collapsingHasEnded)
  1149.                 {
  1150.                    
  1151.                                    
  1152.                     collapsingHasStarted = false;
  1153.                     collapsingPieces = false;
  1154.                     collapsingHasEnded = false;
  1155.                     resetPositionsOfAnimatedNeighbors();               
  1156.                     if (i == indexesToCollapseList.Count - 1) {//el final                      
  1157.                         moveAliens();
  1158.                         animateNeigbors = false;
  1159.                         neighborsList.Clear();
  1160.                         if (indexesToCollapseOriginalCount < indexesToCollapseList.Count) {
  1161.                             continue;
  1162.                         }
  1163.                         bonusMultiplier = 0;
  1164.                         STATE = Estados.WAITING_FOR_CLICK;
  1165.                         //selector.transform.Translate(Vector3.forward*10f);//mostrar selector nuevamente
  1166.                         resetTouch();
  1167.                         indexesToCollapseList.Clear();
  1168.                        
  1169.                        
  1170.                         enableOrDisableUFOGuiButtons(true);
  1171.                     }
  1172.                    
  1173.                    
  1174.                 }
  1175.         }          
  1176.                
  1177.     }
  1178.    
  1179.     public void resetTouch() {
  1180.             touchX = -1;
  1181.             touchY = -1;
  1182.             prevClickX = -1;
  1183.             prevClickY = -1;
  1184.        
  1185.     }
  1186.    
  1187. //  public void purpleAliensOldRaiseFPSspeed() {
  1188. //      foreach(int alienIndex in listAlienPurpleOldIndexes)
  1189. //      {
  1190. //          gamePiecesAnimations[alienIndex].CurrentClip.fps = 20f;
  1191. //      }
  1192. //  }
  1193.    
  1194.    
  1195.    
  1196.     public void purpleAliensTeleportFase1ColorUpdate(Color value)
  1197.     {
  1198.         foreach(int alienIndex in listAlienPurpleOldIndexes)
  1199.         {
  1200.             gamePiecesAnimations[alienIndex].color = value;
  1201.         }
  1202.     }
  1203.    
  1204.     public void purpleAliensTeleportFase1ColorComplete()
  1205.     {
  1206.         foreach(int alienIndex in listAlienPurpleOldIndexes)
  1207.         {
  1208.             gamePiecesAnimations[alienIndex].color = Color.white;
  1209.             if (gameGrid[alienIndex%6, alienIndex/6] == (int)PIECE_TYPE.ROAD) {
  1210.                 gamePiecesAnimations[alienIndex].CurrentClip.fps = 8f;
  1211.                 gamePiecesAnimations[alienIndex].Play("RoadT");
  1212.             }
  1213.         }      
  1214.     }
  1215.    
  1216. //  public void purpleAliensNewRaiseFPSspeed() {
  1217. //      foreach(int alienIndex in listAlienPurpleNewIndexes)
  1218. //      {
  1219. //          gamePiecesAnimations[alienIndex].CurrentClip.fps = 20f;
  1220. //      }
  1221. //  }
  1222.    
  1223.     public void purpleAliensTeleportFase2ColorUpdate(Color value)
  1224.     {
  1225.         foreach(int alienIndex in listAlienPurpleNewIndexes)
  1226.         {          
  1227.             gamePiecesAnimations[alienIndex].color = value;
  1228.         }      
  1229.     }
  1230.    
  1231.     public void purpleAliensTeleportFase2ColorComplete()
  1232.     {
  1233.        
  1234.         foreach(int alienIndex in listAlienPurpleNewIndexes)
  1235.         {
  1236.             gamePiecesAnimations[alienIndex].CurrentClip.fps = 8f;
  1237.         }
  1238.        
  1239.    
  1240.     }  
  1241.    
  1242.     public List<int>    listAlienPurpleOldIndexes = new List<int>();
  1243.     public List<int>    listAlienPurpleNewIndexes = new List<int>();
  1244.    
  1245.     public readonly float teleportTime = 0.65f;
  1246.     public void movePurpleAliens() {
  1247.                        
  1248.         listAlienPurpleOldIndexes.Clear();
  1249.         listAlienPurpleNewIndexes.Clear();
  1250.        
  1251.         fillListAlienPurple();
  1252.         List<int> validMoves = this.getValidPlacesToTeleport();
  1253.         if(listAlienPurpleOldIndexes.Count == 0)
  1254.             return;
  1255.        
  1256.        
  1257.        
  1258.         foreach(int alienIndex in listAlienPurpleOldIndexes)
  1259.         {
  1260.             if (validMoves.Count > 0) {
  1261.                 int alienCurrentX = alienIndex%6;
  1262.                 int alienCurrentY = alienIndex/6;
  1263.                
  1264.                
  1265.                
  1266.                
  1267.                 gameGrid[alienCurrentX,alienCurrentY] = (int)PIECE_TYPE.ROAD;
  1268.                 int indexDestino = validMoves[Random.Range(0, validMoves.Count)];
  1269.                 int alienDestX = indexDestino%6;
  1270.                 int alienDestY = indexDestino/6;
  1271.                 gameGrid[alienDestX, alienDestY] = (int)PIECE_TYPE.ALIEN_TELEPORTER;
  1272.                 validMoves.Remove(indexDestino);
  1273.                 validMoves.Add(alienIndex);
  1274.                 listAlienPurpleNewIndexes.Add(indexDestino);
  1275.                 gamePiecesAnimations[alienIndex].CurrentClip.fps = 20f;
  1276.                
  1277.             }
  1278.            
  1279.         }
  1280.        
  1281.         if (validMoves.Count == 0) {
  1282.             return;
  1283. //          fillListAlienBasics();
  1284. //          if (listGreenAliensIndexes.Count > 0) {
  1285. //              return;
  1286. //          } else {
  1287. //              if (isGameOver()) {
  1288. //                  STATE = Estados.GAME_OVER;
  1289. //              }
  1290. //          }
  1291.         } else {
  1292.            
  1293.        
  1294.                
  1295.             iTween.ValueTo(this.gameObject,
  1296.                 iTween.Hash(
  1297.                 "from",Color.white,
  1298.                 "to",new Color(1.0f,1.0f,1.0f,0.0f),
  1299.                 "time",teleportTime,
  1300. //              "onstart", "purpleAliensOldRaiseFPSspeed",
  1301.                 "onupdate","purpleAliensTeleportFase1ColorUpdate",
  1302.                 "oncomplete","purpleAliensTeleportFase1ColorComplete"
  1303.             ));
  1304.                    
  1305.             foreach(int indexDestino in listAlienPurpleNewIndexes)
  1306.             {      
  1307.                 gamePiecesAnimations[indexDestino].Play("Alien_2");    
  1308.                 gamePiecesAnimations[indexDestino].CurrentClip.fps = 20f;
  1309.                 gamePiecesAnimations[indexDestino].color = new Color(1.0f,1.0f,1.0f,0.0f);
  1310.                
  1311.    
  1312.             }
  1313.                    
  1314.             iTween.ValueTo(this.gameObject,
  1315.                 iTween.Hash(
  1316.                 "from", new Color(1.0f,1.0f,1.0f,0.0f),
  1317.                 "to",Color.white,
  1318.                 "time",teleportTime,
  1319.                 "delay",teleportTime,
  1320. //              "onstart", "purpleAliensNewRaiseFPSspeed",
  1321.                 "onupdate","purpleAliensTeleportFase2ColorUpdate",
  1322.                 "oncomplete","purpleAliensTeleportFase2ColorComplete"          
  1323.             ));        
  1324.         }
  1325.        
  1326.     }
  1327.    
  1328.     private List<List<int>> moaiGroupsList = new List<List<int>>();
  1329.    
  1330.     public void moveAliens() {
  1331.        
  1332.         //bool purple = false;
  1333. //      Estados prevState = STATE;
  1334. //      STATE = Estados.WAIT_END_ANIMATION;
  1335.         if (!alreadyMovedAliens) {         
  1336.             movePurpleAliens();
  1337.             moveGreenAliens();
  1338.            
  1339.  
  1340.            
  1341.             alreadyMovedAliens = true;
  1342.            
  1343.         }
  1344.        
  1345.        
  1346.        
  1347.         if (isGameOver()) {
  1348.             STATE = Estados.GAME_OVER;
  1349.         }
  1350.                
  1351.        
  1352.     }
  1353.    
  1354.    
  1355.    
  1356.    
  1357.    
  1358.     public List<int> listGreenAliensIndexes = new List<int>();
  1359.     public List<int> listGreenAliensMoved = new List<int>();
  1360.     public List<int> listGreenAliensStuck = new List<int>();
  1361.    
  1362.     public void moveGreenAliens()//float timeToWaitBeforeMove)
  1363.     {      
  1364.        
  1365.        
  1366.         listGreenAliensStuck.Clear();
  1367.         listGreenAliensMoved.Clear();
  1368.         listGreenAliensIndexes.Clear();
  1369.         moaiGroupsList.Clear();
  1370.         fillListAlienBasics();
  1371.         if (listGreenAliensIndexes.Count == 0) {
  1372.             return;
  1373.         }
  1374.        
  1375.        
  1376.        
  1377.         for(int i = 0; i < listGreenAliensIndexes.Count; i++)// in listGreenAliensIndexes)
  1378.         {
  1379.             int alienIndex = listGreenAliensIndexes[i];
  1380. //          int alienCurrentX = alienIndex%6;
  1381. //          int alienCurrentY = alienIndex/6;
  1382.            
  1383. //          List<int> validMoves = getValidAlienNeighborsMoves(alienIndex);
  1384.             if (tryToMoveGreenAlien(alienIndex)) {
  1385.                 if (!listGreenAliensMoved.Contains(alienIndex)) {
  1386.                     listGreenAliensMoved.Add(alienIndex);
  1387.                 }
  1388.             } else {
  1389.                
  1390.                 if (!listGreenAliensStuck.Contains(alienIndex)) {
  1391.                     listGreenAliensStuck.Add(alienIndex);
  1392.                 }
  1393.             }
  1394.            
  1395.         }
  1396.        
  1397.         int prevoiusAmountOfAliensStuck = listGreenAliensStuck.Count;
  1398.        
  1399.         do {
  1400.             prevoiusAmountOfAliensStuck = listGreenAliensStuck.Count;
  1401.             for(int i = 0; i < listGreenAliensStuck.Count; i++) {
  1402.                 int alienStuckIndex = listGreenAliensStuck[i];
  1403.                
  1404.                 if (!listGreenAliensMoved.Contains(alienStuckIndex) && tryToMoveGreenAlien(alienStuckIndex)) {//antes estaba pegado y logró moverse...
  1405.                     listGreenAliensStuck.Remove(alienStuckIndex);//lo quitamos de la lista de aliens pegados                   
  1406.                     i--;//se retrocede 1 loop en la iteración, ya que ahora hay un alien pegado menos
  1407.                     listGreenAliensMoved.Add(alienStuckIndex);//añadimos al alien q se movió a la lista de los que ya se han movido
  1408.                    
  1409.                 }                  
  1410.                
  1411.             }
  1412.         } while(listGreenAliensStuck.Count != prevoiusAmountOfAliensStuck);//mientras la cantidad de fe aliens pegados no sea constante
  1413.        
  1414.         checkStuckAliens();
  1415.         resetTouch();
  1416.         //yield return null;
  1417.     }
  1418.    
  1419.     public enum PUNTOS_CARDINALES {
  1420.         NORTE
  1421.         ,SUR
  1422.         ,ESTE
  1423.         ,OESTE
  1424.     }
  1425.    
  1426.     public void initAnimGreenAlien(MoveAlienParams alienParams) {
  1427.         if (alienParams.direccionDeMovimiento == PUNTOS_CARDINALES.NORTE || alienParams.direccionDeMovimiento == PUNTOS_CARDINALES.SUR) {
  1428.             gamePiecesAnimations[alienParams.index].Play("Alien_1_move_v");
  1429.         } else {
  1430.             if (alienParams.direccionDeMovimiento == PUNTOS_CARDINALES.ESTE) {
  1431.                 gamePiecesAnimations[alienParams.index].Play("Alien_1_move_hder");
  1432.             } else {
  1433.                 gamePiecesAnimations[alienParams.index].Play("Alien_1_move_h");
  1434.             }
  1435.            
  1436.            
  1437.         }  
  1438.     }
  1439.    
  1440.    
  1441.    
  1442.     public void endAnimGreenAlien(MoveAlienParams alienParams) {
  1443.         if (gameGrid[alienParams.index%6, alienParams.index/6] == (int)PIECE_TYPE.ALIEN_BASIC) {
  1444.             gamePiecesAnimations[alienParams.index].Play("Alien_1");
  1445.         }
  1446.        
  1447.     }
  1448.    
  1449.     public void keepGreenAlienColor(int indexAlien) {
  1450.         if (gamePiecesAnimations[indexAlien].color != Color.white) {
  1451.             gamePiecesAnimations[indexAlien].color = Color.white;
  1452.            
  1453.         }
  1454.     }
  1455.    
  1456.     public struct MoveAlienParams {
  1457.         public int index;
  1458.         public PUNTOS_CARDINALES direccionDeMovimiento;
  1459.         public float delay;
  1460.     }
  1461.    
  1462.     public bool tryToMoveGreenAlien(int indexIni) {
  1463.         //int indexInicio = currentY*6 + currentX;
  1464.         int currentX = indexIni%6;
  1465.         int currentY = indexIni/6;
  1466.        
  1467.         List<int> validMoves = getValidAlienNeighborsMoves(indexIni);
  1468.        
  1469.        
  1470.        
  1471.         if(validMoves.Count > 0)
  1472.             {                              
  1473.                 int indexDestino = validMoves[Random.Range(0, validMoves.Count)];
  1474.                
  1475.                 int destinyX = indexDestino%6;
  1476.                 int destinyY = indexDestino/6;
  1477. //              moveGreenAlienFromTo(alienCurrentX, alienCurrentY, alienDestX, alienDestY);
  1478.                 gameGrid[currentX,currentY] = (int)PIECE_TYPE.ROAD;
  1479.                 gameGrid[destinyX, destinyY] = (int)PIECE_TYPE.ALIEN_BASIC;
  1480.                
  1481.                 MoveAlienParams alienInfo = new MoveAlienParams();
  1482.                 alienInfo.index = indexDestino;
  1483.                 if (destinyX - currentX < 0) {//izq
  1484.                     alienInfo.direccionDeMovimiento = PUNTOS_CARDINALES.OESTE;
  1485.                 } else {
  1486.                     if (destinyX - currentX > 0) {//derecha
  1487.                         alienInfo.direccionDeMovimiento = PUNTOS_CARDINALES.ESTE;
  1488.                     } else {//en la misma x
  1489.                         if (destinyY - currentY < 0) {
  1490.                             alienInfo.direccionDeMovimiento = PUNTOS_CARDINALES.SUR;
  1491.                         } else {
  1492.                             alienInfo.direccionDeMovimiento = PUNTOS_CARDINALES.NORTE;
  1493.                         }
  1494.                     }
  1495.                 }
  1496.                
  1497.            
  1498. //              if(!gamePiecesAnimations[indexIni].Playing) {
  1499.                     gamePiecesAnimations[indexIni].Play("RoadT");
  1500. //              }
  1501.                 gamePiecesAnimations[indexDestino].Play("Alien_1");
  1502.                
  1503.                
  1504.                
  1505.                 Vector3 DestinyPos = gamePiecesAnimations[indexDestino].transform.position;
  1506.                
  1507.                 gamePiecesAnimations[indexDestino].transform.position = gamePiecesAnimations[indexIni].transform.position;
  1508.                 alienInfo.delay = 0;
  1509.                 if (listAlienPurpleOldIndexes.Count > 0) {
  1510.                     alienInfo.delay = teleportTime;
  1511.                 }
  1512.                 iTween.MoveTo(gamePiecesAnimations[indexDestino].gameObject, iTween.Hash(
  1513.                     "position", DestinyPos,
  1514.                     "onstart", "initAnimGreenAlien",
  1515.                     "onstarttarget", this.gameObject,
  1516.                     "onstartparams", alienInfo,
  1517.                     "onupdate", "keepGreenAlienColor",
  1518.                     "onupdatetarget", this.gameObject,
  1519.                     "onupdateparams", indexDestino,
  1520.                     "oncomplete", "endAnimGreenAlien",
  1521.                     "oncompletetarget", this.gameObject,
  1522.                     "oncompleteparams", alienInfo,
  1523.                     "delay", alienInfo.delay,
  1524.                     "easetype", iTween.EaseType.spring,
  1525.                     "time", 1.0f));
  1526.                 return true;
  1527.                
  1528.             } else {
  1529.            
  1530.                 return false;
  1531.             }              
  1532.     }
  1533.    
  1534.     public void checkStuckAliens() {
  1535.         int alienX;
  1536.         int alienY;
  1537.         bool checkForMoai = false;
  1538.         PIECE_TYPE pieceNorth;
  1539.         PIECE_TYPE pieceEast;
  1540.         PIECE_TYPE pieceSouth;
  1541.         PIECE_TYPE pieceWest;
  1542.         List<int> listAliensStuckNextToAliens = new List<int>();
  1543. //      int lastAloneAlienToMoaiIndex = -1;
  1544.         foreach (int alienStuckIndex in listGreenAliensStuck) {
  1545.             alienX = alienStuckIndex%6;
  1546.             alienY = alienStuckIndex/6;
  1547.            
  1548.             //N
  1549.             pieceNorth = getPieceTypeAt(alienX, alienY + 1);
  1550.             //E
  1551.             pieceEast =  getPieceTypeAt(alienX + 1, alienY);
  1552.            
  1553.             //S
  1554.             pieceSouth = getPieceTypeAt(alienX, alienY - 1);
  1555.                        
  1556.             //O            
  1557.             pieceWest = getPieceTypeAt(alienX - 1, alienY);
  1558.            
  1559.             if ( !(pieceNorth == PIECE_TYPE.ALIEN_BASIC || pieceNorth == PIECE_TYPE.ALIEN_TELEPORTER || pieceNorth == PIECE_TYPE.ROAD) &&
  1560.                     !(pieceEast == PIECE_TYPE.ALIEN_BASIC || pieceEast == PIECE_TYPE.ALIEN_TELEPORTER || pieceEast == PIECE_TYPE.ROAD) &&
  1561.                     !(pieceSouth == PIECE_TYPE.ALIEN_BASIC || pieceSouth == PIECE_TYPE.ALIEN_TELEPORTER || pieceSouth == PIECE_TYPE.ROAD) &&
  1562.                     !(pieceWest == PIECE_TYPE.ALIEN_BASIC || pieceWest == PIECE_TYPE.ALIEN_TELEPORTER || pieceWest == PIECE_TYPE.ROAD)) {
  1563.                
  1564.                 alienToMoaiAt(alienStuckIndex);
  1565.                 checkForMoai = true;
  1566.             } else {
  1567.                 listAliensStuckNextToAliens.Add(alienStuckIndex);
  1568.             }
  1569.            
  1570.             for(int i = 0; i < listAliensStuckNextToAliens.Count; i++) {
  1571.                 int stuckAlienIndex = listAliensStuckNextToAliens[i];
  1572.                 List<int> currentAlienValidMoves = getValidAlienNeighborsMoves(stuckAlienIndex, true);
  1573.                 startNeighborsSearch(PIECE_TYPE.ALIEN_BASIC, alienX, alienY);
  1574. //              neighborsList.Clear();
  1575. //              getNeighBorsListAt(ref neighborsList,alienX,alienY,alienX,alienY, PIECE_TYPE.ALIEN_BASIC);
  1576.                 int countStuck = 0;
  1577.                 for (int n = 0; n < neighborsList.Count; n++) {                
  1578.                     int stuckAlienNeighborIndex = neighborsList[n];
  1579.                     List<int> validMoves = getValidAlienNeighborsMoves(stuckAlienNeighborIndex, true);
  1580.                
  1581.                     if (validMoves.Count + currentAlienValidMoves.Count > 0) { //no convertir, quitarlos de la lista                       
  1582.                         listAliensStuckNextToAliens.Remove(stuckAlienIndex);                       
  1583.                         for (int m = 0; m < neighborsList.Count; m++) {
  1584.                             listAliensStuckNextToAliens.Remove(neighborsList[m]);                          
  1585.                         }
  1586.                        
  1587.                         i = -1;
  1588.                         break;
  1589.                     } else {
  1590.                         countStuck++;//contando los pegados
  1591.                         if (countStuck == neighborsList.Count) {//si todos estan pegados, los convierte a moai                                                     
  1592.                             for (int k = 0; k < neighborsList.Count; k++) {
  1593.                                 int indexNeighbor = neighborsList[k];
  1594.                                 alienToMoaiAt(indexNeighbor);
  1595.                                 listAliensStuckNextToAliens.Remove(neighborsList[k]);                              
  1596.                             }
  1597.                             i = -1;
  1598.                             alienToMoaiAt(stuckAlienIndex);
  1599.                             checkForMoai = true;
  1600.                             break;
  1601.                         }
  1602.                     }
  1603.                 }                              
  1604.             }                      
  1605.                        
  1606.         }
  1607.         if (checkForMoai) {
  1608.             checkForMoaiGroups();
  1609.         }
  1610. //      } else {
  1611. //          if (isGameOver()) {
  1612. //              STATE = Estados.GAME_OVER;
  1613. //          }
  1614. //      }
  1615.        
  1616.        
  1617.     }
  1618.    
  1619.     void checkForMoaiGroups() {
  1620.        
  1621. //      initializeMoaiIndexes();
  1622.         int groupCount = 0;
  1623.         moaiGroupsList.Clear();
  1624.        
  1625.         for (int i = 0; i < listMoaiIndexes.Count; i++) {                      
  1626.             int moaiIndex = listMoaiIndexes[i];        
  1627.             int moaiX = moaiIndex%6;
  1628.             int moaiY = moaiIndex/6;
  1629.             List<int> tempList = new List<int>();
  1630. //          neighborsList.Clear();
  1631. //          getNeighBorsListAt(ref neighborsList, moaiX, moaiY, moaiX, moaiY, PIECE_TYPE.MOAI);//verificando los vecinos moai
  1632.             startNeighborsSearch(PIECE_TYPE.MOAI, moaiX, moaiY);
  1633.             if (neighborsList.Count >= 2) {//si hay un grupo de 3 o más
  1634.                 moaiGroupsList.Add(new List<int>());//se crea un grupo
  1635.                 tempList.Add (moaiIndex);
  1636.                 tempList.AddRange(neighborsList);
  1637.                 moaiGroupsList[groupCount].AddRange(tempList);                             
  1638.                 for (int n = 0; n < tempList.Count; n++) {
  1639.                     int moaiInGroupIndex = tempList[n];
  1640.                     listMoaiIndexes.Remove(moaiInGroupIndex);//se quitan todos los moai del grupo de la lista de moais
  1641.                 }
  1642.                 i--; //como se quitó el moai actual, se retrocede en 1 el loop
  1643.                 groupCount++;
  1644.             }          
  1645.         }
  1646.        
  1647.         //debug
  1648.        
  1649. //      Debug.Log("Grupos: " + moaiGroupsList.Count);
  1650.         if (moaiGroupsList.Count > 0) {
  1651.            
  1652.             for (int i = 0; i < moaiGroupsList.Count; i++ ) {//List<int> lista in moaiGroupsList) {
  1653.                 List<int> lista = moaiGroupsList[i];
  1654. //              Debug.Log("Grupo #" + i + " Tiene " + lista.Count + " moais");
  1655. //              Debug.Log("-----");
  1656.                
  1657.                 if (lista.Contains(touchY*6 + touchX)) {
  1658.                         indexesToCollapseList.Add(touchY*6 + touchX);
  1659. //                      Debug.Log("Grupo #" + i + " Index a colapsar: " + (touchY*6 + touchX));
  1660.                         continue;//nos saltamos al siguiente grupo de moais
  1661.                 } else {
  1662.                    
  1663.                     List<int> candidateToBeCollapseTarget = new List<int>();
  1664.                     for(int m = 0; m < lista.Count; m++) {
  1665.                         int moaiIndex = lista[m];
  1666.                         int currentMoaiX = moaiIndex%6;
  1667.                         int currentMoaiY = moaiIndex/6;                                    
  1668.                            
  1669.                          
  1670.                         float distX = Mathf.Abs(touchX - currentMoaiX);
  1671.                         float distY = Mathf.Abs(touchY - currentMoaiY);
  1672.                        
  1673.                         if (distX <= 1f && distY <= 1f) {
  1674.                             candidateToBeCollapseTarget.Add(moaiIndex);
  1675.                             //indexesToCollapseList.Add(moaiIndex);
  1676.                             //Debug.Log("Grupo #" + i + " Index a colapsar: " + moaiIndex);
  1677.                             //break;
  1678.                         }                                                  
  1679.                     }
  1680.                        
  1681.                     int indexNorth = (touchY + 1)*6 + (touchX);
  1682.                     int indexSouth = (touchY - 1)*6 + (touchX);
  1683.                     int indexEast = (touchY)*6 + (touchX + 1);
  1684.                     int indexWest = (touchY)*6 + (touchX - 1);
  1685.                     if (candidateToBeCollapseTarget.Contains(indexNorth)) {
  1686.                         indexesToCollapseList.Add(indexNorth);
  1687.                         continue;
  1688.                     } else {
  1689.                         if (candidateToBeCollapseTarget.Contains(indexSouth)) {
  1690.                             indexesToCollapseList.Add(indexSouth);
  1691.                             continue;
  1692.                         } else {
  1693.                             if (candidateToBeCollapseTarget.Contains(indexEast)) {
  1694.                                 indexesToCollapseList.Add(indexEast);
  1695.                                 continue;
  1696.                             } else {
  1697.                                 if (candidateToBeCollapseTarget.Contains(indexWest)) {
  1698.                                     indexesToCollapseList.Add(indexWest);
  1699.                                     continue;
  1700.                                 } else {
  1701.                                     indexesToCollapseList.Add(lista[0]);
  1702.                                     continue;
  1703.                                 }
  1704.                             }
  1705.                         }
  1706.                        
  1707.                     }                                              
  1708.                 }
  1709.                
  1710.             }
  1711.             neighborsList.Clear();
  1712.             STATE = Estados.COLLAPSING;
  1713.         }
  1714. //      else {
  1715. //          if (isGameOver()) {
  1716. //              STATE = Estados.GAME_OVER;
  1717. //          }
  1718. //      }
  1719.        
  1720.         //reconstuir la lista
  1721.         initializeMoaiIndexes();
  1722.        
  1723.     }
  1724.    
  1725.    
  1726.     private List<int> listMoaiIndexes = new List<int>();
  1727.     public void alienToMoaiAt(int index) {
  1728.        
  1729.         alienToMoaiAt(index, true);
  1730.                
  1731.     }
  1732.    
  1733.     public void alienToMoaiAt(int index, bool playAnimation) {
  1734.        
  1735.         int alienX = index%6;
  1736.         int alienY = index/6;
  1737.         gameGrid[alienX, alienY] = (int)PIECE_TYPE.MOAI;
  1738.        
  1739.         if (playAnimation) {
  1740.             gamePiecesAnimations[index].Play((string)tablaAllAnimations[(int)PIECE_TYPE.MOAI]);//"Moai_Single" ?
  1741.         }
  1742.        
  1743.         updateBackgroundGridAt(alienX, alienY);
  1744.         updateBackgroundGridAroundAt(alienX, alienY);
  1745.        
  1746.         if (!listMoaiIndexes.Contains(index)) {
  1747.             listMoaiIndexes.Add(index);
  1748.         }
  1749.         //updateBackgroundGraphics();      
  1750.                
  1751.     }
  1752.    
  1753.    
  1754.    
  1755.     public void fillListAlienBasics() {
  1756.         for (int i = 0; i < (int)GAME_PROPERTIES.rowLength; i++) {
  1757.             for (int j = 0; j < (int)GAME_PROPERTIES.columnLength; j++) {
  1758.                 if (gameGrid[i,j] == (int)PIECE_TYPE.ALIEN_BASIC) {
  1759.                     listGreenAliensIndexes.Add(j*6+i);
  1760.                 }
  1761.             }
  1762.         }
  1763.     }
  1764.    
  1765.     public void fillListAlienPurple() {
  1766.         for (int i = 0; i < (int)GAME_PROPERTIES.rowLength; i++) {
  1767.             for (int j = 0; j < (int)GAME_PROPERTIES.columnLength; j++) {
  1768.                 if (gameGrid[i,j] == (int)PIECE_TYPE.ALIEN_TELEPORTER) {
  1769.                     listAlienPurpleOldIndexes.Add(j*6+i);
  1770.                 }
  1771.             }
  1772.         }
  1773.     }
  1774.    
  1775.    
  1776.     public List<int> getValidAlienNeighborsMoves(int alienIndex) {
  1777.        
  1778.                                    
  1779.         return getValidAlienNeighborsMoves(alienIndex, false);
  1780.     }
  1781.    
  1782.     public List<int> getValidAlienNeighborsMoves(int alienIndex, bool countPurpleAlienNeighborAsValidMove) {
  1783.         List<int> listaIndexesValidos = new List<int>();
  1784.         int alienX = alienIndex%6;
  1785.         int alienY = alienIndex/6;
  1786.                
  1787.         if (countPurpleAlienNeighborAsValidMove) {
  1788.             //N
  1789.             if (getPieceTypeAt(alienX, alienY + 1)  == PIECE_TYPE.ROAD || getPieceTypeAt(alienX, alienY + 1)  == PIECE_TYPE.ALIEN_TELEPORTER) {
  1790.                 listaIndexesValidos.Add(alienIndex + 6);
  1791.             }
  1792.             //E
  1793.             if (getPieceTypeAt(alienX + 1, alienY) == PIECE_TYPE.ROAD || getPieceTypeAt(alienX + 1, alienY) == PIECE_TYPE.ALIEN_TELEPORTER) {
  1794.                 listaIndexesValidos.Add(alienIndex + 1);
  1795.             }
  1796.            
  1797.             //S
  1798.             if (getPieceTypeAt(alienX, alienY - 1) == PIECE_TYPE.ROAD || getPieceTypeAt(alienX, alienY - 1) == PIECE_TYPE.ALIEN_TELEPORTER) {
  1799.                 listaIndexesValidos.Add(alienIndex - 6);
  1800.             //O
  1801.             }
  1802.             if (getPieceTypeAt(alienX - 1, alienY) == PIECE_TYPE.ROAD || getPieceTypeAt(alienX - 1, alienY) == PIECE_TYPE.ALIEN_TELEPORTER) {
  1803.                 listaIndexesValidos.Add(alienIndex - 1);
  1804.             }
  1805.            
  1806.         } else {
  1807.            
  1808.             //N
  1809.             if (getPieceTypeAt(alienX, alienY + 1)  == PIECE_TYPE.ROAD) {
  1810.                 listaIndexesValidos.Add(alienIndex + 6);
  1811.             }
  1812.             //E
  1813.             if (getPieceTypeAt(alienX + 1, alienY) == PIECE_TYPE.ROAD) {
  1814.                 listaIndexesValidos.Add(alienIndex + 1);
  1815.             }
  1816.            
  1817.             //S
  1818.             if (getPieceTypeAt(alienX, alienY - 1) == PIECE_TYPE.ROAD) {
  1819.                 listaIndexesValidos.Add(alienIndex - 6);
  1820.             //O
  1821.             }
  1822.             if (getPieceTypeAt(alienX - 1, alienY) == PIECE_TYPE.ROAD) {
  1823.                 listaIndexesValidos.Add(alienIndex - 1);
  1824.             }
  1825.         }
  1826.                                    
  1827.         return listaIndexesValidos;
  1828.     }
  1829.    
  1830.    
  1831.    
  1832.     public List<int> getValidPlacesToTeleport() {
  1833.         List<int> listaIndexesValidos = new List<int>();       
  1834.                
  1835.         for (int i = 0; i < (int)GAME_PROPERTIES.rowLength; i++) {
  1836.                 for (int j = 0; j < (int)GAME_PROPERTIES.columnLength; j++) {
  1837.                     if (gameGrid[i,j]  == (int)PIECE_TYPE.ROAD) {
  1838.                         listaIndexesValidos.Add(j*6+i);
  1839.                     }
  1840.                 }
  1841.         }
  1842.                                            
  1843.         return listaIndexesValidos;
  1844.     }
  1845.    
  1846.    
  1847.     private PIECE_TYPE getPieceTypeAt(int x, int y)
  1848.     {
  1849.         if((x>=0) && (x<=(int)GAME_PROPERTIES.rowLength-1))
  1850.         {
  1851.             if((y>=0) && (y<=(int)GAME_PROPERTIES.columnLength-1))
  1852.             {
  1853.                 if((x!=0) || (y!= (int)GAME_PROPERTIES.columnLength-1))
  1854.                 {
  1855.                     return (PIECE_TYPE)gameGrid[x,y];
  1856.                 }              
  1857.             }
  1858.         }
  1859.        
  1860.         return PIECE_TYPE.OUT_OF_BOUNDS;
  1861.     }
  1862.        
  1863.    
  1864.     public void createBlackHole(PIECE_TYPE pieceTarget) {      
  1865.         int indexPieceAnimation = touchY*6 + touchX;
  1866.         Estados oldState = STATE;
  1867.         STATE = Estados.WAIT_END_ANIMATION;
  1868. //      if (pieceTarget == PIECE_TYPE.ROAD) {
  1869. //          STATE = Estados.WAITING_FOR_CLICK;
  1870. //          return;
  1871. //      }
  1872.                
  1873.         if(neighborsList.Count < 2)
  1874.         {
  1875.             //poner piezas
  1876.             if (pieceTarget == PIECE_TYPE.ALIEN_BASIC || pieceTarget == PIECE_TYPE.ALIEN_TELEPORTER) {                                             
  1877.                 //gameGrid[touchX, touchY] = (int)PIECE_TYPE.MOAI;
  1878.                 alienToMoaiAt(touchY*6 + touchX, false);
  1879.            
  1880.             } else {
  1881.                 if (gameGrid[touchX, touchY] == (int)PIECE_TYPE.MOAI) {
  1882.                     listMoaiIndexes.Remove(touchY * 6 + touchX);
  1883.                    
  1884.                 }
  1885.                 gameGrid[touchX, touchY] = (int)PIECE_TYPE.ROAD;                   
  1886.        
  1887.             }
  1888.             gamePiecesAnimations[indexPieceAnimation].Play("Black_Hole_Full_Animation");
  1889.            
  1890.             float clipTotalTime = gamePiecesAnimations[indexPieceAnimation].CurrentClipTotalAnimationTime;
  1891.            
  1892.             StartCoroutine(changeAnimationBlackHoleToPiece(indexPieceAnimation, (PIECE_TYPE)gameGrid[touchX, touchY], clipTotalTime, oldState, true));//);             
  1893. //          //waitAWhile((float)gamePiecesAnimations[indexPieceAnimation].CurrentClip.frames.Length/gamePiecesAnimations[indexPieceAnimation].CurrentClip.fps);
  1894. //         
  1895.             int scoreAmountToAdd = (int)tablaScorePerPiece[(PIECE_TYPE)gameGrid[touchX, touchY]];
  1896.             currentScore += scoreAmountToAdd;
  1897.             createScoreText(scoreAmountToAdd, touchX, touchY, bonusMultiplier, false);
  1898.            
  1899.             this.updateBackgroundGridAt(touchX, touchY);
  1900.             this.updateBackgroundGridAroundAt(touchX,touchY);
  1901.             getNextPiece();
  1902.             //updateBackgroundGraphics();
  1903.             neighborsList.Clear();                     
  1904.            
  1905.         }
  1906.         else //varios moais
  1907.         {
  1908.             gameGrid[touchX, touchY] = (int)PIECE_TYPE.MOAI;
  1909. //          currentScore += (int)tablaScorePerPiece[PIECE_TYPE.MOAI];          
  1910.             gamePiecesAnimations[indexPieceAnimation].Play("Black_Hole_Full_Animation");           
  1911.             float clipTotalTime = gamePiecesAnimations[indexPieceAnimation].CurrentClipTotalAnimationTime;         
  1912.             StartCoroutine(changeAnimationBlackHoleToPiece(indexPieceAnimation, PIECE_TYPE.MOAI, clipTotalTime, Estados.COLLAPSING, false));
  1913.             indexesToCollapseList.Add(touchY*6 + touchX);
  1914.         }
  1915.        
  1916.                        
  1917.     }
  1918.    
  1919.    
  1920.     IEnumerator changeAnimationBlackHoleToPiece(int indexSpriteAnimado, PIECE_TYPE nuevaPieza, float timeToWait, Estados newState, bool isSingleNeighbor) {
  1921.         hideSelector();
  1922.         yield return new WaitForSeconds(timeToWait);       
  1923.         gamePiecesAnimations[indexSpriteAnimado].Play((string)tablaAllAnimations[(int)nuevaPieza]);
  1924.         //selector.transform.Translate(Vector3.forward*10f);       
  1925.         STATE = newState;
  1926.         if (isSingleNeighbor) {
  1927.             moveAliens();
  1928.            
  1929.         }
  1930.     }
  1931.        
  1932.        
  1933.     public void putOrCollapsePieces (PIECE_TYPE pieceToPut)
  1934.     {
  1935.         gameGrid[touchX,touchY] = (int)pieceToPut;
  1936.         gamePiecesAnimations[touchY*6+touchX].Play((string)tablaAllAnimations[(int)pieceToPut]);
  1937.         hideSelector();//selector.transform.Translate(Vector3.forward*-10f);
  1938. //      lastPieceUsed = pieceToPut;
  1939.         if (pieceToPut == PIECE_TYPE.ALIEN_BASIC || pieceToPut == PIECE_TYPE.ALIEN_TELEPORTER) {           
  1940.             playFX((Instantiate(this.sndAlienTeleportPrefab) as GameObject).GetComponent<AudioSource>());
  1941.         } else {
  1942.             if (neighborsList.Count < 3) {
  1943.                 playFX((Instantiate(this.sndPutPiecePrefab) as GameObject).GetComponent<AudioSource>());   
  1944.             } else {
  1945.                 playFX((Instantiate(this.sndCombinePiecePrefab) as GameObject).GetComponent<AudioSource>());
  1946.             }
  1947.            
  1948.         }
  1949.        
  1950. //      switch(pieceToPut) {
  1951. //          case PIECE_TYPE.ALIEN_BASIC:
  1952. //          case PIECE_TYPE.ALIEN_TELEPORTER:
  1953. //              break;
  1954. //          default:
  1955. //              playFX((Instantiate(this.sndPutPiecePrefab) as GameObject).GetComponent<AudioSource>());
  1956. //              break;
  1957. //         
  1958. //      }
  1959.         updateBackgroundGridAt(touchX, touchY);
  1960.         updateBackgroundGridAroundAt(touchX,touchY);
  1961.        
  1962.         if(neighborsList.Count < 2)
  1963.         {
  1964.             //poner piezas                     
  1965.            
  1966.             if (pieceToPut == PIECE_TYPE.RUCA) {
  1967.                 addVillager(Villager.TIPOS_VILLAGER.CAVERNICOLA, gameGridSprites[touchY*6+ touchX].transform.position);
  1968.             }
  1969.            
  1970.             int scoreAmountToAdd = (int)tablaScorePerPiece[pieceToPut];
  1971.             currentScore += scoreAmountToAdd;
  1972.             createScoreText(scoreAmountToAdd, touchX, touchY, bonusMultiplier, false);         
  1973.             getNextPiece();
  1974.             //updateBackgroundGraphics();
  1975.            
  1976.            
  1977.             moveAliens();
  1978.            
  1979.            
  1980.            
  1981.         }
  1982.         else
  1983.         {  
  1984.            
  1985.             //currentScore += (int)tablaScorePerPiece[(PIECE_TYPE)nextPiece];
  1986.             indexesToCollapseList.Add(touchY*6+touchX);
  1987.             STATE = Estados.COLLAPSING;
  1988.             getNextPiece();
  1989.         }
  1990.     }
  1991.    
  1992.     struct CollapseParams
  1993.     {
  1994.         public Vector3      origin;
  1995.         public GameObject   go;
  1996.         public int          origin_index;
  1997.         public int          destiny_index;
  1998.     };
  1999.    
  2000.     private int collapsingCount = 0;
  2001.    
  2002.     private readonly float DELAY_TO_COLLAPSE = 0.2f;
  2003.     void collapseNeighBors (int x, int y)
  2004.     {
  2005.         int index = y*6 + x;
  2006.        
  2007.         startNeighborsSearch((PIECE_TYPE)gameGrid[x,y], x, y);
  2008.         if (neighborsList.Count >= 2) {
  2009.            
  2010.             Vector3 pos = gamePiecesAnimations[index].transform.position;
  2011.            
  2012.             collapsingPieces = true;
  2013.             bonusMultiplier++;
  2014.            
  2015.             foreach(int i in neighborsList)
  2016.             {
  2017.                 //currentScore += (int)tablaScorePerPiece[(PIECE_TYPE)gameGrid[x,y]]*bonusMultiplier;
  2018.                    
  2019.                 CollapseParams onCollapseParams = new CollapseParams();
  2020.                 onCollapseParams.origin = gamePiecesAnimations[i].transform.position;
  2021.                 onCollapseParams.go = gamePiecesAnimations[i].gameObject;
  2022.                 onCollapseParams.origin_index = i;
  2023.                 onCollapseParams.destiny_index = index;
  2024.                
  2025.                 iTween.MoveTo(gamePiecesAnimations[i].gameObject,iTween.Hash
  2026.                     (
  2027.                          "position",pos
  2028.                         ,"time", 0.7f
  2029.                         ,"delay", DELAY_TO_COLLAPSE
  2030.                         ,"easetype", iTween.EaseType.easeOutBounce
  2031.                         ,"oncomplete","neighborHasReachTarget"
  2032.                         ,"oncompletetarget",this.gameObject
  2033.                         ,"oncompleteparams",onCollapseParams
  2034.                     ));
  2035.             }
  2036.         } else {
  2037.             collapsingPieces = false;
  2038.             neighborsList.Clear();
  2039.             collapsingHasEnded = true;
  2040.         }
  2041.     }
  2042.    
  2043.     void neighborHasReachTarget(CollapseParams onCollapseParams)
  2044.     {
  2045.         collapsingCount++;
  2046.        
  2047.         int x = onCollapseParams.origin_index%6;
  2048.         int y = onCollapseParams.origin_index/6;
  2049.        
  2050.         onCollapseParams.go.transform.position = onCollapseParams.origin;      
  2051.        
  2052.         if (gameGrid[x,y] == (int)PIECE_TYPE.MOAI && !listMoaiIndexes.Contains(onCollapseParams.origin_index)) {
  2053.             listMoaiIndexes.Remove(onCollapseParams.origin_index);
  2054.         }
  2055.        
  2056.         gameGrid[x,y] = (int)PIECE_TYPE.ROAD;
  2057.         gamePiecesAnimations[onCollapseParams.origin_index].Play("RoadT");
  2058.        
  2059.         if(collapsingCount==neighborsList.Count)
  2060.         {
  2061.             int dx = onCollapseParams.destiny_index%6;
  2062.             int dy = onCollapseParams.destiny_index/6;
  2063.            
  2064.             onUpgradeGrid(dx,dy,collapsingCount);          
  2065.             collapsingCount = 0;
  2066.             collapsingPieces = false;
  2067.            
  2068.             startNeighborsSearch((PIECE_TYPE)gameGrid[dx,dy], dx, dy);
  2069.             if(neighborsList.Count>=2)
  2070.             {
  2071.                 collapsingPieces = false;
  2072.             }
  2073.             else
  2074.             {
  2075.                 neighborsList.Clear();
  2076.                 collapsingHasEnded = true;
  2077. //              getNextPiece();
  2078.             }
  2079.            
  2080.             rebuildBackground ();
  2081.         }
  2082.     }
  2083.  
  2084.     void onUpgradeGrid (int x, int y, int count)
  2085.     {              
  2086.         int index = y*6 + x;               
  2087.         updateGameGrid(ref gameGrid[x,y],ref gamePiecesAnimations[index],count, x, y);
  2088.     }
  2089.  
  2090.     void updateGameGrid (ref int pieceValue, ref tk2dAnimatedSprite sprite, int count, int x, int y)
  2091.     {
  2092.         PIECE_TYPE type = (PIECE_TYPE)pieceValue;
  2093.         int montoMonedas;
  2094.         int scoreAmountToAdd = (int)tablaScorePerPiece[type]*(count+1)*bonusMultiplier;
  2095.         //ptje x cada pieza juntada, +1 incluyendo la que se puso para hacer la cadena
  2096.        
  2097.        
  2098.         if (count > 2) {
  2099.             scoreAmountToAdd += (int)tablaScorePerPiece[type]*(count-2)*bonusMultiplier;//ptje extra x cada pieza sobre 2
  2100.            
  2101.            
  2102.             montoMonedas = ((int)tablaScorePerPiece[type]*(count+1)*bonusMultiplier)/5;//count-2                   
  2103.             addCoins(montoMonedas, x, y);
  2104.         }
  2105.        
  2106.         currentScore += scoreAmountToAdd;
  2107.         createScoreText(scoreAmountToAdd, x, y, bonusMultiplier, false);
  2108.         scoreAmountToAdd = 0;
  2109.         Vector3 starPosIni = sprite.transform.position;// + Vector3.up*-altoEnTransformUnitsSquareSprite/2f + Vector3.right*anchoEnTransformUnitsSquareSprite/2f;
  2110.         starPosIni.Set(starPosIni.x + anchoEnTransformUnitsSquareSprite/2f, starPosIni.y - altoEnTransformUnitsSquareSprite/2f + 4f*(bonusMultiplier), 1.45f);
  2111.         GameObject stars = Instantiate(this.comboStarAnimationPrefab, starPosIni, new Quaternion(0f, 0f, Random.Range(0f, 360f + 1f), 0f)) as GameObject;
  2112.         stars.transform.localScale += new Vector3(0.5f*(float)(bonusMultiplier-1), 0.5f*(float)(bonusMultiplier-1), 0.5f*(float)(bonusMultiplier-1));
  2113.        
  2114.         switch(type)
  2115.         {
  2116.             case PIECE_TYPE.BUSH:
  2117.                 pieceValue = (int)PIECE_TYPE.TREE;
  2118.                 scoreAmountToAdd += (int)tablaScorePerPiece[PIECE_TYPE.TREE]*bonusMultiplier;              
  2119.                
  2120.                 //currentScore +=
  2121.                 //int scoreAmountToAdd = (int)tablaScorePerPiece[type]*(count+1)*bonusMultiplier;
  2122.                 if (count>2) {
  2123.                     sprite.Play("Tree_Upgraded");
  2124.                    
  2125.                    
  2126.                 } else {
  2127.                     sprite.Play("Tree");                   
  2128.                 }
  2129.                
  2130.             break;
  2131.            
  2132.             case PIECE_TYPE.TREE:
  2133.                 pieceValue = (int)PIECE_TYPE.RUCA;
  2134.                 //currentScore +=  
  2135.                 scoreAmountToAdd += (int)tablaScorePerPiece[PIECE_TYPE.RUCA]*bonusMultiplier;
  2136.                
  2137.                 if (count>2) {
  2138.                     sprite.Play("Ruca_2");
  2139. //                  currentScore += (int)tablaScorePerPiece[PIECE_TYPE.TREE]*count;
  2140. //                  montoMonedas = ((int)tablaScorePerPiece[PIECE_TYPE.TREE]*(count-2)*bonusMultiplier)/5;
  2141. //                  addCoins(montoMonedas, x, y);
  2142.                 } else {
  2143.                     sprite.Play("Ruca_1");                                     
  2144.                 }
  2145.            
  2146.                 addVillager(Villager.TIPOS_VILLAGER.CAVERNICOLA, sprite.transform.position);
  2147.                
  2148.             break;
  2149.            
  2150.             case PIECE_TYPE.RUCA:
  2151.                 pieceValue = (int)PIECE_TYPE.HOME;
  2152.                 scoreAmountToAdd += (int)tablaScorePerPiece[PIECE_TYPE.HOME]*bonusMultiplier;          
  2153.                
  2154.                 if (count>2) {
  2155.                     sprite.Play("Home_Upgraded");
  2156. //                  currentScore += (int)tablaScorePerPiece[PIECE_TYPE.RUCA]*count;
  2157. //                  montoMonedas = ((int)tablaScorePerPiece[PIECE_TYPE.RUCA]*(count-2)*bonusMultiplier)/5;
  2158. //                  addCoins(montoMonedas, x, y);
  2159.                 } else {
  2160.                     sprite.Play("Home");                   
  2161.                 }
  2162.            
  2163.                 addVillager(Villager.TIPOS_VILLAGER.CIUDADANO, sprite.transform.position);
  2164.             break;
  2165.            
  2166.             case PIECE_TYPE.HOME:
  2167.                 pieceValue = (int)PIECE_TYPE.CASTLE;
  2168.                 scoreAmountToAdd += (int)tablaScorePerPiece[PIECE_TYPE.CASTLE]*bonusMultiplier;
  2169.                
  2170.                 if (count>2) {
  2171.                     sprite.Play("Castle_Upgraded");
  2172. //                  currentScore += (int)tablaScorePerPiece[PIECE_TYPE.HOME]*count;
  2173. //                  montoMonedas = ((int)tablaScorePerPiece[PIECE_TYPE.HOME]*(count-2)*bonusMultiplier)/5;
  2174. //                  addCoins(montoMonedas, x, y);
  2175.                 } else {
  2176.                     sprite.Play("Castle");                 
  2177.                 }  
  2178. //              sprite.Play(count>2? "Castle_Upgraded" : "Castle");
  2179.                 addVillager(Villager.TIPOS_VILLAGER.CIUDADANO, sprite.transform.position);
  2180.             break;
  2181.            
  2182.             case PIECE_TYPE.CASTLE:
  2183.                 pieceValue = (int)PIECE_TYPE.BUILDING;
  2184.                 scoreAmountToAdd += (int)tablaScorePerPiece[PIECE_TYPE.BUILDING]*bonusMultiplier;          
  2185.                
  2186.                 if (count>2) {
  2187.                     sprite.Play("Building_Upgraded");
  2188. //                  currentScore += (int)tablaScorePerPiece[PIECE_TYPE.CASTLE]*count;
  2189. //                  montoMonedas = ((int)tablaScorePerPiece[PIECE_TYPE.CASTLE]*(count-2)*bonusMultiplier)/5;
  2190. //                  addCoins(montoMonedas, x, y);
  2191.                 } else {
  2192.                     sprite.Play("Building");                   
  2193.                 }  
  2194.                
  2195.             break;
  2196.            
  2197.             case PIECE_TYPE.BUILDING:
  2198.                 pieceValue = (int)PIECE_TYPE.FUTURE_HOME;
  2199.                 scoreAmountToAdd += (int)tablaScorePerPiece[PIECE_TYPE.FUTURE_HOME]*bonusMultiplier;
  2200.                
  2201.                 if (count>2) {
  2202.                     sprite.Play("Future_Home_1_Upgraded");
  2203. //                  currentScore += (int)tablaScorePerPiece[PIECE_TYPE.BUILDING]*count;
  2204. //                  montoMonedas = ((int)tablaScorePerPiece[PIECE_TYPE.BUILDING]*(count-2)*bonusMultiplier)/5;
  2205. //                  addCoins(montoMonedas, x, y);
  2206.                 } else {
  2207.                     sprite.Play("Future_Home_1");                  
  2208.                 }  
  2209.                
  2210.             break;
  2211.            
  2212.             case PIECE_TYPE.FUTURE_HOME:
  2213.                 pieceValue = (int)PIECE_TYPE.FUTURE_HOME_HOVERING;
  2214.                 scoreAmountToAdd += (int)tablaScorePerPiece[PIECE_TYPE.FUTURE_HOME_HOVERING]*bonusMultiplier;
  2215.                
  2216.                 if (count>2) {
  2217.                     sprite.Play("Future_Home_2_Upgraded");
  2218. //                  currentScore += (int)tablaScorePerPiece[PIECE_TYPE.FUTURE_HOME]*count;
  2219. //                  montoMonedas = ((int)tablaScorePerPiece[PIECE_TYPE.FUTURE_HOME]*(count-2)*bonusMultiplier)/5;
  2220. //                  addCoins(montoMonedas, x, y);              
  2221.                 } else {
  2222.                     sprite.Play("Future_Home_2");                  
  2223.                 }                  
  2224.             break;
  2225.            
  2226.             case PIECE_TYPE.FUTURE_HOME_HOVERING:
  2227.                 pieceValue = (int)PIECE_TYPE.FUTURE_CITY;
  2228.                 scoreAmountToAdd += (int)tablaScorePerPiece[PIECE_TYPE.FUTURE_CITY]*bonusMultiplier;
  2229.                
  2230.                 if (count>2) {
  2231. //                  currentScore += (int)tablaScorePerPiece[PIECE_TYPE.FUTURE_HOME_HOVERING]*count;
  2232. //                  montoMonedas = ((int)tablaScorePerPiece[PIECE_TYPE.FUTURE_HOME_HOVERING]*(count-2)*bonusMultiplier)/5;
  2233. //                  addCoins(montoMonedas, x, y);
  2234.                 }
  2235.                 sprite.Play("Future_City");
  2236.             break;
  2237.            
  2238.             //aliens y moai
  2239.             case PIECE_TYPE.MOAI://moai single
  2240.                 pieceValue = (int)PIECE_TYPE.MOAIS;
  2241.                 scoreAmountToAdd += (int)tablaScorePerPiece[PIECE_TYPE.MOAIS]*bonusMultiplier;
  2242.                
  2243. //              if (count>2) {
  2244. //                  currentScore += (int)tablaScorePerPiece[PIECE_TYPE.MOAI]*count;
  2245. //                  montoMonedas = ((int)tablaScorePerPiece[PIECE_TYPE.MOAI]*(count-2)*bonusMultiplier)/5;
  2246. //                  addCoins(montoMonedas, x, y);
  2247. //              }
  2248.                 sprite.Play("Moais_Triple");
  2249.             break;
  2250.            
  2251.             case PIECE_TYPE.MOAIS:
  2252.                 pieceValue = (int)PIECE_TYPE.STONEHENGE;
  2253.                 scoreAmountToAdd += (int)tablaScorePerPiece[PIECE_TYPE.STONEHENGE]*bonusMultiplier;
  2254.                
  2255.                 sprite.Play("Stonehenge");
  2256. //              if (count>2) {
  2257. //                  currentScore += (int)tablaScorePerPiece[PIECE_TYPE.MOAIS]*count;
  2258. //                  montoMonedas = ((int)tablaScorePerPiece[PIECE_TYPE.MOAIS]*(count-2)*bonusMultiplier)/5;
  2259. //                  addCoins(montoMonedas, x, y);
  2260. //              }
  2261.             break;
  2262.            
  2263.             case PIECE_TYPE.STONEHENGE:
  2264.                 pieceValue = (int)PIECE_TYPE.DIAMOND;
  2265.                 scoreAmountToAdd += (int)tablaScorePerPiece[PIECE_TYPE.DIAMOND]*bonusMultiplier;
  2266.                
  2267. //              if (count>2) {
  2268. //                  currentScore += (int)tablaScorePerPiece[PIECE_TYPE.STONEHENGE]*count;
  2269. //                  montoMonedas = ((int)tablaScorePerPiece[PIECE_TYPE.STONEHENGE]*(count-2)*bonusMultiplier)/5;
  2270. //                  addCoins(montoMonedas, x, y);
  2271. //              }
  2272.                 sprite.Play("Diamond");
  2273.             break;
  2274.            
  2275.             case PIECE_TYPE.ROCK:
  2276.                 pieceValue = (int)PIECE_TYPE.CAVE;
  2277.                 scoreAmountToAdd += (int)tablaScorePerPiece[PIECE_TYPE.CAVE]*bonusMultiplier;
  2278.                
  2279.                 sprite.Play("Cave");
  2280. //              if (count>2) {
  2281. //                  currentScore += (int)tablaScorePerPiece[PIECE_TYPE.ROCK]*count;
  2282. //                  montoMonedas = ((int)tablaScorePerPiece[PIECE_TYPE.ROCK]*(count-2)*bonusMultiplier)/5;
  2283. //                  addCoins(montoMonedas, x, y);
  2284. //              }
  2285.                 addVillager(Villager.TIPOS_VILLAGER.CAVERNICOLA, sprite.transform.position);
  2286.             break;
  2287.            
  2288.             case PIECE_TYPE.CAVE:
  2289.                 pieceValue = (int)PIECE_TYPE.DIAMOND;
  2290.                 scoreAmountToAdd += (int)tablaScorePerPiece[PIECE_TYPE.DIAMOND]*bonusMultiplier;
  2291.                
  2292. //              if (count>2) {
  2293. //                  currentScore += (int)tablaScorePerPiece[PIECE_TYPE.CAVE]*count;
  2294. //                  montoMonedas = ((int)tablaScorePerPiece[PIECE_TYPE.CAVE]*(count-2)*bonusMultiplier)/5;
  2295. //                  addCoins(montoMonedas, x, y);
  2296. //              }
  2297.                 sprite.Play("Diamond");        
  2298.             break;
  2299.            
  2300.             case PIECE_TYPE.DIAMOND:
  2301.                 pieceValue = (int)PIECE_TYPE.RUBY;
  2302.                 scoreAmountToAdd += (int)tablaScorePerPiece[PIECE_TYPE.RUBY]*bonusMultiplier;
  2303.                
  2304. //              if (count>2) {
  2305. //                  currentScore += (int)tablaScorePerPiece[PIECE_TYPE.DIAMOND]*count;
  2306. //                  montoMonedas = ((int)tablaScorePerPiece[PIECE_TYPE.DIAMOND]*(count-2)*bonusMultiplier)/5;
  2307. //                  addCoins(montoMonedas, x, y);
  2308. //              }
  2309.                 sprite.Play("Ruby");           
  2310.             break;
  2311.            
  2312.            
  2313.             default:
  2314.                
  2315.             break;
  2316.         }
  2317.         StartCoroutine(delayToShowScoreAddText(scoreAmountToAdd, x, y, bonusMultiplier));
  2318. //      currentScore += scoreAmountToAdd;
  2319. //      createScoreText(scoreAmountToAdd, x, y, bonusMultiplier);
  2320.     }
  2321.    
  2322.     IEnumerator delayToShowScoreAddText(int scoreAmount, int x, int y, float currentBonusMultiplier) {
  2323.         yield return new WaitForSeconds(0.5f + currentBonusMultiplier*0.05f);
  2324.         currentScore += scoreAmount;
  2325.         createScoreText(scoreAmount, x, y, currentBonusMultiplier, true);
  2326.        
  2327.     }
  2328.    
  2329. //  struct TxtObject {
  2330. //      public GameObject txtGameObject;
  2331. //  }
  2332. //  private List<GameObject> listScoreAddedText = new List<GameObject>();
  2333.     public void createScoreText(int amountScore, int x, int y, float chainNumber, bool fromMultiCollapse) {
  2334.        
  2335.         if (amountScore == 0) {
  2336.             return;
  2337.         }
  2338.         Vector3 posIni = gameGridSprites[y*6+x].transform.position;// + Vector3.up*-altoEnTransformUnitsSquareSprite/2f
  2339.                         //+ Vector3.right*anchoEnTransformUnitsSquareSprite/2f + Vector3.forward*-10f;
  2340.         posIni.Set(posIni.x + anchoEnTransformUnitsSquareSprite/2f, posIni.y - altoEnTransformUnitsSquareSprite/2f, 1f);
  2341. //      TxtObject paramsObject = new TxtObject();
  2342.        
  2343.         GameObject txtObject = Instantiate(this.txtAddScorePrefab, posIni, Quaternion.identity) as GameObject;     
  2344.        
  2345.         float extraScale = 0f;
  2346.         if (fromMultiCollapse) {
  2347.             extraScale = 0.1f;
  2348.         }
  2349.  
  2350.         txtObject.transform.localScale = new Vector3(0.4f + 0.07f*chainNumber + extraScale, 0.4f + 0.07f*chainNumber + extraScale, 1f);
  2351.         tk2dTextMesh texto = txtObject.GetComponent<tk2dTextMesh>();
  2352.        
  2353.         if (amountScore < 0) {
  2354.             texto.color = Color.red;
  2355.             texto.color2 = new Color(1f, 0.2f, 0.2f, 1f);
  2356.            
  2357.         } else {
  2358.             texto.text = "+";
  2359.         }
  2360.        
  2361.         texto.text += amountScore;
  2362.         texto.Commit();
  2363.        
  2364.         DestroyTextAfterTime scriptDestruyeTexto = txtObject.GetComponent<DestroyTextAfterTime>();
  2365.         iTween.MoveTo(txtObject,
  2366.             iTween.Hash(
  2367.             "position", posIni+Vector3.up*(15f+chainNumber*3),
  2368.             "delay", DELAY_TO_COLLAPSE*chainNumber/1.5f,
  2369.             "time", scriptDestruyeTexto.timeToLive,
  2370.             "easetype", iTween.EaseType.spring
  2371.  
  2372.         ));
  2373.        
  2374.        
  2375.     }
  2376.    
  2377.     public void createBanishText(string textToShow, Vector3 posIni, float zeta, float extraScale, float timeShowing) {
  2378.                        
  2379.         posIni.z = zeta;
  2380.         GameObject txtObject = Instantiate(this.txtAddScorePrefab, posIni, Quaternion.identity) as GameObject;     
  2381.                
  2382.  
  2383.         txtObject.transform.localScale = new Vector3(0.4f + extraScale, 0.4f + extraScale, 1f);
  2384.         tk2dTextMesh texto = txtObject.GetComponent<tk2dTextMesh>();               
  2385.         texto.maxChars = textToShow.Length;
  2386.         texto.text = textToShow;
  2387.         texto.Commit();
  2388.        
  2389.         DestroyTextAfterTime scriptDestruyeTexto = txtObject.GetComponent<DestroyTextAfterTime>();
  2390.         scriptDestruyeTexto.timeToLive = timeShowing;
  2391.         scriptDestruyeTexto.banishTotalTime = 0.5f;
  2392.         iTween.MoveTo(txtObject,
  2393.             iTween.Hash(
  2394.             "position", posIni+Vector3.up*(5f),
  2395.             "delay", 0f,
  2396.             "time", scriptDestruyeTexto.timeToLive,
  2397.             "easetype", iTween.EaseType.spring
  2398.  
  2399.         ));
  2400.        
  2401.        
  2402.     }
  2403.    
  2404.     public void onWaitForClick()
  2405.     {
  2406.         alreadyMovedAliens = false;
  2407.         if (Input.GetMouseButtonDown(0))
  2408.         {
  2409.             if (clickOnGrid())
  2410.             {
  2411.                                    
  2412.                 updateSelectorPosition(touchX, touchY);
  2413.                 if (touchX == 0 && touchY == (int)GAME_PROPERTIES.rowLength - 1) { //click en wildcard
  2414.                     swapWildCardAndNextPiece();                
  2415.                 } else {
  2416.                
  2417.                     if(piecesClick.ContainsKey((PIECE_TYPE)nextPiece))
  2418.                     {
  2419.                         piecesClick[(PIECE_TYPE)nextPiece](firstClick?1:2);
  2420.                     }
  2421.                     else
  2422.                     {
  2423.                         onPieceClickDefault(firstClick?1:2);
  2424.                     }
  2425.                 }
  2426.                            
  2427.             }
  2428.         }
  2429.        
  2430.         if (animateNeigbors) {         
  2431.             this.animateNeighbors();
  2432.         }
  2433.                
  2434.     }
  2435.                        
  2436.     public void onWaitEndOfAnimation(){
  2437.         //just wait
  2438.         if (animateNeigbors) {         
  2439.             this.animateNeighbors();
  2440.         }
  2441.     }
  2442.    
  2443.     public void onBuyScreen() {//hecho solo por si hay que agregar algo mientras se compra
  2444.        
  2445.     }
  2446.    
  2447.     public void onPause() {
  2448.        
  2449.     }
  2450.    
  2451.  
  2452.     private int gameOverCounter = 0;
  2453.     private float countTime = 0f;
  2454.     private readonly float DELAY_BETWEEN_COINS_IN_GAMEOVER = 0.5f;
  2455.     public void onGameOver() {
  2456.         enableOrDisableUFOGuiButtons(false);
  2457.         countTime += Time.deltaTime;
  2458.                        
  2459.         if (countTime >= DELAY_BETWEEN_COINS_IN_GAMEOVER) {
  2460.             countTime = 0f;
  2461.             if (gameOverCounter < 6*6) {
  2462.                 int currentCheckingX = gameOverCounter%6;
  2463.                 int currentCheckingY = gameOverCounter/6;
  2464.                 if (currentCheckingX == 0 && currentCheckingY == (int)GAME_PROPERTIES.rowLength - 1) {
  2465.                     gameOverCounter++;
  2466.                     countTime = DELAY_BETWEEN_COINS_IN_GAMEOVER;
  2467.                     return;
  2468.                 } else {
  2469.                     int amountToAdd = ((int)tablaScorePerPiece[(PIECE_TYPE)gameGrid[currentCheckingX,currentCheckingY]])/5;
  2470.                     if (amountToAdd > 0) {
  2471.                         addCoins(amountToAdd, currentCheckingX, currentCheckingY);
  2472.                     } else {
  2473.                         gameOverCounter++;
  2474.                         countTime = DELAY_BETWEEN_COINS_IN_GAMEOVER;
  2475.                         return;
  2476.                     }                  
  2477.                 }
  2478.                
  2479.                 gameOverCounter++;             
  2480.             }
  2481.            
  2482.             if (gameOverCounter >= 6*6 && !gameOver) {
  2483.                     gameOver = true;
  2484.                     gameOverCounter = 0;
  2485.                     countTime = 0;
  2486.                     openPauseScreen();
  2487.             }
  2488.         }
  2489. //      if (!doingGameOver) {
  2490. //          doingGameOver = true;
  2491. //         
  2492. //          for (int i = 0; i < (int)GAME_PROPERTIES.rowLength; i++) {
  2493. //              for (int j = 0; j < (int)GAME_PROPERTIES.rowLength; j++) {
  2494. //                  if (i == 0 && j == (int)GAME_PROPERTIES.rowLength - 1) {
  2495. //                      continue;
  2496. //                  }
  2497. //                  addCoins(((int)tablaScorePerPiece[(PIECE_TYPE)gameGrid[i,j]])/5, i, j);            
  2498. //              }
  2499. //          }          
  2500.            
  2501.            
  2502. //      }
  2503.     }
  2504.  
  2505.    
  2506.    
  2507.     public void populate(int max, int pieceToFill, int pieceToReplace)
  2508.         {                              
  2509.        
  2510.             int index = 0;
  2511.             int counter = 0;
  2512.             int rowL = (int)GAME_PROPERTIES.rowLength;
  2513.             int  columnL = (int)GAME_PROPERTIES.columnLength;
  2514.            
  2515.             while(counter<max)
  2516.             {
  2517.                 for(index = 0 ; index < (rowL*columnL) ; index++)
  2518.                 {
  2519.                     if(counter >= max)
  2520.                         break;
  2521.                    
  2522.                     int x = index%6;
  2523.                     int y = index/6;
  2524.                     if(x>rowL-1)
  2525.                     {
  2526.                         x=rowL-1;
  2527.                     }
  2528.                     if(y>columnL-1)
  2529.                     {
  2530.                         y=columnL-1;
  2531.                     }
  2532.                     if(gameGrid[y,x] == pieceToReplace)
  2533.                     {
  2534.                         int res = Random.Range(0,6+1);
  2535.                         if(res == 0)
  2536.                         {                                                  
  2537.                             gameGrid[y,x] = pieceToFill;
  2538.                             counter++;
  2539.                         }
  2540.                     }
  2541.                 }
  2542.             }  
  2543.         }
  2544.  
  2545.                
  2546.     //Replace no used values with road values
  2547.     public void replaceNotUsed()
  2548.     {
  2549.         for(int i = 0;i < (int)GAME_PROPERTIES.rowLength; i++)
  2550.         {
  2551.             for(int j = 0; j < (int)GAME_PROPERTIES.columnLength; j++)
  2552.             {
  2553.                 if(gameGrid[i,j] == (int)PIECE_TYPE.NOT_USED)
  2554.                 {
  2555.                     gameGrid[i,j] = (int)PIECE_TYPE.ROAD;
  2556.                 }
  2557.             }
  2558.         }
  2559.     }
  2560.    
  2561.     //Swap the "next piece" with the one saved at the support, graphicGrid[0,5]
  2562.     public void swapWildCardAndNextPiece()
  2563.     {
  2564.         int Temp = (int)PIECE_TYPE.NOT_USED;
  2565. //      changeSelectorAnimationColor(SELECTOR_COLOR_NORMAL);
  2566.         changeSelectorAnimation(true);
  2567. //      STATE = Estados.WAITING_FOR_CLICK;
  2568.         if(wildCard != nextPiece)
  2569.         {
  2570.             if((wildCard != -1) && (wildCard != (int)PIECE_TYPE.ROAD))
  2571.             {
  2572.                 Temp = wildCard;
  2573.                 wildCard = nextPiece;              
  2574.                 nextPiece = Temp;
  2575.                 selectorNextPiece.Play((string)tablaAllAnimations[nextPiece]);
  2576.                
  2577.                 if (nextPiece == (int)PIECE_TYPE.BUSH || nextPiece == (int)PIECE_TYPE.ROCK) {
  2578.                     ufoNextPiece.transform.position = ufoNextPieceOriginPos + Vector3.up*5f;
  2579.                 } else {
  2580.                     ufoNextPiece.transform.position = ufoNextPieceOriginPos;               
  2581.                 }
  2582.                
  2583.             }else
  2584.             {
  2585.                 wildCard = nextPiece;              
  2586.                 getNextPiece();
  2587.                 if (isGameOver()) {
  2588.                     STATE = Estados.GAME_OVER;
  2589.                 }
  2590.             }
  2591.            
  2592.             animateNeigbors = false;           
  2593.             resetPositionsOfAnimatedNeighbors();               
  2594.             //
  2595.             wildCardStoragePiece.Play((string)tablaAllAnimations[wildCard]);
  2596.             ufoNextPiece.Play(ufoNextPiece.GetClipIdByName((string)tablaAllAnimations[nextPiece]));//.spriteId = ufoNextPiece.collection.GetSpriteIdByName((string)tablaAllAnimations[nextPiece]);
  2597.            
  2598.         }
  2599.        
  2600.        
  2601.     }
  2602.    
  2603.     //Randomize the int value of the nextPiece and loads the respective graphic
  2604.     public static readonly int PLAYS_TO_ADD_GREENALIENS = 15;
  2605.     public static readonly int MAX_TIMES_ADDING_GREENALIENS = 7;
  2606.    
  2607.     public static readonly int PLAYS_TO_ADD_PURPLEALIENS = 30;
  2608.     public static readonly int MAX_TIMES_ADDING_PURPLEALIENS = 5;
  2609.    
  2610.     public static readonly int PLAYS_TO_ADD_RUCAS = 45;
  2611.     public static readonly int MAX_TIMES_ADD_RUCAS = 4;
  2612.    
  2613.     public static readonly int PLAYS_TO_ADD_PURPLE_CRISTAL = 40;
  2614.     public static readonly int MAX_TIMES_ADD_PURPLE_CRISTAL = 2;
  2615.    
  2616.     public static readonly int PLAYS_TO_ADD_GREEN_CRISTAL = 50;
  2617.     public static readonly int MAX_TIMES_ADD_GREEN_CRISTAL = 3;
  2618.    
  2619.     public void getNextPiece()
  2620.     {
  2621.         //TUtils.trace("### Changing Next piece ###");
  2622.        
  2623.        
  2624.        
  2625. //      if(!boughtPiece) {
  2626.             //nextPiece = (int)PIECE_TYPE.BUSH;
  2627.        
  2628. //          nextPiece = (int)PIECE_TYPE.RUCA;
  2629.             numberOfPlays++;
  2630.            
  2631.             if (numberOfPlays%PLAYS_TO_ADD_GREENALIENS == 0 && numberOfPlays <= PLAYS_TO_ADD_GREENALIENS*MAX_TIMES_ADDING_GREENALIENS) {
  2632.                 addPiecesToChanceList(1, PIECE_TYPE.ALIEN_BASIC);
  2633.                 Debug.Log("Added 1 alien verdes");
  2634.             }
  2635.        
  2636.             if (numberOfPlays%PLAYS_TO_ADD_PURPLEALIENS == 0 && numberOfPlays <= PLAYS_TO_ADD_PURPLEALIENS*MAX_TIMES_ADDING_PURPLEALIENS) {            
  2637.                 addPiecesToChanceList(2, PIECE_TYPE.ALIEN_TELEPORTER);
  2638.                 addPiecesToChanceList(1, PIECE_TYPE.BLACK_HOLE);
  2639.                 addPiecesToChanceList(1, PIECE_TYPE.MAGIC_CRISTAL_GREEN);
  2640.                 Debug.Log("Added 2 aliens purple");
  2641.                 Debug.Log("Added 1 blackhole");
  2642.                 Debug.Log("Added 1 green crystal");
  2643.             }
  2644.        
  2645.             if (numberOfPlays%PLAYS_TO_ADD_RUCAS == 0 && numberOfPlays <= PLAYS_TO_ADD_RUCAS*MAX_TIMES_ADD_RUCAS) {
  2646.                 addPiecesToChanceList(1, PIECE_TYPE.RUCA);             
  2647.                 Debug.Log("Added 1 ruca");
  2648.                 Debug.Log("Added 1 cristal purple");
  2649.             }
  2650.        
  2651.             if (numberOfPlays%PLAYS_TO_ADD_PURPLE_CRISTAL == 0 && numberOfPlays <= PLAYS_TO_ADD_PURPLE_CRISTAL*MAX_TIMES_ADD_PURPLE_CRISTAL) {
  2652.                 addPiecesToChanceList(1, PIECE_TYPE.MAGIC_CRISTAL_PURPLE);                             
  2653.                 Debug.Log("Added 1 cristal purple");
  2654.             }
  2655.        
  2656.             if (numberOfPlays%PLAYS_TO_ADD_GREEN_CRISTAL == 0 && numberOfPlays <= PLAYS_TO_ADD_GREEN_CRISTAL*MAX_TIMES_ADD_GREEN_CRISTAL) {
  2657.                 addPiecesToChanceList(1, PIECE_TYPE.MAGIC_CRISTAL_GREEN);              
  2658.                
  2659.                 Debug.Log("Added 1 cristal green");
  2660.             }
  2661.        
  2662.            
  2663.             nextPiece = (int)this.pieceChance[Random.Range(0, pieceChance.Count)];
  2664. //      } else {
  2665. //          boughtPiece = false;
  2666. //          nextPiece = pieceBought;
  2667. //          pieceBought = -1;
  2668. ////        }
  2669.        
  2670.         showNextPieceInSelectorAndGui(nextPiece);
  2671.        
  2672.        
  2673.  
  2674.     }
  2675.    
  2676.     public void checkForChancesOnLoadSavedGame() {
  2677.        
  2678.        
  2679.        
  2680.         if (numberOfPlays >= PLAYS_TO_ADD_GREENALIENS && numberOfPlays  <= PLAYS_TO_ADD_GREENALIENS*MAX_TIMES_ADDING_GREENALIENS) {
  2681.             addPiecesToChanceList(numberOfPlays/PLAYS_TO_ADD_GREENALIENS, PIECE_TYPE.ALIEN_BASIC);
  2682.             Debug.Log("Added " + numberOfPlays/PLAYS_TO_ADD_GREENALIENS + " aliens verdes");
  2683.         }
  2684.        
  2685.         if (numberOfPlays >= PLAYS_TO_ADD_PURPLEALIENS && numberOfPlays  <= PLAYS_TO_ADD_PURPLEALIENS*MAX_TIMES_ADDING_PURPLEALIENS) {
  2686.             addPiecesToChanceList(2*(numberOfPlays/PLAYS_TO_ADD_PURPLEALIENS), PIECE_TYPE.ALIEN_TELEPORTER);
  2687.             addPiecesToChanceList(numberOfPlays/PLAYS_TO_ADD_PURPLEALIENS, PIECE_TYPE.BLACK_HOLE);
  2688.             Debug.Log("Added " + 2*(numberOfPlays/PLAYS_TO_ADD_PURPLEALIENS) + " aliens purpuras");
  2689.             Debug.Log("Added " + numberOfPlays/PLAYS_TO_ADD_PURPLEALIENS + " blackholes");
  2690.            
  2691.         }
  2692.                
  2693.        
  2694.         if (numberOfPlays >= PLAYS_TO_ADD_RUCAS && numberOfPlays  <= PLAYS_TO_ADD_RUCAS*MAX_TIMES_ADD_RUCAS) {
  2695.             addPiecesToChanceList(numberOfPlays/PLAYS_TO_ADD_RUCAS, PIECE_TYPE.RUCA);          
  2696.             Debug.Log("Added " + numberOfPlays/PLAYS_TO_ADD_RUCAS + " rucas");         
  2697.         }
  2698.        
  2699.         if (numberOfPlays >= PLAYS_TO_ADD_PURPLE_CRISTAL && numberOfPlays <= PLAYS_TO_ADD_PURPLE_CRISTAL*MAX_TIMES_ADD_PURPLE_CRISTAL) {
  2700.                 addPiecesToChanceList(numberOfPlays/PLAYS_TO_ADD_PURPLE_CRISTAL, PIECE_TYPE.MAGIC_CRISTAL_PURPLE);                             
  2701.                 Debug.Log("Added " + numberOfPlays/PLAYS_TO_ADD_PURPLE_CRISTAL + " cristal purple");
  2702.         }
  2703.        
  2704.         if (numberOfPlays >= PLAYS_TO_ADD_GREEN_CRISTAL && numberOfPlays <= PLAYS_TO_ADD_GREEN_CRISTAL*MAX_TIMES_ADD_GREEN_CRISTAL) {
  2705.             addPiecesToChanceList(numberOfPlays/PLAYS_TO_ADD_GREEN_CRISTAL, PIECE_TYPE.MAGIC_CRISTAL_GREEN);               
  2706.                
  2707.             Debug.Log("Added " + numberOfPlays/PLAYS_TO_ADD_GREEN_CRISTAL + " cristal green");
  2708.         }
  2709.     }
  2710.    
  2711.     //  public void nextPieceCheat()
  2712. //  {
  2713. //      if(pieceBought != -1)
  2714. //      {
  2715. //          boughtPiece = true;
  2716. //      }
  2717. //     
  2718. //      if(!boughtPiece)
  2719. //      {
  2720. //          nextPiece = cheatChance[Random.Range(0, cheatChance.Length)];
  2721. //      }else
  2722. //      {
  2723. //          boughtPiece = false;
  2724. //          nextPiece = pieceBought;
  2725. //          pieceBought = -1;
  2726. //      }
  2727. //     
  2728. ////        if(discMenu != null)
  2729. ////        {
  2730. ////            discMenu.updateCurrentPiece(nextPiece);
  2731. ////        }else
  2732. ////        {
  2733. ////            createDiscMenu();
  2734. ////        }      
  2735. //      selectorNextPiece.Play((string)tablaAllAnimations[nextPiece]);
  2736. //     
  2737. //  }
  2738.     private void cleanVarsFromShop() {
  2739.         firstClick = true;
  2740.         turnOnOffHighLightGrid(false);
  2741.         neighborsList.Clear();
  2742.        
  2743.     }
  2744.  
  2745.     public void buyBush() {
  2746.        
  2747.         nextPiece = (int)PIECE_TYPE.BUSH;
  2748.         currentGold -= (int)tablaBuyForCoinsValue[PIECE_TYPE.BUSH];
  2749.         showNextPieceInSelectorAndGui(nextPiece);
  2750.         closeShopWindow();
  2751.         cleanVarsFromShop();
  2752.         onPieceClickDefault(1);
  2753.     }      
  2754.    
  2755.     public void buyTree() {    
  2756.         nextPiece = (int)PIECE_TYPE.TREE;
  2757.         currentGold -= (int)tablaBuyForCoinsValue[PIECE_TYPE.TREE];
  2758.         showNextPieceInSelectorAndGui(nextPiece);      
  2759.         closeShopWindow();
  2760.         cleanVarsFromShop();       
  2761.         onPieceClickDefault(1);
  2762.     }
  2763.    
  2764.     public void buyRuca() {    
  2765.         nextPiece = (int)PIECE_TYPE.RUCA;
  2766.         currentGold -= (int)tablaBuyForCoinsValue[PIECE_TYPE.RUCA];
  2767.         showNextPieceInSelectorAndGui(nextPiece);
  2768.        
  2769.         closeShopWindow();
  2770.         cleanVarsFromShop();       
  2771.         onPieceClickDefault(1);
  2772.     }
  2773.    
  2774.     public void buyGreenGem() {    
  2775.         nextPiece = (int)PIECE_TYPE.MAGIC_CRISTAL_GREEN;
  2776.         currentGold -= (int)tablaBuyForCoinsValue[PIECE_TYPE.MAGIC_CRISTAL_GREEN];
  2777.         showNextPieceInSelectorAndGui(nextPiece);
  2778.        
  2779.         closeShopWindow();
  2780.         cleanVarsFromShop();       
  2781.         onMagicCrystalGreenClick(1);
  2782.     }
  2783.    
  2784.     public void buyPurpleGem() {       
  2785.         nextPiece = (int)PIECE_TYPE.MAGIC_CRISTAL_PURPLE;
  2786.         currentGold -= (int)tablaBuyForCoinsValue[PIECE_TYPE.MAGIC_CRISTAL_PURPLE];
  2787.         showNextPieceInSelectorAndGui(nextPiece);
  2788.        
  2789.         closeShopWindow();
  2790.         cleanVarsFromShop();       
  2791.         onMagicCrystalPurpleClick(1);
  2792.     }
  2793.    
  2794.     public void buyBlackHole() {       
  2795.         nextPiece = (int)PIECE_TYPE.BLACK_HOLE;
  2796.         currentGold -= (int)tablaBuyForCoinsValue[PIECE_TYPE.BLACK_HOLE];
  2797.         showNextPieceInSelectorAndGui(nextPiece);
  2798.         closeShopWindow();
  2799.         cleanVarsFromShop();
  2800.         this.onBlackHoleClick(1);
  2801.        
  2802.     }
  2803.    
  2804.     //Replace the graphic at graphicGrid[x,y], Temp function, probably
  2805.     public void replaceGraphicGridAt(int x, int y)
  2806.     {      
  2807.         int index = y*6+x;
  2808.         string piece = "";
  2809.                
  2810.         if (!upgradedGraphic) {                    
  2811.             piece = (string)tablaAllAnimations[gameGrid[x,y]];         
  2812.             gamePiecesAnimations[index].Play(piece);                                       
  2813.            
  2814.         }
  2815.        
  2816. //      if(score != 0)
  2817. //      {
  2818. //          //showScoreText(x, y, score);
  2819. //          if((!initializing) && (score>0))
  2820. //          {
  2821. //              if(!upgradedGraphic)
  2822. //              {
  2823. //                  //playFX(PLACE_PIECE, 1);
  2824. //              }else
  2825. //              {
  2826. //                  //playFX(MATCH, 1);
  2827. //              }
  2828. //          }
  2829. //      }
  2830. //      if((gameGrid[x,y] == (int)PIECE_TYPE.RUCA) || (gameGrid[x,y] == (int)PIECE_TYPE.HOME) || (gameGrid[x,y] == (int)PIECE_TYPE.CASTLE) || (gameGrid[x,y] == (int)PIECE_TYPE.BUILDING)
  2831. //              || (gameGrid[x,y] == (int)PIECE_TYPE.FUTURE_HOME) || (gameGrid[x,y] == (int)PIECE_TYPE.FUTURE_HOME_HOVERING) || (gameGrid[x,y] == (int)PIECE_TYPE.CAVE))
  2832. //      {
  2833. //          addVillager(x, y, gameGrid[x,y]);
  2834. //      }
  2835.     }
  2836.    
  2837.     //What the fucking name of the fucking function says, and fuck you spell check, "fucking" is perfectly spelled.
  2838.     public void updateBackgroundGraphics()
  2839.     {
  2840.         for(int i = 0; i < (int)GAME_PROPERTIES.rowLength; i++)
  2841.         {
  2842.             for(int j = (int)GAME_PROPERTIES.columnLength-1; j > -1; j--)
  2843.             {
  2844.                
  2845.                 //Debug.Log("x: " + i + " y: " + j + " valor: " + gameGrid[i,j]);
  2846.                 if((gameGrid[i,j] == (int)PIECE_TYPE.ROAD) || (gameGrid[i,j] == (int)PIECE_TYPE.ALIEN_BASIC) || (gameGrid[i,j] == (int)PIECE_TYPE.ALIEN_TELEPORTER))
  2847.                 {
  2848.                     updateBackgroundGridAt(i, j);
  2849.                 }else
  2850.                 {
  2851.                     replaceBackgroundGraphicGridAt(i, j, (int)BG_TYPE.GRASS);
  2852.                 }
  2853.             }
  2854.         }
  2855.        
  2856.     }
  2857.    
  2858.     public int checkRoadAt(int x, int y)
  2859.     {
  2860.         if((x>=0)&&(x<=(int)GAME_PROPERTIES.rowLength-1))
  2861.         {
  2862.             if((y>=0)&&(y<=(int)GAME_PROPERTIES.columnLength-1))
  2863.             {
  2864.                 if((x==0)&&(y==(int)GAME_PROPERTIES.columnLength-1))
  2865.                 {
  2866.                     return 1;
  2867.                 }else
  2868.                 {
  2869.                     if((gameGrid[x,y] == (int)PIECE_TYPE.ROAD) || (gameGrid[x,y] == (int)PIECE_TYPE.ALIEN_BASIC) || (gameGrid[x,y] == (int)PIECE_TYPE.ALIEN_TELEPORTER))
  2870.                     {
  2871.                         return 0;
  2872.                     }else
  2873.                     {
  2874.                         return 1;
  2875.                     }
  2876.                 }
  2877.             }else
  2878.             {
  2879.                 return 1;
  2880.             }
  2881.         }else
  2882.         {
  2883.             return 1;
  2884.         }
  2885.     }
  2886.    
  2887.    
  2888.     public void updateBackgroundGridAroundAt(int x, int y)
  2889.     {
  2890.         if(checkRoadAt(x+1, y+1) == 0)
  2891.         {
  2892.             updateBackgroundGridAt(x+1, y+1);
  2893.         }
  2894.         if(checkRoadAt(x, y+1) == 0)
  2895.         {
  2896.             updateBackgroundGridAt(x, y+1);
  2897.         }
  2898.         if(checkRoadAt(x-1, y+1) == 0)
  2899.         {
  2900.             updateBackgroundGridAt(x-1, y+1);
  2901.         }
  2902.         if(checkRoadAt(x-1, y) == 0)
  2903.         {
  2904.             updateBackgroundGridAt(x-1, y);
  2905.         }
  2906.         if(checkRoadAt(x-1, y-1) == 0)
  2907.         {
  2908.             updateBackgroundGridAt(x-1, y-1);
  2909.         }
  2910.         if(checkRoadAt(x, y-1) == 0)
  2911.         {
  2912.             updateBackgroundGridAt(x, y-1);
  2913.         }
  2914.         if(checkRoadAt(x+1, y-1) == 0)
  2915.         {
  2916.             updateBackgroundGridAt(x+1, y-1);
  2917.         }
  2918.         if(checkRoadAt(x+1, y) == 0)
  2919.         {
  2920.             updateBackgroundGridAt(x+1, y);
  2921.         }
  2922.     }
  2923.    
  2924. //  public void updateBackgroundGrid()
  2925. //  {
  2926. //      for(int i=0; i<(int)GAME_PROPERTIES.rowLength; i++)
  2927. //      {
  2928. //          for(int j=(int)GAME_PROPERTIES.columnLength-1; j>-1; j--)
  2929. //          {
  2930. //              if(usedGrid[i,j] == true)
  2931. //              {
  2932. //                  if(checkRoadAt(i+1, j+1) == 0)
  2933. //                  {
  2934. //                      updateBackgroundGridAt(i+1, j+1);
  2935. //                  }
  2936. //                  if(checkRoadAt(i, j+1) == 0)
  2937. //                  {
  2938. //                      updateBackgroundGridAt(i, j+1);
  2939. //                  }
  2940. //                  if(checkRoadAt(i-1, j+1) == 0)
  2941. //                  {
  2942. //                      updateBackgroundGridAt(i-1, j+1);
  2943. //                  }
  2944. //                  if(checkRoadAt(i-1, j) == 0)
  2945. //                  {
  2946. //                      updateBackgroundGridAt(i-1, j);
  2947. //                  }
  2948. //                  if(checkRoadAt(i-1, j-1) == 0)
  2949. //                  {
  2950. //                      updateBackgroundGridAt(i-1, j-1);
  2951. //                  }
  2952. //                  if(checkRoadAt(i, j-1) == 0)
  2953. //                  {
  2954. //                      updateBackgroundGridAt(i, j-1);
  2955. //                  }
  2956. //                  if(checkRoadAt(i+1, j-1) == 0)
  2957. //                  {
  2958. //                      updateBackgroundGridAt(i+1, j-1);
  2959. //                  }
  2960. //                  if(checkRoadAt(i+1, j) == 0)
  2961. //                  {
  2962. //                      updateBackgroundGridAt(i+1, j);
  2963. //                  }
  2964. //              }
  2965. //              else if((i==prevClickX) && (j==prevClickY))
  2966. //              {
  2967. //                  replaceBackgroundGraphicGridAt(i, j, (int)BG_TYPE.GRASS);
  2968. //              }
  2969. //          }
  2970. //      }
  2971. //  }
  2972.    
  2973.     public void updateBackgroundGridAt(int x, int y)
  2974.     {
  2975.         if((gameGrid[x,y] != (int)PIECE_TYPE.ROAD) && (gameGrid[x,y] != (int)PIECE_TYPE.ALIEN_BASIC) && (gameGrid[x,y] != (int)PIECE_TYPE.ALIEN_TELEPORTER))
  2976.         {
  2977.             replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.GRASS);
  2978.         } else {
  2979.             int valor = 0;
  2980.            
  2981.             //Check North
  2982.             valor |= checkRoadAt(x, y+1) << 1;
  2983.             //Check West
  2984.             valor |= checkRoadAt(x-1, y) << 3;
  2985.             //Check South
  2986.             valor |= checkRoadAt(x, y-1) << 5;
  2987.             //Check East
  2988.             valor |= checkRoadAt(x+1, y) << 7;
  2989.            
  2990.             if(valor == 170)
  2991.             {
  2992.                 replaceBackgroundGraphicGridAt(x, y, backgroundGraphic.Length-1);
  2993.             }else if(valor == 42)
  2994.             {
  2995.                 replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.TOP_LEFT_DOWN);
  2996.             }else if(valor == 138)
  2997.             {
  2998.                 replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.TOP_LEFT_RIGHT);
  2999.             }else if(valor == 162)
  3000.             {
  3001.                 replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.TOP_DOWN_RIGHT);
  3002.             }else if(valor == 168)
  3003.             {
  3004.                 replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.LEFT_DOWN_RIGHT);
  3005.             }else if(valor == 34)
  3006.             {
  3007.                 replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.HORIZONTAL_GRASS);
  3008.             }else if(valor == 136)
  3009.             {
  3010.                 replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.VERTICAL_GRASS);
  3011.             }else
  3012.             {  
  3013.                 //Check NorthEast
  3014.                 valor |= checkRoadAt(x+1, y+1) << 0;
  3015.                 //Check NorthWest
  3016.                 valor |= checkRoadAt(x-1, y+1) << 2;
  3017.                 //Check SouthWest
  3018.                 valor |= checkRoadAt(x-1, y-1) << 4;
  3019.                 //Check SouthEast
  3020.                 valor |= checkRoadAt(x+1, y-1) << 6;
  3021.                
  3022.                 switch(valor)
  3023.                 {
  3024.                 case 0:
  3025.                     replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.ROAD);
  3026.                     break;
  3027.                 case 1:
  3028.                     replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.CORNER_1);
  3029.                     break;
  3030.                 case 4:
  3031.                     replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.CORNER_2);
  3032.                     break;
  3033.                 case 5:
  3034.                     replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.CORNER_1_2);
  3035.                     break;
  3036.                 case 16:
  3037.                     replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.CORNER_3);
  3038.                     break;
  3039.                 case 17:
  3040.                     replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.CORNER_1_3);
  3041.                     break;
  3042.                 case 20:
  3043.                     replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.CORNER_2_3);
  3044.                     break;
  3045.                 case 21:
  3046.                     replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.CORNER_1_2_3);
  3047.                     break;
  3048.                 case 64:
  3049.                     replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.CORNER_4);
  3050.                     break;
  3051.                 case 65:
  3052.                     replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.CORNER_1_4);
  3053.                     break;
  3054.                 case 68:
  3055.                     replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.CORNER_2_4);
  3056.                     break;
  3057.                 case 69:
  3058.                     replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.CORNER_1_2_4);
  3059.                     break;
  3060.                 case 80:
  3061.                     replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.CORNER_3_4);
  3062.                     break;
  3063.                 case 81:
  3064.                     replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.CORNER_1_3_4);
  3065.                     break;
  3066.                 case 84:
  3067.                     replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.CORNER_2_3_4);
  3068.                     break;
  3069.                 case 85:
  3070.                     replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.CORNER_1_2_3_4);
  3071.                     break;
  3072.                 default:
  3073.                        
  3074.                     int range = this.BGRange(valor);
  3075.                        
  3076.                     switch(range)
  3077.                     {
  3078.                     case 1:
  3079.                         replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.TOP_LEFT);
  3080.                         break;
  3081.                     case 2:
  3082.                         replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.LEFT_DOWN);
  3083.                         break;
  3084.                     case 3:
  3085.                         replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.TOP_RIGHT);
  3086.                         break;
  3087.                     case 4:
  3088.                         replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.DOWN_RIGHT);
  3089.                         break;
  3090.                     case 5:
  3091.                         replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.TOP_LEFT_CORNER_4);
  3092.                         break;
  3093.                     case 6:
  3094.                         replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.LEFT_DOWN_CORNER_1);
  3095.                         break;
  3096.                     case 7:
  3097.                         replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.DOWN_RIGHT_CORNER_2);
  3098.                         break;
  3099.                     case 8:
  3100.                         replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.TOP_RIGHT_CORNER_3);
  3101.                         break;
  3102.                     case 9:
  3103.                         replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.TOP);
  3104.                         break;
  3105.                     case 10:
  3106.                         replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.TOP_CORNER_3);
  3107.                         break;
  3108.                     case 11:
  3109.                         replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.TOP_CORNER_4);
  3110.                         break;
  3111.                     case 12:
  3112.                         replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.TOP_CORNER_3_4);
  3113.                         break;
  3114.                     case 13:
  3115.                         replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.LEFT);
  3116.                         break;
  3117.                     case 14:
  3118.                         replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.LEFT_CORNER_1);
  3119.                         break;
  3120.                     case 15:
  3121.                         replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.LEFT_CORNER_4);
  3122.                         break;
  3123.                     case 16:
  3124.                         replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.LEFT_CORNER_1_4);
  3125.                         break;
  3126.                     case 17:
  3127.                         replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.DOWN);
  3128.                         break;
  3129.                     case 18:
  3130.                         replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.DOWN_CORNER_1);
  3131.                         break;
  3132.                     case 19:
  3133.                         replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.DOWN_CORNER_2);
  3134.                         break;
  3135.                     case 20:
  3136.                         replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.DOWN_CORNER_1_2);
  3137.                         break;
  3138.                     case 21:
  3139.                         replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.RIGHT);
  3140.                         break;
  3141.                     case 22:
  3142.                         replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.RIGHT_CORNER_2);
  3143.                         break;
  3144.                     case 23:
  3145.                         replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.RIGHT_CORNER_3);
  3146.                         break;
  3147.                     case 24:
  3148.                         replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.RIGHT_CORNER_2_3);
  3149.                         break;
  3150.                     default:
  3151.                         replaceBackgroundGraphicGridAt(x, y, (int)BG_TYPE.ROAD);
  3152.                         break;
  3153.                     }
  3154.                     break;
  3155.                 }
  3156.             }
  3157.         }
  3158.     }
  3159.    
  3160.  
  3161.    
  3162.     public void replaceBackgroundGraphicGridAt(int x, int y, int backGroundToLoad)
  3163.     {
  3164.         int index = y*6+x;
  3165.         gameGridSprites[index].spriteId = gameGridSprites[index].collection.GetSpriteIdByName(backgroundGraphic[backGroundToLoad]);    
  3166.     }
  3167.    
  3168.    
  3169.        
  3170.     public void getNeighBorsListAt(ref List<int> list,int originX,int originY,int x,int y, PIECE_TYPE pieceType)
  3171.     {
  3172.         if(pieceType == PIECE_TYPE.RUBY || pieceType == PIECE_TYPE.FUTURE_CITY) {
  3173.             return;
  3174.         }
  3175.        
  3176.         int index = y*6 + x;
  3177.        
  3178.         if((x==originX) && (y==originY))
  3179.         {
  3180.         }
  3181.         else
  3182.         {
  3183.             if(gameGrid[x,y]==(int)pieceType && !list.Contains(index))
  3184.             {
  3185.                 list.Add(index);
  3186.             }
  3187.             else
  3188.             {
  3189.                 return;
  3190.             }
  3191.         }      
  3192.                
  3193.         //Searching north
  3194.         if(y < (int)GAME_PROPERTIES.columnLength - 1)
  3195.         {
  3196.             getNeighBorsListAt(ref list,originX,originY,x, y + 1, pieceType);
  3197.         }
  3198.        
  3199.         //Search West
  3200.         if(x > 0)
  3201.         {
  3202.             getNeighBorsListAt(ref list,originX,originY,x - 1, y, pieceType);
  3203.         }
  3204.        
  3205.         //Search south
  3206.         if(y > 0)
  3207.         {
  3208.             getNeighBorsListAt(ref list,originX,originY,x, y - 1, pieceType);
  3209.         }
  3210.        
  3211.         //Search East
  3212.         if(x < (int)GAME_PROPERTIES.rowLength - 1)
  3213.         {
  3214.             getNeighBorsListAt(ref list,originX,originY, x + 1, y, pieceType);
  3215.         }
  3216.        
  3217.  
  3218.     }          
  3219.    
  3220.     //Animate neighbors on the Y axis 10px Up and back, after being identified.
  3221.     public void animateNeighbors()
  3222.     {
  3223.         angleRadians += (Mathf.PI/9f);
  3224.         angleRadians = angleRadians%(2f*Mathf.PI);
  3225.         foreach (int index in neighborsList) {                                 
  3226.             gamePiecesAnimations[index].transform.Translate(Vector3.up*Mathf.Sin(angleRadians));
  3227.         }              
  3228.     }
  3229.    
  3230.     public void turnOnOffHighLightGrid(bool encender) {
  3231.         foreach (int index in neighborsList) {
  3232.             this.lightCells[index].active = encender;
  3233.         }
  3234.     }
  3235.            
  3236.     //If animated/highlighted frames of the Grid aren't changed, reset positions
  3237.     public void resetPositionsOfAnimatedNeighbors()
  3238.     {
  3239.         Vector3 originalPos;
  3240.         if (neighborsList.Count > 0) {
  3241.             foreach (int index in neighborsList) {
  3242.                 originalPos = gameGridSprites[index].transform.position;
  3243.                 originalPos.Set(originalPos.x, originalPos.y, gamePiecesAnimations[5*6+0].transform.position.z);
  3244.                 gamePiecesAnimations[index].transform.position = originalPos;
  3245.             }
  3246.         } else {
  3247.             for (int index = 0; index < 6*6; index++) {
  3248.                 if (index == (5*6 + 1)) {
  3249.                     continue;
  3250.                 }
  3251.                 originalPos = gameGridSprites[index].transform.position;
  3252.                 originalPos.Set(originalPos.x, originalPos.y, gamePiecesAnimations[5*6+0].transform.position.z);
  3253.                 gamePiecesAnimations[index].transform.position = originalPos;
  3254.             }
  3255.         }
  3256.         angleRadians = 0;
  3257.         turnOnOffHighLightGrid(false);
  3258.     }
  3259.    
  3260.     public void hideSelector() {
  3261.         selector.transform.Translate(Vector3.forward*10f);
  3262.     }
  3263.        
  3264.     public void updateSelectorPosition(int x, int y)
  3265.     {      
  3266.         int index = 6*y + x;
  3267.         Vector3 newPos = gameGridSprites[index].transform.position;// - Vector3.forward * 2f;//moverlo sobre todo      
  3268.         newPos.Set(newPos.x, newPos.y, 0.85f);
  3269.         selector.transform.position = newPos;
  3270.     }
  3271.            
  3272.     private void changeSelectorAnimationColor(Color newColor)
  3273.     {
  3274.         if (selectorAnimation.color != newColor) {
  3275.             selectorAnimation.color = newColor;
  3276.         }
  3277.     }
  3278.    
  3279.     private void changeSelectorAnimation(bool allowMove) {
  3280.         int idAnimation = selectorAnimation.clipId;
  3281.         if (allowMove) {
  3282.             if (idAnimation != selectorAnimation.GetClipIdByName("Selector")) {            
  3283.                 selectorAnimation.Play(selectorAnimation.GetClipIdByName("Selector"));
  3284.             }
  3285.         } else {
  3286.             if (idAnimation != selectorAnimation.GetClipIdByName("Selector_wrong")) {              
  3287.                 selectorAnimation.Play(selectorAnimation.GetClipIdByName("Selector_wrong"));
  3288.             }
  3289.         }
  3290.        
  3291.     }
  3292.        
  3293.    
  3294.    
  3295.    
  3296.     public void playFX(AudioSource sound)
  3297.     {
  3298.         //setFX(FX[FXpath], loopCount);
  3299.         if (!SoundController.enabledSound) {
  3300.             return;
  3301.         }
  3302.         AudioUtils.playSound(sound);
  3303.        
  3304.     }
  3305.    
  3306.     public void playFX(AudioSource sound, float delay)
  3307.     {
  3308.         //setFX(FX[FXpath], loopCount);
  3309.         if (!SoundController.enabledSound) {
  3310.             return;
  3311.         }
  3312.         AudioUtils.playSound(sound, delay);
  3313.        
  3314.     }
  3315.    
  3316.     public void playFX(List<AudioSource> soundList)
  3317.     {
  3318.         //setFX(FX[FXpath], loopCount);
  3319.         if (!SoundController.enabledSound) {
  3320.             return;
  3321.         }
  3322.         AudioUtils.playSoundFromList(soundList);
  3323.        
  3324.     }
  3325.    
  3326.     public void playFX(List<AudioSource> soundList, float delay)
  3327.     {
  3328.         //setFX(FX[FXpath], loopCount);
  3329.         if (!SoundController.enabledSound) {
  3330.             return;
  3331.         }
  3332.         AudioUtils.playSoundFromList(soundList);
  3333.        
  3334.     }
  3335.    
  3336.     public void playBGMusic()
  3337.     {
  3338.         /*
  3339.         if(gameOver)
  3340.         {
  3341.             if(Globals.soundEnabled)
  3342.             {
  3343.                 TUtils.getSoundManager().setMusic("/City_of_Ages_In_game_v1_3.mp3");
  3344.             }else
  3345.             {
  3346.                 TUtils.getSoundManager().stopSound();
  3347.             }
  3348.         }
  3349.         */
  3350.     }
  3351.        
  3352.    
  3353.     public void enableOrDisableUFOGuiButtons(bool shouldEnable) {
  3354.         ((tk2dButton)btnBuy.GetComponent(typeof(tk2dButton))).enabled   = shouldEnable;
  3355.         btnMuteSoundScript.isSpriteClickeable                           = shouldEnable;
  3356.         ((tk2dButton)btnHelp.GetComponent(typeof(tk2dButton))).enabled  = shouldEnable;
  3357.         ((tk2dButton)btnPause.GetComponent(typeof(tk2dButton))).enabled = shouldEnable;    
  3358.     }
  3359.    
  3360.     public void closeShopWindow() {
  3361.         Destroy(buyScreen);
  3362.         buyScreen = null;
  3363.         enableOrDisableUFOGuiButtons(true);
  3364.         STATE = Estados.WAITING_FOR_CLICK;
  3365.     }
  3366.     public void openShopWindow() {
  3367.        
  3368.         enableOrDisableUFOGuiButtons(false);
  3369.         buyScreen = Instantiate(buyScreenPrefab as GameObject) as GameObject;
  3370.         buyScreen.transform.FindChild("btnCerrar").GetComponent<tk2dButton>().targetObject = this.gameObject;
  3371.         //buyScreen.transform.FindChild("btnClose").GetComponent<tk2dButton>().enabled = true;
  3372.         STATE = Estados.BUYING;    
  3373.         checkForEnableShopButtons ();                                              
  3374.        
  3375.        
  3376.     }
  3377.  
  3378.     private void checkForEnableShopButtons ()
  3379.     {
  3380.         tk2dSprite[] listaSprites = buyScreen.GetComponentsInChildren<tk2dSprite>(true);
  3381.                
  3382.                 for(int i = 0; i < listaSprites.Length; i++) {
  3383.                     tk2dSprite sprite = listaSprites[i];
  3384.                     if (sprite.name == "bushBuy") {
  3385.                         tk2dButton btn = (tk2dButton)sprite.GetComponent(typeof(tk2dButton));
  3386.                         btn.targetObject = this.gameObject;
  3387.                         if (currentGold < (int)tablaBuyForCoinsValue[PIECE_TYPE.BUSH]) {
  3388.         //                 
  3389.                             sprite.spriteId = sprite.GetSpriteIdByName("disabled_bush");
  3390.                            
  3391.                             if (btn.enabled) {
  3392.                                 btn.enabled = false;
  3393.                             }
  3394.                         } else {
  3395.                             sprite.spriteId = sprite.GetSpriteIdByName("Bush");
  3396.                             if (!btn.enabled) {
  3397.                                 btn.enabled = true;
  3398.                             }
  3399.                         }
  3400.                     }
  3401.                     if (sprite.name == "rucaBuy") {
  3402.                         tk2dButton btn = (tk2dButton)sprite.GetComponent(typeof(tk2dButton));
  3403.                         btn.targetObject = this.gameObject;
  3404.                         if (currentGold < (int)tablaBuyForCoinsValue[PIECE_TYPE.RUCA]) {
  3405.                             sprite.spriteId = sprite.GetSpriteIdByName("disabled_ruca");
  3406.                            
  3407.                             if (btn.enabled) {
  3408.                                 btn.enabled = false;
  3409.                             }
  3410.                         } else {
  3411.                             sprite.spriteId = sprite.GetSpriteIdByName("Ruca_1");
  3412.                            
  3413.                             if (!btn.enabled) {
  3414.                                 btn.enabled = true;
  3415.                             }
  3416.                         }
  3417.                     }
  3418.                     if (sprite.name == "treeBuy") {
  3419.                         tk2dButton btn = (tk2dButton)sprite.GetComponent(typeof(tk2dButton));
  3420.                         btn.targetObject = this.gameObject;
  3421.                         if (currentGold < (int)tablaBuyForCoinsValue[PIECE_TYPE.TREE]) {
  3422.                             sprite.spriteId = sprite.GetSpriteIdByName("disabled_tree");
  3423.                            
  3424.                             if (btn.enabled) {
  3425.                                 btn.enabled = false;
  3426.                             }
  3427.                         } else {
  3428.                             sprite.spriteId = sprite.GetSpriteIdByName("Tree");
  3429.                            
  3430.                             if (!btn.enabled) {
  3431.                                 btn.enabled = true;
  3432.                             }
  3433.                         }
  3434.                     }
  3435.                     if (sprite.name == "blackHoleBuy") {
  3436.                         tk2dButton btn = (tk2dButton)sprite.GetComponent(typeof(tk2dButton));
  3437.                         btn.targetObject = this.gameObject;
  3438.                         if (currentGold < (int)tablaBuyForCoinsValue[PIECE_TYPE.BLACK_HOLE]) {
  3439.         //                  ((tk2dAnimatedSprite)sprite).Pause();
  3440.                             ((tk2dAnimatedSprite)sprite).playAutomatically = false;
  3441.                             sprite.spriteId = sprite.GetSpriteIdByName("disabled_blackhole");
  3442.                            
  3443.                             if (btn.enabled) {
  3444.                                 btn.enabled = false;
  3445.                             }
  3446.                         } else {
  3447.                             sprite.spriteId = sprite.GetSpriteIdByName("Black_Hole_A/20");
  3448.                            
  3449.                             if (!btn.enabled) {
  3450.                                 btn.enabled = true;
  3451.                             }
  3452.                         }
  3453.                     }
  3454.                     if (sprite.name == "greenGemBuy") {
  3455.                         tk2dButton btn = (tk2dButton)sprite.GetComponent(typeof(tk2dButton));
  3456.                         btn.targetObject = this.gameObject;
  3457.                         if (currentGold < (int)tablaBuyForCoinsValue[PIECE_TYPE.MAGIC_CRISTAL_GREEN]) {
  3458.                             sprite.spriteId = sprite.GetSpriteIdByName("disabled_crystals");
  3459.                            
  3460.                             if (btn.enabled) {
  3461.                                 btn.enabled = false;
  3462.                             }
  3463.                         } else {
  3464.                             sprite.spriteId = sprite.GetSpriteIdByName("Magic_Cristal_Green2");
  3465.                            
  3466.                             if (!btn.enabled) {
  3467.                                 btn.enabled = true;
  3468.                             }
  3469.                         }
  3470.                     }
  3471.                     if (sprite.name == "purpleGemBuy") {
  3472.                         tk2dButton btn = (tk2dButton)sprite.GetComponent(typeof(tk2dButton));
  3473.                         btn.targetObject = this.gameObject;
  3474.                         if (currentGold < (int)tablaBuyForCoinsValue[PIECE_TYPE.MAGIC_CRISTAL_PURPLE]) {
  3475.                             sprite.spriteId = sprite.GetSpriteIdByName("disabled_crystals");
  3476.                             if (btn.enabled) {
  3477.                                 btn.enabled = false;
  3478.                             }
  3479.                             btn.enabled = false;
  3480.                         } else {
  3481.                             sprite.spriteId = sprite.GetSpriteIdByName("Magic_Cristal_Purple2");
  3482.                            
  3483.                             if (!btn.enabled) {
  3484.                                 btn.enabled = true;
  3485.                             }
  3486.                         }
  3487.                     }
  3488.            
  3489.                     if (sprite.name == "coinBuy") {
  3490.                         tk2dButton btn = (tk2dButton)sprite.GetComponent(typeof(tk2dButton));
  3491.                         btn.targetObject = this.gameObject;                    
  3492.                     }
  3493.                    
  3494.                     if (sprite.name == "freecoinBuy") {
  3495.                         tk2dButton btn = (tk2dButton)sprite.GetComponent(typeof(tk2dButton));
  3496.                         btn.targetObject = this.gameObject;                    
  3497.                     }
  3498.            
  3499.             }
  3500.     }
  3501.    
  3502.     private tk2dSprite spriteHelp = null;
  3503.     private tk2dSprite btnHelpBack = null;
  3504.     private tk2dSprite btnHelpNext = null;
  3505.    
  3506.     public void openHelpWindow() {
  3507.        
  3508.         enableOrDisableUFOGuiButtons(false);
  3509.         helpScreen = Instantiate(helpScreenPrefab as GameObject) as GameObject;
  3510.         spriteHelp = (tk2dSprite)helpScreen.GetComponent(typeof(tk2dSprite));
  3511.         helpScreen.transform.FindChild("btnCloseHelp").GetComponent<tk2dButton>().targetObject = this.gameObject;
  3512.         //buyScreen.transform.FindChild("btnClose").GetComponent<tk2dButton>().enabled = true;
  3513.         STATE = Estados.PAUSE;
  3514.        
  3515.         tk2dSprite[] listaSprites = helpScreen.GetComponentsInChildren<tk2dSprite>(true);//.GetComponents<Component>();
  3516.        
  3517.        
  3518.         for(int i = 0; i < listaSprites.Length; i++) {
  3519.             tk2dSprite sprite = listaSprites[i];
  3520.             if (sprite.name == "btnHelpBack") {
  3521.                 btnHelpBack = sprite;
  3522.                 tk2dButton btn = (tk2dButton)btnHelpBack.GetComponent(typeof(tk2dButton));
  3523.                 btn.targetObject = this.gameObject;
  3524. //              btnHelpBack.spriteId = btnHelpBack.collection.GetSpriteIdByName("botons  of menu/0");
  3525.                 btn.enabled = false;
  3526.             }
  3527.            
  3528.             if (sprite.name == "btnHelpNext") {
  3529.                 btnHelpNext = sprite;
  3530.                 tk2dButton btn = (tk2dButton)btnHelpNext.GetComponent(typeof(tk2dButton));
  3531.                 btn.targetObject = this.gameObject;
  3532.                
  3533.             }                                              
  3534.         }
  3535.        
  3536.     }
  3537.    
  3538.     public void closeHelpScreen() {
  3539.         Destroy(helpScreen);
  3540.         if (coinsHelp != null) {
  3541.             Destroy(coinsHelp);
  3542.             coinsHelp = null;
  3543.         }
  3544.         helpScreen = null;
  3545.         btnHelpBack = null;
  3546.         btnHelpNext = null;
  3547.         enableOrDisableUFOGuiButtons(true);
  3548.         helpScreenNumber = 0;
  3549.         STATE = Estados.WAITING_FOR_CLICK;
  3550.     }
  3551.    
  3552.     public enum HELP_SCREEN {
  3553.         PIECES_COMBINATIONS
  3554.         , ALIENS
  3555.         , GEMS
  3556.         , COINS
  3557.     }
  3558.    
  3559.     HELP_SCREEN screenToShow;
  3560.    
  3561.     public int helpScreenNumber = 0;
  3562.    
  3563.     public void backHelpScreen() {
  3564.        
  3565.         if (helpScreenNumber > 0) {                    
  3566.             helpScreenNumber--;
  3567.             screenToShow = (HELP_SCREEN)helpScreenNumber;                      
  3568.             changeHelpScreen(screenToShow);
  3569.         }
  3570.     }
  3571.    
  3572.     public void nextHelpScreen() {     
  3573.         if (helpScreenNumber < (int)HELP_SCREEN.COINS) {                       
  3574.             helpScreenNumber++;
  3575.             screenToShow = (HELP_SCREEN)helpScreenNumber;
  3576.             changeHelpScreen(screenToShow);
  3577.         }
  3578.     }
  3579.    
  3580.     public GameObject coinsPivotPrefab;
  3581.     private GameObject coinsHelp = null;
  3582.     public void changeHelpScreen(HELP_SCREEN screenToShow) {
  3583.         tk2dButton btnBack = (tk2dButton)btnHelpBack.GetComponent(typeof(tk2dButton));
  3584.         tk2dButton btnNext = (tk2dButton)btnHelpNext.GetComponent(typeof(tk2dButton));
  3585.        
  3586.         if (screenToShow!= HELP_SCREEN.COINS && coinsHelp != null) {
  3587.             Destroy(coinsHelp);
  3588.             coinsHelp = null;
  3589.         }
  3590.        
  3591.         switch(screenToShow) {
  3592.             case HELP_SCREEN.PIECES_COMBINATIONS:
  3593.                 btnBack.enabled = false;
  3594. //              btnHelpBack.spriteId = btnHelpBack.collection.GetSpriteIdByName("botons  of menu/0");
  3595.                 spriteHelp.spriteId = spriteHelp.collection.GetSpriteIdByName("townPiecesCombinations");
  3596.                 break;
  3597.            
  3598.            
  3599.             case HELP_SCREEN.ALIENS:
  3600.                 if (!btnBack.enabled) {
  3601.                     btnBack.enabled = true;
  3602.                 }
  3603.            
  3604.                 if (!btnNext.enabled) {
  3605.                     btnNext.enabled = true;
  3606.                 }
  3607.                 spriteHelp.spriteId = spriteHelp.collection.GetSpriteIdByName("TutorialsBG");
  3608.                 break;
  3609.            
  3610.            
  3611.             case HELP_SCREEN.GEMS:
  3612.                 if (!btnBack.enabled) {
  3613.                     btnBack.enabled = true;
  3614.                 }
  3615.            
  3616.                 if (!btnNext.enabled) {
  3617.                     btnNext.enabled = true;
  3618.                 }
  3619.            
  3620.                 spriteHelp.spriteId = spriteHelp.collection.GetSpriteIdByName("TutorialsBG2");
  3621.                 break;
  3622.            
  3623.            
  3624.             case HELP_SCREEN.COINS:
  3625.                 btnNext.enabled = false;
  3626. //              btnHelpNext.spriteId = btnHelpNext.collection.GetSpriteIdByName("botons  of menu/0");
  3627.                 spriteHelp.spriteId = spriteHelp.collection.GetSpriteIdByName("TutorialsBG3");
  3628.                 coinsHelp = Instantiate(coinsPivotPrefab) as GameObject;
  3629.                 tk2dTextMesh txtSilver = coinsHelp.transform.Find("txtSilver").GetComponent<tk2dTextMesh>();
  3630.                 txtSilver.text = " = " + SILVER_COIN_VALUE + " COINS";
  3631.                 txtSilver.Commit();
  3632.            
  3633.            
  3634.                 break;
  3635.            
  3636.            
  3637.             default:
  3638.                 break;
  3639.         }
  3640.     }
  3641.    
  3642.    
  3643.     public void closePauseScreen() {       
  3644.         Destroy(pauseScreen);
  3645.         pauseScreen = null;
  3646.         enableOrDisableUFOGuiButtons(true);
  3647.         STATE = Estados.WAITING_FOR_CLICK;
  3648.     }
  3649.     public void openPauseScreen() {
  3650.        
  3651.         enableOrDisableUFOGuiButtons(false);
  3652.         pauseScreen = Instantiate(pauseScreenPrefab as GameObject) as GameObject;
  3653.         GameObject SubGameChangeScreen = pauseScreen.transform.FindChild("GameChangeScreen").gameObject;
  3654.         //pauseScreen.transform.FindChild("btnPauseBack").GetComponent<tk2dButton>().targetObject = this.gameObject;
  3655.         if (!gameOver) {
  3656.             SubGameChangeScreen.transform.FindChild("btnGameResume").GetComponent<tk2dButton>().targetObject = this.gameObject;
  3657.             SubGameChangeScreen.transform.FindChild("btnFB/FBborder").gameObject.active = false;
  3658.             SubGameChangeScreen.transform.FindChild("btnFB").gameObject.active = false;
  3659.         }
  3660.         SubGameChangeScreen.transform.FindChild("btnGameRetry").GetComponent<tk2dButton>().targetObject = this.gameObject;     
  3661.         SubGameChangeScreen.transform.FindChild("btnSaveGame").GetComponent<tk2dButton>().targetObject = this.gameObject;
  3662.        
  3663.         if (gameOver) {
  3664.            
  3665.             txtGameOver.gameObject.active = true;
  3666.             txtGameOver.transform.FindChild("frameGameOver").gameObject.active = true;
  3667. //          SubGameChangeScreen.transform.position += Vector3.up*-20f;
  3668.            
  3669. //          SubGameChangeScreen.transform.FindChild("btnGameResume").GetComponent<tk2dButton>().enabled = false;
  3670. //          SubGameChangeScreen.transform.FindChild("btnGameResume").GetComponent<tk2dSprite>().spriteId =
  3671. //              SubGameChangeScreen.transform.FindChild("btnGameResume").GetComponent<tk2dSprite>().collection.GetSpriteIdByName("botons  of menu/0");
  3672.             tk2dTextMesh txtExit = SubGameChangeScreen.transform.FindChild("btnSaveGame/TextMesh").GetComponent<tk2dTextMesh>();
  3673.             txtExit.text = "Exit";
  3674.             txtExit.Commit();
  3675.             SubGameChangeScreen.transform.FindChild("btnSaveGame/barra/Sprite0").GetComponent<tk2dSprite>().spriteId =
  3676.                 SubGameChangeScreen.transform.FindChild("btnSaveGame/barra/Sprite0").GetComponent<tk2dSprite>().collection.GetSpriteIdByName("navegation_indexes/3");
  3677.            
  3678.             SubGameChangeScreen.transform.FindChild("btnGameResume/Sprite0").gameObject.active = false;
  3679.             SubGameChangeScreen.transform.FindChild("btnGameResume").gameObject.active = false;
  3680.             GameObject go = SubGameChangeScreen.transform.Find("btnGameResume/barra/txtResume").gameObject;        
  3681.             tk2dTextMesh txtMesh = go.GetComponent<tk2dTextMesh>();
  3682.             txtMesh.gameObject.transform.localScale = new Vector3(0.44f, 1f, 1f);
  3683.             txtMesh.text = "SHARE SCORE";
  3684.             txtMesh.maxChars = txtMesh.text.Length;
  3685.             txtMesh.Commit();
  3686.             GameObject btnFB = SubGameChangeScreen.transform.FindChild("btnFB").gameObject;
  3687.             btnFB.active = true;
  3688.             btnFB.GetComponent<tk2dButton>().targetObject = GameObject.Find("FacebookEventListener").gameObject;
  3689.             SubGameChangeScreen.transform.Find("btnGameResume/barra").parent = btnFB.transform;
  3690. //          InitiateFontColors txtColorsToInitiate = SubGameChangeScreen.transform.Find("btnGameResume/barra/txtResume").GetComponent<InitiateFontColors>();
  3691. //          txtColorsToInitiate.color1 = new Color(0.8f, 0.8f, 0.8f, 1f);
  3692. //          txtColorsToInitiate.color2 = new Color(0.4f, 0.4f, 0.4f, 1f);
  3693.             //txtColorsToInitiate.Commit();
  3694.            
  3695.            
  3696.             pauseScreen.transform.FindChild("imgNanos").gameObject.active = false;
  3697.             pauseScreen.transform.FindChild("imgPausa").gameObject.active = false;
  3698. //          pauseScreen.active = false;
  3699.         }
  3700.         STATE = Estados.PAUSE;
  3701.                                
  3702.     }
  3703.    
  3704. //  public void closeGameChangeScreen() {
  3705. //      Destroy(gameChangeScreen);
  3706. //      gameChangeScreen = null;
  3707. //      enableOrDisableUFOGuiButtons(true);
  3708. //      STATE = Estados.WAITING_FOR_CLICK;
  3709. //  }
  3710.    
  3711.    
  3712.    
  3713. //  public void openGameChangeScreen() {
  3714. //     
  3715. //      enableOrDisableUFOGuiButtons(false);
  3716. //      gameChangeScreen = Instantiate(gameChangeScreenPrefab as GameObject) as GameObject;
  3717. //      gameChangeScreen.transform.FindChild("btnGameResume").GetComponent<tk2dButton>().targetObject = this.gameObject;
  3718. //      gameChangeScreen.transform.FindChild("btnGameRetry").GetComponent<tk2dButton>().targetObject = this.gameObject;    
  3719. //      gameChangeScreen.transform.FindChild("btnGameExit").GetComponent<tk2dButton>().targetObject = this.gameObject;     
  3720. //      if (gameOver) {
  3721. //          txtGameOver.gameObject.active = true;
  3722. //          gameChangeScreen.transform.position += Vector3.up*-20f;
  3723. //          gameChangeScreen.transform.FindChild("btnGameResume").GetComponent<tk2dButton>().enabled = false;
  3724. //          gameChangeScreen.transform.FindChild("btnGameResume").GetComponent<tk2dSprite>().spriteId =
  3725. //                  gameChangeScreen.transform.FindChild("btnGameResume").GetComponent<tk2dSprite>().collection.GetSpriteIdByName("botons  of menu/0");
  3726. //      }
  3727. //      STATE = Estados.PAUSE;                             
  3728. //  }
  3729.    
  3730.     public void enableOrDisablePauseButtons(bool shouldEnable) {
  3731.         GameObject SubGameChangeScreen = pauseScreen.transform.FindChild("GameChangeScreen").gameObject;
  3732.         SubGameChangeScreen.transform.FindChild("btnGameResume").GetComponent<tk2dButton>().enabled = shouldEnable;
  3733.         SubGameChangeScreen.transform.FindChild("btnGameRetry").GetComponent<tk2dButton>().enabled = shouldEnable;     
  3734.         SubGameChangeScreen.transform.FindChild("btnSaveGame").GetComponent<tk2dButton>().enabled = shouldEnable;
  3735.     }
  3736.            
  3737.    
  3738.     private string[] popUpDialogues = {
  3739.         "Start a NEW GAME?"
  3740.         ,"Do you want to\nsave before exit?"
  3741.         ,"Buying 15000 coins for $0.99\nAre you sure?"
  3742.     };
  3743.    
  3744.     private enum POP_UP_DIALOGOS {
  3745.         NEW_GAME
  3746.         ,SAVE
  3747.         ,CONFIRM_PURCHASE
  3748.     }
  3749.    
  3750.     public void OpenPopUpFromRetryGame() {
  3751.         if (gameOver) {
  3752.             closePauseScreen();
  3753.             txtGameOver.gameObject.active = false;
  3754.             txtGameOver.transform.FindChild("frameGameOver").gameObject.active = false;
  3755.             STATE = Estados.INITIALIZE;
  3756.             LOAD_GAME_TYPE = TipoJuego.NEW_GAME;
  3757.         } else {
  3758.             enableOrDisablePauseButtons(false);
  3759.             popUpConfirmWindow = Instantiate(popUpConfirmWindowPrefab as GameObject) as GameObject;
  3760.             popUpConfirmWindow.transform.FindChild("btnYES").GetComponent<tk2dButton>().targetObject = this.gameObject;
  3761.             popUpConfirmWindow.transform.FindChild("btnNO").GetComponent<tk2dButton>().targetObject = this.gameObject;
  3762.             popUpQuestionString = popUpDialogues[(int)POP_UP_DIALOGOS.NEW_GAME];
  3763.             txtPopUpQuestion = popUpConfirmWindow.transform.FindChild("txtConfirmQuestion").GetComponent<tk2dTextMesh>();
  3764.             txtPopUpQuestion.text = popUpQuestionString;
  3765.             txtPopUpQuestion.Commit();
  3766.         }
  3767.                        
  3768.        
  3769.     }
  3770.    
  3771.     public void OpenPopUpFromSaveGame() {
  3772.         if (gameOver) {
  3773.             goToMainMenu();
  3774.             return;
  3775.         }
  3776.         enableOrDisablePauseButtons(false);
  3777.         popUpSaveGameWindow = Instantiate(popUpSaveGameWindowPrefab as GameObject) as GameObject;
  3778.         popUpSaveGameWindow.transform.FindChild("btnSaveExit").GetComponent<tk2dButton>().targetObject = this.gameObject;
  3779.         popUpSaveGameWindow.transform.FindChild("btnSaveContinue").GetComponent<tk2dButton>().targetObject = this.gameObject;
  3780.         popUpSaveGameWindow.transform.FindChild("btnSaveCancel").GetComponent<tk2dButton>().targetObject = this.gameObject;
  3781.                                        
  3782.         //popUpQuestionString = popUpDialogues[(int)POP_UP_DIALOGOS.SAVE];
  3783.         //txtPopUpQuestion = popUpConfirmWindow.transform.FindChild("txtConfirmQuestion").GetComponent<tk2dTextMesh>();
  3784.         //txtPopUpQuestion.text = popUpQuestionString;
  3785.         //txtPopUpQuestion.Commit();                                   
  3786.        
  3787.     }
  3788.    
  3789.     public void initPurchase() {
  3790.        
  3791.             //enableOrDisablePauseButtons(false);          
  3792.             popUpPurchaseFeedbackWindow = Instantiate(popUpPurchaseFeedbackPrefab as GameObject) as GameObject;        
  3793.             enableOrDisableBuyScreenButtons(false);
  3794.             //checkForEnableShopButtons();
  3795.             Debug.Log("init purchase clicked");
  3796. //          popUpPurchaseMessageWindow.transform.FindChild("btnOk").GetComponent<tk2dButton>().targetObject;
  3797.        
  3798.                        
  3799.        
  3800.     }
  3801.    
  3802.    
  3803.                            
  3804.     public void finishPurchase() {
  3805.         if (popUpPurchaseFeedbackWindow != null) {
  3806.             Destroy(popUpPurchaseFeedbackWindow);
  3807.             popUpPurchaseFeedbackWindow = null;
  3808.             enableOrDisableBuyScreenButtons(true);
  3809.             checkForEnableShopButtons();
  3810.         }
  3811.     }
  3812.    
  3813.     private void enableOrDisableBuyScreenButtons(bool shouldEnable) {
  3814.         if (buyScreen != null) {
  3815.            
  3816.             tk2dButton[] listaButtons = buyScreen.GetComponentsInChildren<tk2dButton>(true);
  3817.                    
  3818.             for(int i = 0; i < listaButtons.Length; i++) {
  3819.                 listaButtons[i].enabled = shouldEnable;
  3820.                
  3821.             }
  3822.         }
  3823.     }
  3824.    
  3825.     protected void openFreeCoinsWindow() {
  3826.         popUpFreeCoinsWindow = Instantiate(popUpFreeCoinsPrefab as GameObject) as GameObject;          
  3827.         enableOrDisableBuyScreenButtons(false);
  3828.         //checkForEnableShopButtons();
  3829.         STATE = Estados.BUYING;
  3830.        
  3831.     }
  3832.    
  3833.     public void closeFreeCoinsWindow() {
  3834.         Destroy(popUpFreeCoinsWindow);
  3835.         popUpFreeCoinsWindow = null;
  3836.         enableOrDisableBuyScreenButtons(true);
  3837.         checkForEnableShopButtons();
  3838.        
  3839.     }
  3840.    
  3841.    
  3842.    
  3843.     public void popUpSaveExit() {
  3844.         saveData();
  3845.         Destroy(popUpSaveGameWindow);
  3846.         popUpSaveGameWindow = null;
  3847.         goToMainMenu();
  3848.     }
  3849.    
  3850.     public void popUpSaveContinue() {
  3851.         saveData();
  3852.         Destroy(popUpSaveGameWindow);
  3853.         popUpSaveGameWindow = null;
  3854.         closePauseScreen();
  3855.     }
  3856.    
  3857.     public void popUpSaveCancel() {    
  3858.         Destroy(popUpSaveGameWindow);
  3859.         popUpSaveGameWindow = null;
  3860.         enableOrDisablePauseButtons(true);
  3861.     }
  3862.    
  3863.     public void closePopUpConfirm() {
  3864.         enableOrDisablePauseButtons(true);
  3865.         if (popUpQuestionString == popUpDialogues[(int)POP_UP_DIALOGOS.SAVE]) {
  3866.             goToMainMenu();
  3867.         }
  3868.         Destroy(popUpConfirmWindow);
  3869.         txtPopUpQuestion = null;
  3870.         popUpQuestionString = null;
  3871.         popUpConfirmWindow = null;
  3872.        
  3873.        
  3874. //      enableOrDisableUFOGuiButtons(true);
  3875.     }
  3876.    
  3877.     public void popUpYesSelected() {
  3878.         if (popUpQuestionString != null) {
  3879.             if (popUpQuestionString == popUpDialogues[(int)POP_UP_DIALOGOS.NEW_GAME]) {
  3880.                 closePopUpConfirm();
  3881. //              closeGameChangeScreen();
  3882.                 closePauseScreen();
  3883.                 STATE = Estados.INITIALIZE;
  3884.                 LOAD_GAME_TYPE = TipoJuego.NEW_GAME;
  3885.             }
  3886.            
  3887.             if (popUpQuestionString == popUpDialogues[(int)POP_UP_DIALOGOS.SAVE]) {
  3888.                 closePopUpConfirm();
  3889.                 saveData();
  3890. //              closeGameChangeScreen();
  3891.                 closePauseScreen();
  3892.                 goToMainMenu();
  3893. //              Destroy(this);
  3894.             }
  3895.            
  3896.             if (popUpQuestionString == popUpDialogues[(int)POP_UP_DIALOGOS.CONFIRM_PURCHASE]) {
  3897.                 closePopUpConfirm();
  3898.                 //codigo de compra aqui
  3899.                
  3900.                 //saveData();
  3901. //              closeGameChangeScreen();
  3902.                
  3903.                 //closePauseScreen();
  3904.                 //goToMainMenu();
  3905. //              Destroy(this);
  3906.             }
  3907.         }
  3908.     }
  3909.  
  3910.     public void saveData()
  3911.     {
  3912.         DataGame.writeSaveGame();
  3913.     }
  3914.  
  3915.     public void goToMainMenu ()
  3916.     {
  3917.         MainMenu.gold = currentGold;           
  3918.         MainMenu.highScore = highScore;
  3919.         Application.LoadLevel("mainMenu");
  3920.     }
  3921.    
  3922.     public void popUpNoSelected() {
  3923.         closePopUpConfirm();
  3924.     }
  3925.    
  3926.     /**
  3927.      * Unico Metodo de BG_TYPE.java
  3928.      * */
  3929.     public int BGRange(int num)
  3930.     {
  3931.         return connections[num];
  3932.     }
  3933.    
  3934.    
  3935.     public bool clickOnGrid ()
  3936.     {      
  3937.  
  3938.         RaycastHit hitInfo;    
  3939.         for (int aux = 0; aux < 6*6; aux++) {
  3940.             //if (clickReference[aux].gotHit) {
  3941.             if (gameGridSprites[aux].collider.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo, 1.0e8f)) {
  3942.                
  3943.                 prevClickX = touchX;
  3944.                 prevClickY = touchY;
  3945.                 touchX = aux%6;
  3946.                 touchY = aux/6;
  3947.                 if(prevClickX==touchX && prevClickY == touchY)
  3948.                 {
  3949.                     firstClick = false;
  3950.                 } else {
  3951.                     firstClick = true;
  3952.                     animateNeigbors = false;
  3953.                     turnOnOffHighLightGrid(false);
  3954.                     resetPositionsOfAnimatedNeighbors();
  3955.                 }              
  3956.                    
  3957. //              debugTextGridClick = "x: " + touchX + " y: " + touchY + "\nValor es: " + gameGrid[touchX,touchY];
  3958.                 //Debug.Log(debugTextGridClick);
  3959.                 //Debug.Log("Prev. click x: " + prevClickX + " y: " + prevClickY);
  3960.                 return true; //se clickeo en la grilla
  3961.             }                                      
  3962.         }
  3963.         return false; //no se clickeo en la grilla
  3964.        
  3965.     }
  3966.    
  3967. //  private List<GameObject> listVillagers = new List<GameObject>();
  3968.    
  3969.    
  3970.    
  3971.     private GameObject villager;
  3972.     private List<GameObject> listAldeanos = new List<GameObject>();
  3973.     public void addVillager(Villager.TIPOS_VILLAGER tipoVillager, Vector3 posIni) {
  3974.         posIni.Set (posIni.x, posIni.y, 3f);  
  3975.         villager = Instantiate(villagerPrefab, posIni, Quaternion.identity) as GameObject;
  3976.         Villager villagerScript = villager.GetComponent<Villager>();
  3977.         villagerScript.tipoVillager = tipoVillager;
  3978.         villagerScript.changeAnimation();
  3979.         villagerScript.setGameScript(this.GetComponent<Game>());
  3980. //      if (tipoVillager == Villager.TIPOS_VILLAGER.CAVERNICOLA) {
  3981. //          if (villagerScript.sex == Villager.GENERO.MALE) {          
  3982. //              playFX((Instantiate(this.sndCavernicolaMPrefab) as GameObject).GetComponent<AudioSource>());
  3983. //          } else {
  3984. //              playFX((Instantiate(this.sndCavernicolaFPrefab) as GameObject).GetComponent<AudioSource>());
  3985. //          }
  3986. //      } else {
  3987. //          playFX((Instantiate(this.sndVillagerPrefab) as GameObject).GetComponent<AudioSource>());   
  3988. //      }
  3989.        
  3990.         listAldeanos.Add(villager);    
  3991.        
  3992.                
  3993.     }
  3994.            
  3995.     private List<List<GameObject>> listGoldCoins = new List<List<GameObject>>();
  3996.     private List<List<GameObject>> listSilverCoins = new List<List<GameObject>>();
  3997.     private List<List<GameObject>> listCopperCoins = new List<List<GameObject>>();
  3998.    
  3999.     public struct CoinParams {
  4000.         public List<GameObject> currentList;
  4001.         public int amountToAdd;
  4002.         public GameObject coinToDestroy;
  4003.         public bool mustRemoveCurrentList;
  4004.     }
  4005. //  private int amountGoldCoins;
  4006. //  private int amountSilverCoins;
  4007. //  private int amountCopperCoins;
  4008.     private readonly int GOLD_COIN_VALUE = 100;
  4009.     private readonly int SILVER_COIN_VALUE = 10;
  4010.     private readonly int COPPER_COIN_VALUE = 1;
  4011.     private readonly int MAX_AMOUNT_OF_COINS = 4;
  4012.     public void addCoins(int amount, int iniX, int iniY)
  4013.     {
  4014.         listCashSounds.Clear();
  4015.         listCashSounds.Add((Instantiate(this.sndCashSound1Prefab) as GameObject).GetComponent<AudioSource>());
  4016.         listCashSounds.Add((Instantiate(this.sndCashSound2Prefab) as GameObject).GetComponent<AudioSource>());
  4017.         playFX(listCashSounds);
  4018.         int amountGoldCoins = amount/GOLD_COIN_VALUE;
  4019.         int amountSilverCoins = (amount%GOLD_COIN_VALUE)/SILVER_COIN_VALUE;
  4020.         int amountCopperCoins = ((amount%GOLD_COIN_VALUE)%SILVER_COIN_VALUE)/COPPER_COIN_VALUE;
  4021.        
  4022.         Vector3 posIni = gameGridSprites[iniY*6+iniX].transform.position + Vector3.right*10f + Vector3.up*-10f + Vector3.forward*-5f;
  4023.         float totalGoldDelay = 0;
  4024.        
  4025.         if (amountGoldCoins > 0) {
  4026.             List<GameObject> listaGold = new List<GameObject>();
  4027.             listGoldCoins.Add(listaGold);
  4028.            
  4029.            
  4030.             for (int i = 1; i <= amountGoldCoins; i++) {
  4031.                 listaGold.Add(Instantiate(goldCoinPrefab as GameObject, posIni, Quaternion.identity) as GameObject);               
  4032.                 if (amountGoldCoins > MAX_AMOUNT_OF_COINS) {
  4033.                     totalGoldDelay += (float)i/(MAX_AMOUNT_OF_COINS*4.5f);
  4034.                 } else {
  4035.                     totalGoldDelay += (float)i/(amountGoldCoins*4.5f);
  4036.                 }
  4037.                
  4038.                 CoinParams coinParams = new CoinParams();
  4039.                 coinParams.amountToAdd = 1;
  4040.                 coinParams.currentList = listaGold;
  4041.                 coinParams.coinToDestroy = listaGold[i-1];
  4042.                 coinParams.mustRemoveCurrentList = false;
  4043.                
  4044.                 if (amountGoldCoins <= MAX_AMOUNT_OF_COINS && i == amountGoldCoins) {
  4045.                    
  4046.                     coinParams.mustRemoveCurrentList = true;
  4047.                 } else {
  4048.                     if (i > MAX_AMOUNT_OF_COINS) {                     
  4049.                         coinParams.amountToAdd = amountGoldCoins - MAX_AMOUNT_OF_COINS;
  4050.                         coinParams.mustRemoveCurrentList = true;
  4051.                     }
  4052.                 }
  4053.                                                
  4054.                 iTween.MoveTo(listaGold[i-1].gameObject, iTween.Hash(
  4055.                     "position", guiCoin.transform.position + Vector3.forward*-0.5f,
  4056.                     "easetype", iTween.EaseType.easeInOutQuad,
  4057.                     "time", 0.8f,
  4058.                     "delay", totalGoldDelay + 0.5f,                
  4059.                     "oncomplete", "addGoldCoins",
  4060.                     "oncompleteparams", coinParams,
  4061.                     "oncompletetarget", this.gameObject
  4062.                 ));
  4063.                
  4064.                 if (i > MAX_AMOUNT_OF_COINS) {
  4065.                         break;
  4066.                 }
  4067.             }                                                                      
  4068.             totalGoldDelay += 0.5f;
  4069.         }      
  4070.        
  4071.        
  4072.         float totalSilverDelay = 0;
  4073.        
  4074.        
  4075.         if (amountSilverCoins > 0) {
  4076.                 List<GameObject> listaSilver = new List<GameObject>();
  4077.                 listSilverCoins.Add(listaSilver);
  4078.             for (int i = 1; i <= amountSilverCoins; i++) {
  4079.                 listaSilver.Add(Instantiate(silverCoinPrefab as GameObject, posIni, Quaternion.identity) as GameObject);
  4080.                
  4081.                 totalSilverDelay += (float)i/(amountSilverCoins*4.5f);
  4082.                
  4083.                 CoinParams coinParams = new CoinParams();
  4084.                 coinParams.amountToAdd = 1;
  4085.                 coinParams.currentList = listaSilver;
  4086.                 coinParams.coinToDestroy = listaSilver[i-1];
  4087.                 coinParams.mustRemoveCurrentList = false;
  4088.                
  4089.                 if (amountSilverCoins <= MAX_AMOUNT_OF_COINS && i == amountSilverCoins) {
  4090.                    
  4091.                     coinParams.mustRemoveCurrentList = true;
  4092.                 } else {
  4093.                     if (i > MAX_AMOUNT_OF_COINS) {                     
  4094.                         coinParams.amountToAdd = amountSilverCoins - MAX_AMOUNT_OF_COINS;
  4095.                         coinParams.mustRemoveCurrentList = true;
  4096.                     }
  4097.                 }
  4098.                
  4099.                 iTween.MoveTo(listaSilver[i-1].gameObject, iTween.Hash(
  4100.                     "position", guiCoin.transform.position + Vector3.forward*-0.5f,
  4101.                     "time", 0.8f,
  4102.                     "easetype", iTween.EaseType.easeInOutQuad,
  4103.                     "delay", totalGoldDelay + totalSilverDelay + 0.5f,
  4104.                     "oncomplete", "addSilverCoins",
  4105.                     "oncompleteparams", coinParams,
  4106.                     "oncompletetarget", this.gameObject
  4107.                 ));
  4108.                
  4109.                 if (i > MAX_AMOUNT_OF_COINS) {
  4110.                         break;
  4111.                 }
  4112.             }
  4113.             totalSilverDelay += 0.5f;
  4114.         }
  4115.        
  4116.        
  4117.         float totalCopperDelay = 0;
  4118.         if (amountCopperCoins > 0) {
  4119.             List<GameObject> listaCopper = new List<GameObject>();
  4120.             listCopperCoins.Add(listaCopper);
  4121.            
  4122.             for (int i = 1; i <= amountCopperCoins; i++) {
  4123.                 listaCopper.Add(Instantiate(copperCoinPrefab as GameObject, posIni, Quaternion.identity) as GameObject);
  4124.                 if (amountCopperCoins > MAX_AMOUNT_OF_COINS) {
  4125.                     totalCopperDelay += (float)i/(MAX_AMOUNT_OF_COINS*4.5f);
  4126.                 } else {
  4127.                     totalCopperDelay += (float)i/(amountCopperCoins*4.5f);
  4128.                 }
  4129.                
  4130.                
  4131.                 CoinParams coinParams = new CoinParams();
  4132.                 coinParams.amountToAdd = 1;
  4133.                 coinParams.currentList = listaCopper;
  4134.                 coinParams.coinToDestroy = listaCopper[i-1];
  4135.                 coinParams.mustRemoveCurrentList = false;
  4136.                
  4137.                 if (amountCopperCoins <= MAX_AMOUNT_OF_COINS && i == amountCopperCoins) {                  
  4138.                     coinParams.mustRemoveCurrentList = true;
  4139.                 } else {
  4140.                     if (i > MAX_AMOUNT_OF_COINS) {                     
  4141.                         coinParams.amountToAdd = amountCopperCoins - MAX_AMOUNT_OF_COINS;
  4142.                         coinParams.mustRemoveCurrentList = true;
  4143.                     }
  4144.                 }
  4145.                                                
  4146.                 iTween.MoveTo(listaCopper[i-1].gameObject, iTween.Hash(
  4147.                     "position", guiCoin.transform.position + Vector3.forward*-0.5f,
  4148.                     "time", 0.8f,
  4149.                     "delay", totalGoldDelay + totalSilverDelay + totalCopperDelay + 0.5f,
  4150.                     "easetype", iTween.EaseType.easeInOutQuad,
  4151.                     "oncomplete", "addCopperCoins",
  4152.                     "oncompleteparams", coinParams,
  4153.                     "oncompletetarget", this.gameObject
  4154.                 ));
  4155.                
  4156.                 if (i > MAX_AMOUNT_OF_COINS) {
  4157.                         break;
  4158.                 }
  4159.             }
  4160.         }
  4161.        
  4162.                
  4163.     }
  4164.    
  4165.     public void addCoinsFromBuyScreen(int amount, Vector3 posIni, float zeta)
  4166.     {
  4167.         listCashSounds.Clear();
  4168.         listCashSounds.Add((Instantiate(this.sndCashSound1Prefab) as GameObject).GetComponent<AudioSource>());
  4169.         listCashSounds.Add((Instantiate(this.sndCashSound2Prefab) as GameObject).GetComponent<AudioSource>());
  4170.         playFX(listCashSounds);    
  4171.         posIni.Set(posIni.x, posIni.y, zeta);
  4172.         int amountGoldCoins = amount/GOLD_COIN_VALUE;
  4173.         int amountSilverCoins = (amount%GOLD_COIN_VALUE)/SILVER_COIN_VALUE;
  4174.         int amountCopperCoins = ((amount%GOLD_COIN_VALUE)%SILVER_COIN_VALUE)/COPPER_COIN_VALUE;
  4175.        
  4176.         //Vector3 posIni = gameGridSprites[iniY*6+iniX].transform.position + Vector3.right*10f + Vector3.up*-10f + Vector3.forward*-5f;
  4177.         float totalGoldDelay = 0;
  4178.        
  4179.         if (amountGoldCoins > 0) {
  4180.             List<GameObject> listaGold = new List<GameObject>();
  4181.             listGoldCoins.Add(listaGold);
  4182.            
  4183.            
  4184.             for (int i = 1; i <= amountGoldCoins; i++) {
  4185.                 listaGold.Add(Instantiate(goldCoinPrefab as GameObject, posIni, Quaternion.identity) as GameObject);               
  4186.                 if (amountGoldCoins > MAX_AMOUNT_OF_COINS) {
  4187.                     totalGoldDelay += (float)i/(MAX_AMOUNT_OF_COINS*4.5f);
  4188.                 } else {
  4189.                     totalGoldDelay += (float)i/(amountGoldCoins*4.5f);
  4190.                 }
  4191.                
  4192.                 CoinParams coinParams = new CoinParams();
  4193.                 coinParams.amountToAdd = 1;
  4194.                 coinParams.currentList = listaGold;
  4195.                 coinParams.coinToDestroy = listaGold[i-1];
  4196.                 coinParams.mustRemoveCurrentList = false;
  4197.                
  4198.                 if (amountGoldCoins <= MAX_AMOUNT_OF_COINS && i == amountGoldCoins) {
  4199.                    
  4200.                     coinParams.mustRemoveCurrentList = true;
  4201.                 } else {
  4202.                     if (i > MAX_AMOUNT_OF_COINS) {                     
  4203.                         coinParams.amountToAdd = amountGoldCoins - MAX_AMOUNT_OF_COINS;
  4204.                         coinParams.mustRemoveCurrentList = true;
  4205.                     }
  4206.                 }
  4207.                                                
  4208.                 iTween.MoveTo(listaGold[i-1].gameObject, iTween.Hash(
  4209.                     "position", new Vector3(guiCoin.transform.position.x, guiCoin.transform.position.y, zeta),
  4210.                    
  4211.                     "easetype", iTween.EaseType.easeInOutQuad,
  4212.                     "time", 0.8f,
  4213.                     "delay", totalGoldDelay + 0.5f,                
  4214.                     "oncomplete", "addGoldCoins",
  4215.                     "oncompleteparams", coinParams,
  4216.                     "oncompletetarget", this.gameObject
  4217.                 ));
  4218.                
  4219.                 if (i > MAX_AMOUNT_OF_COINS) {
  4220.                         break;
  4221.                 }
  4222.             }                                                                      
  4223.             totalGoldDelay += 0.5f;
  4224.         }      
  4225.        
  4226.        
  4227.         float totalSilverDelay = 0;
  4228.        
  4229.        
  4230.         if (amountSilverCoins > 0) {
  4231.                 List<GameObject> listaSilver = new List<GameObject>();
  4232.                 listSilverCoins.Add(listaSilver);
  4233.             for (int i = 1; i <= amountSilverCoins; i++) {
  4234.                 listaSilver.Add(Instantiate(silverCoinPrefab as GameObject, posIni, Quaternion.identity) as GameObject);
  4235.                
  4236.                 totalSilverDelay += (float)i/(amountSilverCoins*4.5f);
  4237.                
  4238.                 CoinParams coinParams = new CoinParams();
  4239.                 coinParams.amountToAdd = 1;
  4240.                 coinParams.currentList = listaSilver;
  4241.                 coinParams.coinToDestroy = listaSilver[i-1];
  4242.                 coinParams.mustRemoveCurrentList = false;
  4243.                
  4244.                 if (amountSilverCoins <= MAX_AMOUNT_OF_COINS && i == amountSilverCoins) {
  4245.                    
  4246.                     coinParams.mustRemoveCurrentList = true;
  4247.                 } else {
  4248.                     if (i > MAX_AMOUNT_OF_COINS) {                     
  4249.                         coinParams.amountToAdd = amountSilverCoins - MAX_AMOUNT_OF_COINS;
  4250.                         coinParams.mustRemoveCurrentList = true;
  4251.                     }
  4252.                 }
  4253.                
  4254.                 iTween.MoveTo(listaSilver[i-1].gameObject, iTween.Hash(
  4255.                     "position", new Vector3(guiCoin.transform.position.x, guiCoin.transform.position.y, zeta),
  4256.                     "time", 0.8f,
  4257.                     "easetype", iTween.EaseType.easeInOutQuad,
  4258.                     "delay", totalGoldDelay + totalSilverDelay + 0.5f,
  4259.                     "oncomplete", "addSilverCoins",
  4260.                     "oncompleteparams", coinParams,
  4261.                     "oncompletetarget", this.gameObject
  4262.                 ));
  4263.                
  4264.                 if (i > MAX_AMOUNT_OF_COINS) {
  4265.                         break;
  4266.                 }
  4267.             }
  4268.             totalSilverDelay += 0.5f;
  4269.         }
  4270.        
  4271.        
  4272.         float totalCopperDelay = 0;
  4273.         if (amountCopperCoins > 0) {
  4274.             List<GameObject> listaCopper = new List<GameObject>();
  4275.             listCopperCoins.Add(listaCopper);
  4276.            
  4277.             for (int i = 1; i <= amountCopperCoins; i++) {
  4278.                 listaCopper.Add(Instantiate(copperCoinPrefab as GameObject, posIni, Quaternion.identity) as GameObject);
  4279.                 if (amountCopperCoins > MAX_AMOUNT_OF_COINS) {
  4280.                     totalCopperDelay += (float)i/(MAX_AMOUNT_OF_COINS*4.5f);
  4281.                 } else {
  4282.                     totalCopperDelay += (float)i/(amountCopperCoins*4.5f);
  4283.                 }
  4284.                
  4285.                
  4286.                 CoinParams coinParams = new CoinParams();
  4287.                 coinParams.amountToAdd = 1;
  4288.                 coinParams.currentList = listaCopper;
  4289.                 coinParams.coinToDestroy = listaCopper[i-1];
  4290.                 coinParams.mustRemoveCurrentList = false;
  4291.                
  4292.                 if (amountCopperCoins <= MAX_AMOUNT_OF_COINS && i == amountCopperCoins) {                  
  4293.                     coinParams.mustRemoveCurrentList = true;
  4294.                 } else {
  4295.                     if (i > MAX_AMOUNT_OF_COINS) {                     
  4296.                         coinParams.amountToAdd = amountCopperCoins - MAX_AMOUNT_OF_COINS;
  4297.                         coinParams.mustRemoveCurrentList = true;
  4298.                     }
  4299.                 }
  4300.                                                
  4301.                 iTween.MoveTo(listaCopper[i-1].gameObject, iTween.Hash(
  4302.                     "position", new Vector3(guiCoin.transform.position.x, guiCoin.transform.position.y, zeta),
  4303.                     "time", 0.8f,
  4304.                     "delay", totalGoldDelay + totalSilverDelay + totalCopperDelay + 0.5f,
  4305.                     "easetype", iTween.EaseType.easeInOutQuad,
  4306.                     "oncomplete", "addCopperCoins",
  4307.                     "oncompleteparams", coinParams,
  4308.                     "oncompletetarget", this.gameObject
  4309.                 ));
  4310.                
  4311.                 if (i > MAX_AMOUNT_OF_COINS) {
  4312.                         break;
  4313.                 }
  4314.             }
  4315.         }
  4316.        
  4317.                
  4318.     }
  4319.    
  4320. //  private int numGoldCoins = 0;
  4321.     private void addGoldCoins(CoinParams coinParams) {
  4322.         currentGold += coinParams.amountToAdd*GOLD_COIN_VALUE;
  4323.        
  4324. //      numCopperCoins++;      
  4325.         Destroy(coinParams.coinToDestroy);//listCopperCoins[listCopperCoins.Count - 1]);
  4326.         coinParams.currentList.Remove(coinParams.coinToDestroy);//[listCopperCoins.Count - 1]
  4327.         if (coinParams.mustRemoveCurrentList) {
  4328.             listGoldCoins.Remove(coinParams.currentList);
  4329.         }
  4330.        
  4331.     }
  4332.  
  4333. //  private int numSilverCoins = 0;
  4334.     private void addSilverCoins(CoinParams coinParams) {
  4335.         currentGold += coinParams.amountToAdd*SILVER_COIN_VALUE;
  4336. //      numSilverCoins++;
  4337.         Destroy(coinParams.coinToDestroy);//listCopperCoins[listCopperCoins.Count - 1]);
  4338.         coinParams.currentList.Remove(coinParams.coinToDestroy);//[listCopperCoins.Count - 1]
  4339.         if (coinParams.mustRemoveCurrentList) {
  4340.             listSilverCoins.Remove(coinParams.currentList);
  4341.         }
  4342.     }      
  4343.    
  4344.    
  4345. //  private int numCopperCoins = 0;
  4346.     private void addCopperCoins(CoinParams coinParams) {
  4347.         currentGold += coinParams.amountToAdd*COPPER_COIN_VALUE;
  4348.        
  4349.  
  4350.         Destroy(coinParams.coinToDestroy);
  4351.         coinParams.currentList.Remove(coinParams.coinToDestroy);
  4352.         if (coinParams.mustRemoveCurrentList) {
  4353.             listCopperCoins.Remove(coinParams.currentList);
  4354.         }
  4355.  
  4356.     }
  4357.    
  4358.     private void addLastCopperCoin(CoinParams coinParams) {
  4359.         currentGold += coinParams.amountToAdd;//(int)Mathf.Abs(amountCopperCoins - numCopperCoins);    
  4360.         Destroy(coinParams.coinToDestroy);//listCopperCoins[listCopperCoins.Count - 1]);
  4361.         coinParams.currentList.Remove(coinParams.coinToDestroy);
  4362.         listCopperCoins.Remove(coinParams.currentList);
  4363.     }
  4364.    
  4365.    
  4366.        
  4367.     private bool isGameOver() {
  4368.        
  4369.        
  4370.         if (wildCard == (int)PIECE_TYPE.BLACK_HOLE || wildCard == (int)PIECE_TYPE.MAGIC_CRISTAL_GREEN || wildCard == (int)PIECE_TYPE.ROAD
  4371.                 || nextPiece == (int)PIECE_TYPE.BLACK_HOLE || nextPiece == (int)PIECE_TYPE.MAGIC_CRISTAL_GREEN) {
  4372.             return false;
  4373.         } else {
  4374.             for (int i = 0; i < (int)GAME_PROPERTIES.rowLength; i++) {
  4375.                 for (int j = 0; j < (int)GAME_PROPERTIES.rowLength; j++) {
  4376.                     if (i == 0 && j == (int)GAME_PROPERTIES.rowLength - 1) {
  4377.                         continue;
  4378.                     }
  4379.                
  4380.                     if (gameGrid[i,j] == (int)PIECE_TYPE.ROAD) {
  4381.                         return false;
  4382.                     }
  4383.                 }
  4384.             }
  4385.             //si llega hasta aca, gg
  4386.             return true;
  4387.         }
  4388.        
  4389.        
  4390.     }
  4391.    
  4392.  
  4393.     private void initializeMouseColliderHelper ()
  4394.     {
  4395.         for (int aux = 0; aux < 6*6; aux++) {
  4396.  
  4397.             if (this.gameGridSprites[aux].collider == null) {
  4398.                 BoxCollider newCollider = gameGridSprites[aux].gameObject.AddComponent<BoxCollider>();
  4399.                 Vector3 colliderExtents = newCollider.extents;
  4400.                 colliderExtents.z = 0.2f;
  4401.                 newCollider.extents = colliderExtents;
  4402.             }          
  4403.         }
  4404.     }
  4405.  
  4406.     public void initializeArrayConnections ()
  4407.     {
  4408.         connections[10]=1;
  4409.         connections[11]=1;
  4410.         connections[14]=1;
  4411.         connections[15]=1;
  4412.         connections[26]=1;
  4413.         connections[27]=1;
  4414.         connections[30]=1;
  4415.         connections[31]=1;
  4416.        
  4417.         connections[40]=2;
  4418.         connections[44]=2;
  4419.         connections[56]=2;
  4420.         connections[60]=2;
  4421.         connections[104]=2;
  4422.         connections[108]=2;
  4423.         connections[120]=2;
  4424.         connections[124]=2;
  4425.        
  4426.         connections[130]=3;
  4427.         connections[131]=3;
  4428.         connections[134]=3;
  4429.         connections[135]=3;
  4430.         connections[194]=3;
  4431.         connections[195]=3;
  4432.         connections[198]=3;
  4433.         connections[199]=3;
  4434.        
  4435.         connections[160]=4;
  4436.         connections[161]=4;
  4437.         connections[176]=4;
  4438.         connections[177]=4;
  4439.         connections[224]=4;
  4440.         connections[225]=4;
  4441.         connections[240]=4;
  4442.         connections[241]=4;
  4443.        
  4444.         connections[74]=5;
  4445.         connections[75]=5;
  4446.         connections[78]=5;
  4447.         connections[79]=5;
  4448.         connections[90]=5;
  4449.         connections[91]=5;
  4450.         connections[94]=5;
  4451.         connections[95]=5;
  4452.        
  4453.         connections[41]=6;
  4454.         connections[45]=6;
  4455.         connections[57]=6;
  4456.         connections[61]=6;
  4457.         connections[105]=6;
  4458.         connections[109]=6;
  4459.         connections[121]=6;
  4460.         connections[125]=6;
  4461.        
  4462.         connections[164]=7;
  4463.         connections[165]=7;
  4464.         connections[180]=7;
  4465.         connections[181]=7;
  4466.         connections[228]=7;
  4467.         connections[229]=7;
  4468.         connections[244]=7;
  4469.         connections[245]=7;
  4470.        
  4471.         connections[146]=8;
  4472.         connections[147]=8;
  4473.         connections[150]=8;
  4474.         connections[151]=8;
  4475.         connections[210]=8;
  4476.         connections[211]=8;
  4477.         connections[214]=8;
  4478.         connections[215]=8;
  4479.        
  4480.         connections[2]=9;
  4481.         connections[3]=9;
  4482.         connections[6]=9;
  4483.         connections[7]=9;
  4484.        
  4485.         connections[18]=10;
  4486.         connections[19]=10;
  4487.         connections[22]=10;
  4488.         connections[23]=10;
  4489.        
  4490.         connections[66]=11;
  4491.         connections[67]=11;
  4492.         connections[70]=11;
  4493.         connections[71]=11;
  4494.        
  4495.         connections[82]=12;
  4496.         connections[83]=12;
  4497.         connections[86]=12;
  4498.         connections[87]=12;
  4499.        
  4500.         connections[8]=13;
  4501.         connections[12]=13;
  4502.         connections[24]=13;
  4503.         connections[28]=13;
  4504.        
  4505.         connections[9]=14;
  4506.         connections[13]=14;
  4507.         connections[25]=14;
  4508.         connections[29]=14;
  4509.        
  4510.         connections[72]=15;
  4511.         connections[76]=15;
  4512.         connections[88]=15;
  4513.         connections[92]=15;
  4514.        
  4515.         connections[73]=16;
  4516.         connections[77]=16;
  4517.         connections[89]=16;
  4518.         connections[93]=16;
  4519.        
  4520.         connections[32]=17;
  4521.         connections[48]=17;
  4522.         connections[96]=17;
  4523.         connections[112]=17;
  4524.        
  4525.         connections[33]=18;
  4526.         connections[49]=18;
  4527.         connections[97]=18;
  4528.         connections[113]=18;
  4529.        
  4530.         connections[36]=19;
  4531.         connections[52]=19;
  4532.         connections[100]=19;
  4533.         connections[116]=19;
  4534.        
  4535.         connections[37]=20;
  4536.         connections[53]=20;
  4537.         connections[101]=20;
  4538.         connections[117]=20;
  4539.        
  4540.         connections[128]=21;
  4541.         connections[129]=21;
  4542.         connections[192]=21;
  4543.         connections[193]=21;
  4544.        
  4545.         connections[132]=22;
  4546.         connections[133]=22;
  4547.         connections[196]=22;
  4548.         connections[197]=22;
  4549.        
  4550.         connections[144]=23;
  4551.         connections[145]=23;
  4552.         connections[208]=23;
  4553.         connections[209]=23;
  4554.        
  4555.         connections[148]=24;
  4556.         connections[149]=24;
  4557.         connections[212]=24;
  4558.         connections[213]=24;
  4559.     }
  4560.  
  4561.     public void initializeTablaAllAnimations ()
  4562.     {
  4563.         tablaAllAnimations = new Hashtable();
  4564.         tablaAllAnimations.Add((int)PIECE_TYPE.OUT_OF_BOUNDS, "OutOfBounds");
  4565.         tablaAllAnimations.Add((int)PIECE_TYPE.ROAD, "RoadT");     
  4566.         tablaAllAnimations.Add((int)PIECE_TYPE.BUSH, "Bush");
  4567.         tablaAllAnimations.Add((int)PIECE_TYPE.TREE, "Tree");
  4568.         tablaAllAnimations.Add((int)PIECE_TYPE.RUCA, "Ruca_1");
  4569.         tablaAllAnimations.Add((int)PIECE_TYPE.HOME, "Home");
  4570.         tablaAllAnimations.Add((int)PIECE_TYPE.CASTLE, "Castle");              
  4571.         tablaAllAnimations.Add((int)PIECE_TYPE.BUILDING, "Building");
  4572.         tablaAllAnimations.Add((int)PIECE_TYPE.FUTURE_HOME, "Future_Home_1");
  4573.         tablaAllAnimations.Add((int)PIECE_TYPE.FUTURE_HOME_HOVERING, "Future_Home_2");
  4574.         tablaAllAnimations.Add((int)PIECE_TYPE.FUTURE_CITY, "Future_City");
  4575.         tablaAllAnimations.Add((int)PIECE_TYPE.ALIEN_BASIC, "Alien_1");
  4576.         tablaAllAnimations.Add((int)PIECE_TYPE.ALIEN_TELEPORTER, "Alien_2");
  4577.         tablaAllAnimations.Add((int)PIECE_TYPE.MOAI, "Moai_Single");
  4578.         tablaAllAnimations.Add((int)PIECE_TYPE.MOAIS, "Moais_Triple");
  4579.         tablaAllAnimations.Add((int)PIECE_TYPE.STONEHENGE, "Stonehenge");
  4580.         tablaAllAnimations.Add((int)PIECE_TYPE.ROCK, "Rock");
  4581.         tablaAllAnimations.Add((int)PIECE_TYPE.CAVE, "Cave");
  4582.         tablaAllAnimations.Add((int)PIECE_TYPE.DIAMOND, "Diamond");
  4583.         tablaAllAnimations.Add((int)PIECE_TYPE.RUBY, "Ruby");
  4584.         tablaAllAnimations.Add((int)PIECE_TYPE.MAGIC_CRISTAL_PURPLE, "Magic_Cristal_Purple");
  4585.         tablaAllAnimations.Add((int)PIECE_TYPE.MAGIC_CRISTAL_GREEN, "Magic_Cristal_Green");
  4586.         tablaAllAnimations.Add((int)PIECE_TYPE.BLACK_HOLE, "Black_Hole_Icon_A");
  4587.     }
  4588.    
  4589.    
  4590.  
  4591.     public void initializeArrayPieceChance ()
  4592.     {
  4593.         pieceChance = new List<PIECE_TYPE>();
  4594.        
  4595.        
  4596.         addPiecesToChanceList(1, PIECE_TYPE.MAGIC_CRISTAL_PURPLE);
  4597.         addPiecesToChanceList(1, PIECE_TYPE.MAGIC_CRISTAL_GREEN);
  4598.         addPiecesToChanceList(2, PIECE_TYPE.BLACK_HOLE);
  4599.         addPiecesToChanceList(1, PIECE_TYPE.RUCA);
  4600.         addPiecesToChanceList(1, PIECE_TYPE.ALIEN_BASIC);      
  4601.         addPiecesToChanceList(14, PIECE_TYPE.TREE);
  4602.         addPiecesToChanceList(20, PIECE_TYPE.BUSH);
  4603.        
  4604.        
  4605. //               {
  4606. //      (int)PIECE_TYPE.MAGIC_CRISTAL_PURPLE
  4607. //      ,(int)PIECE_TYPE.BUSH
  4608. //      ,(int)PIECE_TYPE.BUSH
  4609. //      ,(int)PIECE_TYPE.BUSH
  4610. //      ,(int)PIECE_TYPE.BUSH
  4611. //      ,(int)PIECE_TYPE.BUSH
  4612. //      ,(int)PIECE_TYPE.MAGIC_CRISTAL_GREEN
  4613. //      ,(int)PIECE_TYPE.BUSH
  4614. //      ,(int)PIECE_TYPE.BUSH
  4615. //      ,(int)PIECE_TYPE.ALIEN_BASIC
  4616. //      ,(int)PIECE_TYPE.ALIEN_BASIC
  4617. //      ,(int)PIECE_TYPE.BUSH
  4618. //      ,(int)PIECE_TYPE.BUSH
  4619. //      ,(int)PIECE_TYPE.BUSH
  4620. //      ,(int)PIECE_TYPE.ALIEN_BASIC
  4621. //      ,(int)PIECE_TYPE.ALIEN_BASIC
  4622. //      ,(int)PIECE_TYPE.BUSH
  4623. //      ,(int)PIECE_TYPE.BUSH
  4624. //      ,(int)PIECE_TYPE.BUSH
  4625. //      ,(int)PIECE_TYPE.TREE
  4626. //      ,(int)PIECE_TYPE.BUSH
  4627. //      ,(int)PIECE_TYPE.BUSH
  4628. //      ,(int)PIECE_TYPE.ALIEN_TELEPORTER
  4629. //      ,(int)PIECE_TYPE.BUSH
  4630. //      ,(int)PIECE_TYPE.BUSH
  4631. //      ,(int)PIECE_TYPE.TREE
  4632. //      ,(int)PIECE_TYPE.BUSH
  4633. //      ,(int)PIECE_TYPE.BUSH
  4634. //      ,(int)PIECE_TYPE.BLACK_HOLE
  4635. //      ,(int)PIECE_TYPE.BLACK_HOLE
  4636. //      ,(int)PIECE_TYPE.BUSH
  4637. //      ,(int)PIECE_TYPE.BUSH
  4638. //      ,(int)PIECE_TYPE.TREE
  4639. //      ,(int)PIECE_TYPE.BUSH
  4640. //      ,(int)PIECE_TYPE.BUSH
  4641. //      ,(int)PIECE_TYPE.ALIEN_BASIC
  4642. //      ,(int)PIECE_TYPE.ALIEN_BASIC
  4643. //      ,(int)PIECE_TYPE.TREE
  4644. //      ,(int)PIECE_TYPE.TREE
  4645. //      ,(int)PIECE_TYPE.TREE
  4646. //      ,(int)PIECE_TYPE.TREE
  4647. //      ,(int)PIECE_TYPE.TREE
  4648. //      ,(int)PIECE_TYPE.TREE
  4649. //      ,(int)PIECE_TYPE.ALIEN_TELEPORTER
  4650. //      ,(int)PIECE_TYPE.ALIEN_TELEPORTER
  4651. //      ,(int)PIECE_TYPE.ALIEN_TELEPORTER
  4652. //      ,(int)PIECE_TYPE.TREE
  4653. //      ,(int)PIECE_TYPE.TREE
  4654. //      ,(int)PIECE_TYPE.TREE
  4655. //      ,(int)PIECE_TYPE.ALIEN_BASIC
  4656. //      ,(int)PIECE_TYPE.ALIEN_BASIC
  4657. //      ,(int)PIECE_TYPE.RUCA
  4658. //      ,(int)PIECE_TYPE.RUCA
  4659. //      ,(int)PIECE_TYPE.MAGIC_CRISTAL_GREEN
  4660. //              };
  4661.     }
  4662.    
  4663.     private void addPiecesToChanceList(int amount, PIECE_TYPE pieza) {
  4664.         if (amount <= 0) {
  4665.             return;
  4666.         }
  4667.        
  4668.         for (int i = 0; i < amount; i++) {
  4669.             pieceChance.Add(pieza);
  4670.         }
  4671.        
  4672.     }
  4673.  
  4674.     public void initializeTablaScorePerPiece ()
  4675.     {
  4676.         tablaScorePerPiece = new Hashtable();              
  4677.         tablaScorePerPiece.Add(PIECE_TYPE.ROAD, 0);
  4678.         tablaScorePerPiece.Add(PIECE_TYPE.BUSH, 5);
  4679.         tablaScorePerPiece.Add(PIECE_TYPE.TREE, 10);
  4680.         tablaScorePerPiece.Add(PIECE_TYPE.RUCA, 15);
  4681.         tablaScorePerPiece.Add(PIECE_TYPE.HOME, 20);
  4682.         tablaScorePerPiece.Add(PIECE_TYPE.CASTLE, 25);             
  4683.         tablaScorePerPiece.Add(PIECE_TYPE.BUILDING, 30);
  4684.         tablaScorePerPiece.Add(PIECE_TYPE.FUTURE_HOME, 35);
  4685.         tablaScorePerPiece.Add(PIECE_TYPE.FUTURE_HOME_HOVERING, 40);
  4686.         tablaScorePerPiece.Add(PIECE_TYPE.FUTURE_CITY, 45);
  4687.        
  4688.         tablaScorePerPiece.Add(PIECE_TYPE.ALIEN_BASIC, 0);
  4689.         tablaScorePerPiece.Add(PIECE_TYPE.ALIEN_TELEPORTER, 0);
  4690.         tablaScorePerPiece.Add(PIECE_TYPE.BLACK_HOLE, 0);
  4691.        
  4692.         tablaScorePerPiece.Add(PIECE_TYPE.MOAI, 65);
  4693.         tablaScorePerPiece.Add(PIECE_TYPE.MOAIS, 70);
  4694.         tablaScorePerPiece.Add(PIECE_TYPE.STONEHENGE, 75);
  4695.         tablaScorePerPiece.Add(PIECE_TYPE.ROCK, 90);
  4696.         tablaScorePerPiece.Add(PIECE_TYPE.CAVE, 100);
  4697.         tablaScorePerPiece.Add(PIECE_TYPE.DIAMOND, 90);
  4698.         tablaScorePerPiece.Add(PIECE_TYPE.RUBY, 100);
  4699.         tablaScorePerPiece.Add(PIECE_TYPE.MAGIC_CRISTAL_PURPLE, 90);
  4700.         tablaScorePerPiece.Add(PIECE_TYPE.MAGIC_CRISTAL_GREEN, 100);
  4701.     }
  4702.    
  4703.     public void initializeTablaBuyForCoinsValue() {
  4704.         tablaBuyForCoinsValue = new Hashtable();
  4705.        
  4706.         tablaBuyForCoinsValue.Add(PIECE_TYPE.BUSH, 50);
  4707.         tablaBuyForCoinsValue.Add(PIECE_TYPE.TREE, 100);
  4708.         tablaBuyForCoinsValue.Add(PIECE_TYPE.RUCA, 200);
  4709.         tablaBuyForCoinsValue.Add(PIECE_TYPE.MAGIC_CRISTAL_GREEN, 600);
  4710.         tablaBuyForCoinsValue.Add(PIECE_TYPE.MAGIC_CRISTAL_PURPLE, 1500);
  4711.         tablaBuyForCoinsValue.Add(PIECE_TYPE.BLACK_HOLE, 1500);
  4712.        
  4713.     }
  4714.    
  4715.     public void initializeTablaSellForCoinsValue() {
  4716.         tablaSellForCoinsValue = new Hashtable();
  4717.         tablaSellForCoinsValue.Add(PIECE_TYPE.ROAD, 1);
  4718.         tablaSellForCoinsValue.Add(PIECE_TYPE.BUSH, 1);
  4719.         tablaSellForCoinsValue.Add(PIECE_TYPE.TREE, 2);
  4720.         tablaSellForCoinsValue.Add(PIECE_TYPE.RUCA, 4);
  4721.         tablaSellForCoinsValue.Add(PIECE_TYPE.HOME, 8);
  4722.         tablaSellForCoinsValue.Add(PIECE_TYPE.CASTLE, 16);             
  4723.         tablaSellForCoinsValue.Add(PIECE_TYPE.BUILDING, 32);
  4724.         tablaSellForCoinsValue.Add(PIECE_TYPE.FUTURE_HOME, 64);
  4725.         tablaSellForCoinsValue.Add(PIECE_TYPE.FUTURE_HOME_HOVERING, 128);
  4726.         tablaSellForCoinsValue.Add(PIECE_TYPE.FUTURE_CITY, 256);
  4727.        
  4728.         tablaSellForCoinsValue.Add(PIECE_TYPE.ALIEN_BASIC, 1);
  4729.         tablaSellForCoinsValue.Add(PIECE_TYPE.ALIEN_TELEPORTER, 2);            
  4730.         tablaSellForCoinsValue.Add(PIECE_TYPE.MOAI, 3);
  4731.         tablaSellForCoinsValue.Add(PIECE_TYPE.MOAIS, 4);
  4732.         tablaSellForCoinsValue.Add(PIECE_TYPE.STONEHENGE, 5);
  4733.         tablaSellForCoinsValue.Add(PIECE_TYPE.ROCK, 150);
  4734.         tablaSellForCoinsValue.Add(PIECE_TYPE.CAVE, 250);
  4735.         tablaSellForCoinsValue.Add(PIECE_TYPE.DIAMOND, 1500);
  4736.         tablaSellForCoinsValue.Add(PIECE_TYPE.RUBY, 2000);     
  4737.     }
  4738.    
  4739. //  private Hashtable tablaDemoCases;
  4740. //  public void initializeTablaDemoCases() {
  4741. //      initializeTablaDemoCases = new Hashtable();
  4742. //      int[,] casoVacio = new int[6,6]();
  4743. //     
  4744. //  }
  4745.    
  4746.     public void initializeMoaiIndexes() {
  4747.         //listMoaiIndexes.Clear();
  4748.         for (int i = 0; i < (int)GAME_PROPERTIES.rowLength; i++) {
  4749.             for (int j = 0; j < (int)GAME_PROPERTIES.columnLength; j++) {
  4750.                 if (i != 0 && j != (int)GAME_PROPERTIES.columnLength - 1) {
  4751.                     if (gameGrid[i,j] == (int)PIECE_TYPE.MOAI && !listMoaiIndexes.Contains(j*6+i)) {
  4752.                         listMoaiIndexes.Add(j*6+i);
  4753.                     }
  4754.                 }
  4755.             }
  4756.         }
  4757.     }
  4758.  
  4759.     public void showNextPieceInSelectorAndGui(int pieceToShow)
  4760.     {
  4761.         this.selectorNextPiece.Play((string)tablaAllAnimations[pieceToShow]);
  4762.         ufoNextPiece.Play (ufoNextPiece.GetClipIdByName((string)tablaAllAnimations[pieceToShow]));//.spriteId = ufoNextPiece.collection.GetSpriteIdByName((string)tablaAllAnimations[pieceToShow]);
  4763.         if (pieceToShow == (int)PIECE_TYPE.BUSH || pieceToShow == (int)PIECE_TYPE.ROCK) {          
  4764.             ufoNextPiece.transform.position = ufoNextPieceOriginPos + Vector3.up*5f;
  4765.         } else {
  4766.             ufoNextPiece.transform.position = ufoNextPieceOriginPos;               
  4767.         }
  4768.     }
  4769.    
  4770.     public List<Vector2> getListaRucasAndCavesPostions() {
  4771.         List<Vector2> listaRetorno = new List<Vector2>();
  4772.         for (int i = 0; i < (int)GAME_PROPERTIES.rowLength; i++) {
  4773.             for (int j = 0; j < (int)GAME_PROPERTIES.columnLength; j++) {
  4774.                 if (gameGrid[i,j] == (int)PIECE_TYPE.RUCA || gameGrid[i,j] == (int)PIECE_TYPE.CAVE || gameGrid[i,j] == (int)PIECE_TYPE.HOME) {
  4775.                 Vector2 vectorAprox = (Vector2)gamePiecesAnimations[j*6 + i].transform.position;
  4776.                 vectorAprox.Set((float)((int)vectorAprox.x), (float)((int)vectorAprox.y));
  4777.                 listaRetorno.Add(vectorAprox);
  4778.             }
  4779.         }
  4780.        
  4781.            
  4782.            
  4783.         }
  4784.         return listaRetorno;
  4785.     }
  4786.    
  4787.     public List<Vector2> getListaHomesOrCastlesPostions() {
  4788.         List<Vector2> listaRetorno = new List<Vector2>();
  4789.         for (int i = 0; i < (int)GAME_PROPERTIES.rowLength; i++) {
  4790.             for (int j = 0; j < (int)GAME_PROPERTIES.columnLength; j++) {
  4791.                 if (gameGrid[i,j] == (int)PIECE_TYPE.HOME || gameGrid[i,j] == (int)PIECE_TYPE.CASTLE
  4792.                     || gameGrid[i,j] == (int)PIECE_TYPE.FUTURE_HOME || gameGrid[i,j] == (int)PIECE_TYPE.FUTURE_HOME_HOVERING ) {
  4793.                 Vector2 vectorAprox = (Vector2)gamePiecesAnimations[j*6 + i].transform.position;
  4794.                 vectorAprox.Set((float)((int)vectorAprox.x), (float)((int)vectorAprox.y));
  4795.                 listaRetorno.Add(vectorAprox);
  4796.             }
  4797.         }
  4798.        
  4799.            
  4800.            
  4801.         }
  4802.         return listaRetorno;
  4803.     }
  4804.            
  4805.  
  4806.     public void printGameGrid ()
  4807.     {
  4808.         string testMatrix = "";
  4809.             for(int j=(int)GAME_PROPERTIES.columnLength - 1; j > -1; j--)
  4810.             {
  4811.                 for(int i=0; i < (int)GAME_PROPERTIES.rowLength; i++)
  4812.                 {                      
  4813.                     testMatrix += gameGrid[i,j].ToString() + " ";                      
  4814.                    
  4815.                 }
  4816.                 testMatrix += "\n";
  4817.             }
  4818.             Debug.Log(testMatrix);
  4819.     }
  4820. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement