Example #1
0
        public void Given_Game_When_OnePlayerSendTheGreatestValue_Then_GetWinnerAndLostPlayer()
        {
            var playerOne = "Player1";
            var playerTwo = "Player2";

            _gameEngine.AddPlayer(playerOne);
            _gameEngine.AddPlayer(playerTwo);

            _gameEngine.SetPlayerNumber(playerOne, 2);
            _gameEngine.SetPlayerNumber(playerTwo, 3);

            _gameEngine.GameResultForPlayer(playerOne).Should().Be(GameResulsForPlayer.Lost);
            _gameEngine.GameResultForPlayer(playerTwo).Should().Be(GameResulsForPlayer.Won);
        }
Example #2
0
        private Task <bool> HandleGameForPlayer(TcpClient client, string clientId)
        {
            var    stream = client.GetStream();
            string imei   = String.Empty;
            string data   = null;

            Byte[] bytes = new Byte[256];
            int    i;

            try
            {
                string str   = $"Welcome in PoloGame! Send your number to the server...!";
                Byte[] reply = System.Text.Encoding.ASCII.GetBytes(str);
                stream.Write(reply, 0, reply.Length);
                _logger.LogInformation("{1}: Sent: {0}", str, Thread.CurrentThread.ManagedThreadId);
                while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
                {
                    string hex = BitConverter.ToString(bytes);
                    data = Encoding.ASCII.GetString(bytes, 0, i);
                    _logger.LogInformation("{1}: Received: {0}", data, Thread.CurrentThread.ManagedThreadId);
                    return(Task.FromResult(_game.SetPlayerNumber(clientId, Convert.ToInt32(data))));
                }
                return(Task.FromResult(false));
            }
            catch (Exception e)
            {
                _logger.LogError("Exception: {0}", e.ToString(), e);
                return(Task.FromResult(false));
            }
        }