示例#1
0
        static void TakeTurn(ITicTacToe g)
        {
            PlayerMark whoturn = g.GetWhoTurn();
            bool       placed  = false;

            while (!placed)
            {
                bool gotX = false;
                bool gotY = false;
                int  x, y;
                x = y = 0;
                Console.WriteLine("Entering Player Move For: {0}", GetMark(whoturn));
                while (!gotX)
                {
                    Console.WriteLine("Enter Column:");
                    string lineIn = Console.ReadLine();
                    gotX = int.TryParse(lineIn, out x);
                }
                while (!gotY)
                {
                    Console.WriteLine("Enter Row:");
                    string lineIn = Console.ReadLine();
                    gotY = int.TryParse(lineIn, out y);
                }
                placed = g.TryPlaceMarkAt(whoturn, x, y);
                if (!placed)
                {
                    Console.WriteLine("Invalid Move!");
                }
            }
        }
示例#2
0
        public bool MakeTurn(string name, string value, ITicTacToe platform = null, IUIHelper uIHelper = null)
        {
            this.platform = platform;
            this.uIHelper = uIHelper;

            if (Turn)
            {
                uIHelper?.ChangeButtonText(name, "X");
                ArrayHelper.PutValuesInMap(Map, name, MapValues.X);
                //uIHelper?.ChangeTurnLabel(MapValues.O);
                (int, int)aiMove = AI.GetAIMove(Map);
                var aiButton = ArrayHelper.GetButtonNameFromIntTuple(aiMove);
                uIHelper?.ChangeButtonText(aiButton, "O");
                ArrayHelper.PutValuesInMap(Map, aiButton, MapValues.O);
                uIHelper?.DisableButton(aiButton);
            }
            else
            {
                uIHelper?.ChangeButtonText(name, "O");
                ArrayHelper.PutValuesInMap(Map, name, MapValues.O);
                uIHelper?.ChangeTurnLabel(MapValues.X);
            }
            uIHelper?.DisableButton(name);
            //Turn = !Turn;
            TurnCount++;
            CheckForWinner();
            if (TurnCount == 9)
            {
                platform?.ShowDrow();
            }
            return(winState);
        }
示例#3
0
        /// <inheritdoc/>
        public BoringToeMoveResponse PlayerMove(long gameId, BoringToeMoveRequest request)
        {
            Player responsePlayer = null;

            Player     player = FindPlayerInDatabase(request.PlayerId, ErrorCode.PLAYER_NOT_EXISTS);
            ITicTacToe game   = FindGameInDatabase(gameId, ErrorCode.GAME_NOT_EXISTS);

            try
            {
                responsePlayer = game.PlayerMove(player, new Coordinate(request.XCoord, request.YCoord));
            }
            catch (TicTacToeGameOverException tttgoe)
            {
                return(GenerateGameOverWinnerResponseData(tttgoe.Player, game.GetGrid()));
            }
            catch (PlayerMovementException)
            {
                return(GenerateRepeatUserResponseData(player, game.GetGrid()));
            }
            catch (GameOverException)
            {
                return(GenerateGameOverNoWinnerResponseData(game.GetGrid()));
            }

            return(GenerateOkNextPlayerResponseData(responsePlayer, game.GetGrid()));
        }
 /// <summary>
 /// Gets user input on what play he wants to make
 /// </summary>
 /// <param name="user">User making the play</param>
 public void GetPlayerInput(String user, ITicTacToe t)
 {
     //throw new NotImplementedException();
     try
     {
         Console.WriteLine(user + "'s game: ");
         var input = Console.ReadLine();
         if (input.ToString().ToLower() == "r")
         {
             selectedSquare = t.GetRandomPlay()+1; // +1 til að velja rétta reitinn
                                                   // og fara ekki niður fyrir 0
                                                   // og ná upp í 9
         }
         else
         {
             selectedSquare = Convert.ToInt32(input);
             if (selectedSquare < 1 || selectedSquare > 9)
                 throw new Exception("Please select numbers between 1-9");
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         Console.WriteLine("Try again!");
         GetPlayerInput(user, t);
     }
 }
        public void HorizontalMovesO(ITicTacToe g, int row)
        {
            int low  = 0;
            int high = 1;

            switch (row)
            {
            case 0:
                low  = 1;
                high = 2;
                break;

            case 1:
                low  = 0;
                high = 2;
                break;

            case 2:
                low  = 0;
                high = 1;
                break;

            default:
                break;
            }
            for (int x = 0; x < 3; ++x)
            {
                g.TryPlaceMarkAt(PlayerMark.X, x, x == 1 ? high : low);
                g.TryPlaceMarkAt(PlayerMark.O, x, row);
            }
        }
        public void VerticalMovesO(ITicTacToe g, int column)
        {
            int low  = 0;
            int high = 1;

            switch (column)
            {
            case 0:
                low  = 1;
                high = 2;
                break;

            case 1:
                low  = 0;
                high = 2;
                break;

            case 2:
                low  = 0;
                high = 1;
                break;

            default:
                break;
            }
            for (int y = 0; y < 3; ++y)
            {
                g.TryPlaceMarkAt(PlayerMark.X, y == 1 ? high : low, y);
                g.TryPlaceMarkAt(PlayerMark.O, column, y);
            }
        }
示例#7
0
 /// <summary>
 /// Constructor
 /// </summary>
 public BoringToe(IBoringToeHelper boringToeHelper)
 {
     _game            = new TicTacToeImpl();
     _player1         = new Player();
     _player2         = new Player();
     _grid            = new Grid();
     _boringToeHelper = boringToeHelper;
 }
示例#8
0
 public static void GetData(ITicTacToe platform, IUIHelper uIHelper = null)
 {
     using (DataContext db = new DataContext(connectionString))
     {
         GetMap(db, platform, uIHelper);
         GetTurns(db, platform);
         GetWinnersCount(db, platform);
     }
 }
 void TestMovesExpectWinner(ITicTacToe g, point[] moves, PlayerMark winner)
 {
     foreach (point p in moves)
     {
         g.TryPlaceMarkAt(g.GetWhoTurn(), p.x, p.y);
     }
     Assert.IsTrue(g.IsGameOver());
     Assert.AreEqual <PlayerMark>(winner, g.GetWinner());
 }
        public TicTacToeServer(ITicTacToe ticTacToeGame, IClientManager clientManager, ITicTacToeClientUpdater clientUpdater)
        {
            _ticTacToeGame = ticTacToeGame;
            _ticTacToeGame.GameCompleted += OnGameCompleted;

            _clientManager = clientManager;
            _clientManager.ClientRoleAssigned += OnClientRoleAssigned;

            _clientUpdater = clientUpdater;
        }
 public void SetUp()
 {
     game = MockRepository.GenerateMock<ITicTacToe>();
     clientManager = MockRepository.GenerateMock<IClientManager>();
     clientUpdater = MockRepository.GenerateMock<ITicTacToeClientUpdater>();
     server = new TicTacToeServer(
                     game,
                     clientManager,
                     clientUpdater);
 }
示例#12
0
        static void PrintBoard(ITicTacToe g)
        {
            PlayerMark whoturn = g.GetWhoTurn();

            Console.WriteLine("Player {0}'s Turn", GetMark(whoturn));
            Console.WriteLine("Board:");
            Console.WriteLine("   0 | 1 | 2 ");
            for (int row = 0; row < 3; ++row)
            {
                Console.WriteLine("{3}: {0} | {1} | {2} ",
                                  GetMark(g.GetMarkAt(0, row)), GetMark(g.GetMarkAt(1, row)), GetMark(g.GetMarkAt(2, row)), row);
            }
        }
示例#13
0
        public static void GetData(ITicTacToe platform, IUIHelper uIHelper = null)
        {
            switch (setting)
            {
            case Settings.DataBase:
                DataBaseSaver.GetData(platform, uIHelper);
                break;

            case Settings.JSON:
                JSONSaver.GetData();
                break;
            }
            ;
        }
示例#14
0
        /// <summary>
        /// Wrapper function for player database get
        /// </summary>
        /// <param name="id">Id to find</param>
        /// <param name="notExistingErrorCode">Error code to add in NotExistingValueException</param>
        /// <returns>Player data</returns>
        private ITicTacToe FindGameInDatabase(long id, ErrorCode notExistingErrorCode)
        {
            ITicTacToe resp = null;

            try
            {
                resp = _boringToeRepository.GetGameById(id);
            }
            catch (NotExistingValueException neve)
            {
                if (neve.ErrorCode == ErrorCode.VALUE_NOT_EXISTING_IN_DATABASE)
                {
                    throw new NotValidValueException("Game not existing in database", notExistingErrorCode);
                }
                else
                {
                    throw;
                }
            }

            return(resp);
        }
示例#15
0
 public void SetNullToPlatform()
 {
     platform = null;
 }
示例#16
0
        private void NewGame()
        {
            _ittt = new TicTacToe("Player 1", "Player 2");
            _board = _ittt.GetGameBoard();
            label1.Text = "To start the game select your first move Player 1";
            _player1ToDo = true;
            _playcount = 0;

            foreach (var btn in _buttonArray)
            {
                btn.Enabled = true;
                btn.Text = "";
            }
        }