From a67a04fbbf048dc08edd2ed726aa8c6da4c26a6b Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 16 Apr 2010 18:11:19 +0000 Subject: [PATCH] New map method Map.GetStartingPositionForPlayer to, uh, get the starting positions for the players... git-svn-id: https://bd85.net/svn/cs3505_group@96 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- CarFire/CarFire/CarFire/Map.cs | 22 +++++++++++++++++++--- CarFire/CarFire/CarFire/MapReader.cs | 2 +- CarFire/CarFire/CarFire/Parse.cs | 4 ++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CarFire/CarFire/CarFire/Map.cs b/CarFire/CarFire/CarFire/Map.cs index ddfa9d5..f3d59d4 100644 --- a/CarFire/CarFire/CarFire/Map.cs +++ b/CarFire/CarFire/CarFire/Map.cs @@ -154,9 +154,9 @@ namespace CarFire /// The metadata. /// The grid. /// The entities. - public Map(Metadata metadata, char[,] grid, List entities) + public Map(Metadata metadata, char[,] grid, List entities, Point[] playerPositions) { - mData = new Modal(metadata, grid, entities); + mData = new Modal(metadata, grid, entities, playerPositions); mView = new View(mData); } @@ -236,6 +236,19 @@ namespace CarFire } + /// + /// Get the starting position of a player. + /// + /// The number of the player (i.e. 1-4). + /// This number must be a valid player number. + /// The starting position of the player. + public Point GetStartingPositionForPlayer(int playerNumber) + { + Debug.Assert(1 <= playerNumber && playerNumber <= NumPlayers.Max()); + return mData.PlayerPositions[playerNumber]; + } + + /// /// Get all the entities loaded from the map file. Exceptions could be /// thrown if there are entities without associated classes. @@ -267,8 +280,9 @@ namespace CarFire Metadata mMetadata; char[,] mGrid; List mEntities; + Point[] mPlayerPositions; - public Modal(Metadata metadata, char[,] grid, List entities) + public Modal(Metadata metadata, char[,] grid, List entities, Point[] playerPositions) { Debug.Assert(metadata != null); Debug.Assert(grid != null); @@ -278,6 +292,7 @@ namespace CarFire mMetadata = metadata; mGrid = grid; mEntities = entities; + mPlayerPositions = playerPositions; #if DEBUG Console.WriteLine("Loaded map {0} of type {1} written by {2}.", @@ -290,6 +305,7 @@ namespace CarFire public Metadata Metadata { get { return mMetadata; } } public List Entities { get { return mEntities; } } + public Point[] PlayerPositions { get { return mPlayerPositions; } } public bool IsCellOpen(int x, int y) diff --git a/CarFire/CarFire/CarFire/MapReader.cs b/CarFire/CarFire/CarFire/MapReader.cs index 3d43f36..8eb7e16 100644 --- a/CarFire/CarFire/CarFire/MapReader.cs +++ b/CarFire/CarFire/CarFire/MapReader.cs @@ -96,7 +96,7 @@ namespace CarFire public Map GetMap() { - return new Map(mMetadata, mGrid, mEntities); + return new Map(mMetadata, mGrid, mEntities, mPlayerPositions); } diff --git a/CarFire/CarFire/CarFire/Parse.cs b/CarFire/CarFire/CarFire/Parse.cs index be11a9a..bb2e9c1 100644 --- a/CarFire/CarFire/CarFire/Parse.cs +++ b/CarFire/CarFire/CarFire/Parse.cs @@ -10,7 +10,7 @@ namespace CarFire /// /// Class with handy static methods taking strings and returning objects /// parsed from those strings. For all of these functions, white space is - /// generally ignored, but any superfluous characters will make the parse fail. + /// generally ignored, but superfluous characters are not allowed. /// public class Parse { @@ -30,7 +30,7 @@ namespace CarFire /// Parses a comment of an INI file. /// /// Text. - /// The comment. + /// The comment, or null if parsing failed. public static string IniComment(string line) { Match match = Regex.Match(line, @"^;\s*(.*)\s*$"); -- 2.45.2