コード例 #1
0
        public void ChangePlotState(PlotState ps, CalendarPlotTimeSpan span = new CalendarPlotTimeSpan())
        {
            switch (ps)
            {
            case PlotState.ReadyToPlay:
                parent.playingPlot.Remove(this);
                parent.Calendar.Add(this, span);
                Init();
                break;

            case PlotState.Playing:
                parent.playingPlot.Add(this);
                if (Services.game.runState == RunState.Load)
                {
                    LateStart();
                }
                else
                {
                    Start();
                }
                onPlotStart.Invoke();
                break;

            case PlotState.Finished:
                parent.playingPlot.Remove(this);
                OnFinished();
                onPlotFinish.Invoke();
                parent.Calendar[this] = new CalendarPlotTimeSpan()
                {
                    startTime          = parent.Calendar[this].startTime,
                    potentialBreakTime = DateTime.Now
                };
                break;

            case PlotState.Broke:
                parent.playingPlot.Remove(this);
                OnBreak();
                onPlotBreak.Invoke();
                parent.Calendar[this] = new CalendarPlotTimeSpan()
                {
                    startTime          = parent.Calendar[this].startTime,
                    potentialBreakTime = DateTime.Now
                };
                break;

            case PlotState.Abandoned:
                parent.playingPlot.Remove(this);
                OnAbandon();
                CoroutineManager.DoOneFrameDelay((() =>
                {
                    parent.Calendar[this] = new CalendarPlotTimeSpan()
                    {
                        startTime = parent.Calendar[this].startTime,
                        potentialBreakTime = DateTime.Now
                    };
                }));
                break;
            }
            _plotState = ps;
        }
コード例 #2
0
 public void ClearPlot()
 {
     /*
      * I considered setting itemToGrow to null, but that will cause errors and
      * I *assume* that a new Item will be set anyway.
      * I also assume that ClearPlot will be called.
      */
     currentState = PlotState.Empty;
     Destroy(itemGrowing);
 }
コード例 #3
0
    void BeginGrowth()
    {
        // Set plot variables.
        currentState = PlotState.Growing;
        currentScale = initialScale;
        currentTime  = 0;

        // Create new Item Object and remove Physics components.
        itemGrowing = (GameObject)Object.Instantiate(itemToGrow, transform.position + new Vector3(0, bottomPosition, 0), transform.rotation, transform);
        // UnityEngine.Debug.Log(itemGrowing.GetComponent<Item>().itemType.itemName);
        Destroy(itemGrowing.GetComponent <Rigidbody>());
        Destroy(itemGrowing.GetComponent <Collider>());

        // Set Rotation and Scale
        itemGrowing.transform.eulerAngles = itemGrowing.GetComponent <Item>().GetItemStack().itemID == "Egg" ? new Vector3(0, 0, 0) : new Vector3(-90, 0, 0);
        itemGrowing.transform.localScale  = initialScale * itemToGrow.transform.localScale;
    }
コード例 #4
0
 public void SetItem(ItemStack item)
 {
     if (item.itemID == "Egg" || item.itemID == "Blueberry" || item.itemID == "Sugar")
     {
         itemToGrow = (GameObject)Resources.Load <GameObject>("Models/Plots/" + item.itemID + "_Prefab");
         Item newItem = itemToGrow.AddComponent <Item>();
         newItem.SetItemStack(item);
         newItem.inert = true;
         newItem.transform.localScale *= item.itemID == "Egg" ? 0.75f : 0.65f;
     }
     else
     {
         itemToGrow = (GameObject)Resources.Load <GameObject>("Prefabs/Items/" + item.itemID);
     }
     currentState = PlotState.Growing;
     PlaySound(2f);
 }
コード例 #5
0
        public static string Encode(PlotColor color, int h, int w, PlotState state, int waitTime)
        {
            string str;

            // height
            str = Seperator + h.ToString();

            // color
            switch (color)
            {
            case PlotColor.Clear: str += "c"; break;

            case PlotColor.Red: str += "r"; break;

            case PlotColor.Blue: str += "b"; break;

            case PlotColor.Green: str += "g"; break;

            case PlotColor.Yellow: str += "y"; break;
            }

            // waittime
            str += waitTime;

            // state
            switch (state)
            {
            case PlotState.Forbidden: str += "f"; break;

            case PlotState.Unoccupied: str += "u"; break;

            case PlotState.Occupied: str += "o"; break;

            case PlotState.Defended: str += "e"; break;

            case PlotState.Duplication: str += "d"; break;

            case PlotState.Visited: str += "v"; break;
            }

            // width
            str += w;

            return(str);
        }
    //player2
    internal void InteractP2(Player2Control.InHand currently_Holding)
    {
        switch (currently_Holding)
        {
        case Player2Control.InHand.Empty:
            // Check harvest etc.. (When the player harvests the plant)
            if (plotIs == PlotState.Tomatoe_Plant)
            {
                plotIs = PlotState.Rubbish;
            }

            if (plotIs == PlotState.Carrot_Plant)
            {
                plotIs = PlotState.Rubbish;
            }

            break;


        case Player2Control.InHand.Carrot_Seeds:

            if (plotIs == PlotState.Soil)
            {
                plotIs = PlotState.Carrot_Seedling;
            }
            break;

        case Player2Control.InHand.Tomatoe_Seeds:


            if (plotIs == PlotState.Soil)
            {
                plotIs = PlotState.Tomatoe_Seedling;
            }
            break;

        case Player2Control.InHand.Plucker:
            if (plotIs == PlotState.Rubbish)
            {
                plotIs = PlotState.Soil;
            }
            break;
        }
    }
コード例 #7
0
ファイル: Field.cs プロジェクト: speedyjeff/swarm
        public bool ChangeState(PlotColor color, int h, int w, PlotState state, int waitTime)
        {
            if (h >= 0 && h < m_field.GetLength(0) && w >= 0 && w < m_field.GetLength(1))
            {
                // append transaction
                m_transaction += SwarmUtil.Encode(color, h, w, state, waitTime);

                // upate color counts
                m_count[(int)m_field[h, w].Color]--;
                m_count[(int)color]++;

                m_field[h, w].State        = state;
                m_field[h, w].Color        = color;
                m_field[h, w].WaitDuration = waitTime;
                return(true);
            }

            return(false);
        }
コード例 #8
0
    void GrowthTick()
    {
        // set ring to Growing Color
        rend.material.SetColor("LineColor", Color.Lerp(growthColor, completeColor, currentScale));

        // Update time and scale values.
        currentTime += Time.deltaTime;
        currentScale = currentTime / timeToGrow; // Range [0, 1]

        // Update position and scale.
        itemGrowing.transform.localScale = currentScale * itemToGrow.transform.localScale;
        itemGrowing.transform.position   = transform.position + new Vector3(0, Mathf.Lerp(bottomPosition, topPosition, currentScale), 0);

        // Transition if necessary.
        if (currentTime >= timeToGrow)
        {
            currentTime  = 0;
            currentState = PlotState.Complete;
            rend.material.SetInt("IsGrowing", 0);
        }
    }
コード例 #9
0
ファイル: PlotEvent.cs プロジェクト: WHYingg/MG2020
 public PlotEvent(PlotState state, Delegate listener, Delegate callback)
 {
     this.state    = state;
     this.listener = listener;
     this.callback = callback;
 }
コード例 #10
0
ファイル: Field.cs プロジェクト: speedyjeff/swarm
 public bool ChangeState(PlotColor color, int h, int w, PlotState state)
 {
     return(ChangeState(color, h, w, state, m_field[h, w].WaitDuration));
 }
コード例 #11
0
 public void AssignPlotState(PlotState ps, CalendarPlotTimeSpan span = new CalendarPlotTimeSpan())
 {
     _plotState = ps;
 }
コード例 #12
0
    private List <KeyValuePair <Plot, CalendarPlotTimeSpan> > _GetPlotWithStateFromCalendar(PlotState state)
    {
        var list = new List <KeyValuePair <Plot, CalendarPlotTimeSpan> >();

        foreach (var pair in Calendar)
        {
            if (pair.Key.plotState == state)
            {
                list.Add(pair);
            }
        }
        return(list);
    }
コード例 #13
0
 public void ResetState(PlotState current, int x, int y)
 {
     current.Visible = false;
     LayerAxis.ResetState(current.AxisState, x, y);
     LayerSignal.ResetState(current.SignalState, x, y);
 }
コード例 #14
0
        public int GetNext(PlotState current)
        {
            int intensityAxis = Blend(Controls.IntensityBackground, Controls.IntensityAxis, alpha: LayerAxis.GetNext(current.AxisState));

            return(Blend(intensityAxis, Controls.IntensitySignal, alpha: LayerSignal.GetNext(current.SignalState)));
        }
コード例 #15
0
ファイル: Plot.cs プロジェクト: speedyjeff/swarm
 public Plot()
 {
     State        = PlotState.Forbidden;
     Color        = PlotColor.Clear;
     WaitDuration = 0;
 }
コード例 #16
0
        public static bool Decode(string str, out PlotColor color, out int h, out int w, out PlotState state, out int waitTime)
        {
            // the rest should follow this format
            //  HEIGHTcolorWAITDURATIONstateWIDTH
            int    part;
            string numStr;

            char[] chArray;

            part     = 0;
            numStr   = "";
            color    = PlotColor.Clear;
            h        = w = 0;
            state    = PlotState.Forbidden;
            waitTime = 0;
            chArray  = str.ToCharArray();

            // check that this is a valid message
            if (0 == chArray.Length || !Char.IsDigit(chArray[0]))
            {
                return(false);
            }

            foreach (char c in chArray)
            {
                switch (part)
                {
                case 0:
                    if (Char.IsDigit(c))
                    {
                        numStr += c;
                    }
                    else
                    {
                        // height
                        h      = Convert.ToInt32(numStr);
                        numStr = "";
                        // color
                        switch (c)
                        {
                        case 'r': color = PlotColor.Red; break;

                        case 'b': color = PlotColor.Blue; break;

                        case 'g': color = PlotColor.Green; break;

                        case 'y': color = PlotColor.Yellow; break;

                        case 'c': color = PlotColor.Clear; break;
                        }
                        part = 1;
                    }
                    break;

                case 1:
                    if (Char.IsDigit(c))
                    {
                        numStr += c;
                    }
                    else
                    {
                        // wait time
                        waitTime = Convert.ToInt32(numStr);
                        numStr   = "";
                        // state
                        switch (c)
                        {
                        case 'f': state = PlotState.Forbidden; break;

                        case 'u': state = PlotState.Unoccupied; break;

                        case 'o': state = PlotState.Occupied; break;

                        case 'e': state = PlotState.Defended; break;

                        case 'd': state = PlotState.Duplication; break;

                        case 'v': state = PlotState.Visited; break;
                        }
                        part = 2;
                    }
                    break;

                case 2:
                    numStr += c;
                    break;
                }
            }
            // width
            w = Convert.ToInt32(numStr);

            return(true);
        }
    // Update is called once per frame
    void Update()
    {
        print("Plot is: " + plotIs);


        //Plants
        if (plotName == "PlotOne")
        {
            //Rubbish
            if (plotIs == PlotState.Rubbish)
            {
                TomatoPlant1.SetActive(false);
                CarrotPlant1.SetActive(false);
                Rubbish1.SetActive(true);
            }

            //Soil plot
            if (plotIs == PlotState.Soil)
            {
                Rubbish1.SetActive(false);
            }

            //Tomato
            if (plotIs == PlotState.Tomatoe_Seedling)
            {
                TomatoSeedling1.SetActive(true);

                growthTimer = growthTimer - Time.deltaTime;

                if (growthTimer <= 0)
                {
                    plotIs      = PlotState.Tomatoe_Plant;
                    growthTimer = timerAfterGrowth;
                }
            }

            if (plotIs == PlotState.Tomatoe_Plant)
            {
                TomatoSeedling1.SetActive(false);
                TomatoPlant1.SetActive(true);
            }

            //Carrot
            if (plotIs == PlotState.Carrot_Seedling)
            {
                CarrotSeedling1.SetActive(true);

                growthTimer = growthTimer - Time.deltaTime;

                if (growthTimer <= 0)
                {
                    plotIs      = PlotState.Carrot_Plant;
                    growthTimer = timerAfterGrowth;
                }
            }

            if (plotIs == PlotState.Carrot_Plant)
            {
                CarrotSeedling1.SetActive(false);
                CarrotPlant1.SetActive(true);
            }
        }


        if (plotName == "PlotTwo")
        {
            //Rubbish
            if (plotIs == PlotState.Rubbish)
            {
                TomatoPlant2.SetActive(false);
                CarrotPlant2.SetActive(false);
                Rubbish2.SetActive(true);
            }

            //Soil plot
            if (plotIs == PlotState.Soil)
            {
                Rubbish2.SetActive(false);
            }

            //Tomato
            if (plotIs == PlotState.Tomatoe_Seedling)
            {
                TomatoSeedling2.SetActive(true);

                growthTimer = growthTimer - Time.deltaTime;

                if (growthTimer <= 0)
                {
                    plotIs      = PlotState.Tomatoe_Plant;
                    growthTimer = timerAfterGrowth;
                }
            }

            if (plotIs == PlotState.Tomatoe_Plant)
            {
                TomatoSeedling2.SetActive(false);
                TomatoPlant2.SetActive(true);
            }

            //Carrot
            if (plotIs == PlotState.Carrot_Seedling)
            {
                CarrotSeedling2.SetActive(true);

                growthTimer = growthTimer - Time.deltaTime;

                if (growthTimer <= 0)
                {
                    plotIs      = PlotState.Carrot_Plant;
                    growthTimer = timerAfterGrowth;
                }
            }

            if (plotIs == PlotState.Carrot_Plant)
            {
                CarrotSeedling2.SetActive(false);
                CarrotPlant2.SetActive(true);
            }
        }

        if (plotName == "PlotThree")
        {
            //Rubbish
            if (plotIs == PlotState.Rubbish)
            {
                TomatoPlant3.SetActive(false);
                CarrotPlant3.SetActive(false);
                Rubbish3.SetActive(true);
            }

            //Soil plot
            if (plotIs == PlotState.Soil)
            {
                Rubbish3.SetActive(false);
            }

            //Tomato
            if (plotIs == PlotState.Tomatoe_Seedling)
            {
                TomatoSeedling3.SetActive(true);

                growthTimer = growthTimer - Time.deltaTime;

                if (growthTimer <= 0)
                {
                    plotIs      = PlotState.Tomatoe_Plant;
                    growthTimer = timerAfterGrowth;
                }
            }

            if (plotIs == PlotState.Tomatoe_Plant)
            {
                TomatoSeedling3.SetActive(false);
                TomatoPlant3.SetActive(true);
            }

            //Carrot
            if (plotIs == PlotState.Carrot_Seedling)
            {
                CarrotSeedling3.SetActive(true);

                growthTimer = growthTimer - Time.deltaTime;

                if (growthTimer <= 0)
                {
                    plotIs      = PlotState.Carrot_Plant;
                    growthTimer = timerAfterGrowth;
                }
            }

            if (plotIs == PlotState.Carrot_Plant)
            {
                CarrotSeedling3.SetActive(false);
                CarrotPlant3.SetActive(true);
            }
        }
    }