Exemplo n.º 1
0
 public void GiveMoneyTo(EventSelector eventSelector)
 {
     eventSelector.GiveMoney(mGameDifficulty * 3);
 }
Exemplo n.º 2
0
        public List <GameEvent>[] Assemble(LinkedList <GameEvent> mGameEventList, int tubeCapacity)
        {
            if (mGameEventList.Count == 0)
            {
                return(null);
            }

            EventSelector selector = EventSelector.Instance;

            Debug.unityLogger.Log(TAG, string.Format("Event Assembler now has {0} money", selector.GetMoney()));

            int maxCost = GetMaxCost(mGameEventList);


            //return null;

            selector.GiveMoney(maxCost);

            Debug.unityLogger.Log(TAG, string.Format("Event Assembler now has {0} money", selector.GetMoney()));

            //collect gameEvents from the bank
            FisherYatesShuffle.Shuffle(mGameEventList);

            //Choose one random game event
            LinkedList <GameEvent> .Enumerator enumarator = mGameEventList.GetEnumerator();
            enumarator.MoveNext();

            //Iterate the list until we find an event we can buy
            int    cost = enumarator.Current.GetCost();
            string name = enumarator.Current.mName;

            while (selector.GetMoney() < cost)
            {
                //This means we couldn't find any GameEvent
                if (!enumarator.MoveNext())
                {
                    return(null);
                }

                cost = enumarator.Current.GetCost();
            }

            //--Initialize the result array
            List <GameEvent>[] gameEventsListArray = new List <GameEvent> [ApplicationConstants.NumberOfScenes];
            for (int i = 0; i < ApplicationConstants.NumberOfScenes; i++)
            {
                gameEventsListArray[i] = new List <GameEvent>();
            }

            //List<GameEvent> gEvents = new List<GameEvent>();

            List <int> scenesLeft = new List <int>()
            {
                1, 2, 3
            };

            int selectedScene = UnityEngine.Random.Range(0, ApplicationConstants.NumberOfScenes);

            scenesLeft.Remove(selectedScene);

            GameEvent gEventFirst = enumarator.Current;

            gEventFirst.SetScene(selectedScene);
            gameEventsListArray[selectedScene].Add(gEventFirst);
            selector.ChargeMoney(cost);

            string gameEventType = gEventFirst.GetEventType();

            Debug.unityLogger.Log(TAG, string.Format("Event Assembler bought {0} that cost {1} of type {2}, it was" +
                                                     "deployed to scene {3}", name, cost, gameEventType, selectedScene));

            //enumarator.MoveNext();
            mGameEventList.Remove(gEventFirst);

            //Move current to first node
            //GameEvent currentGEvent = gEventFirst;

            //Populate the remaining scenes list



            //scenesLeft.AddLast(0);
            //scenesLeft.AddLast(1);
            //scenesLeft.AddLast(2);

            //Shuffle the last to generate randomness
            //FisherYatesShuffle.Shuffle(scenesLeft);

            //Draw a random scene
            //int currScene = scenesLeft.Last.Value;
            //scenesLeft.RemoveLast();
            //gEventFirst.SetScene(selectedScene);

            //Release variables for an additional use
            //enumarator.Dispose() ;
            //cost = -1;

            //Get list enumarator
            //enumarator = mGameEventList.GetEnumerator();
            //enumarator.MoveNext();

            bool cantFind    = false;
            bool isReady     = false;
            int  guessesLeft = 2;

            int count0 = 0;
            int count1 = 0;
            int count2 = 0;

            GameEvent gEventInspected;

            float random = UnityEngine.Random.Range(0f, 1f);

            enumarator = mGameEventList.GetEnumerator();
            enumarator.MoveNext();

            //iterate the list looking for a matching puzzle piece that is also
            while (guessesLeft > 0 && random < .7f && scenesLeft.Count > 0 && ++count1 != 100)
            {
                if (count1 == 9)
                {
                    Debug.Log("help");
                }
                guessesLeft--;

                gEventInspected = enumarator.Current;
                cost            = gEventInspected.GetCost();
                name            = gEventInspected.mName;
                gameEventType   = gEventInspected.GetEventType();

                Debug.unityLogger.Log(TAG, string.Format("Event Assembler got a chance to buy"));


                //Update current Event
                //currentGEvent = gEventInspected;

                if (selector.GetMoney() >= cost)
                {
                    //Random if should add to scene ot change to a different one
                    random = UnityEngine.Random.Range(0f, 1f);
                    if (random > .5f)
                    {
                        selectedScene = mod((selectedScene + 1), ApplicationConstants.NumberOfScenes);
                        scenesLeft.Remove(selectedScene);
                    }
                    gEventInspected.SetScene(selectedScene);

                    selector.ChargeMoney(cost);

                    //Debug.unityLogger.Log(TAG, string.Format("Event Assembler bought {0} that cost {1} of type {2}", name, cost, gameEventType));

                    Debug.unityLogger.Log(TAG, string.Format("Event Assembler bought {0} that cost {1} of type {2}, it was" +
                                                             "deployed to scene {3}", name, cost, gameEventType, selectedScene));

                    gameEventsListArray[selectedScene].Add(gEventInspected);
                }

                enumarator.MoveNext();

                //attach the pieces together
                //currentGEvent.Attach(gEventInspected);



                random = UnityEngine.Random.Range(0f, 1f);

                //Update Current Scene



                ////Populate the Remaining moves left
                //LinkedList<AttachmentType> attachmentList
                //    = PopulateAttachmentsList(currScene, scenesLeft);

                ////Shuffle the moves list to generate randomnes
                //FisherYatesShuffle.Shuffle(attachmentList);

                ////Draw a random move
                //AttachmentType attachment = attachmentList.Last.Value;
                //attachmentList.RemoveLast();



                //    if (GameEventRules.IsValidCombination(currentGEvent, gEventInspected, attachment))
                //    {
                //        //Update Current Scene
                //        currScene = GetSceneAfterAttachment(currScene, attachment);

                //        //attach the pieces together
                //        currentGEvent.Attach(attachment, gEventInspected);
                //        mGameEventList.Remove(gEventInspected);

                //        //Charge for attachment
                //        money -= cost;
                //        tubeCapacity -= cost;

                //        //Update current Event
                //        currentGEvent = gEventInspected;
                //        currentGEvent.SetScene(currScene);

                //        //Restarting the enumarator
                //        enumarator = mGameEventList.GetEnumerator();
                //        enumarator.MoveNext();


                //        break;
                //    }

                //    //Draw a random move
                //    attachment = attachmentList.Last.Value;
                //    attachmentList.RemoveLast();


                //}
                //if (!enumarator.MoveNext())
                //{
                //    cantFind = true;
                //    break;
                //}
            }
            Debug.unityLogger.Log(TAG, string.Format("Event Assembler now has {0} money", selector.GetMoney()));

            //return the combined piece
            return(gameEventsListArray);
        }