コード例 #1
0
ファイル: GameState.cs プロジェクト: m-s-z/SE2
        public GameState(Messages.ParametersReader reader)
        {
            _pieceIdCounter = 0;
            _redPlayers     = new List <IPlayer>();
            _bluePlayers    = new List <IPlayer>();
            _name           = reader.GameName;
            var settings = reader.ReadGameMasterSettings;

            _redTeamMax                 = _blueTeamMax = ulong.Parse(settings.GameDefinition.NumberOfPlayersPerTeam);
            _goals                      = settings.GameDefinition.Goals;
            _shamProbability            = settings.GameDefinition.ShamProbability;
            _placingNewPiecesFrequency  = settings.GameDefinition.PlacingNewPiecesFrequency;
            _initialNumberOfPiecesField = settings.GameDefinition.InitialNumberOfPieces;
            _boardWidth                 = Convert.ToInt16(settings.GameDefinition.BoardWidth);
            _taskAreaLength             = Convert.ToInt16(settings.GameDefinition.TaskAreaLength);
            _goalAreaLength             = Convert.ToInt16(settings.GameDefinition.GoalAreaLength);
            _actionCosts                = settings.ActionCosts;
            foreach (var g in _goals)
            {
                if (g.team == Configuration.TeamColour.red)
                {
                    _redNumberOfGoals++;
                }
                else
                {
                    _blueNumberOfGoals++;
                }
            }

            _spawnPieceTimer          = new Timer(_placingNewPiecesFrequency);
            _spawnPieceTimer.Elapsed += new ElapsedEventHandler(SpawnPiece);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: m-s-z/SE2
        static void Main(string[] args)
        {
            foreach (var s in args)
            {
                Console.WriteLine("args: {0}", s);
            }
            _parametersReader = new Messages.ParametersReader(args);
            Tuple <string, int> endPoint = _parametersReader.Validate();

            _parametersReader.ReadGameMasterInputSettings();
            var gameState = new GameState(_parametersReader);

            Console.WriteLine(_parametersReader.ConfigurationFilePath);
            Connection connection = new Connection(endPoint.Item1, endPoint.Item2, _parametersReader);

            try
            {
                connection.Connect();
            }
            catch (Exception e)
            {
                Console.WriteLine("{0} has encountered exception: {1} while trying to connect", nameof(Program), e.Message);
                Console.WriteLine("{0} will now exit", nameof(Program));
            }

            var    gameMessage = new Xsd2.RegisterGame(new Xsd2.GameInfo(connection.GameState));
            var    serializer  = new Serializer(gameMessage);
            string gameMsg     = serializer.Serialize();

            Console.WriteLine(gameMsg);
            connection.SendMessage(gameMsg);

            Task.WaitAll();
            Cleanup();
            Console.ReadLine();
        }