예제 #1
0
 private BubbleController controllerForBubble(Bubble bubble)
 {
     foreach (BubbleController bubbleController in this._bubbleControllers)
     {
         if (bubbleController.bubble == bubble)
         {
             return(bubbleController);
         }
     }
     return(null);
 }
예제 #2
0
 /*
  * Returns the location of a bubble in the matrix
  * @param {Bubble} bubble
  */
 public Vector2 location(Bubble bubble)
 {
     for (int i = 0; i < this._rows; i++)
     {
         for (int j = 0; j < this._columns; j++)
         {
             Bubble someBubble = this._bubbleMatrix[i, j];
             if (bubble == someBubble)
             {
                 return(new Vector2(i, j));
             }
         }
     }
     return(new Vector2(-1, -1));
 }
예제 #3
0
        /*
         * Backtrackng recursive function that obtains the cluster of bubble
         * which share the same color for a given location
         */
        private ArrayList colorClusterRecursive(Bubble bubble, ArrayList visited)
        {
            ArrayList similarColorNeighbours = JQUtils.FilterByColor(this.neighbours(bubble), bubble.color);

            similarColorNeighbours.Exclusive(visited);
            visited.Add(bubble);
            ArrayList returnArray = new ArrayList();

            returnArray.Add(bubble);
            foreach (Bubble aBubble in similarColorNeighbours)
            {
                if (bubble != aBubble)
                {
                    returnArray.AddRange(colorClusterRecursive(aBubble, visited));
                }
            }
            return(returnArray);
        }
예제 #4
0
        private ArrayList connectedBubblesRecursive(Bubble bubble, ArrayList visited, bool isBasedAlignedLeft)
        {
            ArrayList neighboursNotVisited = this.neighbours(bubble);

            neighboursNotVisited.Exclusive(visited);
            //neighboursNotVisited.Remove(bubble);
            visited.Add(bubble);
            ArrayList returnArray = new ArrayList();

            returnArray.Add(bubble);
            foreach (Bubble someBubble in neighboursNotVisited)
            {
                if (bubble != someBubble)
                {
                    returnArray.AddRange(connectedBubblesRecursive(someBubble, visited, isBasedAlignedLeft));
                }
            }
            return(returnArray);
        }
예제 #5
0
 private ArrayList connectedBubbles(Bubble bubble)
 {
     return(connectedBubblesRecursive(bubble, new ArrayList(), isBaselineAlignedLeft));
 }
예제 #6
0
 /*
  * Returns the cluster of connected similar colored bubble for a given bubble
  * @param {Bubble} bubble
  * @return {ArrayList}
  */
 public ArrayList colorCluster(Bubble bubble)
 {
     return(colorClusterRecursive(bubble, new ArrayList()).Distinct());
 }
예제 #7
0
 /*
  * Returns the neighbours of a given bubble
  * @param {Bubble} bubble
  * @return {ArrayList}
  */
 public ArrayList neighbours(Bubble bubble)
 {
     return(neighbours(location(bubble)));
 }
		/*
		 * Returns the neighbours of a given bubble
		 * @param {Bubble} bubble
		 * @return {ArrayList}
		 */
		public ArrayList neighbours(Bubble bubble){
			return neighbours(location(bubble));
		}
		/*
		 * Removes a bubble of the matrix if this exists
		 * @param {Bubble} bubble
		 */
		public void remove(Bubble bubble){
			Vector2 location = this.location(bubble);
			if ((int)location.x > -1 && (int)location.y > -1)
				this.remove((int)location.x, (int)location.y);
		}
		/*
		 * Backtrackng recursive function that obtains the cluster of bubble
		 * which share the same color for a given location
		 */
		private ArrayList colorClusterRecursive(Bubble bubble, ArrayList visited){		
			ArrayList similarColorNeighbours = JQUtils.FilterByColor(this.neighbours(bubble), bubble.color);
			similarColorNeighbours.Exclusive(visited);
			visited.Add(bubble);
			ArrayList returnArray = new ArrayList();
			returnArray.Add(bubble);
			foreach (Bubble aBubble in similarColorNeighbours){
				if (bubble != aBubble)
					returnArray.AddRange(colorClusterRecursive(aBubble, visited));
			}
			return returnArray;
		}
		/*
		 * Inserts a bubble into the bubble matrix
		 * @param {Int,Int} location
		 */
		public void insert(Bubble bubble, int x, int y){
			if (x < 0 || x > this._rows -1 || y < 0 || y > this._columns -1)
				throw new System.ArgumentException("Adding Bubble to ilegal coordinates");
			
			this._bubbleMatrix[x,y] = bubble;
		}
		private ArrayList connectedBubblesRecursive(Bubble bubble, ArrayList visited, bool isBasedAlignedLeft){
			ArrayList neighboursNotVisited = this.neighbours(bubble);
			neighboursNotVisited.Exclusive(visited);
			//neighboursNotVisited.Remove(bubble);
			visited.Add(bubble);
			ArrayList returnArray = new ArrayList();
			returnArray.Add(bubble);
			foreach (Bubble someBubble in neighboursNotVisited){
				if (bubble != someBubble)
					returnArray.AddRange(connectedBubblesRecursive(someBubble, visited, isBasedAlignedLeft));
			}
			return returnArray;
		}
		private ArrayList connectedBubbles(Bubble bubble){
			return connectedBubblesRecursive(bubble, new ArrayList(), isBaselineAlignedLeft);	
		}
		/*
		 * Returns the cluster of connected similar colored bubble for a given bubble
		 * @param {Bubble} bubble
		 * @return {ArrayList}
		 */
		public ArrayList colorCluster(Bubble bubble){
			return colorClusterRecursive(bubble, new ArrayList()).Distinct();
		}
 void Awake()
 {
     bubble = new Bubble(JQUtils.GetRandomEnum <BubbleColor>());
 }
		void Awake(){
			bubble = new Bubble(JQUtils.GetRandomEnum<BubbleColor>());
		}
		private BubbleController controllerForBubble(Bubble bubble){
			foreach (BubbleController bubbleController in this._bubbleControllers){
				if (bubbleController.bubble == bubble)
					return bubbleController;
			}
			return null;
		}
		/*
		 * Returns the location of a bubble in the matrix
		 * @param {Bubble} bubble
		 */
		public Vector2 location(Bubble bubble){
			for (int i = 0 ; i< this._rows; i++)
			{
				for (int j = 0; j< this._columns; j++){
					Bubble someBubble = this._bubbleMatrix[i,j];
					if (bubble == someBubble){
						return new Vector2(i, j);
					}
				}				
			}
			return new Vector2(-1,-1);
		}