Пример #1
0
        public IEnumerator Server_HTTP_PUT_CallTest()
        {
            // ARRANGE
            ServerCommunications communications = new ServerCommunications();
            Response             response       = new Response();
            string  url         = "http://localhost:3000/play/";
            bool    isValidated = false;
            Request request     = new Request()
            {
                cardOneId = 5,
                cardTwoId = 5
            };
            string jsonRequest = JsonUtility.ToJson(request);

            communications.OnServerCheck += delegate(string json)
            {
                response    = JsonUtility.FromJson <Response>(json);
                isValidated = true;
            };
            // ACT
            TestRoutineRunner.Instance.StartCoroutine(communications.CheckPair(url, jsonRequest));

            while (!isValidated)
            {
                yield return(null);
            }
            // ASSERT
            Assert.IsTrue(response.isCorrect);
        }
Пример #2
0
        public void DependencyContainer_Gets_Initialized_And_Used_On_PairChecker()
        {
            // ARRANGE
            DependencyContainer  dependencyContainer  = new DependencyContainer();
            ServerCommunications serverCommunications = new ServerCommunications();
            GameDataManager      gameData             = new GameDataManager();
            IMain main = Substitute.For <IMain>();

            dependencyContainer.Bind <Main>(main as Main);
            dependencyContainer.Bind <GameDataManager>(gameData);
            dependencyContainer.Bind <ServerCommunications>(serverCommunications);

            gameData.currentPowerUps = 2;
            int expected = 1;

            PairChecker pairChecker = new PairChecker();

            pairChecker.Initialize(dependencyContainer);

            // ACT
            pairChecker.UsePowerUp();

            // ASSERT
            Assert.AreEqual(expected, gameData.currentPowerUps);
        }
Пример #3
0
 public RoboExplorer(string robotName, ServerCommunications serverCommunications, MoveCreator moveCreator, TimeSleeper timeSleeper, int timeToWaitForNextMove)
 {
     this.robotName = robotName;
     this.serverCommunications = serverCommunications;
     this.moveCreator = moveCreator;
     this.timeSleeper = timeSleeper;
     this.timeToWaitForNextMove = timeToWaitForNextMove;
 }
Пример #4
0
        public override void TextInputEvent(object sender, TextInputEventArgs e)
        {
            // Handle special keys first...
            if (_possibleInputs.Contains(e.Character.ToString()))
            {
                if (_selectedInput == InputControlEnum.IP)
                {
                    _ipInput += e.Character.ToString();
                }
                else
                {
                    _portInput += e.Character.ToString();
                }
            }
            else if (e.Character.ToString() == "\b" && _ipInput.Length > 0 && _selectedInput == InputControlEnum.IP)
            {
                _ipInput = _ipInput.Substring(0, _ipInput.Length - 1);
            }
            else if (e.Character.ToString() == "\r" && _ipInput.Length > 0 && _selectedInput == InputControlEnum.IP)
            {
                _selectedInput = InputControlEnum.Port;
            }
            else if (e.Character.ToString() == "\b" && _portInput.Length > 0 && _selectedInput == InputControlEnum.Port)
            {
                _portInput = _portInput.Substring(0, _portInput.Length - 1);
            }
            else if (e.Character.ToString() == "\b" && _portInput.Length == 0 && _selectedInput == InputControlEnum.Port)
            {
                _selectedInput = InputControlEnum.IP;
            }
            else if (e.Character.ToString() == "\r" && _portInput.Length > 0 && _selectedInput == InputControlEnum.Port)
            {
                // Todo: check values are valid...
                IP   = _ipInput;
                Port = Convert.ToInt32(_portInput);

                BattleshipsGame.ServerIP   = IP;
                BattleshipsGame.ServerPort = Port;

                if (ServerCommunications.Connect())
                {
                    InputComplete = true;
                }
                else
                {
                    _portInput = "";
                    _ipInput   = "";
                }
            }
        }
Пример #5
0
        private void DoneButton_Click(Button button)
        {
            PlacementDone = true;

            // Send placement communcation
            string placementData = "";

            foreach (var ship in _board.PlacedShips)
            {
                foreach (var tile in ship.ShipTiles)
                {
                    placementData += Convert.ToInt32(tile.TileIndex.X) + "," + Convert.ToInt32(tile.TileIndex.Y) + ";";
                }
            }

            ServerCommunications.SendPieces(placementData);
        }
Пример #6
0
        public IEnumerator Server_HTTP_GET_CallTest()
        {
            // ARRANGE
            ServerCommunications communications = new ServerCommunications();
            Configuration        deserialized   = new Configuration();
            string url             = "http://localhost:3000/configuration/1";
            int    expectedRowSize = 4;
            bool   isValidated     = false;

            communications.OnServerResponse += delegate(string json)
            {
                deserialized = JsonUtility.FromJson <Configuration>(json);
                isValidated  = true;
            };
            // ACT
            TestRoutineRunner.Instance.StartCoroutine(communications.GetRequest(url));

            while (!isValidated)
            {
                yield return(null);
            }
            // ASSERT
            Assert.AreEqual(expectedRowSize, deserialized.rowSize);
        }
Пример #7
0
        private void HandleGameReady()
        {
            if (_gameReady == false && ConnectionTimer.Tick)
            {
                _statusText = "Waiting for the other player to connect and place their pieces";
                // Check if both players have connected and placed their pieces before continuting
                _gameReady = ServerCommunications.CheckGameReady();
            }
            else if (ConnectionTimer.Tick && _myTurn == false)
            {
                // Send off the check request or something
                RecieveTurnResult res = ServerCommunications.RecieveOpponentMove();
                if (res.Pending == false && res.TileIndex != null)
                {
                    // Apply the players turn
                    bool hitLocal = _playerBoard.ApplyHit(res.TileIndex.Value);


                    if (!hitLocal)
                    {
                        _myTurn = true;
                    }
                    else
                    {
                        _myTurn = false;
                        _successfulEnemyHits++;
                    }
                }
            }
            else if (_myTurn && _gameReady == true)
            {
                if (_opponentBoard.SelectedTileIndex != null)
                {
                    bool?sendTurnResult = ServerCommunications.SendTurn(_opponentBoard.SelectedTileIndex.Value);
                    // send your turn
                    if (sendTurnResult.HasValue == false)
                    {
                        // They clicked too early
                    }
                    else if (sendTurnResult.Value)
                    {
                        // Hit enemy so stay on
                        _opponentBoard.ApplyHit(_opponentBoard.SelectedTileIndex.Value, true);
                        _opponentBoard.SelectedTileIndex = null;
                        _myTurn = true;
                        _successfulHits++;
                    }
                    else
                    {
                        _opponentBoard.ApplyHit(_opponentBoard.SelectedTileIndex.Value);
                        _opponentBoard.SelectedTileIndex = null;
                        _myTurn = false;
                    }
                }
                _statusText = "Your Turn!";
            }
            else if (!_myTurn && _gameReady == true)
            {
                _statusText = "Other players turn!";
            }
        }
Пример #8
0
 private void TakeTurn()
 {
     ServerCommunications.SendTurnData(PlayerAction);
     PlayerAction = null;
     MainMap      = MapParser.ParseMap(ServerCommunications.ReceiveGameState());
 }