Пример #1
0
        public GameSession Initialization(string map = "Map_004")
        {
            _gameSession = ScenarioConvertor.ToGameSession(ScenarioConvertor.GetSavedMap(map));

            _gameSession.Commands = new List <Command>();

            return(_gameSession);
        }
Пример #2
0
        private GameSession GetGameSession(string route)
        {
            var stopwatch = Stopwatch.StartNew();

            // Create a request for the URL.
            var request = WebRequest.Create(_applicationSettings.ServerAddress + route);

            // If required by the server, set the credentials.
            request.Credentials = CredentialCache.DefaultCredentials;

            // GetInteger the response.
            var response = request.GetResponse();
            // Display the status.
            //Console.WriteLine(((HttpWebResponse)response).StatusDescription);

            var mapContent = "";

            // GetInteger the stream containing content returned by the server.
            // The using block ensures the stream is automatically closed.
            using (var dataStream = response.GetResponseStream())
            {
                // Open the stream using a StreamReader for easy access.
                var reader = new StreamReader(dataStream);
                // Read the content.
                mapContent = reader.ReadToEnd();
                // Display the content.
                //Console.WriteLine(responseFromServer);
            }

            response.Close();

            //mapContent = GetSavedMap("Map_001");

            stopwatch.Stop();

            _logger($"GetInteger game session from server {_applicationSettings.ServerAddress + route} finished for {stopwatch.Elapsed.TotalMilliseconds}.");

            stopwatch.Start();

            var stopwatchParsing = Stopwatch.StartNew();

            var gameSession = ScenarioConvertor.ToGameSession(mapContent);

            stopwatchParsing.Stop();

            _logger($"GetInteger game session parsing finished for {stopwatchParsing.Elapsed.TotalMilliseconds}. " +
                    $"Game session id = {gameSession.Id}. " +
                    $" Turn = {gameSession.Turn}. " +
                    $" SpaceMap objects count is {gameSession.SpaceMap.CelestialObjects.Count}.");

            return(gameSession);
        }
Пример #3
0
        public void GetPlayerSpaceShipTest()
        {
            var gameSession = ScenarioConvertor.ToGameSession(ScenarioConvertor.GetSavedMap("PlayerSpaceShipTest"));

            Assert.AreEqual("HMS Glowworm", gameSession.GetPlayerSpaceShip().Name);
            Assert.AreEqual(90, gameSession.GetPlayerSpaceShip().Direction);
            Assert.AreEqual(10000, gameSession.GetPlayerSpaceShip().PositionX);
            Assert.AreEqual(10000, gameSession.GetPlayerSpaceShip().PositionY);

            var spaceShip = (Spaceship)gameSession.GetPlayerSpaceShip();

            Assert.AreEqual(8, spaceShip.Modules.Count);

            Assert.AreEqual(1, spaceShip.GetModules(Category.DeepScanner).Count);
            Assert.AreEqual(1, spaceShip.GetModules(Category.SpaceScanner).Count);
            Assert.AreEqual(2, spaceShip.GetModules(Category.Shield).Count);
            Assert.AreEqual(2, spaceShip.GetModules(Category.Reactor).Count);
            Assert.AreEqual(1, spaceShip.GetModules(Category.Weapon).Count);

            var deepScanners = spaceShip.GetModules(Category.DeepScanner);

            Assert.AreEqual(2, deepScanners[0].Compartment);
            Assert.AreEqual(2, deepScanners[0].Slot);

            var spaceScanners = spaceShip.GetModules(Category.SpaceScanner);

            Assert.AreEqual(2, spaceScanners[0].Compartment);
            Assert.AreEqual(1, spaceScanners[0].Slot);

            var compartmentModules = spaceShip.GetModules(2);

            Assert.AreEqual(2, compartmentModules.Count);
            Assert.AreEqual(2, compartmentModules[0].Compartment);
            Assert.AreEqual(1, compartmentModules[0].Slot);
            Assert.AreEqual(2, compartmentModules[1].Compartment);
            Assert.AreEqual(2, compartmentModules[1].Slot);
        }
Пример #4
0
        public GameSession Initialization()
        {
            _gameSession = ScenarioConvertor.ToGameSession(ScenarioConvertor.GetSavedMap("Map_003"));

            return(_gameSession);
        }