Example #1
0
        // Click handler
        public void ClickHandler()
        {
            // toggle the type of cell in the block through the bacTypes
            currentType++;
            if (bacTypes.Length <= currentType)
            {
                currentType = 0;
            }

            // Load the type
            // export the array
            // Get rid of the last spawned item
            if (LastSpawned)
            {
                DestroyImmediate(LastSpawned);
            }

            LastSpawned = Instantiate(bacTypes [currentType]) as GameObject;
            if (LastSpawned)
            {
                currentBacteria = LastSpawned.GetComponent <Bacteria> ();
                // add the row/col to the bacteria data
                currentBacteria.row = (int)row;
                currentBacteria.col = (int)col;

                // Add the bacteria to the quorum
                qc.AddBacteria(currentBacteria);
            }

            // Set the values in the display
            SetValues();
        }
Example #2
0
        // Add bacteria to quorum
        public void AddBacteria(Bacteria bacteria)
        {
            if (bacs == null || bacteria == null)
            {
                return;
            }

            bacs[bacteria.row, bacteria.col] = bacteria;

            Debug.Log("Add bacteria at position" + bacteria.row + bacteria.col);

            if (notificationText != null)
            {
                if (bacteria.funFacts != null && bacteria.funFacts.Length != 0)
                {
                    notificationText.text = bacteria.Name + ":   " + bacteria.funFacts [Random.Range(0, bacteria.funFacts.Length - 1)];
                }
                else
                {
                    notificationText.text = bacteria.Name + ":   " + bacteria.Description;
                }
            }
            ComputeQuorumValue();
            UpdateCanvas();
        }
Example #3
0
        private bool isAlone(Bacteria bac)
        {
            // If there's a non null item in a row that is the same and 1 col away from col
            // return true;

            // If there's a non null item in a col that is the same and 1 row away from row
            // return true;

            return(false);
        }
Example #4
0
        public void BacteriaKilled(Bacteria killed)
        {
            // remove the bacteria specified
            bacs[killed.col, killed.row] = null;

            // Examine each bacs and make sure it's connected to other bacteria
            // if it isn't, then destroy it
            foreach (Bacteria bac in bacs)
            {
                if (isAlone(bac))
                {
                    bac.GetComponent <Health> ().Kill();
                }
            }
        }
Example #5
0
        void OnCollisionEnter(Collision col)
        {
            Debug.Log("collision" + col.collider.name);
            // Get the bacteria of the collision
            Bacteria colBac = col.collider.gameObject.GetComponent <Bacteria>();

            if (colBac != null && colBac.eatRatio > 0)
            {
                Debug.Log("bacteria" + colBac.Name);
                colBac.Feed(value);
                Destroy(gameObject, 2);
                if (replacement != null)
                {
                    replacement.SetActive(true);
                    replacement.transform.parent = null;
                }
                gameObject.SetActive(false);
            }
        }
Example #6
0
        public void Start()
        {
            // get the quorum controller
            qc = FindObjectOfType <QuorumController>();

            // Load the type
            GameObject gm = bacTypes [currentType];

            if (gm)
            {
                currentBacteria = gm.GetComponent <Bacteria> ();
            }

            // add the row/col to the bacteria data
            currentBacteria.row = row;
            currentBacteria.col = col;

            // Set the values in the display
            SetValues();

            // Add the bacteria to the quorum
            qc.AddBacteria(currentBacteria);
        }
Example #7
0
        private void FeedBacteria(int row, int col, float food)
        {
            // Get the bacteria at the coordinates
            Bacteria bac = bacs[row, col];

            // Feed it the food
            Health bacHealth = bac.GetComponent <Health>();

            if (bacHealth && bacHealth.current < bacHealth.max)
            {
                bacHealth.Heal(food);
                food -= bacHealth.max - bacHealth.current;
            }

            // If there's still more food, spread it according to the Bacteria resourceSpread
            // We only want to propagate food away from here

            // If there's a non null item in a row that is the same and resourceSpread col away from col
            // return true;

            // If there's a non null item in a col that is the same and resourceSpread row away from row
            // return true;
        }