예제 #1
0
        public MonopolyGame(List <Pawn> list_players)
        {
            Init_MonopolyGame(list_players);
            bool isEnded = false;

            while (!isEnded)
            {
                List <Thread> thread_collection = new List <Thread>();
                foreach (Pawn player in list_players.ToList())
                {
                    Console.WriteLine("\t-=+ " + player.ToString() + " turn +=-");
                    //Single_player_turn(player);
                    Thread thread = new Thread(() => Single_player_turn(player));
                    thread.Start();
                    thread_collection.Add(thread);
                    Console.WriteLine();
                }
                foreach (Thread t in thread_collection)
                {
                    t.Join();
                }
                Jail.GetInstance().AddTurnInJail();
                isEnded = Winner();
                Thread.Sleep(500);
            }
            var winner = number_of_turn.First(x => x.Value == max_turn);

            Console.WriteLine("Winner is " + winner.Key.ToString());
        }
예제 #2
0
        public static Jail GetInstance()
        {
            if (_jail == null)
            {
                _jail = new Jail(10);
            }

            return(_jail);
        }
예제 #3
0
        public void MovePlayer(Pawn player, int diceValue)
        {
            KeyValuePair <Cell, List <Pawn> > position = board.FindPlayer(player);
            int cell_id = ComputePosition(position.Key.CellNumber, diceValue, player);

            position.Value.Remove(player);
            KeyValuePair <Cell, List <Pawn> > kvp = board.Cells.FirstOrDefault(x => x.Key.CellNumber == cell_id);

            if (kvp.Key.CellNumber == 30)
            {
                player.ChangeState();
                kvp = board.Cells.FirstOrDefault(x => x.Key == Jail.GetInstance());
            }
            board.Cells[kvp.Key].Add(player);
        }