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]); }
        /// <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);
        }
        public ClassicGame(IDNumber roundID, ActiveMatch match)
            : base(roundID, match)
        {
            FormTeams();
            turns = RandomizeTurns();
            shipsPlaced = false;
            CurrentTurnPlayer = NextTurn();

            AddEventAction(typeof(MatchAddPlayerEvent), PlayerInit);
        }
 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();
 }
 private void PlayerDead(IDNumber plr)
 {
     //Match.Teams[DeadTeam].Members.Add(plr);
     PlayerLose(plr);
 }
 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);
 }
        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;
        }
 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));
 }
 /// <summary>
 /// <see cref="IController.OpponentDestroyed()"/>
 /// </summary>
 public virtual void OpponentDestroyed(IDNumber destroyedID)
 {
 }
 /// <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>();
 }
Exemple #10
0
 public Shot(IDNumber receiver, Coordinates coords)
 {
     this.coords = coords;
     Receiver    = receiver;
 }
Exemple #11
0
 public Shot(IDNumber receiver)
     : this(receiver, new Coordinates(-1, -1))
 {
 }
 /// <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);
 }
 /// <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;
 }
 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);
     }
 }
 protected Shot CreateShot(IDNumber opponent, Coordinates shotCoords)
 {
     return(new Shot(opponent, shotCoords));
 }
 private void PlayerTimedOut(IDNumber plr, ControllerTimeoutException ex)
 {
     ApplyEvent(new PlayerTimeoutEvent(plr, ex));
     PlayerLose(plr);
 }
 public Register(IDNumber id, string name)
 {
     ID   = id;
     Name = name;
 }
 /// <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;
 }