Exemplo n.º 1
0
        public Game(Player p1, Player p2)
        {
            // setting defaults
            IsFinished = false;

            // adding players into list
            Players.Add(p1);
            Players.Add(p2);

            // assigning marks to list and then losowaning them across players
            MarksToAssign.Add("X");
            MarksToAssign.Add("O");
            AssignMark();

            // print players info
            foreach (var player in Players)
            {
                Console.WriteLine($"PlayerInfo: {player.Name}, {player.Mark}, {player.IsTurn}");
            }

            // assigining turn to player with 'X'
            AssignTurn();

            foreach (var player in Players)
            {
                Console.WriteLine($"PlayerInfo after turn assignment: {player.Name}, {player.Mark}, {player.IsTurn}");
            }
        }
Exemplo n.º 2
0
        // assign one of two marks randomly to players
        // method called right at beggining
        private void AssignMark()
        {
            var random = new Random();

            foreach (var player in Players)
            {
                int index = random.Next(MarksToAssign.Count);
                player.Mark = MarksToAssign.ElementAt(index);
                MarksToAssign.RemoveAt(index);
            }
        }