private void NewGame_Click(object sender, RoutedEventArgs e) {

			FormNew fn = new FormNew();
			fn.Owner   = this;

			if (fn.ShowDialog() == true) {
				// Convention for the whole application: 
				// player1 always stores the first player
				player1 = new Player(fn.Name1, fn.IsHuman1, true);
				player2 = new Player(fn.Name2, fn.IsHuman2, false);

				DIM = fn.DIM;
				InitialiseBoards();
				gameStats = new GameStats();

				// Update GUI
				player1name.Text = fn.Name1;
				player2name.Text = fn.Name2;

				player1stats.Text = "0 0 0";
				player2stats.Text = "0 0 0";

				footerlabel1.Visibility = Visibility.Visible;
				footerlabel2.Visibility = Visibility.Visible;

				Start();
			}
		}
        public void TestCopy()
        {
            player = new Player();

            player.Name    = "Jane";
            player.IsHuman = true;
            player.IsFirst = true;

            Player copy = player.Copy();

            Assert.AreEqual(player.Name,    copy.Name,    " \n--- Expected: " + player.Name    + ". Actual copy.Name: "    + copy.Name);
            Assert.AreEqual(player.IsHuman, copy.IsHuman, " \n--- Expected: " + player.IsHuman + ". Actual copy.IsHuman: " + copy.IsHuman);
            Assert.AreEqual(player.IsFirst, copy.IsFirst, " \n--- Expected: " + player.IsFirst + ". Actual copy.IsFirst: " + copy.IsFirst);
        }
Example #3
0
        public bool HasPlayerWon(Player player)
        {
            foreach (var winningCombination in WinningCombinations)
            {
                if (Board.Cells[winningCombination[0]].Value == player &&
                    Board.Cells[winningCombination[1]].Value == player &&
                    Board.Cells[winningCombination[2]].Value == player)
                {
                    return true;
                }
            }

            return false;
        }
        private static string ConvertToSign(Player? cellValue)
        {
            switch (cellValue)
            {
                case null:
                    return " ";
                case Player.Player1:
                    return "X";
                case Player.Player2:
                    return "O";
            }

            throw new NotImplementedException();
        }
Example #5
0
 public void MakeNextMove(Player player, int cellIndex)
 {
     Board.Cells[cellIndex].Value = player;
 }
Example #6
0
        /// <summary>
        /// Makes a random move for a player and then checks if the player wins or checks if all cells in the game board were used
        /// </summary>
        /// <param name="player"></param>
        /// <returns>True when game is over</returns>
        public bool PlayAndCheck(Player player)
        {
            MakeNextMove(player, GetNextRandomAvailableCellIndex());
            _boardDisplayer.DisplayBoard(Board);

            if (HasPlayerWon(player))
            {
                _boardDisplayer.DisplayWinner(player);
                return true;
            }

            return IsGameFinished();
        }
 public void DisplayWinner(Player player)
 {
     Console.WriteLine("{0} wins", player);
 }