예제 #1
0
 void Start()
 {
     gamekeeper    = GameObject.FindObjectOfType <GameKeeper>();
     body          = GetComponent <Rigidbody2D>();
     body.bodyType = RigidbodyType2D.Static;
     scorekeeper   = GameObject.FindObjectOfType <ScoreKeeper>();
 }
예제 #2
0
        /// <summary>
        ///  Domain Service create
        ///       CalculateStats( Match)
        ///
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task EndMatch(EndMatch input)
        {
            var match = await _matchRepository.GetAsync(input.MatchId);

            match.End();
            GameKeeper.CalculateTicTacToeStats(match);

            //if (input.WinningPlayerId == match.FirstPlayerId)
            //{
            //    match.FirstPlayer.Win = Convert.ToInt32(match.FirstPlayer.Win) + 1;
            //    match.FirstPlayer.Score = Convert.ToInt32(match.FirstPlayer.Score) + 1;
            //    match.SecondPlayer.Loss = Convert.ToInt32(match.SecondPlayer.Loss) + 1;

            //if (input.WinningPlayerId == match.SecondPlayerId)
            //{
            //    match.SecondPlayer.Win = Convert.ToInt32(match.SecondPlayer.Win) + 1;
            //    match.SecondPlayer.Score = Convert.ToInt32(match.SecondPlayer.Score)+ 1;
            //    match.FirstPlayer.Loss = Convert.ToInt32(match.FirstPlayer.Loss) + 1;
            //    match.WinningPlayerId = match.SecondPlayerId;
            //}
            //if (input.WinningPlayerId == 0)
            //{
            //    match.FirstPlayer.Ties = match.FirstPlayer.Ties.Value + 1;
            //    match.FirstPlayer.Score = Convert.ToInt32(match.FirstPlayer.Score) + 0.5;
            //    match.SecondPlayer.Ties = Convert.ToInt32(match.SecondPlayer.Ties) + 1;
            //    match.SecondPlayer.Score = Convert.ToInt32(match.SecondPlayer.Score) + 0.5;
            //}
        }
예제 #3
0
        public HttpResponseMessage QuitGame(string gameId, string playerId)
        {
            try
            {
                var move    = new QuitMove(playerId);
                var moveNum = GameKeeper.RegisterMove(gameId, move);

                return(new HttpResponseMessage(HttpStatusCode.Accepted));
            }
            catch (KeyNotFoundException ex)
            {
                // game not found
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content = new StringContent(ex.Message)
                });
            }
            catch (InvalidPlayerException ex)
            {
                // player is not part of game
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content = new StringContent(ex.Message)
                });
            }
            catch (IllegalMoveException ex)
            {
                // game is already done
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Gone)
                {
                    Content = new StringContent(ex.Message)
                });
            }
        }
예제 #4
0
 public void GettingInvalidGameStateReturnsNull()
 {
     Assert.Throws <KeyNotFoundException>(() =>
     {
         var gameState = GameKeeper.GetGameState("bogusId");
     });
 }
예제 #5
0
        public void GetGameMovesIsEmptyForNewGame()
        {
            var newGameId = GameKeeper.AddGame(4, 4, players);
            var moves     = GameKeeper.GetGameMoves(newGameId);

            Assert.IsEmpty(moves);
        }
예제 #6
0
        public void MajorDiagonalWinRegistersProperly()
        {
            /*   |1| | | |
             *   |0|1| |0|
             *   |1|0|1|0|
             *   |0|1|0|1|
             * */

            var newGameId = GameKeeper.AddGame(4, 4, players);
            var move1     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            var move2     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 1));
            var move3     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 2));
            var move4     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 3));
            var move5     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 1));
            var move6     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 0));
            var move7     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 3));
            var move8     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 2));
            var move9     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            var move10    = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 1));
            var move11    = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 3));

            var beforeMoveGameState = GameKeeper.GetGameState(newGameId);
            var move12             = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 0));
            var afterMoveGameState = GameKeeper.GetGameState(newGameId);

            Assert.AreEqual(Game.GameStates.IN_PROGRESS, beforeMoveGameState.State);
            Assert.IsNull(beforeMoveGameState.Winner);
            Assert.AreEqual(Game.GameStates.DONE, afterMoveGameState.State);
            Assert.AreEqual(players[1], afterMoveGameState.Winner);
        }
예제 #7
0
        public GameStatusResponse GetGameStatus(string gameId)
        {
            var gameStatus = GameKeeper.GetGameState(gameId);
            var response   = new GameStatusResponse(gameStatus);

            return(response);
        }
예제 #8
0
        public GetMovesResponse GetGameMoves(string gameId, [FromUri] int?start = null, [FromUri] int?until = null)
        {
            try
            {
                var moves       = GameKeeper.GetGameMoves(gameId, start, until);
                var moveResults = new List <GetMoveResponse>();

                foreach (var move in moves)
                {
                    var moveResult = new GetMoveResponse()
                    {
                        player = move.Player,
                        type   = move.MoveType
                    };
                    if (move is TokenMove)
                    {
                        moveResult.column = ((TokenMove)move).Column;
                    }
                    ;
                    moveResults.Add(moveResult);
                }

                return(new GetMovesResponse()
                {
                    moves = moveResults
                });
            }
            catch (KeyNotFoundException ex)
            {
                // game not found
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content = new StringContent(ex.Message)
                });
            }
            catch (ApplicationException ex)
            {
                // moves not found
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content = new StringContent(ex.Message)
                });
            }
            catch (IndexOutOfRangeException ex)
            {
                // invalid start or end indexes = malformed request
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content = new StringContent(ex.Message)
                });
            }
            catch (ArgumentException ex)
            {
                // the end index is less than the start index - malformed request
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content = new StringContent(ex.Message)
                });
            }
        }
    public void EnableActionCamera(AbstractPiece movingPiece, AbstractPiece dyingPiece)
    {
        // The action camera will always point towards a dying object from the initial position of the object destroying it
        GameKeeper gameKeeper = GameObject.Find(Constants.PieceNames.ChessBoard).GetComponent <GameKeeper>();

        if (movingPiece.side == Side.White)
        {
            // Positive music
            this.deathAudioSource.clip = (AudioClip)Resources.Load(Constants.AudioClipNames.AudioDirectory + Constants.AudioClipNames.RebelAttack, typeof(AudioClip));
        }
        if (movingPiece.side == Side.Black)
        {
            // Badass music
            this.deathAudioSource.clip = (AudioClip)Resources.Load(Constants.AudioClipNames.AudioDirectory + Constants.AudioClipNames.ImperialMarch, typeof(AudioClip));
        }

        StartCoroutine(this.PlayDeathMusic());

        Vector3 forward        = gameKeeper.GetTransformFromPosition(movingPiece.GetCurrentPosition()) - gameKeeper.GetTransformFromPosition(dyingPiece.GetCurrentPosition());
        Vector3 up             = new Vector3(0, 1, 0);
        Vector3 cameraPosition = gameKeeper.GetTransformFromPosition(dyingPiece.GetCurrentPosition()) - 2 * gameKeeper.GetSquareSpacing() * forward.normalized;

        cameraPosition.y = 1;

        this.gameObject.GetComponent <Transform>().position = cameraPosition;
        this.gameObject.GetComponent <Transform>().rotation = Quaternion.LookRotation(forward, up);

        GameObject.Find(Constants.MainCameraObject).GetComponent <Camera>().enabled = false;
        this.gameObject.GetComponent <Camera>().enabled = true;
    }
예제 #10
0
    public void SetMovePosition(Position position)
    {
        this.movePosition = position;
        GameKeeper gameKeeper = GameObject.Find(Constants.PieceNames.ChessBoard).GetComponent <GameKeeper>();

        this.gameObject.GetComponent <Transform>().position = new Vector3(gameKeeper.GetTransformFromPosition(position).x, 0.05f, gameKeeper.GetTransformFromPosition(position).z);
    }
예제 #11
0
    // Start is called before the first frame update
    void Start()
    {
        state = battleStates.START;

        //FIND HOW TO GET ACTIVE GAME MANGER!
        keeper = GameObject.Find("GameManager");
        StartCoroutine(SetupBattle());
    }
예제 #12
0
        public void CanGetGameState()
        {
            var gameId1   = GameKeeper.AddGame(4, 4, players);
            var gameState = GameKeeper.GetGameState(gameId1);

            Assert.IsNotNull(gameState);
            Assert.AreEqual(Game.GameStates.IN_PROGRESS, gameState.State);
            Assert.IsNull(gameState.Winner);
            Assert.AreEqual(players, gameState.Players);
        }
예제 #13
0
        public void CanGetGameIds()
        {
            var gameId1 = GameKeeper.AddGame(4, 4, players);
            var gameId2 = GameKeeper.AddGame(4, 4, players);
            var gameIds = GameKeeper.GetGameIds();

            Assert.IsNotEmpty(gameIds);
            Assert.Contains(gameId1, gameIds);
            Assert.Contains(gameId2, gameIds);
        }
예제 #14
0
        public void SamePlayerCantPlayTwoTokenMovesInARow()
        {
            var newGameId = GameKeeper.AddGame(4, 4, players);

            GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));

            Assert.Throws <OutOfTurnException>(new TestDelegate(() =>
            {
                GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            }));
        }
예제 #15
0
    // Start is called before the first frame update
    void Start()
    {
        gameKeeper     = GameObject.FindObjectOfType <GameKeeper>();
        canFinishLevel = true;

        randomColorAlignment = Random.Range(0f, 1f);
        colorOffset          = Random.Range(0, 5);

        breakableBricks = Random.Range(5, (numColumns * numRows) / 10);
        GenerateLayout(breakableBricks);
    }
예제 #16
0
        public IHttpActionResult GetGames()
        {
            var games = GameKeeper.GetGameIds();

            var response = new GetGamesResponse()
            {
                games = games
            };

            return(Ok(response));
        }
예제 #17
0
        public void CanGetAllGameMoves()
        {
            var newGameId = GameKeeper.AddGame(4, 4, players);
            var move1     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            var move2     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 1));
            var move3     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            var move4     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 1));

            var moves = GameKeeper.GetGameMoves(newGameId);

            Assert.AreEqual(4, moves.Count());
        }
예제 #18
0
        public void CanAddGamesWithExpectedIds()
        {
            var gameId1 = GameKeeper.AddGame(4, 4, players);
            var gameId2 = GameKeeper.AddGame(4, 4, players);

            Assert.NotNull(gameId1);
            Assert.NotNull(gameId2);
            Assert.AreNotEqual(string.Empty, gameId1);
            Assert.AreNotEqual(string.Empty, gameId2);
            Assert.AreEqual("Game0", gameId1);
            Assert.AreEqual("Game1", gameId2);
        }
예제 #19
0
        public void PuttingTokenInFullColumnWillThrow()
        {
            var newGameId = GameKeeper.AddGame(4, 4, players);
            var move1     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            var move2     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 0));
            var move3     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            var move4     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 0));

            // the first column should now be full...try one more
            Assert.Throws <IllegalMoveException>(() => {
                var move5 = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            });
        }
예제 #20
0
 void Awake()
 //singleton pattern
 {
     if (gameKeeper == null)
     {
         gameKeeper = this;
     }
     else if (gameKeeper != this)
     {
         Destroy(gameObject);
     }
     DontDestroyOnLoad(gameObject);
 }
예제 #21
0
        public void CanPostMoves()
        {
            var newGameId = GameKeeper.AddGame(4, 4, players);
            var move1     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            var move2     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 0));

            Assert.AreEqual(0, move1);
            Assert.AreEqual(1, move2);

            var moves = GameKeeper.GetGameMoves(newGameId);

            Assert.AreEqual(2, moves.Count());
        }
예제 #22
0
        public void PlayerCanQuitEvenWhenNotThatPlayersTurn()
        {
            var newGameId = GameKeeper.AddGame(4, 4, players);
            var move1     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));

            var beforeMoveGameState = GameKeeper.GetGameState(newGameId);
            var move2 = GameKeeper.RegisterMove(newGameId, new QuitMove(players[0]));
            var afterMoveGameState = GameKeeper.GetGameState(newGameId);

            Assert.AreEqual(Game.GameStates.IN_PROGRESS, beforeMoveGameState.State);
            Assert.IsNull(beforeMoveGameState.Winner);
            Assert.AreEqual(Game.GameStates.DONE, afterMoveGameState.State);
            Assert.AreEqual(players[1], afterMoveGameState.Winner);     // the player that didn't quit is the winner
        }
예제 #23
0
        public void CanGetFirstTwoGameMoves()
        {
            var newGameId = GameKeeper.AddGame(4, 4, players);
            var move1     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            var move2     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 1));
            var move3     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            var move4     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 1));

            var moves = GameKeeper.GetGameMoves(newGameId, 0, 1);

            Assert.AreEqual(2, moves.Count());
            Assert.AreEqual(0, ((TokenMove)moves.First()).Column);
            Assert.AreEqual(1, ((TokenMove)moves.Last()).Column);
        }
예제 #24
0
        public void CanGetFirstGameMove()
        {
            var newGameId = GameKeeper.AddGame(4, 4, players);
            var move1     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            var move2     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 1));
            var move3     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[0], 0));
            var move4     = GameKeeper.RegisterMove(newGameId, new TokenMove(players[1], 1));

            var move = GameKeeper.GetGameMove(newGameId, move1);

            Assert.AreEqual(players[0], move.Player);
            Assert.AreEqual(DropTokenGame.MoveTypes.MOVE, move.MoveType);
            Assert.AreEqual(0, ((TokenMove)move).Column);
        }
예제 #25
0
    // Start is called before the first frame update
    void Start()
    {
        // find references
        gameKeeper   = FindObjectOfType <GameKeeper>();
        loseCollider = FindObjectOfType <LoseCollider>();
        ball         = FindObjectOfType <Ball>();
        paddle       = FindObjectOfType <PaddleController>();

        // initialize power up
        object[] powerUps       = Resources.LoadAll("Power-Ups", typeof(Sprite));
        int      maxSpriteIndex = (gameKeeper.level < 5) ? 3 : (gameKeeper.level < 10) ? 8 : powerUps.Length;

        gameObject.GetComponent <SpriteRenderer>().sprite = (Sprite)powerUps[Random.Range(0, maxSpriteIndex)];
        gameObject.GetComponent <Rigidbody2D>().velocity  = new Vector2(0, -2f);
    }
예제 #26
0
        public PostMoveResponse PostMove(string gameId, string playerId, [FromBody] PostMoveRequest request)
        {
            try
            {
                var move       = new TokenMove(playerId, request.column);
                var moveNumber = GameKeeper.RegisterMove(gameId, move);

                return(new PostMoveResponse()
                {
                    move = String.Format("{0}/moves/{1}", gameId, moveNumber)
                });
            }
            catch (KeyNotFoundException ex)
            {
                // game not found
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content = new StringContent(ex.Message)
                });
            }
            catch (InvalidPlayerException ex)
            {
                // player not part of the game
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content = new StringContent(ex.Message)
                });
            }
            catch (IllegalMoveException ex)
            {
                // game is done, or column is full
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content = new StringContent(ex.Message)
                });
            }
            catch (OutOfTurnException ex)
            {
                // not the player's turn
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Conflict)
                {
                    Content = new StringContent(ex.Message)
                });
            }
        }
예제 #27
0
 public CreateGameResponse CreateGame(CreateGameRequest request)
 {
     try
     {
         var gameId = GameKeeper.AddGame(request.rows, request.columns, request.players);
         return(new CreateGameResponse()
         {
             gameId = gameId
         });
     }
     catch (Exception ex)
     {
         throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)
         {
             Content = new StringContent(ex.Message)
         });
     }
 }
예제 #28
0
        public GetMoveResponse GetMove(string gameId, int move_number)
        {
            try
            {
                var move = GameKeeper.GetGameMove(gameId, move_number);

                var response = new GetMoveResponse()
                {
                    type   = move.MoveType,
                    player = move.Player
                };

                if (move.MoveType == MoveTypes.MOVE)
                {
                    response.column = ((TokenMove)move).Column;
                }

                return(response);
            }
            catch (KeyNotFoundException ex)
            {
                // game not found
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content = new StringContent(ex.Message)
                });
            }
            catch (ApplicationException ex)
            {
                // game moves not found
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content = new StringContent(ex.Message)
                });
            }
            catch (ArgumentOutOfRangeException ex)
            {
                // invalid move number
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content = new StringContent(ex.Message)
                });
            }
        }
예제 #29
0
    // cached references

    // Start is called before the first frame update
    void Start()
    {
        gameKeeper     = FindObjectOfType <GameKeeper>();
        spriteRenderer = gameObject.GetComponent <SpriteRenderer>();
        sprites        = Resources.LoadAll("Brick", typeof(Sprite));

        if (tag == "Breakable")
        {
            SetMaxHits();
            spriteRenderer.sprite = (Sprite)sprites[timesHit];
            spriteRenderer.color  = colors[colorIndex];
            if (maxHits > 1)
            {
                GameObject metalPlates = new GameObject("metal plates");
                metalPlates.AddComponent <SpriteRenderer>().sprite = (Sprite)sprites[2];
                metalPlates.transform.position   = new Vector3(transform.position.x, transform.position.y, -1);
                metalPlates.transform.localScale = new Vector3(0.45f, 0.45f, 1);
                metalPlates.transform.parent     = gameObject.transform;
            }
        }
    }
예제 #30
0
    private void init()
    {
        boomBoom   = FindObjectOfType <explodything>();
        fanfare    = FindObjectOfType <startingFanfare>();
        gameKeeper = FindObjectOfType <GameKeeper>();

        if (boomBoom == null)
        {
            Debug.LogError("NO BOOM BOOM");
        }

        if (fanfare == null)
        {
            Debug.LogError("NO FANFARE");
        }

        if (gameKeeper == null)
        {
            Debug.LogError("NO GAME KEEPER");
        }
    }