Esempio n. 1
0
        public Guid CreateAndSaveGame()
        {
            var gameManager = GameManagerFactory.CreateGameManager(new TicTacToeData());    // TODO - should I be explicitly constructing concrete TTTData here?

            gameManager.ResetGame();
            Adapter.Save(gameManager.GameData);
            return(gameManager.GameData.Id);
        }
Esempio n. 2
0
        public MoveResult AttemptAndSaveMove(Guid gameId, int cellNum)
        {
            var(readSuccessfully, gameData) = Adapter.Read(gameId);
            if (!readSuccessfully)
            {
                // TODO - throw exception? have (bool, MoveResult) return type instead?
                throw new Exception("Game doesn't exist!");
            }

            var gameManager = GameManagerFactory.CreateGameManager(gameData);
            var result      = gameManager.MakeMove(cellNum);

            // if move was successful, game state is changed, save it via adapter
            if (result == MoveResult.WaitingForMove || result == MoveResult.GameFinished)
            {
                Adapter.Save(gameManager.GameData);
            }

            return(result);
        }