// Game over handling
        private void GameOver()
        {
            CurrentGame.Player1Score      = PlayerOneScore;
            CurrentGame.Player2Score      = PlayerTwoScore;
            CurrentGame.LongestVolleyHits = LongestVolleyHits;
            CurrentGame.LongestVolleyTime = (float)Math.Round((decimal)LongestVolleyTime, 2);
            CurrentGame.MaxVelocity       = (float)Math.Round((decimal)maxSpeed, 2);
            gs.AddGame(CurrentGame, Bounces);

            // Write bounce locn data to file (temporary code for testing)
            if (debug)
            {
                string[] bounceOut = new string[this.Bounces.Count + 1];
                bounceOut[0] = "X, Y, Z";
                int i = 1;
                foreach (HitLocation item in this.Bounces)
                {
                    bounceOut[i] = item.X.ToString() + ", " + item.Y.ToString() + ", " + item.Z.ToString();
                    i++;
                }
                string myPhotos = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
                string path1    = System.IO.Path.Combine(myPhotos, "BounceData" + ".txt");
                File.WriteAllLines(path1, bounceOut);

                string path2 = System.IO.Path.Combine(myPhotos, "SpeedData.txt");
                File.WriteAllLines(path2, SpeedData);
            }
        }
Beispiel #2
0
        public async void ShouldAddGameIfNotDuplicate()
        {
            var name           = "test";
            var description    = "opis";
            var model          = new ImageModel();
            var repo           = new Mock <IRepository <Game> >();
            var guideRepo      = new Mock <IRepository <Guide> >();
            var gameReviewRepo = new Mock <IRepository <GameReview> >();

            repo.Setup(x => x.Exists(It.IsAny <Expression <Func <Game, bool> > >())).Returns(Task.FromResult(false));
            var hosting = new Mock <IHostingEnvironment>();

            var gModel = new GameModel()
            {
                Name        = name,
                Description = description,
                Image       = model.Image
            };

            var gameService = new GameService(repo.Object, guideRepo.Object, hosting.Object, gameReviewRepo.Object);


            var result = await gameService.AddGame(gModel);

            Assert.Null(result.Error);
        }
Beispiel #3
0
        public async void ShouldNotAddGameIfNameExists()
        {
            var name           = "test";
            var description    = "opis";
            var model          = new ImageModel();
            var repo           = new Mock <IRepository <Game> >();
            var guideRepo      = new Mock <IRepository <Guide> >();
            var gameReviewRepo = new Mock <IRepository <GameReview> >();

            repo.Setup(x => x.Exists(It.IsAny <Expression <Func <Game, bool> > >())).Returns(Task.FromResult(true));
            var hosting = new Mock <IHostingEnvironment>();

            var gModel = new GameModel()
            {
                Name        = name,
                Description = description,
                Image       = model.Image
            };

            var gameService = new GameService(repo.Object, guideRepo.Object, hosting.Object, gameReviewRepo.Object);

            var result = await gameService.AddGame(gModel);

            string error = "Gra o podanej nazwie została już utworzona";

            Assert.Contains(error, result.Error);
        }
        public IActionResult AddGame(AddGameViewModel addGameViewModel, IFormCollection form)
        {
            GameModel gameModel = addGameViewModel.GameModel;

            gameModel.Id = Guid.NewGuid();
            GameService.AddGame(gameModel);
            LinkGameToSpots(form.Keys, gameModel);
            LinkGameToRewards(form.Keys, gameModel);

            return(RedirectToAction(nameof(Index)));
        }
        public void AddGame(long team1Id, long team2Id)
        {
            Team team1 = teamService.GetOne(team1Id);

            if (team1 == null)
            {
                throw new Exception("There no team with that corresponds to the first ID!");
            }
            Team team2 = teamService.GetOne(team2Id);

            if (team2 == null)
            {
                throw new Exception("There no team with that corresponds to the second ID!");
            }
            if (team1 == team2)
            {
                throw new Exception("Team cannot play itself!");
            }
            gameService.AddGame(new Game(team1, team2));
        }
Beispiel #6
0
        public void AddGame_WhenNewGameIsPassed_ShouldAddGameToRepository()
        {
            // Arrange
            var gameRepository   = A.Fake <IGameRepository>();
            var sharedRepository = A.Fake <ISharedRepository>();

            var processGameStrategyFactory = A.Fake <IProcessGameStrategyFactory>();
            var strategy = A.Fake <ProcessGameStrategyBase>();

            A.CallTo(() => processGameStrategyFactory.CreateStrategy(Direction.Up)).Returns(strategy);

            var service = new GameService(gameRepository, sharedRepository, processGameStrategyFactory);

            var newGame = new Game();

            // Act
            service.AddGame(newGame);

            // Assert
            A.CallTo(() => gameRepository.Add(newGame)).MustHaveHappened();
            A.CallTo(() => processGameStrategyFactory.CreateStrategy(Direction.Up)).MustHaveHappened();
            A.CallTo(() => strategy.ProcessGame(A <IGameDecorator> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => sharedRepository.SaveChanges()).MustHaveHappenedOnceExactly();
        }
Beispiel #7
0
 public ActionResult PostGame(Game newGame)
 {
     _gameService.AddGame(newGame);
     return(Ok());
 }
Beispiel #8
0
 //添加
 public static void AddGame(Game game)
 {
     GameService.AddGame(game);
 }
Beispiel #9
0
        public void OnSubmit()
        {
            bool isValid = EditContext.Validate();

            if (isValid)
            {
                ImageValidationErrors     = new List <string>();
                ShowImageValidationErrors = false;

                if (Id != 0)
                {
                    if (!string.IsNullOrWhiteSpace(ImageBase64))
                    {
                        string newImagePath = GetNewImagePath();

                        if (!string.IsNullOrWhiteSpace(newImagePath))
                        {
                            GameFromId.Title     = Game.Title;
                            GameFromId.ImagePath = newImagePath;
                        }
                        else
                        {
                            ShowImageValidationErrors = true;
                        }
                    }
                    else
                    {
                        GameFromId.Title = Game.Title;
                    }
                }
                else if (GameParameter != null)
                {
                    if (!string.IsNullOrWhiteSpace(ImageBase64))
                    {
                        string newImagePath = GetNewImagePath();

                        if (!string.IsNullOrWhiteSpace(newImagePath))
                        {
                            GameParameter.Title     = Game.Title;
                            GameParameter.ImagePath = newImagePath;
                        }
                        else
                        {
                            ShowImageValidationErrors = true;
                        }
                    }
                    else
                    {
                        GameParameter.Title = Game.Title;
                    }
                }
                else
                {
                    string newImagePath = GetNewImagePath();

                    if (!string.IsNullOrWhiteSpace(newImagePath))
                    {
                        GameService.AddGame(new Game {
                            Id = GameService.NextId, Title = Game.Title, ImagePath = newImagePath
                        });
                    }
                    else
                    {
                        ShowImageValidationErrors = true;
                    }
                }


                if (ImageValidationErrors.Count > 0)
                {
                    isValid = false;
                }

                if (isValid)
                {
                    NavigationManager.NavigateTo("");
                }
            }
        }
Beispiel #10
0
 public IHttpActionResult Create([FromBody] CreateGameDto game)
 {
     gameService.AddGame(game);
     return(Json(true));
 }
Beispiel #11
0
 public async Task <Game> AddGame(string SeasonCode, int WeekNumber, [FromBody] GameAdd newGame)
 {
     return(await _gameService.AddGame(SeasonCode, WeekNumber, newGame));
 }