Пример #1
0
        public PacMan(Game game)
            : base(game)
        {
            // TODO: Construct any child components her
            pi = 0;

            input = (InputHandler)game.Services.GetService(typeof(IInputHandler));

            //Make sure input service exists
            if (input == null)
            {
                throw new Exception("PacMan Depends on Input service please add input service before you add PacMan.");
            }

            console = (GameConsole)game.Services.GetService(typeof(IGameConsole));
            //Make sure input service exists
            if (console == null)
            {
                throw new Exception("PacMan Depends on Console service please add Console service before you add PacMan.");
            }

            score = (ScoreService)game.Services.GetService(typeof(IScoreService));
            //Make sure input service exists
            if (console == null)
            {
                throw new Exception("PacMan Depends on Score service please add Score service before you add PacMan.");
            }
        }
Пример #2
0
        public void GetAspectScores_InputIsAnswers_AspectScores()
        {
            var answers = new List <AnsweredQuestionDTO>()
            {
                new AnsweredQuestionDTO
                {
                    Aspect     = 1,
                    Multiplier = 0.3f
                },
                new AnsweredQuestionDTO
                {
                    Aspect     = 1,
                    Multiplier = 0.2f
                },
                new AnsweredQuestionDTO
                {
                    Aspect     = 2,
                    Multiplier = 0.1f
                }
            };

            var scoreService = new ScoreService();
            var scores       = scoreService.GetAspectScores(answers);

            Assert.Equal(0.25f, scores[1], 1);
            Assert.Equal(0.1f, scores[2], 1);
        }
Пример #3
0
        public void StoryRuleShouldReturn0WhenAllVotesCorrect()
        {
            var storyTeller = player4;
            var storyCard   = card4;
            var votes       = new List <Vote> {
                new Vote(player1, storyCard), new Vote(player2, storyCard), new Vote(player3, storyCard)
            };

            var rules = new List <IScoringRule> {
                new BonusRule(), new CorrectRule(), new StoryTellerRule()
            };

            var scoreService = new ScoreService(rules);
            var scoreBoard   = scoreService.VallyVotes(votes, player4, storyCard);

            var player1Score = scoreBoard.Find(board => board.Player == player1);
            var player2Score = scoreBoard.Find(board => board.Player == player2);
            var player3Score = scoreBoard.Find(board => board.Player == player3);
            var player4Score = scoreBoard.Find(board => board.Player == player4);

            player1Score.Score.Should().Be(2);
            player2Score.Score.Should().Be(2);
            player3Score.Score.Should().Be(2);
            player4Score.Should().BeNull();
        }
Пример #4
0
 /// <summary>
 /// 根据成绩ID修改成绩分数
 /// </summary>
 /// <param name="scoreId"></param>
 /// <param name="result"></param>
 /// <returns></returns>
 public static async Task ChangeScore(Guid scoreId, int result)
 {
     using (var scoreSvc = new ScoreService())
     {
         await scoreSvc.ChangeScore(scoreId, result);
     }
 }
Пример #5
0
        public ScoreApi(RequestContext request)
        {
            _request = request;
            IScoreService scoreService = new ScoreService();

            _scoreController = new ScoreController(scoreService);
        }
Пример #6
0
    private void Awake()
    {
        YouLose.gameObject.SetActive(false);
        InstanceCache.Flush();

        gameRepository   = InstanceCache.GetOrInstanciate <InMemoryGameRepository>(() => new InMemoryGameRepository());
        resultRepository = InstanceCache.GetOrInstanciate <InMemoryResultRepository>(() => new InMemoryResultRepository());
        scoreService     = InstanceCache.GetOrInstanciate <LocalScoreService>(() => new LocalScoreService());
        resultRepository.Clear();
        gameRepository.Clear();
        scoreService.Reset();

        gamePresenter = InstanceCache.GetOrInstanciate <GamePresenter>(
            () => {
            resultGenerator = new ResultGenerator(4, new AdditionOperator(), new RandomNumberGenerator(5, 15));
            return(new GamePresenter(
                       this,
                       new CreateGame(gameRepository,
                                      new FixedInitialNumber(),
                                      resultGenerator,
                                      resultRepository),
                       new Guess(gameRepository, resultRepository, resultGenerator, scoreService),
                       scoreService));
        });
    }
Пример #7
0
        static void Main(string[] args)
        {
            var userProvider  = new UsersDataProvider(_connection);
            var scoreProvider = new ScoreDataProvider(_connection);
            var scoreService  = new ScoreService(scoreProvider, userProvider);

            Stopwatch watch = new Stopwatch();

            watch.Start();



            for (int i = 0; i < 100; i++)
            {
                scoreService.AddScore($"Player_{i}", $"Victim_{i}", getRandWeapon(), getRandBodyPart()).Wait();
                for (int j = 0; j < 10 + i; j++)
                {
                    scoreService.AddSuicide("Nub").Wait();
                    scoreService.AddTeamKill($"Player_{i}", $"Victim_{i}", getRandWeapon(), getRandBodyPart()).Wait();
                    scoreService.AddSpawnKill($"Player_{i}", $"Victim_{i}", getRandWeapon(), getRandBodyPart()).Wait();
                }
            }



            watch.Stop();

            Console.WriteLine($"Done\nTime elapsed: {watch.Elapsed}");
            Console.Read();
        }
Пример #8
0
        private ScoreService CreateScoreService()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new ScoreService(userId);

            return(service);
        }
Пример #9
0
        public ActionResult <IEnumerable <string> > Get()
        {
            ScoreService scoreService = new ScoreService(_dbConnectionFactory);
            var          highscores   = scoreService.GetHighscores();

            return(highscores.Select(x => x.Name).ToArray());
        }
Пример #10
0
 public GamePresenter(MainComponent mainComponent, CreateGame createGame, Guess guess, ScoreService scoreService)
 {
     this.mainComponent = mainComponent;
     this.createGame    = createGame;
     this.guess         = guess;
     this.scoreService  = scoreService;
 }
Пример #11
0
 void Awake()
 {
     ScoreService.NewGame(this.maps.Length);
     this.music = GetComponent <LevelAudio>();
     this.music.Initialize();
     Initialize();
 }
Пример #12
0
        private IScoreService ScoreService()
        {
            var scoreService = new ScoreService();

            scoreService.ClearScores();
            return(scoreService);
        }
Пример #13
0
        public PacMan(Game game)
            : base(game)
        {
            // TODO: Construct any child components her
            playerIndex = 0;

            //PacMan Depends on some game sevices
            #region Dependancy Services
            input = (InputHandler)game.Services.GetService(typeof(IInputHandler));

            //Make sure input service exists
            if (input == null)  //if it doesn't add it this is lazy loading
            {
                throw new Exception("PacMan Depends on Input service please add input service before you add PacMan.");
            }

            console = (GameConsole)game.Services.GetService(typeof(IGameConsole));
            //Make sure input service exists
            if (console == null) //if it doesn't add it
            {
                throw new Exception("PacMan Depends on Console service please add Console service before you add PacMan.");
            }

            score = (ScoreService)game.Services.GetService(typeof(IScoreService));
            //Make sure input service exists
            if (console == null) //if it doesn't add it
            {
                throw new Exception("PacMan Depends on Score service please add Score service before you add PacMan.");
            }
            #endregion
        }
Пример #14
0
        static void Main(string[] args)
        {
            const string dbFileName = "Scores.sqlite";

            Console.WriteLine("Hello World!");

            // todo: Use dependency injection
            var dbConnectionFactor = new SqliteDbConnectionFactory(dbFileName);

            if (!File.Exists(dbFileName))
            {
                dbConnectionFactor.CreateDatabase();
            }

            ScoreService scoreService = new ScoreService(dbConnectionFactor);

            scoreService.AddHighscore(new Highscore()
            {
                Name = "Fred", Score = 123
            });
            scoreService.AddHighscore(new Highscore()
            {
                Name = "Frank", Score = 999
            });

            var highscores = scoreService.GetHighscores();

            foreach (var highscore in highscores)
            {
                Console.WriteLine(highscore);
            }

            Console.ReadLine();
        }
Пример #15
0
        public Score(string category)
        {
            scoreService = new ScoreService(category);

            highestStreak = scoreService.GetScore(HIGHEST_STREAK);
            answered      = scoreService.GetScore(ANSWERED);
            correct       = scoreService.GetScore(CORRECT);
        }
Пример #16
0
        public ActionResult <string> Get(int id)
        {
            ScoreService scoreService = new ScoreService(_dbConnectionFactory);
            var          highscores   = scoreService.GetHighscores();
            var          highscore    = highscores.Single(x => x.Id == id);

            return(highscore.Name);
        }
Пример #17
0
        // GET: Score
        public ActionResult Index()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new ScoreService(userId);
            var model   = service.GetScores();

            return(View(model));
        }
Пример #18
0
 internal static ScoreService getInstance()
 {
     if (instance == null)
     {
         instance = new ScoreService();
     }
     return(instance);
 }
Пример #19
0
    public override void Execute()
    {
        Retain();

        ScoreService.Dispatcher.AddListener(Demo1ServiceEvent.RequsetScore, OnComplete);

        ScoreService.RequestScore("http://xxx.xxx.xxx");
    }
        public void ShouldReturnIntForAnyCPF()
        {
            var serviceProvider   = new ServiceCollection().AddHttpClient().BuildServiceProvider();
            var httpClientFactory = serviceProvider.GetService <IHttpClientFactory>();
            var scoreService      = new ScoreService(httpClientFactory);
            var result            = scoreService.GetScore("teste").Result;

            Assert.NotNull(result);
        }
Пример #21
0
        private void buttonCompute_Click(object sender, EventArgs e)
        {
            List <miniScore> GetSelect = GetCheckBoxSelect();
            GPAInfo          StuGPA    = ScoreService.ComputeUI(GetSelect);

            labelGPA.Text       = StuGPA.GPA.ToString();
            labelAverage.Text   = StuGPA.AverageScore.ToString();
            labelCreditAll.Text = StuGPA.CreditSum.ToString();
        }
Пример #22
0
 public Experience(IExperienceUi experienceUi, ScoreService score,
                   ExperienceService experienceService, IGameEvents gameEvents)
 {
     _experienceUi      = experienceUi;
     _score             = score;
     _experienceService = experienceService;
     _gameEvents        = gameEvents;
     Init();
 }
Пример #23
0
        public ActionResult <string> ShowMoney()
        {
            var idClaim = User.Claims.FirstOrDefault(x => x.Type.Equals(JwtRegisteredClaimNames.Jti, StringComparison.InvariantCultureIgnoreCase));

            if (idClaim != null)
            {
                Guid tokenGuid = Guid.Parse(idClaim.ToString().Remove(0, 5));

                var      scService    = new ScoreService();
                var      workerCount  = 0;
                var      oldCount     = 1;
                int      count        = 2;
                string[] numStringNew = new string[count];
                string[] numString    = new string[count];
                while (workerCount != oldCount)
                {
                    try
                    {
                        var showScore = scService.ReturnScore(new ScoreModel {
                            ClientId = tokenGuid, Id = workerCount
                        }, "SELECT * FROM viewscores WHERE clientid = @clientid AND id >= @id AND exist = TRUE;");
                        oldCount                = workerCount;
                        workerCount             = showScore.Id + 1;
                        numString               = new string[count];
                        numStringNew[count - 2] = showScore.NumScore;
                        numStringNew[count - 1] = showScore.Cash.ToString();
                        for (int i = 0; i < count; i++)
                        {
                            numString[i] = numStringNew[i];
                        }

                        count        = count + 2;
                        numStringNew = new string[count];
                        for (int i = 0; i < count - 2; i++)
                        {
                            numStringNew[i] = numString[i];
                        }
                    }
                    catch
                    {
                        workerCount = oldCount;
                    }
                }

                List <Scores> scores = new List <Scores>();
                for (int i = 0; i < count / 2 - 1; i++)
                {
                    Scores num = new Scores()
                    {
                        Number = numString[i * 2], Amount = numString[i * 2 + 1]
                    };
                    scores.Add(num);
                }
                return(Ok(scores));
            }
            return(BadRequest("No claim"));
        }
Пример #24
0
        public FormScores()
        {
            InitializeComponent();

            _scoreService = new ScoreService();

            EnableButtonEditAndDelete(false);
            LoadData();
        }
Пример #25
0
 public Guess(GameRepository gameRepository,
              IResultRepository resultRepository,
              ResultGenerator resultGenerator,
              ScoreService scoreService)
 {
     this.gameRepository   = gameRepository;
     this.resultRepository = resultRepository;
     this.resultGenerator  = resultGenerator;
     this.scoreService     = scoreService;
 }
Пример #26
0
        private void UpdateRanking()
        {
            Ranking.Clear();
            var games   = new ResultService().GetGamesThatArePlayed();
            var ranking = new ScoreService().GetRanking(Users, games);

            foreach (var score in ranking)
            {
                Ranking.Add(score);
            }
        }
Пример #27
0
        private void Get_Info()
        {
            int       userid = int.Parse(Session["UserID"].ToString());
            DataTable dt     = ScoreService.SelectAll(userid);

            if (dt != null && dt.Rows.Count != 0)
            {
                ListView1.DataSource = dt;
                ListView1.DataBind();
            }
        }
Пример #28
0
        public void GetScore_OnExecuteWith5Hints_SetsOverallScoreTo0()
        {
            var scoreService = new ScoreService();
            var pageAnalysis = new PageAnalysis()
            {
                SummaryResults =
                {
                    new SummaryResult()
                    {
                        Analysis = new Analysis()
                        {
                            Results = new List <AnalyzeResult>()
                            {
                                new AnalyzeResult()
                                {
                                    ResultRules = new List <ResultRule>()
                                    {
                                        new ResultRule()
                                        {
                                            Type = ResultType.Hint
                                        },
                                        new ResultRule()
                                        {
                                            Type = ResultType.Hint
                                        },
                                        new ResultRule()
                                        {
                                            Type = ResultType.Hint
                                        },
                                        new ResultRule()
                                        {
                                            Type = ResultType.Hint
                                        },
                                        new ResultRule()
                                        {
                                            Type = ResultType.Hint
                                        },
                                    }
                                }
                            }
                        }
                    }
                }
            };

            var result = scoreService.GetScore(pageAnalysis);

            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.ErrorCount);
            Assert.AreEqual(0, result.WarningCount);
            Assert.AreEqual(5, result.HintCount);
            Assert.AreEqual(0, result.SuccessCount);
            Assert.AreEqual(0, result.OverallScore);
        }
        public Result <IList <Score> > GetAll()
        {
            var          result       = new Result <IList <Score> >();
            ScoreService ScoreService = new ScoreService();

            var lstClient = ScoreService.Get();

            result.Value     = (IList <Score>)lstClient;
            result.IsSuccess = true;
            return(result);
        }
Пример #30
0
        public static void Initialize(GameContext context)
        {
            _scoreService = new ScoreService();
            // Gets each day's stats the number of days before today
            int daysFromToday = 5;

            Calculate(context, daysFromToday);

            JobManager.AddJob(() => UserScoreSeed.Initialize(context),
                              s => s.WithName("userScore")
                              .ToRunNow());
        }
Пример #31
0
        public void Should_allow_to_save_current_statistics()
        {
            // Arrange
            var repository = Substitute.For<IRepository>();
            var scorerService = new ScoreService(repository);

            // Act
            scorerService.Roll(5);
            scorerService.Roll(5);
            var statistics = scorerService.GetStatistics();
            scorerService.SaveStatistics();

            // Assert
            repository.Received(1)
                      .Save(statistics);
        }
Пример #32
0
        public void Should_load_statistics_from_file()
        {
            // Arrange
            var service = new ScoreService(new XmlRepository());
            int?[] fakeStatistics = new int?[21];
            fakeStatistics[0] = 10;
            fakeStatistics[2] = 5;
            fakeStatistics[3] = 1;

            using (var writer = File.OpenWrite(Path.Combine(Path.GetTempPath(), "statistics.xml")))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(int?[]));
                serializer.Serialize(writer, fakeStatistics);
                writer.Close();
            }

            // Act
            service.LoadStatistics();
            var score = service.CalculateScore();

            // Assert
            score.Should().Be(22);
        }
Пример #33
0
        public void Should_save_statistics_to_xml_file()
        {
            // Arrange
            var scoreService = new ScoreService(new XmlRepository());

            // Act
            scoreService.Roll(3);
            scoreService.SaveStatistics();

            // Assert
            string path = Path.Combine(Path.GetTempPath(), "statistics.xml");
            using (var reader = File.OpenText(path))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(int?[]));
                var statistics = (int?[])serializer.Deserialize(reader);

                statistics.Should().ContainSingle(s => s.HasValue, "Only one record should be saved");

                reader.Close();
            }

            // Tear down
            File.Delete(path);
        }