Beispiel #1
0
        // The name is pure rubbish, I should change it later
        // Can't get my G if he's in a safe zone
        public bool TryHunting()
        {
            if (CurrentEdge.Preys.Count == 0 && CurrentEdge.Reverse().Preys.Count == 0)
            {
                HuntingMode = false;

                return(false);
            }

            foreach (Prey currentPrey in CurrentEdge.Preys)
            {
                if (EdgePosition >= currentPrey.EdgePosition)
                {
                    HuntedPreys.Add(currentPrey);
                }
            }

            foreach (Prey currentPrey in CurrentEdge.Reverse().Preys)
            {
                if (CurrentEdge.LinePoints.Count - 1 - EdgePosition <= currentPrey.EdgePosition)
                {
                    HuntedPreys.Add(currentPrey);
                }
            }

            if (HuntedPreys.Count != 0)
            {
                return(true);
            }

            return(false);
        }
Beispiel #2
0
        public void OnPointerClick(PointerEventData eventData)
        {
            if (CurrentTool == SPTool.Pointer)
            {
                // do nothing
            }
            else if (CurrentTool == SPTool.Pan)
            {
                throw new NotImplementedException();
            }
            else if (CurrentTool == SPTool.Zoom)
            {
                throw new NotImplementedException();
            }
            else if (CurrentTool == SPTool.NewComponent)
            {
                UIToolboxComponentEntry chosenComponentEntry = GameObject.FindObjectOfType <UIToolboxContainer>().CurrentPanel.CurrentlySelectedEntry as UIToolboxComponentEntry;
                Assert.IsNotNull(chosenComponentEntry);

                if (eventData.button == PointerEventData.InputButton.Left)
                {
                    // Can't build in ActivateAllOutputs mode
                    if (CurrentMode == GameMode.ActivateAllOutputsChallenge)
                    {
                        return;
                    }

                    // Build component configuration
                    LogicComponentConfig componentConfig = new LogicComponentConfig(
                        chosenComponentEntry.ComponentClassname,
                        eventData.pointerCurrentRaycast.worldPosition.x,
                        eventData.pointerCurrentRaycast.worldPosition.y);

                    // Pass config to factory
                    var newComponent = LogicComponentFactory.MakeFromConfig(componentConfig);

                    Components.Add(newComponent);
                }
                else if (eventData.button == PointerEventData.InputButton.Right)
                {
                    //
                }
            }
            else if (CurrentTool == SPTool.DrawEdge)
            {
                if (eventData.button == PointerEventData.InputButton.Right)
                {
                    // Cancel drawing edge
                    Assert.IsNotNull(CurrentEdge);
                    CurrentEdge.Delete();
                    RestorePreviousTool();
                }
            }
        }
Beispiel #3
0
 public void StartEdge(SPConnector connector)
 {
     CurrentEdge = Instantiate(SPEdgePrefab, Foreground.transform);
     Assert.IsNotNull(CurrentEdge);
     CurrentEdge.AddStartingConnector(connector);
 }
Beispiel #4
0
 public void FinishEdge(SPConnector connector)
 {
     // this may throw ArgumentException, let SPConnector.OnPointerClick handle that
     CurrentEdge.AddFinishingConnector(connector);
     CurrentEdge = null;
 }
Beispiel #5
0
        public void UpdateEdgePosition()
        {
            if (Path.Count == 0 && EdgePosition == CurrentEdge.LinePoints.Count - 1)
            {
                return;
            }

            EdgePosition += EdgePositionIncrement;

            if (EdgePosition >= CurrentEdge.LinePoints.Count)
            {
                CurrentEdge.NumberOfPredators--;

                if (Path.Count != 0)
                {
                    CurrentEdge = Path.Dequeue();
                    CurrentEdge.NumberOfPredators++;

                    if (CurrentEdge.Preys.Count != 0)
                    {
                        HuntingMode = true;
                    }
                    else if (CurrentEdge.Reverse().Preys.Count != 0)
                    {
                        HuntingMode = true;
                    }
                    else
                    {
                        if (HuntingMode)
                        {
                            HuntingMode = false;
                        }
                    }

                    /*if (CurrentEdge.Preys.Count != 0)
                     * {
                     *  HuntingMode = true;
                     *
                     *  HuntingModeCase = (int)HuntingModeType.SameEdge;
                     * }
                     * else if (CurrentEdge.Reverse().Preys.Count != 0)
                     * {
                     *  HuntingMode = true;
                     *
                     *  HuntingModeCase = (int)HuntingModeType.ReverseEdge;
                     * }
                     * else
                     * {
                     *  if (HuntingMode)
                     *  {
                     *      HuntingMode = false;
                     *  }
                     * }*/

                    EdgePosition = 0;
                }
                else
                {
                    EdgePosition = CurrentEdge.LinePoints.Count - 1;
                }
            }
        }
Beispiel #6
0
        public void UpdateEdgePosition()
        {
            // Check if there's a predator on the current Edge
            if (OnSafeZone)
            {
                if (CurrentEdge.NumberOfPredators != 0)
                {
                    return;
                }
                else
                {
                    if (CurrentEdge.Reverse().NumberOfPredators != 0)
                    {
                        return;
                    }
                }

                OnSafeZone = false;
                CurrentEdge.Preys.Add(this);
            }

            // Check if a Predator appeared, backtrack on the same Edge if it did
            if (CurrentEdge.Reverse().NumberOfPredators != 0)
            {
                SurvivalMode = true;
            }

            if (SurvivalMode)
            {
                EdgePosition -= EdgePositionIncrement;

                if (EdgePosition <= 0)
                {
                    CurrentEdge.Preys.Remove(this);

                    OnSafeZone   = true;
                    SurvivalMode = false;
                }
            }
            else
            {
                EdgePosition += EdgePositionIncrement;

                if (EdgePosition >= CurrentEdge.LinePoints.Count)
                {
                    CurrentEdge.Preys.Remove(this);

                    if (Path.Count != 0)
                    {
                        CurrentEdge = Path.Dequeue();

                        OnSafeZone = true;

                        EdgePosition = 0;
                    }
                    else
                    {
                        EdgePosition = CurrentEdge.LinePoints.Count - 1;

                        IsActive = false;
                    }
                }
            }
        }