Exemplo n.º 1
0
        public async Task <IEnumerable <Player> > RejoinGame(string gameCode, string connectionId)
        {
            await _gameService.RemovePlayer(connectionId, gameCode);

            var player = await _gameService.GetPlayerByConnectionId(connectionId, gameCode);

            await _gameService.AddPlayer(player, Context.ConnectionId, gameCode);

            return(await _gameService.GetPlayersByCode(gameCode));
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var player1 = Console.ReadLine()?.Split(" ") ?? new string[] { };
            var player2 = Console.ReadLine()?.Split(" ") ?? new string[] { };

            var game = new GameService();

            game.AddPlayer(new Player(player1[1], player1[0][0]));
            game.AddPlayer(new Player(player2[1], player2[0][0]));
            game.DisplayGameBoard();

            while (true)
            {
                try
                {
                    var cmd = Console.ReadLine();
                    if (string.IsNullOrEmpty(cmd) || cmd == "exit")
                    {
                        break;
                    }

                    var location = cmd.Split(" ");
                    var status   = game.MakeAMove(new Location(int.Parse(location[0]) - 1, int.Parse(location[1]) - 1));

                    game.DisplayGameBoard();

                    if (status == GameMoveStatus.GameMove)
                    {
                        Console.WriteLine("\nGame Over");
                        break;
                    }

                    if (status == GameMoveStatus.WinningMove)
                    {
                        break;
                    }

                    if (status == GameMoveStatus.InvalidMove)
                    {
                        Console.WriteLine("Invalid Move");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("\n" + e.Message);
                }
            }

            Console.WriteLine("\nPress any key to exit");
            Console.ReadKey();
        }
Exemplo n.º 3
0
        public void Draw()
        {
            var players = new List <Player>
            {
                new Player {
                    Name = "Joe", Cards = new string[] { "AH", "KH", "QH", "JH", "10H" }
                },
                new Player {
                    Name = "Jen", Cards = new string[] { "5C", "4S", "9H", "9S", "QS" }
                },
                new Player {
                    Name = "Bob", Cards = new string[] { "10D", "JD", "QD", "KD", "AD" }
                },
            };

            var game = new GameService();

            // add the players
            foreach (var p in players)
            {
                // validate player cards
                Assert.IsTrue(game.AddPlayer(p, out var message), message);
            }

            var winners = game.Winners;

            Assert.True(winners.Count == 2);
        }
Exemplo n.º 4
0
        public void HighCard()
        {
            var players = new List <Player>
            {
                new Player {
                    Name = "Joe", Cards = new string[] { "3H", "4D", "9C", "9D", "QH" }
                },
                new Player {
                    Name = "Jen", Cards = new string[] { "5C", "7D", "9H", "9S", "QS" }
                },
                new Player {
                    Name = "Bob", Cards = new string[] { "2H", "2C", "5S", "10C", "AH" }
                },
            };

            var game = new GameService();

            // add the players
            foreach (var p in players)
            {
                // validate player cards
                Assert.IsTrue(game.AddPlayer(p, out var message), message);
            }

            var winners = game.Winners;

            Assert.True(winners[0].Name == "Jen");
        }
Exemplo n.º 5
0
        public void DuplicateCardWithOtherPlayer()
        {
            // add the players
            var players = new List <Player>
            {
                new Player {
                    Name = "Joe", Cards = new string[] { "3H", "6H", "8H", "JH", "KH" }
                },
                new Player {
                    Name = "Jen", Cards = new string[] { "3C", "3D", "3S", "8C", "10H" }
                },
                new Player {
                    Name = "Bob", Cards = new string[] { "2H", "5C", "7S", "10C", "3H" }
                },
            };

            var game = new GameService();

            var message = "";

            foreach (var p in players)
            {
                game.AddPlayer(p, out message);
            }

            // validate if player cards has duplicate with other player
            Assert.AreEqual("Player Bob has duplicate cards with other player", message);
        }
Exemplo n.º 6
0
        public void Flush()
        {
            var players = new List <Player>
            {
                new Player {
                    Name = "Joe", Cards = new string[] { "3H", "6H", "8H", "JH", "KH" }
                },
                new Player {
                    Name = "Jen", Cards = new string[] { "3C", "3D", "3S", "8C", "10H" }
                },
                new Player {
                    Name = "Bob", Cards = new string[] { "2H", "5C", "7S", "10C", "AC" }
                },
            };

            var game = new GameService();

            // add the players
            foreach (var p in players)
            {
                // validate player cards
                Assert.IsTrue(game.AddPlayer(p, out var message), message);
            }

            var winners = game.Winners;

            Assert.True(winners[0].Name == "Joe");
        }
Exemplo n.º 7
0
 private void AddPlayer(string playerId, Color color)
 {
     if (playerId != "")
     {
         GameService.AddPlayer(Convert.ToInt32(playerId), Utils.Util.GetQuadrantFromColor(color));
     }
 }
Exemplo n.º 8
0
        public async Task AddToGroup(string gameId, string name, string avatarCode)
        {
            await Groups.AddToGroupAsync(Context.ConnectionId, gameId);

            await service.AddPlayer(Context.ConnectionId, name, gameId, avatarCode);

            await SendNameToHost(gameId, name, avatarCode);
        }
Exemplo n.º 9
0
        static void Main()
        {
            var addPlayer = true;

            var game = new GameService();

            do
            {
                var player = new Player();

                Console.Write("Enter player name: ");
                player.Name = Console.ReadLine();

                Console.Write("Enter player cards: [separated by comma] ");
                player.Cards = Console.ReadLine().Replace(" ", "").Split(',', StringSplitOptions.RemoveEmptyEntries);


                if (!game.AddPlayer(player, out var message))
                {
                    Console.WriteLine(message);
                }

                Console.Write("Add more player [Y/N]? ");
                var add = Console.ReadLine();

                if (add.ToLower() != "y")
                {
                    addPlayer = false;
                }
            }while (addPlayer);

            var winners = game.Winners;

            foreach (var p in game.Players)
            {
                Console.WriteLine($"Name: {p.Name}, Hand: {p.Hand}");
            }

            Console.WriteLine("Congratulations!");

            foreach (var w in winners)
            {
                Console.WriteLine($"Name: {w.Name}, Hand: {w.Hand}");
            }
        }