Пример #1
0
    IEnumerator Start()
    {
        // Set up the decision tree
        Decision isEnemy            = new DecisionIsEnemy(this);
        Decision isAirplane         = new DecisionIsAirplane(this);
        Decision isDistanceLessThan = new DecisionIsDistanceLessThan(this, 30);
        // To do : Create an isVehicle object
        DecisionIsVehicle isVehicle   = new DecisionIsVehicle(this);
        Action            fireMissile = new ActionFireMissile(this);
        // To do : Create a laser-firing-action object.
        Action fireLaser = new ActionFireLaser(this);
        // To do : Create a cannon-firing-action object.
        Action fireCannon = new ActionFireCannon(this);

        Decision decisionTree = isEnemy;

        isEnemy.trueNode  = isDistanceLessThan;
        isEnemy.falseNode = null;

        isDistanceLessThan.trueNode  = isAirplane;
        isDistanceLessThan.falseNode = null;

        isAirplane.trueNode = fireMissile;

        // To do : Connect the falseNode of isAirplane to isVehicle
        isAirplane.falseNode = isVehicle;

        // To do : Set the child nodes with proper actions
        isVehicle.trueNode  = fireCannon;
        isVehicle.falseNode = fireLaser;

        yield return(null);

        while (true)       // main loop
        {
            DoRadarScan(); // Scan a new unit or update the scanned unit

            // Get an action from the decision tree
            Action action = decisionTree.MakeDecision() as Action;
            if (action != null)
            {
                if (action.Perform())                    // action performed
                {
                    yield return(new WaitForSeconds(3)); // wait for 3 sec

                    scannedUnit = null;
                }
            }

            if (scannedUnit != null && scannedUnit.distance < 0)
            {
                actionDisplay = "No action";
                yield return(new WaitForSeconds(3)); // wait for 3 sec

                scannedUnit = null;
            }

            yield return(null);
        }
    }
Пример #2
0
    private void TakeAction()
    {
        if (AI == null)
        {
            return;
        }

        Action action = AI.TakeTurn();

        if (action != null && action.Cost <= energy.Bars)
        {
            ActionResult result;
            do
            {
                result = action.Perform(this);
                if (result.Type == ActionResultType.ALTERNATE)
                {
                    action = result.AlternateAction;
                }
            } while (result.Type == ActionResultType.ALTERNATE);

            if (result.Type == ActionResultType.SUCCESS)
            {
                energy.Spend(action.Cost);
            }
        }
    }
Пример #3
0
        protected void InvokeActions()
        {
            int commandCount = _queue.Count;             //retaining commands will enqueue again

            while (commandCount > 0)
            {
                Action action = _queue.Peek();
                commandCount--;
                PrefromResult result = action.Perform(Time.deltaTime);

                switch (result)
                {
                case (PrefromResult.COMPLETED):
                    _queue.Dequeue();
                    break;

                case (PrefromResult.BLOCK):
                    return;

                case (PrefromResult.PROCEED):
                    _queue.Dequeue();
                    _queue.Enqueue(action);
                    break;
                }
            }
        }
Пример #4
0
    private void PerformAction()
    {
        currentAction = GetCurrentActor().GetAction();
        if (currentAction == null)
        {
            return;                                //Should only happen for player actor
        }
        bool loopAction = true;

        while (loopAction)
        {
            ActionResult result = currentAction.Perform();
            if (result.Succeeded)
            {
                loopAction = false;
            }
            else
            {
                if (currentAction == result.Alternate)
                {
                    Debug.Log("alternate should be a different action");
                    break;
                }
                currentAction = result.Alternate;
            }
        }
    }
Пример #5
0
    public void SwitchTo(string gameObjectName, float timeToTravel, float travelingPrecision, Action callbackAction)
    {
        if (nextTarget != null) { return; }

        nextTarget = GameObject.Find(gameObjectName);

        if (nextTarget == null) { Debug.LogWarning("target " + gameObjectName + " Not found. Camera stay here."); return; }

        actionToPerform = callbackAction;

        if (timeToTravel <= 0)
        {
            target = nextTarget;
            nextTarget = null;

            callbackAction.Perform(target);
        }
        else
        {
            this.travelingPrecision = travelingPrecision;
            xTarget = nextTarget.transform.position.x + this.deltaPosition.x;
            yTarget = nextTarget.transform.position.y + this.deltaPosition.y;
            travelingTime = timeToTravel;
        }
    }
//		bool transitioning = false;


        public void Entered(State self, State previous)
        {
            Debug.Log("==ACTOR ACTION " + action.actor.CharSheet.Name + " PHASE with " + action.GetType().ToString() + "==");

//			transitioning = false;

            action.OnFinished += Completed;
            action.Perform();
        }
Пример #7
0
    /// <summary>
    /// In here a Perform Action state is created.
    /// If the Agent does NOT have an Action plan, the FSM gets pushed back to the IdleState.
    /// If a plan is available, the first Action in the queue is peeked, and, if completed, it is removed.
    /// If the Action has NOT been completed, on the other hand, it will be taken into consideration for completion.
    /// A distance check will be made if the Action requires to be in range. At this point if still it is not, the MoveTo state will be pushed.
    /// If NONE of the above is true, the action will be performed and marked as completed.
    /// </summary>
    private void createPerformActionState()
    {
        performActionState = (fsm, gameObj) => {
            // perform the action

            if (!hasActionPlan())
            {
                // no actions to perform
                Debug.Log("<color=red>Done actions</color>");
                fsm.PopState();
                fsm.PushState(idleState);
                dataProvider.actionsFinished();
                return;
            }

            Action action = currentActions.Peek();
            if (action.IsDone())
            {
                // the action is done. Remove it so we can perform the next one
                currentActions.Dequeue();
            }

            if (hasActionPlan())
            {
                // perform the next action
                action = currentActions.Peek();
                bool inRange = action.RequiresInRange() ? action.GetInRange() : true;

                if (inRange)
                {
                    // we are in range, so perform the action
                    bool success = action.Perform(gameObj);

                    if (!success)
                    {
                        // action failed, we need to plan again
                        fsm.PopState();
                        fsm.PushState(idleState);
                        dataProvider.planAborted(action);
                    }
                }
                else
                {
                    // we need to move there first
                    // push moveTo state
                    fsm.PushState(moveToState);
                }
            }
            else
            {
                // no actions left, move to Plan state
                fsm.PopState();
                fsm.PushState(idleState);
                dataProvider.actionsFinished();
            }
        };
    }
Пример #8
0
    private IEnumerator Act()
    {
        while (!Health.GetHP().IsEmpty())
        {
            int    i      = Random.Range(0, actions.Count - 1);
            Action action = actions[i];

            yield return(action.Perform(targetObject));
        }

        //TODO: Die animation
        promptEvent.Raise("Judgement died violently.");
    }
        void CommentService_Created(object sender, CommentEventArgs e)
        {
            if (e.Comment != null && e.Comment.MemberId > 0)
            {
                var ms     = ApplicationContext.Current.Services.MemberService;
                var member = ms.GetById(e.Comment.MemberId);
                member.IncreaseForumPostCount();
                ms.Save(member);

                Action a = new Action("NewComment");
                a.Perform(member.Id, e.Comment.Id, "New comment created");
            }
        }
        void TopicService_Created(object sender, TopicEventArgs e)
        {
            if (e.Topic != null && e.Topic.MemberId > 0)
            {
                var ms     = ApplicationContext.Current.Services.MemberService;
                var member = ms.GetById(e.Topic.MemberId);
                member.IncreaseForumPostCount();
                ms.Save(member);

                Action a = new Action("NewTopic");
                a.Perform(member.Id, e.Topic.Id, "New topic created");
            }
        }
Пример #11
0
 void Update()
 {
     // start next action if this one's done
     if (currentAction == null || currentAction.status == ActionStatus.Acted)
     {
         currentAction = GetNextAction();
         if (currentAction != null)
         {
             currentAction.status = ActionStatus.Acting;
             currentAction.Perform(gm);
         }
     }
 }
Пример #12
0
        private void StepUnit(CombatUnit unit)
        {
            if (unit.Energy < unit.EnergyMax && unit.EnergyMax > 0)
            {
                unit.Energy = System.Math.Min(unit.Energy + 0.03516f, unit.EnergyMax);
            }

            if (unit.FramesUntilNextAttack > 0)
            {
                unit.FramesUntilNextAttack--;
            }
            if (unit.SecondaryAttackFrame == SimulationFrame && unit.AdditionalAttacksRemaining > 0)
            {
                unit.PerformAdditionalAttack(this);
            }

            Action action = unit.GetAction(this);

            if (!(action is Attack))
            {
                unit.AdditionalAttacksRemaining = 0;
            }
            action.Perform(this, unit);

            foreach (Buff buff in unit.Buffs)
            {
                buff.OnFrame(this, unit);
            }

            bool buffRemoved = false;

            for (int i = unit.Buffs.Count - 1; i >= 0; i--)
            {
                Buff buff = unit.Buffs[i];
                if (buff.ExpireFrame > SimulationFrame)
                {
                    continue;
                }
                buffRemoved = true;
                unit.Buffs.RemoveAt(i);
                if (buff is DamageProcessor)
                {
                    unit.DamageProcessors.Remove((DamageProcessor)buff);
                }
            }
            if (buffRemoved)
            {
                unit.RecalculateBuffs();
            }
        }
Пример #13
0
 public void PerformAction(UnitPiece piece, Action action, Point tile, bool free = false)
 {
     if (!free)
     {
         piece.unit.hasActionLeft = false;
     }
     action.Perform(mapManager, tile);
     piece.PerformingAction(action);
     piece.Animation(action.type);
     if (action.type == ActionType.Attack)
     {
         Unit target = GetUnit(tile).unit;
         if (!target.IsAlive())
         {
             RemoveUnit(tile);
         }
     }
 }
Пример #14
0
    bool PerformActions()
    {
        for (int i = 0; i < characters.Count; i++)
        {
            Character player = characters[i];

            for (int s = 0; s < player.history.Count; s++)
            {
                Action action      = player.history[s];
                int    startTime   = action.time;
                int    performTime = startTime + action.duration - 1;

                if (currentTime < startTime)
                {
                    continue;
                }
                else if (currentTime == performTime)
                {
                    if (action.Perform(player) == false)
                    {
                        return(false);
                    }

                    break;
                }
                else if (currentTime < performTime)
                {
                    if (action.Prepare(player) == false)
                    {
                        return(false);
                    }

                    break;
                }
                else if (startTime > currentTime)
                {
                    break;
                }
            }
        }

        return(true);
    }
Пример #15
0
 public override void PerformTurn(GameController p_Context, Unit p_Unit)
 {
     if (GetComponent <Unit>().GetStat("Health").CurrentValue <= 0)
     {
         Lose.SetActive(true);
         ButnController.DeactiveAll();
         p_Context.Over = true;
         return;
     }
     if (!DisableAction)
     {
         p_Context.UnMark();
         ActiveAction.Perform(p_Unit, null, p_Context);
         ProcessPlayerInput(p_Context, p_Unit);
     }
     if (GetComponent <Unit>().CurTile.Type == 'V')
     {
         Win.SetActive(true);
         ButnController.DeactiveAll();
         p_Context.Over = true;
     }
 }
 public void TryToPassiveChat()
 {
     foreach (NPC npc in npcDict.Values) {
         DecrementPassiveChatTimer(npc);
         if (npc.CanPassiveChat() && npc.timeTillPassiveChatAgain <= 0 && InSight(npc.gameObject, player.gameObject)) {
             SetPassiveChatTimer(npc);
             if (Random.Range(1, CHANCE_TO_PASSIVE_CHAT) > 1) {
                 if (InPassiveChatDistance(npc.gameObject, player.gameObject)) {
                     sayHi = new ShowOneOffChatAction(npc, PassiveChatToPlayer.instance.GetTextToSay(npc));
                     sayHi.Perform();
                 } else {
                     foreach (NPC npcToCheck in npcDict.Values) {
                         if (npc != npcToCheck && InPassiveChatDistance(npc.gameObject, npcToCheck.gameObject) && RequestChat(npcToCheck)) {
                             npc.AddSchedule(new NPCConvoSchedule(npc, npcToCheck, NPCPassiveConvoDictionary.instance.GetConversation(npc)));
                             break;
                         }
                     }
                 }
             }
         }
     }
 }
Пример #17
0
    public bool PerformAction(Point tile)
    {
        bool found = false;

        foreach (TargetTile targetTile in targets)
        {
            if (targetTile.point == tile)
            {
                found = targetTile.type == TargetType.Valid;
                break;
            }
        }

        if (found)
        {
            if (!action.CanUse())
            {
                // ToDo: Show lack of energy
                return(false);
            }
            actionPerformed = true;
            targets.Clear();
            mapManager.RemoveMarkings();
            action.Perform(mapManager, tile);
            selectedUnit.PerformingAction(action);
            selectedUnit.Animation(action.type);
            if (action.type == ActionType.Attack)
            {
                Unit target = GetUnit(tile).unit;
                if (!target.IsAlive())
                {
                    RemoveUnit(tile);
                }
            }
            combatManager.EndTurn();
            return(true);
        }
        return(false);
    }
Пример #18
0
 private void PerformAction()
 {
     currentAction = GetCurrentActor().GetAction();
     if (currentAction == null)
     {
         return;                                //Should only happen for player actor
     }
     while (true)
     {
         ActionResult result = currentAction.Perform();
         if (result.Succeeded)
         {
             if (!GetCurrentActor().HasEnergyToActivate(currentAction.EnergyCost))
             {
                 Debug.LogError(currentAction + "Perform should check if actor has sufficient energy, and return an alternate if it does not. Defaulting to rest action.");
                 currentAction = GetCurrentActor().GetRestAction();
             }
             GetCurrentActor().SpendEnergyForActivation(currentAction.EnergyCost);
             break;
         }
         currentAction = result.Alternate;
     }
 }
Пример #19
0
    public void DoAction(eActionType type, int iRow, int iCol, int iIcon)
    {
        switch (type)
        {
        case eActionType.eAT_EliminateIcon:
            //m_SoundManager.PlayGameEliminateIcon();
            break;

        case eActionType.eAT_RestoreIcon:
            //m_SoundManager.PlayGameRestoreIcon();
            break;

        case eActionType.eAT_SetFinalIcon:
            //m_SoundManager.PlayGameSetFinalIcon();
            break;
        }

        Action a = new Action(type, iRow, iCol, iIcon, HappinessGameInfo.Puzzle);

        a.Perform(HappinessGameInfo.Puzzle);

        UnityEngine.Debug.Log("TODO: Implmenet undo size");

        /*
         * int undoSize = Game.TheGameInfo.VipData.UndoSize <= 0 ? int.MaxValue : Game.TheGameInfo.VipData.UndoSize;
         * while (m_History.Count >= undoSize)
         * {
         *      m_History.RemoveAt(0);
         * }
         */
        History.Add(a);


        UnityEngine.Debug.Log("TODO: Implement save puzzle");
        //SavePuzzle();
    }
Пример #20
0
    private void CheckAction()
    {
        if (!(action is null))
        {
            if (timeKeeper.Finished("action"))
            {
                if (action.notifiable)
                {
                    SendAction(action);
                }
                else
                {
                    action.Perform();
                }

                action.Success();
                action = null;
            }
            else
            {
                action.Progress();
            }
        }
    }
Пример #21
0
    IEnumerator TypeSentence(string sentence)
    {
        if (sentence != null)
        {
            dialogueText.text = "<mspace=1em>";
            currentSentence   = sentence;
            Debug.Log(currentSentence);
            coroutineRunning = true;
            currentChar      = 0;
            currentLine      = 0;
            foreach (char letter in sentence.ToCharArray())
            {
                if (letter != '&' && letter != '%' && letter != '@')
                {
                    dialogueText.text += letter;
                }
                if (letter == ' ')
                {
                    //Debug.Log(currentChar);

                    string subStr = sentence.Substring(currentChar + 1);
                    lineOffset = 0;
                    bool escape = false;
                    foreach (char letter2 in subStr.ToCharArray())
                    {
                        if (!escape)
                        {
                            if (letter2 == ' ')
                            {
                                escape = true;
                            }
                            if (currentLine + lineOffset >= lineSize - 2)
                            {
                                dialogueText.text += '\n';
                                currentLine        = -1;
                                escape             = true;
                            }
                            if (letter != '&' && letter != '%')
                            {
                                lineOffset++;
                            }
                        }
                    }
                }

                if (letter == '&')
                {
                    yield return(new WaitForSeconds(timeDelay));

                    currentLine -= 1;
                }
                if (letter == '%')
                {
                    dialogueText.text += '\n';
                    currentLine        = -1;
                }
                if (letter == '@')
                {
                    GameControl.EndBattle();
                    yield return(new WaitForSeconds(10));
                }
                currentChar++;
                currentLine++;
                yield return(new WaitForSeconds(timeDelay));
            }
            coroutineRunning = false;
            yield return(new WaitForSeconds((timeDelay * messagePause)));

            if (bonusSentences.Count <= 0 && sentences.Count < actionOrder.Count)
            {
                if (actionOrder.Count > 0)
                {
                    List <List <Object> > objectsList = actionOrder[0];
                    actionOrder.RemoveAt(0);

                    if (objectsList != null)
                    {
                        foreach (List <Object> objects in objectsList)
                        {
                            GameObject casterObj = (GameObject)objects[0];
                            GameObject targetObj = (GameObject)objects[1];


                            CharacterStats casterStats = casterObj.GetComponent <CharacterStats>();
                            CharacterStats targetStats = targetObj.GetComponent <CharacterStats>();
                            Action         action      = (Action)objects[2];

                            int deathCount = 0;
                            foreach (GameObject player in battleManager.players)
                            {
                                if (!player.activeSelf)
                                {
                                    deathCount++;
                                }
                            }

                            if (casterObj.activeSelf)
                            {
                                if (battleManager.players.Contains(casterObj))
                                {
                                    battleManager.healthBlocks[battleManager.players.IndexOf(casterObj)].GetComponent <Animator>().SetInteger("State", 0);
                                }
                                action.Perform(casterStats, targetStats);

                                foreach (GameObject player in battleManager.players)
                                {
                                    CharacterStats currStats = player.GetComponent <CharacterStats>();
                                    battleManager.healthBlocks[battleManager.players.IndexOf(player)].transform.GetChild(0).GetChild(1).GetChild(0).GetChild(1).GetComponent <TextMeshProUGUI>().SetText(currStats.characterName + "\n" + currStats.currentHealth + "/" + currStats.maxHealth.GetValue());
                                    battleManager.healthBlocks[battleManager.players.IndexOf(player)].transform.GetChild(0).GetChild(1).GetChild(0).GetChild(2).GetChild(0).GetComponent <Slider>().value = (float)(((float)currStats.currentHealth) / ((float)currStats.maxHealth.GetValue()));
                                }
                            }
                        }
                    }
                }

                if (passiveOrder.Count > 0)
                {
                    List <List <Object> > objectsList = passiveOrder[0];
                    passiveOrder.RemoveAt(0);

                    if (objectsList != null)
                    {
                        foreach (List <Object> objects in objectsList)
                        {
                            GameObject casterObj = (GameObject)objects[0];
                            GameObject targetObj = (GameObject)objects[1];


                            CharacterStats casterStats = casterObj.GetComponent <CharacterStats>();
                            CharacterStats targetStats = targetObj.GetComponent <CharacterStats>();
                            Action         action      = (Action)objects[2];
                            //Debug.Log("TESTING!");
                            action.PerformPassive(casterStats, targetStats);

                            foreach (GameObject player in battleManager.players)
                            {
                                CharacterStats currStats = player.GetComponent <CharacterStats>();

                                battleManager.healthBlocks[battleManager.players.IndexOf(player)].transform.GetChild(0).GetChild(1).GetChild(0).GetChild(1).GetComponent <TextMeshProUGUI>().SetText(currStats.characterName + "\n" + currStats.currentHealth + "/" + currStats.maxHealth.GetValue());
                                battleManager.healthBlocks[battleManager.players.IndexOf(player)].transform.GetChild(0).GetChild(1).GetChild(0).GetChild(2).GetChild(0).GetComponent <Slider>().value = (float)(((float)currStats.currentHealth) / ((float)currStats.maxHealth.GetValue()));
                            }
                        }
                    }
                }
            }
        }
        else
        {
            if (actionOrder.Count > 0)
            {
                actionOrder.RemoveAt(0);
            }
            if (passiveOrder.Count > 0)
            {
                passiveOrder.RemoveAt(0);
            }
        }


        RecheckActive();


        //Debug.Log(actionOrder.Count);
        //Debug.Log(passiveOrder.Count);
        //Debug.Log(sentences.Count);
        //Debug.Log("");

        DisplayNextSentence();
    }
Пример #22
0
    public override void PerformTurn(GameController p_Context, Unit p_Unit)
    {
        Vector2Int warrior_position = p_Unit.CurTile.RoomPosition;
        Vector2Int player_position  = p_Context.Player.CurTile.RoomPosition;

        int distance = calculate_distance(warrior_position, player_position);

        if (distance == 1)
        {
            Action attack = p_Unit.GetAction("Attack");
            attack.Perform(p_Unit, p_Context.Player, null);
        }
        else
        {
            Vector2Int move_to_pos = warrior_position;

            // Left
            Vector2Int left    = new Vector2Int(warrior_position.x - 1, warrior_position.y);
            Tile       curTile = p_Context.CurRoom.GetTileAt(left);
            if (CanMoveTo(p_Unit, curTile) && !curTile.IsDoorTile)
            {
                if (calculate_distance(left, player_position) < distance)
                {
                    distance    = calculate_distance(left, player_position);
                    move_to_pos = left;
                }
            }

            // Right
            Vector2Int right = new Vector2Int(warrior_position.x + 1, warrior_position.y);
            curTile = p_Context.CurRoom.GetTileAt(right);
            if (CanMoveTo(p_Unit, curTile) && !curTile.IsDoorTile)
            {
                if (calculate_distance(right, player_position) < distance)
                {
                    distance    = calculate_distance(right, player_position);
                    move_to_pos = right;
                }
            }

            // Up
            Vector2Int up = new Vector2Int(warrior_position.x, warrior_position.y + 1);
            curTile = p_Context.CurRoom.GetTileAt(up);
            if (CanMoveTo(p_Unit, curTile) && !curTile.IsDoorTile)
            {
                if (calculate_distance(up, player_position) < distance)
                {
                    distance    = calculate_distance(up, player_position);
                    move_to_pos = up;
                }
            }

            // Down
            Vector2Int down = new Vector2Int(warrior_position.x, warrior_position.y - 1);
            curTile = p_Context.CurRoom.GetTileAt(down);
            if (CanMoveTo(p_Unit, curTile) && !curTile.IsDoorTile)
            {
                if (calculate_distance(down, player_position) < distance)
                {
                    distance    = calculate_distance(down, player_position);
                    move_to_pos = down;
                }
            }

            curTile = p_Context.CurRoom.GetTileAt(move_to_pos);
            p_Context.MoveUnitToTile(p_Unit, curTile);
        }
    }
Пример #23
0
        static void Main(string[] args)
        {
            IWebDriver driver = new FirefoxDriver();

            driver.Manage().Window.Maximize();
            driver.Navigate().GoToUrl("https://www.redbus.in/");
            IWebElement src = driver.FindElement(By.XPath("//*[@id='src']"));

            src.SendKeys("Hyderabad");
            System.Threading.Thread.Sleep(1000);
            IWebElement dest = driver.FindElement(By.XPath("//*[@id='dest']"));

            dest.SendKeys("Bangalore");
            System.Threading.Thread.Sleep(1000);
            IWebElement startDate = driver.FindElement(By.Id("onward_cal"));
            //startDate.Click();
            IJavaScriptExecutor js = (IJavaScriptExecutor)driver;

            js.ExecuteScript("arguments[0].setAttribute('value','26-Aug-2018');", startDate);
            //var startDates = driver.FindElements(By.TagName("table"));
            //var dates = startDates[0].FindElement(By.ClassName("current day"));
            System.Threading.Thread.Sleep(1000);
            var search = driver.FindElement(By.Id("search_btn"));

            search.Click();
            System.Threading.Thread.Sleep(5000);
            var buses = driver.FindElements(By.ClassName("row-sec"));

            Dictionary <string, int>    prices = new Dictionary <string, int>();
            Dictionary <string, string> ids    = new Dictionary <string, string>();
            //int[] prices = new int[buses.Count];
            int i = 0;

            foreach (var bus in buses)
            {
                string busId   = bus.GetAttribute("id");
                var    fare    = bus.FindElement(By.ClassName("seat-fare"));
                var    fare1   = fare.FindElement(By.ClassName("f-bold"));
                string busName = bus.FindElement(By.ClassName("travels")).Text;
                string value   = fare1.Text;
                int    busFare = Convert.ToInt32(Convert.ToDouble(value));

                //int busFare = Int32.Parse(fare1.Text);
                Console.WriteLine("fare for bus {0} is {1}", busName, busFare);
                try
                {
                    prices.Add(busName, busFare);
                    ids.Add(busName, busId);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception thrown: " + e.StackTrace);
                }
                //prices[i++] = busFare;
            }

            string minFareBus = "";
            int    minFare    = int.MaxValue;

            //string key = "";
            foreach (string key in prices.Keys)
            {
                if (prices[key] < minFare)
                {
                    minFare    = prices[key];
                    minFareBus = key;
                }
            }

            Console.WriteLine("Lowest price is {0} for travels: {1}", minFare, minFareBus);
            var selectedBus = driver.FindElement(By.Id(ids[minFareBus]));
            var button      = selectedBus.FindElement(By.ClassName("button"));

            button.Click();

            IWebElement element = driver.FindElement(By.TagName("canvas"));

            Actions builder    = new Actions(driver);
            Action  drawAction = builder.MoveToElement(element, 135, 15)
                                 .Click()
                                 .MoveByOffset(200, 60)         // 2nd points (x1,y1)
                                 .Click()
                                 .MoveByOffset(100, 70)         // 3rd points (x2,y2)
                                 .DoubleClick()
                                 .Build();



            drawAction.Perform();



            Console.ReadLine();
        }
 public void Perform(SelectList list)
 {
     _action.Perform(list);
 }
Пример #25
0
 public void Activate()      // What this thing does when it's activated
 {
     triggeredAction.Perform();
 }
Пример #26
0
    public override void PerformTurn(GameController p_Context, Unit p_Unit)
    {
        Vector2Int archer_position = p_Unit.CurTile.RoomPosition;
        Vector2Int player_position = p_Context.Player.CurTile.RoomPosition;

        if (Can_shoot(archer_position, player_position))
        {
            Action attack = p_Unit.GetAction("Attack");
            attack.Perform(p_Unit, p_Context.Player, null);
        }
        else
        {
            // Left
            Vector2Int left        = new Vector2Int(archer_position.x - 1, archer_position.y);
            Tile       curTile     = p_Context.CurRoom.GetTileAt(left);
            int        distance    = 0;
            Vector2Int move_to_pos = archer_position;
            if (CanMoveTo(p_Unit, curTile) && !curTile.IsDoorTile)
            {
                distance    = Mathf.Abs(left.x - player_position.x);
                move_to_pos = left;
            }

            // Right
            Vector2Int right = new Vector2Int(archer_position.x + 1, archer_position.y);
            curTile = p_Context.CurRoom.GetTileAt(right);
            if (CanMoveTo(p_Unit, curTile) && !curTile.IsDoorTile)
            {
                if (Mathf.Abs(right.x - player_position.x) < distance)
                {
                    distance    = Mathf.Abs(right.x - player_position.x);
                    move_to_pos = right;
                }
            }

            // Up
            Vector2Int up = new Vector2Int(archer_position.x, archer_position.y + 1);
            curTile = p_Context.CurRoom.GetTileAt(up);
            if (CanMoveTo(p_Unit, curTile) && !curTile.IsDoorTile)
            {
                if (Mathf.Abs(up.y - player_position.y) < distance)
                {
                    distance    = Mathf.Abs(up.y - player_position.y);
                    move_to_pos = up;
                }
            }

            // Down
            Vector2Int down = new Vector2Int(archer_position.x, archer_position.y - 1);
            curTile = p_Context.CurRoom.GetTileAt(down);
            if (CanMoveTo(p_Unit, curTile) && !curTile.IsDoorTile)
            {
                if (Mathf.Abs(down.y - player_position.y) < distance)
                {
                    distance    = Mathf.Abs(down.y - player_position.y);
                    move_to_pos = down;
                }
            }

            curTile = p_Context.CurRoom.GetTileAt(move_to_pos);
            if (move_to_pos == archer_position)
            {
                curTile = p_Context.CurRoom.GetTileAt(left);
                if (!CanMoveTo(p_Unit, curTile) || curTile.IsDoorTile)
                {
                    curTile = p_Context.CurRoom.GetTileAt(right);
                    if (!CanMoveTo(p_Unit, curTile) || curTile.IsDoorTile)
                    {
                        curTile = p_Context.CurRoom.GetTileAt(up);
                        if (!CanMoveTo(p_Unit, curTile) || curTile.IsDoorTile)
                        {
                            curTile = p_Context.CurRoom.GetTileAt(down);
                        }
                    }
                }
            }
            p_Context.MoveUnitToTile(p_Unit, curTile);
        }
    }