コード例 #1
0
ファイル: ServerClient.cs プロジェクト: jascou/PanzerKontrol
        // Converts unit data from messages to actual units for the game state
        // Also generates IDs for units
        // The reinforcement point calculation is also justified as it is only used in multiplayer and is not used in singleplayer games
        void InitialiseArmy(BaseArmy army)
        {
            List <Unit> units = new List <Unit>();

            if (army.Units.Count == 0)
            {
                throw new ServerClientException("You cannot play a game with an empty base army");
            }

            int pointsSpent = 0;

            foreach (var unitConfiguration in army.Units)
            {
                if (unitConfiguration.FactionId != PlayerState.Faction.Id)
                {
                    throw new ServerClientException("Tried to deploy an army with units from another faction");
                }
                Unit unit = new Unit(PlayerState, Game.GetUnitId(), unitConfiguration, Server);
                pointsSpent += unit.Points;
                units.Add(unit);
            }
            int pointsAvailable = Game.GameConfiguration.Points;

            if (pointsSpent > pointsAvailable)
            {
                throw new ServerClientException("You have spent too many points");
            }
            int reinforcementPoints = (int)(GameConstants.ReinforcementPointsPenaltyFactor * (pointsAvailable - pointsSpent) + GameConstants.ReinforcementPointsBaseRatio * pointsAvailable);

            PlayerState.InitialiseArmy(units, reinforcementPoints);
        }
コード例 #2
0
ファイル: Message.cs プロジェクト: jascou/PanzerKontrol
 private JoinGameRequest(BaseArmy army, bool isPrivate, string owner, string privateKey)
 {
     Army       = army;
     IsPrivate  = isPrivate;
     Owner      = owner;
     PrivateKey = privateKey;
 }
コード例 #3
0
ファイル: Message.cs プロジェクト: jascou/PanzerKontrol
        public GameStart(GameConfiguration gameConfiguration, BaseArmy myArmy, BaseArmy enemyArmy, string opponent, int reinforcementPoints)
        {
            GameConfiguration = gameConfiguration;

            MyArmy    = myArmy;
            EnemyArmy = enemyArmy;

            Opponent = opponent;

            ReinforcementPoints = reinforcementPoints;
        }
コード例 #4
0
ファイル: Message.cs プロジェクト: jascou/PanzerKontrol
 public static JoinGameRequest JoinPrivateGame(BaseArmy army, string privateKey)
 {
     return(new JoinGameRequest(army, false, null, privateKey));
 }
コード例 #5
0
ファイル: Message.cs プロジェクト: jascou/PanzerKontrol
 public static JoinGameRequest JoinPublicGame(BaseArmy army, string owner)
 {
     return(new JoinGameRequest(army, false, owner, null));
 }
コード例 #6
0
ファイル: Message.cs プロジェクト: jascou/PanzerKontrol
 public CreateGameRequest(BaseArmy army, bool isPrivate, GameConfiguration gameConfiguration)
 {
     Army              = army;
     IsPrivate         = isPrivate;
     GameConfiguration = gameConfiguration;
 }