示例#1
0
 void ShuffleInputs(ShuffleBag <Command> bag)
 {
     //ideally this should work with the pointers?
     //as is it works with a predefined set
     //maybe this can be a use for enums
     buttonW = bag.Next();
     buttonA = bag.Next();
     buttonS = bag.Next();
     buttonD = bag.Next();
     UpdateUI();
 }
示例#2
0
        public PoolManager(Transform container, int size, bool autoReuse, bool autoResize, T[] prefabs, params int[] prefabsShuffleBag)
        {
            _autoReuse  = autoReuse;
            _autoResize = autoResize;
            _pool       = new List <T>();
            _active     = new List <T>();

            _container = container;
            T[] children = _container.GetComponentsInChildren <T>();
            foreach (T child in children)
            {
                child.Init();
                _pool.Add(child);
            }

            if (_pool.Count < size && prefabs != null && prefabs.Length > 0 && prefabs[0] != null)
            {
                ShuffleBag <int> bag = new ShuffleBag <int>();
                for (int i = 0; i < prefabs.Length; i++)
                {
                    bag.Add(i, prefabsShuffleBag.Length > i ? prefabsShuffleBag[i] : 1);
                }

                int attempts = size + 200;
                while (_pool.Count < size && attempts > 0)
                {
                    T prefab = prefabs[bag.Next()];
                    if (prefab != null)
                    {
                        T newPoolObject = GameObject.Instantiate(prefabs[bag.Next()]) as T;
                        if (newPoolObject != null)
                        {
                            newPoolObject.transform.SetParent(container);
                            newPoolObject.Init();
                            _pool.Add(newPoolObject);
                        }
                        else
                        {
                            attempts--;
                        }
                    }
                    else
                    {
                        attempts--;
                    }
                }

                bag.Clear();
                bag = null;
            }

            prefabs = null;
        }
 void SetNextCard()
 {
     nextCard = deck.Next();
     nextCardObj.GetComponentInChildren <Text>().text        = GetNumberString(nextCard);
     nextCardObj.GetComponentsInChildren <Image>()[1].sprite = GetSuitSprite(nextCard);
     //print("Next: " + nextCard.suit + " " + nextCard.cardNum);
 }
示例#4
0
    IEnumerator resetGame(float numEndJuiceBubbles)
    {
        ShuffleBag <int> juiceAreas = new ShuffleBag <int>();

        juiceAreas.Add(0, 1);
        juiceAreas.Add(1, 1);
        juiceAreas.Add(2, 1);
        juiceAreas.Add(3, 1);
        yield return(new WaitForSeconds(2f));

        for (int i = 0; i < numEndJuiceBubbles; i++)
        {
            addRainbow(juiceAreas.Next());
            Services.Audio.PlaySoundEffect(Services.Clips.EndGamePop[Random.Range(0, Services.Clips.EndGamePop.Length)], 0.7f);
            yield return(new WaitForSeconds(.33f));
        }
        yield return(new WaitForSeconds(1f));

        addRainbow(4);
        Services.Audio.PlaySoundEffect(Services.Clips.EndGamePop[Random.Range(0, Services.Clips.EndGamePop.Length)], 0.7f);
        yield return(new WaitForSeconds(3f));

        SceneManager.LoadScene(SceneManager.GetActiveScene().name);
        yield return(null);
    }
示例#5
0
    public void Attack()
    {
        string result = "";      //var for result

        if (useBag)              //if we're using the bag
        {
            result = bag.Next(); //get the next result from the bag
        }
        else //otherwise
        {
            result = "Miss!";                   //make the result a miss

            float rando = Random.Range(0f, 1f); //get random float between 0-1

            print("random num: " + rando);      //print random num

            if (rando <= successChance)         //if the random num is lower than success %
            {
                result = "Hit!";                //change to a hit
            }
        }

        if (prevResult == result) //if the result is the same as the last one
        {
            streak++;             //increase streak
        }
        else //otherwise
        {
            streak = 1; //reset streak
        }

        prevResult = result;                                                  //set prevResult to the new result

        attackText.text = "Attack Result :" + result + "\nStreak: " + streak; //update display
    }
示例#6
0
        // Setup the wall of cubes: 10x10 cubes on top of the T bar in the middle of the game area
        public void SetupWall()
        {
            // Create wall of cubes using the Shufflebag to get 50x green and 50x red cubes
            // Each integer in the Shufflebag represents a green (0) or red (1) cube
            // Usign the Shufflebag we know for sure that the number of green and red cubes is the same while the distribution is random.
            allCubes = new ShuffleBag(100);
            allCubes.Add(0, 50);    // Add 50x Green
            allCubes.Add(1, 50);    // Add 50x Red

            for (int y = 0; y < 10; y++)
            {
                for (int z = 0; z < 10; z++)
                {
                    // The position on top of the T bar where the cube will be instantiated
                    Vector3 pos = new Vector3(startX, startY + y, startZ + z);

                    CubeBehavior cb;

                    if (allCubes.Next() == 0)
                    {
                        cb = NetworkManager.Instance.InstantiateCube(0, pos, Quaternion.identity);
                        cb.networkObject.colorId = 1; // Green
                    }
                    else
                    {
                        cb = NetworkManager.Instance.InstantiateCube(1, pos, Quaternion.identity);
                        cb.networkObject.colorId = 2; // Red
                    }

                    // Assign the host's Id to the ownerNetId
                    cb.networkObject.ownerNetId = networkObject.MyPlayerId;
                }
            }
        }
示例#7
0
    // Use this for initialization
    void Start()
    {
        ShuffleBag <int> bag = new ShuffleBag <int>();
        int wallcount        = 15;

        for (int i = 0; i < walls.Length; i++)
        {
            walls[i].transform.localScale = new Vector3(Screen.width, 1.0f, 0.01f);
        }

        bag.Add(0);
        bag.Add(1);
        bag.Add(2);
        bag.Add(3);

        Instantiate(walls [0], new Vector3(0, wallcount, 0), new Quaternion(0, 0, 0, 0));
        wallcount += 15;

        Instantiate(walls [1], new Vector3(0, wallcount, 0), new Quaternion(0, 0, 0, 0));
        wallcount += 15;

        Instantiate(walls [2], new Vector3(0, wallcount, 0), new Quaternion(0, 0, 0, 0));
        wallcount += 15;

        Instantiate(walls [3], new Vector3(0, wallcount, 0), new Quaternion(0, 0, 0, 0));
        wallcount += 15;

        for (int i = 0; i < 2000; i++)
        {
            Instantiate(walls [bag.Next()], new Vector3(0, wallcount, 0), new Quaternion(0, 0, 0, 0));
            wallcount += 15;
        }
    }
示例#8
0
    // ---- public methods ----

    public void Fire()
    {
        // spawn ball from pool
        GameObject ball = ammoPool.Spawn(spawnPoint.position, spawnPoint.rotation);

        // add initial velocity
        ball.rigidbody.velocity = transform.up * (force / mass);

        // set color: chance of 1/2 red, 1/3 green, 1/6 blue
        ball.renderer.material.SetColor("_Color", bag.Next());

        // add a bit of rotation
        //System.Random random = new System.Random();
        //ball.rigidbody.angularVelocity = new Vector3(random.Next(-1, 1), random.Next(-1, 1), random.Next(-1, 1));

        // play sound in random pitch
        audio.pitch = Random.Range(0.9f, 1.1f);
        audio.PlayOneShot(fireSound);

        // add muzzle effect
        Instantiate(muzzleFlare, spawnPoint.position, spawnPoint.rotation);

        // update statistics
        GameStatistics.bulletsFired++;
    }
    public void SpawnCube()
    {
        int toneInt = Random.Range(0, Tones.Length);

        GameObject newToneCube = Instantiate(ToneCubePrefab, new Vector3(Random.Range(-10f, 10f), 0.5f, Random.Range(-10f, 10f)), Quaternion.identity);

        newToneCube.GetComponent <DisSoundBlock>().thisOrigClip = toneCue.Next();
        Debug.Log(toneCue.Cursor);
        newToneCube.GetComponent <Renderer>().material.SetColor("_LowColor", new Color((float)toneInt * (1f / (float)Tones.Length), (float)toneInt * (1f / (float)Tones.Length), (float)toneInt * (1f / (float)Tones.Length)));
    }
示例#10
0
    public List <Food.FoodType> CreateOrder(int orderSize)
    {
        List <Food.FoodType> order = new List <Food.FoodType>();

        for (int i = 0; i < orderSize; i++)
        {
            order.Add(randomBag.Next());
        }
        return(order);
    }
示例#11
0
    private IEnumerator FetchStereoImg()
    {
        WWW           www;
        PanoramaImage image;

        analytics.gav3.LogEvent("Panorama:" + analytics.sessionId, "RequestedStereoImg", "foo", 1);

        statusMessage.text = "Waiting for me.cmdr2.org...";

        string url = STEREO_IMAGES_BASE + "/" + stereoImagesShuffle.Next();

        www = new WWW(url);
        networkConns.Add(www);
        print("Fetching page: " + url);
        yield return(www);

        image = ExtractImageInfo(www.text);
        www   = null;

        if (image != null)
        {
            image.stereoType       = StereoType.CROSS_EYE;
            image.imageInfo.width /= 2;

            statusMessage.text = "";

            DrawPanorama(image);

            analytics.LogStereoImgViewCount();
        }
        else
        {
            statusMessage.text = "Failed to find a stereo image to show!";
            analytics.LogException("Failed to extract URL from Flickriver", true);
        }

        // clear previous info
        foreach (Transform child in titleMessage.transform)
        {
            Destroy(child.gameObject);
        }
    }
    void generateTargets()
    {
        // get an available position and R
        Vector2 newPos;
        float   newR;
        bool    conflicted = false;
        int     TrialCount = 5; // after trying multiple times, give up generating

        while (true)
        {
            newPos     = new Vector2(Random.Range(-7f, 7f), Random.Range(-4f, 3.5f));
            newR       = Random.Range(1f, 1.5f);
            conflicted = false;
            foreach (GameObject oldTarget in LiveTargetsArray)
            {
                // if conflict exists
                if (Vector2.Distance(newPos, oldTarget.transform.position) <= (newR + oldTarget.transform.localScale.x) / 2)
                {
                    conflicted = true;
                    break;
                }
            }
            if (!conflicted)
            {
                break;
            }
            if (--TrialCount <= 0)
            {
                return;
            }
        }
        target = Get();                              // get one target out of object pool
        GameObject targetPrefab = TargetsBag.Next(); // assign the type of new targets

        target.RemoveComponent(target.GetComponent <TargetBase>().GetType(), true);
        target.CopyComponent(targetPrefab.GetComponent <TargetBase>());
        target.GetComponent <SpriteRenderer>().color = targetPrefab.GetComponent <SpriteRenderer>().color;
        target.GetComponent <TargetBase>().R         = newR;
        target.transform.position = newPos;
        LiveTargetsArray.Add(target);
        target.GetComponent <TargetBase>().Begin();
    }
示例#13
0
    // Update is called once per frame
    void Update()
    {
        //update ASMR Timers
        for (int i = 0; i < asmrScriptSources.Count; i++)
        {
            //check if audiosource is not playing
            if (!asmrScriptSources[i].isPlaying)
            {
                //update timer
                scriptSourceTimer += Time.deltaTime;
                //check if timer is greater than start delay
                if (scriptSourceTimer >= nextScriptStartDelay)
                {
                    //play the next clip in the shuffle bag and reset the timer
                    asmrScriptSources[i].clip = ASMRcue.Next();
                    asmrScriptSources[i].Play();
                    scriptSourceTimer    = 0f;
                    nextScriptStartDelay = 10f + Random.Range(-2f, 2f);
                }
            }
        }

        //Update Drone Timers
        if (!droneSource.isPlaying)
        {
            droneSourceTimer += Time.deltaTime;
            if (droneSourceTimer > nextDroneStartDelay)
            {
                //reset timer, update drone index, assign clip and play
                droneSourceTimer = 0f;
                droneIndex++;
                droneSource.clip = droneClips[droneIndex % droneClips.Length];
                droneSource.Play();
            }
        }

        //Update Drone Volume

        droneSourceVolume = MyMath.Map(numLinks, 0, 10, 0f, 0.5f);
    }
示例#14
0
    private TwitterItem GenerateTwitterItem(ShuffleBag <string> bag, bool withImage)
    {
        string famousPerson = StaticData.Name;

        // have a start tweet first
        if (!hasStartTweet)
        {
            bag           = startBag;
            hasStartTweet = true;
        }

        string shortName = famousPerson.Replace(" ", "_").Substring(0, Math.Min(famousPerson.Length, 8));

        return(new TwitterItem
        {
            Username = String.Format(nameBag.Next(), shortName),
            Name = nameGenerator.GenerateRandomFirstAndLastName(),
            Tweet = String.Format(bag.Next(), famousPerson),
            Timestamp = DateTime.Now,
            ImageSeed = withImage ? GetImageSeed : (int?)null
        });
    }
示例#15
0
    void Spawn()
    {
        int        myRegion           = spawnRegionsBag.Next();
        int        myType             = isDropSpawner ? 0 : bubbleTypesBag.Next();
        float      spawnXpos          = Random.Range(spawnRegions[myRegion].x, spawnRegions[myRegion].y);
        GameObject thingToInstantiate = isDropSpawner ? dropPrefab : bubblePrefab;

        if (myType == 1 && !isDropSpawner)
        {
            thingToInstantiate = smallBubblePrefab;
        }
        GameObject newBub = Instantiate(
            thingToInstantiate,
            new Vector3(
                Mathf.Floor(spawnXpos) + .5f,
                transform.position.y,
                transform.position.z
                ),
            Quaternion.identity
            );

        if (!isDropSpawner)
        {
            Bubble bubble = newBub.GetComponent <Bubble>();

            if (bubble)
            {
                bubble.player1 = player1;
                bubble.player2 = player2;
            }

            if (myType == 1)
            {
                newBub.transform.ShiftX(-.5f);
                newBub.transform.ShiftY(-.5f);
                //newBub.GetComponent<Bubble>().timeBetweenMoves *= Mathf.Floor(Random.Range(8f, 9f)) / 10;
            }
        }

        // if (myType == 1 && !isDropSpawner)
        // {
        //   newBub.transform.ShiftX(-.5f);
        //   newBub.transform.ShiftY(-.5f);
        //   //newBub.GetComponent<Bubble>().timeBetweenMoves *= Mathf.Floor(Random.Range(8f, 9f)) / 10;
        // }
        // spawnedBubbles.Add(newBub);
        // if ((myRegion != 2) && !isDropSpawner)
        // {
        //   Debug.Log(alreadyTaggedSpawnCounter);
        //   if (alreadyTaggedSpawnCounter >= 3)
        //   {
        //     int playerColor = Random.Range(0, 2);
        //     newBub.GetComponent<SpriteRenderer>().color =
        //       playerColor == 0
        //         ? p1Color
        //         : p2Color;
        //     if (playerColor == 0)
        //     {
        //       newBub.GetComponent<Bubble>().p1tagged = true;
        //     }
        //     else
        //     {
        //       newBub.GetComponent<Bubble>().p2tagged = true;
        //     }
        //     alreadyTaggedSpawnCounter = 0;
        //   }
        //   else
        //   {
        //     alreadyTaggedSpawnCounter++;
        //   }
        // }
        SetNewSpawnTime();
    }
示例#16
0
        public void ChooseAction(ulong id, AIStat aiStat, CombatInstance instance)
        {
            ulong[] actions = aInventorySystem.GetHand(id);
            if (actions == null) return;

            int count = 4;
            List<ulong> canUse = new List<ulong>();
            for (int i = 0; i < count; i++)
            {
                if (actions[i] != 0)
                    if (CanPerform(id, actions[i])) canUse.Add(actions[i]);
            }

            count = canUse.Count;
            if (count == 0) return;
            ShuffleBag<ulong> actionBag = new ShuffleBag<ulong>();

            for (int i = 0; i < count; i++)
            {
                string s = actionSystem.GetActionKey(canUse[i]);
                switch (aiStat)
                {
                    case AIStat.AGGRESSION:
                        actionBag.Add(canUse[i], (int)actionSystem.GetAggression(s));
                        break;
                    case AIStat.BALANCE:
                        actionBag.Add(canUse[i], (int)actionSystem.GetBalance(s));
                        break;
                    case AIStat.DEFENSE:
                        actionBag.Add(canUse[i], (int)actionSystem.GetDefense(s));
                        break;
                }
            }

            PerformAction(id, actionBag.Next(), instance);
        }
示例#17
0
 //public StringBuilder TextGenerator(ShuffleBag shuffleBag)
 void TextGenerator(ShuffleBag shuffleBag)
 {
     sbText.Append(shuffleBag.Next());
     mainText.text = sbText.ToString();
     //return sb;
 }
示例#18
0
    public virtual Card DrawCard()
    {
        Card nextCard = deck.Next();

        return(nextCard);
    }
示例#19
0
 void EndTitleGenerator(ShuffleBag shuffleBag)
 {
     sbEndTitle.Append(shuffleBag.Next());
     endTitle.text = sbEndTitle.ToString();
     //return sb;
 }
示例#20
0
    private IEnumerator FetchMono()
    {
//		analytics.gav3.LogEvent ("Panorama:" + analytics.sessionId, "RequestedMono", "foo", 1);
//		analytics.LogEvent ("Panorama", "Requested");

        WWW           www;
        PanoramaImage image;

        // first try recommendation
        image = GetRecommendedImage(analytics.monoViewCount);

        analytics.gav3.LogEvent("Panorama:" + analytics.sessionId, "DebugGotRecommendation", "foo", 1);

        // else get random
        if (image == null)
        {
            analytics.gav3.LogEvent("Panorama", "FetchingRandom", "foo", 1);
            statusMessage.text = "Waiting for www.flickr.com...";

            bool      censored;
            Stopwatch s = new Stopwatch();
            s.Start();

            do
            {
                string url = MONO_PANO_IMAGES_BASE + "/" + monoPanoramaShuffle.Next();
                www = new WWW(url);
                networkConns.Add(www);
                print("Fetching page: " + url);
                yield return(www);

                try {
                    image = ExtractImageInfo(www.text);
                } catch (System.Exception e) {
                    analytics.gav3.LogException("Failed to read from index: " + e.Message, true);
                }
                www = null;

                censored = IsCensored(image.imageInfo);
            } while (censored);

            s.Stop();
            analytics.LogTiming("Loading", s.ElapsedMilliseconds, "cmdr2", "FetchPage");
        }
        else
        {
            analytics.LogEvent("Panorama", "FetchingRecommendation" + analytics.monoViewCount);
        }

        if (image != null)
        {
            statusMessage.text = "";

            if (renderMode == RenderMode.MONO_PANORAMA)
            {
                /* draw! */
                DrawPanorama(image);
                ShowInfo(image.imageInfo);

                /* log */
                analytics.LogMonoViewCount();
                analytics.LogEvent("Panorama", "ImagesLoading");
            }
        }
        else
        {
            statusMessage.text = "Failed to find a panorama to show!";
            analytics.gav3.LogException("Failed to show panorama", true);
        }
    }