Identical to an integer and can be used exactly as such in code. Used to identify a Controller in a specific index of arrays present in Register and MatchConfig. { var matchInfo = ...; //get the MatchInfo from somewhere ControllerID opponent = ...; //get it from somewhere Console.WriteLine("Playing against " + matchInfo.Players[opponent]); }
コード例 #1
0
        /// <summary>
        /// Generates and returns a ShotList of Shot objects that have been received by a specific ControllerID
        /// </summary>
        public ShotList ShotsToReceiver(IDNumber idx)
        {
            ShotList newList = new ShotList();

            newList.allShots             = allShots;
            newList.shotsByReceiver[idx] = shotsByReceiver[idx];
            return(newList);
        }
コード例 #2
0
        public ClassicGame(IDNumber roundID, ActiveMatch match)
            : base(roundID, match)
        {
            FormTeams();
            turns = RandomizeTurns();
            shipsPlaced = false;
            CurrentTurnPlayer = NextTurn();

            AddEventAction(typeof(MatchAddPlayerEvent), PlayerInit);
        }
コード例 #3
0
 private void PlayerLose(IDNumber plr)
 {
     Match.Teams[DeadTeam].Members.Add(plr);
     turns.Remove(plr);
     ApplyEvent(new PlayerLostEvent(plr));
     try
     {
         Match.Controllers[plr].RoundLost();
     }
     catch (ControllerTimeoutException ex)
     {
         ApplyEvent(new PlayerTimeoutEvent(plr, ex));
     }
     CurrentTurnPlayer = NextTurn();
 }
コード例 #4
0
 private void PlayerDead(IDNumber plr)
 {
     //Match.Teams[DeadTeam].Members.Add(plr);
     PlayerLose(plr);
 }
コード例 #5
0
 public bool ShotValid(IDNumber shooter, Shot shot)
 {
     return shot != null &&
         shot.Coordinates < Match.CompiledConfig.FieldSize &&
         shot.Coordinates >= new Coordinates(0, 0) &&
         shooter != shot.Receiver &&
         !Match.Fields[shooter].Shots.Contains(shot) &&
         !Match.Teams[DeadTeam].Members.Contains(shot.Receiver);
 }
コード例 #6
0
        public bool ShipsValid(IDNumber player)
        {
            bool result = Match.Fields[player].Ships != null &&
                Match.Fields[player].Ships.EqualLengthsAs(Match.CompiledConfig.StartingShips) &&
                Match.Fields[player].Ships.ShipsPlaced &&
                Match.Fields[player].Ships.GetConflictingShips().Count == 0;
            foreach (var ship in Match.Fields[player].Ships)
            {
                ship.IsValid(Match.CompiledConfig.FieldSize);
            }

            return result;
        }
コード例 #7
0
 public virtual void UnsetControllerFromTeam(IDNumber ctrl, IDNumber team)
 {
     if (!controllers.ContainsKey(ctrl))
     {
         throw new ArgumentException("Controller ID number " + ctrl + " does not exist in the current match.");
     }
     if (!Teams.ContainsKey(team))
     {
         throw new ArgumentException("Team ID number " + team + " does not exist in the current match.");
     }
     ApplyEvent(new PlayerTeamUnassignEvent(ctrl, team));
 }
コード例 #8
0
 /// <summary>
 /// <see cref="IController.OpponentDestroyed()"/>
 /// </summary>
 public virtual void OpponentDestroyed(IDNumber destroyedID)
 {
 }
コード例 #9
0
 /// <summary>
 /// Creates a new empty internal list for Shot objects for a specific receiver ID.
 /// </summary>
 /// <param name="receiver">The ControllerID of the receiver to create the list for.</param>
 public void MakeReceiver(IDNumber receiver)
 {
     shotsByReceiver[receiver] = new List <Shot>();
 }
コード例 #10
0
 public Shot(IDNumber receiver, Coordinates coords)
 {
     this.coords = coords;
     Receiver    = receiver;
 }
コード例 #11
0
 public Shot(IDNumber receiver)
     : this(receiver, new Coordinates(-1, -1))
 {
 }
コード例 #12
0
 /// <summary>
 /// This method is called when an opponent controller has had all their ships destroyed, and is no longer
 /// active in the game.
 /// </summary>
 /// <param name="destroyedID"></param>
 public override void OpponentDestroyed(IDNumber destroyedID)
 {
     base.OpponentDestroyed(destroyedID);
 }
コード例 #13
0
 /// <summary>
 /// Stores the information provided by the <paramref name="exception"/> and bases the <see cref="Event.Message"/>
 /// from it.
 /// </summary>
 /// <param name="exception">The <see cref="ControllerTimeoutException"/> generated by a <see cref="Player"/>.</param>
 public PlayerTimeoutEvent(IDNumber playerID, ControllerTimeoutException exception)
     : base(playerID)
 {
     TimeTaken = 500;
     Method = exception.MethodName;
 }
コード例 #14
0
 private void ASCIIWriteShip(IDNumber ctrlIdx, Ship ship, char character, ConsoleColor colorText, ConsoleColor colorBack)
 {
     foreach (Coordinates coord in ship.Locations)
     {
         ModifyASCII(ctrlIdx, coord.X, coord.Y, character, colorText, colorBack);
     }
 }
コード例 #15
0
 protected Shot CreateShot(IDNumber opponent, Coordinates shotCoords)
 {
     return(new Shot(opponent, shotCoords));
 }
コード例 #16
0
 private void PlayerTimedOut(IDNumber plr, ControllerTimeoutException ex)
 {
     ApplyEvent(new PlayerTimeoutEvent(plr, ex));
     PlayerLose(plr);
 }
コード例 #17
0
 public Register(IDNumber id, string name)
 {
     ID   = id;
     Name = name;
 }
コード例 #18
0
 /// <summary>
 /// Passes the <paramref name="round"/> to the base constructor
 /// </summary>
 /// <param name="round"></param>
 public RoundEndEvent(Match match, IDNumber roundNumber)
     : base(match)
 {
     Round = roundNumber;
 }