Ejemplo n.º 1
0
        public async Task Handle_GivenInvalidRequest_ShouldThrowNotFoundException()
        {
            // Arrange
            var command = new AddPointsCommand {
                Points = 5, TeamId = 212, TournamentId = 112
            };
            var sut = new AddPointsCommandHandler(this.deletableEntityRepository);

            // Act & Assert
            await Should.ThrowAsync <NotFoundException>(sut.Handle(command, It.IsAny <CancellationToken>()));
        }
Ejemplo n.º 2
0
        public async Task Handle_GivenValidRequest_ShouldAddPoints()
        {
            // Arrange
            var command = new AddPointsCommand {
                Points = 5, TeamId = 1, TournamentId = 1
            };
            var sut = new AddPointsCommandHandler(this.deletableEntityRepository);

            // Act
            var rowsAffected = await sut.Handle(command, It.IsAny <CancellationToken>());

            // Assert
            rowsAffected.ShouldBe(1);

            var desiredTTR = this.deletableEntityRepository.AllAsNoTracking().OrderByDescending(x => x.ModifiedOn).FirstOrDefault();

            desiredTTR.Points.ShouldBe(5);
        }
        public void RemoveCoins()
        {
            var cmd = new AddPointsCommand(-Random.Range(1, 5));

            gameOperator.gameExecutor.Execute(cmd);
        }
Ejemplo n.º 4
0
    public static void executeCommand(ICommand command)
    {
        if (command.GetType().Equals(typeof(SpeakerCommand)))                                       //speaker
        {
            SpeakerCommand speakerCommand = (SpeakerCommand)command;
            currentSpeaker = speakerCommand.speaker;
            GameObject speakerBox   = GameObject.Find("Speaker");
            Text       speakerText  = speakerBox.GetComponentInChildren <Text>();
            Image      speakerImage = speakerBox.GetComponentInChildren <Image>();
            if (speakerCommand.speaker.Equals(""))
            {
                speakerText.color  = Color.clear;
                speakerImage.color = Color.clear;
            }
            else
            {
                speakerText.color  = Color.white;
                speakerImage.color = new Color(1f, 1f, 1f, 0.4f);
                speakerText.text   = speakerCommand.speaker;
            }
            advanceScript();
        }
        else if (command.GetType().Equals(typeof(TextCommand)))                                     //text
        {
            TextCommand textCommand = (TextCommand)command;
            GameObject.Find("Dialogue").GetComponentInChildren <Text>().text = textCommand.text;
        }
        else if (command.GetType().Equals(typeof(PortraitCommand)))                                 //portrait
        {
            PortraitCommand portraitCommand = (PortraitCommand)command;
            Image           portrait        = GameObject.Find(portraitCommand.side == 'L' ? "LeftPortrait" : "RightPortrait").GetComponentInChildren <Image>();
            if (portraitCommand.character.Equals(""))
            {
                portrait.color = Color.clear;
            }
            else
            {
                portrait.color  = Color.white;
                portrait.sprite = Resources.Load <Sprite>("Characters\\" + portraitCommand.character + "Girl");
            }
            advanceScript();
        }
        else if (command.GetType().Equals(typeof(BackgroundCommand)))                               //background
        {
            BackgroundCommand backgroundCommand = (BackgroundCommand)command;
            Image             background        = GameObject.Find("Background").GetComponentInChildren <Image>();
            if (backgroundCommand.name.Equals(""))
            {
                background.color = Color.black;
            }
            else
            {
                background.color  = Color.white;
                background.sprite = Resources.Load <Sprite>("Backgrounds\\" + backgroundCommand.name);
            }
            advanceScript();
        }
        else if (command.GetType().Equals(typeof(LinkCommand)))                                     //link
        {
            LinkCommand linkCommand = (LinkCommand)command;
            readScript(linkCommand.fileName);
            advanceScript();
        }
        else if (command.GetType().Equals(typeof(AddPointsCommand)))                                //addpoints
        {
            AddPointsCommand addPointsCommand = (AddPointsCommand)command;
            switch (addPointsCommand.character)
            {
            case "Java":
                GameControl.control.JavaLovePoints += addPointsCommand.points;
                break;

            case "JSHTML":
                GameControl.control.JSHTMLLovePoints += addPointsCommand.points;
                break;

            case "C++":
                GameControl.control.CPPLovePoints += addPointsCommand.points;
                break;

            case "C#":
                GameControl.control.CSLovePoints += addPointsCommand.points;
                break;

            case "Python":
                GameControl.control.PYLovePoints += addPointsCommand.points;
                break;
            }
            advanceScript();
        }
        else if (command.GetType().Equals(typeof(PromptCommand)))                                   //prompt
        {
            PromptCommand promptCommand = (PromptCommand)command;
            isPrompting = true;
            int i = 0;
            List <GameObject> promptButtons = new List <GameObject>();
            foreach (string choice in promptCommand.getChoices())
            {
                GameObject promptButton = Instantiate(Resources.Load <GameObject>("Prefabs\\PromptButton"),
                                                      new Vector3(0, 0), Quaternion.identity);
                promptButtons.Add(promptButton);
                promptButton.transform.SetParent(GameObject.Find("Background").transform);
                promptButton.transform.position = new Vector3(Screen.width / 2, (Screen.height - 55) - i * 40);
                promptButton.GetComponentInChildren <Text>().text = choice;
                promptButton.GetComponentInChildren <Button>().onClick.AddListener(delegate {
                    isPrompting = false;
                    foreach (GameObject button in promptButtons)
                    {
                        Destroy(button);
                    }
                    currentScript.InsertRange(commandIndex, promptCommand.getConsequences(choice));
                    advanceScript();
                });
                i++;
            }
        }
        else if (command.GetType().Equals(typeof(DateCheckCommand)))                                //datecheck
        {
            DateCheckCommand dateCheckCommand = (DateCheckCommand)command;
            switch (dateCheckCommand.character)
            {
            case "Java":
                if (GameControl.control.JavaLovePoints >= 15)
                {
                    //date start
                }
                break;

            case "JSHTML":
                if (GameControl.control.JSHTMLLovePoints >= 15)
                {
                    //date start
                }
                break;

            case "C++":
                if (GameControl.control.CPPLovePoints >= 15)
                {
                    //date start
                }
                break;

            case "C#":
                if (GameControl.control.CSLovePoints >= 15)
                {
                    //date start
                }
                break;

            case "Python":
                if (GameControl.control.PYLovePoints >= 15)
                {
                    //date start
                }
                break;
            }
        }
        else if (command.GetType().Equals(typeof(FinalCheckCommand)))                               //finalcheck
        {
            FinalCheckCommand finalCheckCommand = (FinalCheckCommand)command;
            PromptCommand     promptCommand     = new PromptCommand();
            if (GameControl.control.JavaLovePoints >= 15)
            {
                List <ICommand> commandList = new List <ICommand>();
                commandList.Add(new LinkCommand("\\Home\\Narrator\\Endings\\Java.txt"));
                promptCommand.addConsequences("Java", commandList);
            }
            if (GameControl.control.JSHTMLLovePoints >= 15)
            {
                List <ICommand> commandList = new List <ICommand>();
                commandList.Add(new LinkCommand("\\Home\\Narrator\\Endings\\HTML&JS.txt"));
                promptCommand.addConsequences("HTML & JS", commandList);
            }
            if (GameControl.control.CPPLovePoints >= 15)
            {
                List <ICommand> commandList = new List <ICommand>();
                commandList.Add(new LinkCommand("\\Home\\Narrator\\Endings\\C++.txt"));
                promptCommand.addConsequences("C++", commandList);
            }
            if (GameControl.control.CSLovePoints >= 15)
            {
                List <ICommand> commandList = new List <ICommand>();
                commandList.Add(new LinkCommand("\\Home\\Narrator\\Endings\\C#.txt"));
                promptCommand.addConsequences("C#", commandList);
            }
            if (GameControl.control.PYLovePoints >= 15)
            {
                List <ICommand> commandList = new List <ICommand>();
                commandList.Add(new LinkCommand("\\Home\\Narrator\\Endings\\Python.txt"));
                promptCommand.addConsequences("Python", commandList);
            }
            List <ICommand> noneCommandList = new List <ICommand>();
            noneCommandList.Add(new LinkCommand("\\Home\\Narrator\\Endings\\None.txt"));
            promptCommand.addConsequences("None", noneCommandList);
            currentScript.Insert(commandIndex, promptCommand);
            advanceScript();
        }
    }