Example #1
0
        /// <summary>
        /// Crea una solicitud al servidor para actualiza el tablero de la partida
        /// despues de una accion por el jugador 1 de la partida
        /// </summary>
        /// <param name="updateBoardMatrix"></param>
        /// <param name="matchNumber"></param>
        /// <param name="playerTwoCheckers"></param>
        /// <param name="playerOneCheckers"></param>
        /// <exception>
        /// Esta excepcion puede retornar una excepcion tipo EndpointNotFoundException
        /// </exception>
        public static void Player1TurnResult(Checker [,] updateBoardMatrix, int matchNumber, int playerTwoCheckers, int playerOneCheckers)
        {
            Checker[][] checkersNewMatrix = new Checker[updateBoardMatrix.GetLength(0)][];
            int         rowNumber         = 0;
            int         columnNumber      = 0;

            for (rowNumber = 0; rowNumber < 8; rowNumber++)
            {
                checkersNewMatrix[rowNumber] = new Checker[updateBoardMatrix.GetLength(1)];
                for (columnNumber = 0; columnNumber < 8; columnNumber++)
                {
                    checkersNewMatrix[rowNumber][columnNumber] = updateBoardMatrix[rowNumber, columnNumber];
                }
            }
            try
            {
                InstanceContext   instanceContext = new InstanceContext(new GameManagerCallbackHandler());
                GameManagerClient server          = new GameManagerClient(instanceContext);
                server.Player1Turn(checkersNewMatrix, matchNumber, playerTwoCheckers, playerOneCheckers);
            }
            catch (EndpointNotFoundException)
            {
                MessageBox.Show(Properties.Resources.NoConnectionMessage);
            }
        }
        public void ReportPlayer_ReturnErrorSaving_ReportResult()
        {
            try
            {
                var baseAddress = new Uri("net.tcp://localhost:8090/Contratos");
                serviceHost = new ServiceHost(typeof(Contratos.MainService), baseAddress);
                System.ServiceModel.Channels.Binding binding = new NetTcpBinding();
                var address  = new EndpointAddress("net.tcp://localhost:8090/ServerTests");
                var endpoint = serviceHost
                               .AddServiceEndpoint(typeof(Contratos.IGameManager), binding, address.Uri);

                var smb = new ServiceMetadataBehavior {
                    HttpGetEnabled = false
                };
                serviceHost.Description.Behaviors.Add(smb);
                InstanceContext instanceContext = new InstanceContext(new GameManagerCallbackHandler());
                gameClient    = new GameManagerClient(instanceContext);
                endpoint.Name = gameClient.Endpoint.Name;

                InstanceContext   instanceContext2 = new InstanceContext(new GameManagerCallbackHandler());
                GameManagerClient gameClient2      = new GameManagerClient(instanceContext2);
                endpoint.Name = gameClient.Endpoint.Name;

                serviceHost.Open();

                Jugador testPlayer = new Jugador
                {
                    Apodo       = "pklove3456",
                    Contrasenia = "bobcholo1",
                };
                gameClient.CreateMatch(testPlayer, CheckersGameMode.ClassicCheckers);

                Jugador testPlayer2 = new Jugador
                {
                    Apodo       = "frews2",
                    Contrasenia = "frews1",
                };
                gameClient2.CreateMatch(testPlayer2, CheckersGameMode.ClassicCheckers);

                serviceHost.Close();
                gameClient.ReportPlayer(2, 1, "testReport reasonings");

                GameManagerCallbackHandler gameHandler = new GameManagerCallbackHandler();
                ReportSaveResult           result      = gameHandler.reportSaveResult;

                Assert.AreEqual(result, ReportSaveResult.ERROR_SAVING);
            }
            catch (EndpointNotFoundException)
            {
                gameClient.Abort();
            }
            catch (CommunicationException)
            {
                gameClient.Abort();
            }
        }
Example #3
0
 /// <summary>
 /// Crea una solicitud para que el <c>Jugador</c> cliente salga de una partida de juego checkers
 /// </summary>
 /// <param name="matchNumber"></param>
 /// <param name="playerNumberLeaving"></param>
 /// <exception>
 /// Esta excepcion puede retornar una excepcion tipo EndpointNotFoundException
 /// </exception>
 public static void LeaveMatchmaking(int matchNumber, int playerNumberLeaving)
 {
     try
     {
         InstanceContext   instanceContext = new InstanceContext(new GameManagerCallbackHandler());
         GameManagerClient server          = new GameManagerClient(instanceContext);
         server.LeaveMatch(matchNumber, playerNumberLeaving);
     }
     catch (EndpointNotFoundException)
     {
         MessageBox.Show(Properties.Resources.NoConnectionMessage);
     }
 }
Example #4
0
 /// <summary>
 /// Crea una solicitud para que un <c>Jugador</c> se una a una partida de juego checkers
 /// </summary>
 /// <param name="player"></param>
 /// <param name="gameMode"></param>
 /// <exception>
 /// Esta excepcion puede retornar una excepcion tipo EndpointNotFoundException
 /// </exception>
 public static void EnterMatchmaking(Jugador player, CheckersGameMode gameMode)
 {
     try
     {
         InstanceContext   instanceContext = new InstanceContext(new GameManagerCallbackHandler());
         GameManagerClient server          = new GameManagerClient(instanceContext);
         server.CreateMatch(player, gameMode);
     }
     catch (EndpointNotFoundException)
     {
         MessageBox.Show(Properties.Resources.NoConnectionMessage);
     }
 }
Example #5
0
        /// <summary>
        /// Crea una solicitud al servidor para crear un <c>Reporte</c> para acusar al oponente por mal comportamiento
        /// </summary>
        /// <param name="playerReporting"></param>
        /// <param name="matchNumber"></param>
        /// <param name="reportText"></param>
        /// <exception>
        /// Esta excepcion puede retornar una excepcion tipo EndpointNotFoundException
        /// </exception>
        public static void ReportPlayer(int playerReporting, int matchNumber, string reportText)
        {
            InstanceContext   instanceContext = new InstanceContext(new GameManagerCallbackHandler());
            GameManagerClient server          = new GameManagerClient(instanceContext);

            try
            {
                server.ReportPlayer(playerReporting, matchNumber, reportText);
            }
            catch (EndpointNotFoundException)
            {
                MessageBox.Show(Properties.Resources.NoConnectionMessage);
            }
        }
Example #6
0
        /// <summary>
        /// Crea una solicitud al servidor para enviar un mensaje del jugador local a su oponente
        /// </summary>
        /// <param name="matchNumber"></param>
        /// <param name="localPlayer"></param>
        /// <param name="message"></param>
        /// <exception>
        /// Esta excepcion puede retornar una excepcion tipo EndpointNotFoundException
        /// </exception>
        public static void SendMessage(int matchNumber, int localPlayer, string message)
        {
            InstanceContext   instanceContext = new InstanceContext(new GameManagerCallbackHandler());
            GameManagerClient server          = new GameManagerClient(instanceContext);

            try
            {
                server.SendGameMessage(localPlayer, message, matchNumber);
            }
            catch (EndpointNotFoundException)
            {
                MessageBox.Show(Properties.Resources.NoConnectionMessage);
            }
        }
Example #7
0
        /// <summary>
        /// Crea una solicitud al servidor para terminar la partida despues de un juego exitoso de checkers
        /// </summary>
        /// <param name="matchNumber"></param>
        /// <param name="localPlayer"></param>
        /// <param name="playerTwoCheckers"></param>
        /// <param name="playerOneCheckers"></param>
        /// <exception>
        /// Esta excepcion puede retornar una excepcion tipo EndpointNotFoundException
        /// </exception>
        public static void EndPlayerGame(int matchNumber, int localPlayer, int playerTwoCheckers, int playerOneCheckers)
        {
            InstanceContext   instanceContext = new InstanceContext(new GameManagerCallbackHandler());
            GameManagerClient server          = new GameManagerClient(instanceContext);

            try
            {
                server.FinishPlayerGame(matchNumber, localPlayer, playerTwoCheckers, playerOneCheckers);
            }
            catch (EndpointNotFoundException)
            {
                MessageBox.Show(Properties.Resources.NoConnectionMessage);
            }
        }
Example #8
0
        public void FinishPlayerGame_PlayerOneLose_int()
        {
            try
            {
                var baseAddress = new Uri("net.tcp://localhost:8090/Contratos");
                serviceHost = new ServiceHost(typeof(Contratos.MainService), baseAddress);
                System.ServiceModel.Channels.Binding binding = new NetTcpBinding();
                var address  = new EndpointAddress("net.tcp://localhost:8090/ServerTests");
                var endpoint = serviceHost
                               .AddServiceEndpoint(typeof(Contratos.IGameManager), binding, address.Uri);

                var smb = new ServiceMetadataBehavior {
                    HttpGetEnabled = false
                };
                serviceHost.Description.Behaviors.Add(smb);
                InstanceContext instanceContext = new InstanceContext(new GameManagerCallbackHandler());
                gameClient    = new GameManagerClient(instanceContext);
                endpoint.Name = gameClient.Endpoint.Name;

                serviceHost.Open();

                gameClient.FinishPlayerGame(1, 2, 10, 0);
                GameManagerCallbackHandler gameHandler = new GameManagerCallbackHandler();
                int result = gameHandler.playerOneCheckers;

                Assert.AreEqual(result, 0);
            }
            catch (EndpointNotFoundException)
            {
                gameClient.Abort();
            }
            catch (CommunicationException)
            {
                gameClient.Abort();
            }
        }