/// <summary> /// Converts <see cref="System.Data.DataRow"/> to <see cref="PlatformRow"/>. /// </summary> /// <param name="row">The <see cref="System.Data.DataRow"/> object to be mapped.</param> /// <returns>A reference to the <see cref="PlatformRow"/> object.</returns> protected virtual PlatformRow MapRow(DataRow row) { PlatformRow mappedObject = new PlatformRow(); DataTable dataTable = row.Table; DataColumn dataColumn; // Column "Platform_id" dataColumn = dataTable.Columns["Platform_id"]; if (!row.IsNull(dataColumn)) { mappedObject.Platform_id = (short)row[dataColumn]; } // Column "Location" dataColumn = dataTable.Columns["Location"]; if (!row.IsNull(dataColumn)) { mappedObject.Location = (string)row[dataColumn]; } // Column "Status" dataColumn = dataTable.Columns["Status"]; if (!row.IsNull(dataColumn)) { mappedObject.Status = (byte)row[dataColumn]; } // Column "Platform_config" dataColumn = dataTable.Columns["Platform_config"]; if (!row.IsNull(dataColumn)) { mappedObject.Platform_config = (int)row[dataColumn]; } return(mappedObject); }
// JRH v0.1.8 /// <summary> /// Modifies a newly instantiated row using a specified code to add pits, obstacles and rewards /// </summary> /// <param name="row"></param> /// <param name="codeA"></param> /// <param name="codeB"></param> /// <param name="codeC"></param> void SetRow(ref PlatformRow row, char codeA, char codeB, char codeC) { char[] code = new char[3] { codeA, codeB, codeC }; // JRH v0.1.8: Put the three codes into an array // JRH v0.1.8: Set functionality to PlatformRow / gameObject row.gameObject.name += row.transform.GetSiblingIndex(); // JRH v0.1.8: Add the row's in-scene position relative to the other rows to the gameObject's name if (GameManager.Instance.PlatformManager.LastRow != null) { row.transform.position = new Vector3(0f, 0f, GameManager.Instance.PlatformManager.LastRow.transform.position.z - GameManager.Instance.LaneDistance); } // JRH v0.1.8: Move the new Row to one laneDistance unit behind the last row for (int i = 0; i < 3; i++) { row.Platforms[i].SetPlatform(code[i]); row.Platforms[i].SetCritical(true); if (ObstacleLibrary.DecipherCode(row.Platforms[i].Code, PlatformType.PIT)) { row.Platforms[i].SetPit(); } //if (DecipherCode(row.Platforms[i].Code, ItemType.OBS)) row.Platforms[i].SetObstacle(GenerateObstacle(row.Platforms[i])); } }
// JRH v0.1.8: /// <summary> /// Called by PlatformManager, creates a default set of platforms and then sets them using the code specified (default code, if none specified) /// </summary> /// <param name="code A"></param> /// <param name="code B"></param> /// <param name="code C"></param> /// <returns></returns> public PlatformRow GenerateRow(char codeA = 'P', char codeB = 'P', char codeC = 'P') { PlatformRow newRow = InstantiateRow(); SetRow(ref newRow, codeA, codeB, codeC); return(newRow); }
// JRH v0.1.10: /// <summary> /// Called by PlatformManager, creates a default set of platforms and then sets them using the data specified /// </summary> /// <param name="data"></param> /// <returns></returns> public PlatformRow GenerateRow(RowData data) { PlatformRow newRow = InstantiateRow(); SetRow(ref newRow, data); return(newRow); }
// JRH v0.1.2 /// <summary> /// Instantiates a default row of three platforms /// </summary> /// <returns></returns> PlatformRow InstantiateRow() { GameObject rowObj = new GameObject("Platform Row #"); // JRH v0.1.2: Creates the initial object rowObj.transform.SetParent(parentTransform); // JRH v0.1.2: Attaches the just created row object to the parent transform PlatformRow row = rowObj.AddComponent <PlatformRow>(); // JRH v0.1.2: Adds a fresh PlatformRow script to the row object Platform[] platforms = new Platform[3]; // JRH v0.1.2: Used to hold the platforms the following loop creates so they can be passed through Initialize for (int i = 0; i < 3; i++) { // JRH v0.1.2: Instantiate as many platform prefabs as there are lanes in-game GameObject platformObj = Instantiate(platformPrefabs[UnityEngine.Random.Range(0, platformPrefabs.Count)]); // JRH v0.2.9: Instantiates a random platform from the prefabs list; platformObj.transform.GetChild(0).GetComponent <Renderer>().material = platformMaterials[UnityEngine.Random.Range(0, platformMaterials.Count)]; // JRH 0.3.10: Apply a random material to the platform platformObj.transform.SetParent(rowObj.transform); // JRH v0.1.2: Attach that GameObject to the parent transform platformObj.transform.Translate(new Vector3((i - 1) * GameManager.Instance.LaneDistance, 0f, 0f)); // JRH v0.1.2: Position it accordingly based on the current value of i platforms[i] = platformObj.AddComponent <Platform>(); // JRH v0.1.2: Add a Platform component to the object } row.Initialize(platforms[0], platforms[1], platforms[2]); // JRH v0.1.2: Initialize the row with each new Platform under it return(row); }
public void TestCaseStartedMessageShouldHaveBeenSentWithPlatformInformation(PlatformRow platformRow) { var messageQueue = _cucumberMessagesDriver.LoadMessageQueue(); var testCaseStarted = messageQueue.ToArray().OfType <TestCaseStarted>().First(); if (platformRow.Cpu is string cpu) { testCaseStarted.Platform.Cpu.Should().Be(cpu); } if (platformRow.Os is string os) { testCaseStarted.Platform.Os.Should().Be(os); } if (platformRow.Implementation is string implementation) { testCaseStarted.Platform.Implementation.Should().Be(implementation); } if (platformRow.Version is string version) { testCaseStarted.Platform.Version.Should().Be(version); } }
internal static void DeletePlatform(Rbr_Db pDb, PlatformRow pPlatform) { NodeRow[] _nodes = NodeManager.GetAll(pDb, pPlatform.Platform_id); if (_nodes != null && _nodes.Length > 0) { throw new ApplicationException("Platform has existing child Nodes. Cannot delete."); } pDb.PlatformCollection.Delete(pPlatform); }
internal static PlatformDto MapToPlatform(PlatformRow pPlatformRow) { if (pPlatformRow == null) { return(null); } PlatformDto _platform = new PlatformDto(); _platform.PlatformId = pPlatformRow.Platform_id; _platform.Location = pPlatformRow.Location; _platform.Status = (Status)pPlatformRow.Status; _platform.PlatformConfig = pPlatformRow.PlatformConfiguration; return(_platform); }
internal static PlatformRow MapToPlatformRow(PlatformDto pPlatform) { if (pPlatform == null) { return(null); } PlatformRow _platformRow = new PlatformRow(); _platformRow.Platform_id = pPlatform.PlatformId; _platformRow.Location = pPlatform.Location; _platformRow.Status = (byte)pPlatform.Status; _platformRow.PlatformConfiguration = pPlatform.PlatformConfig; return(_platformRow); }
/// <summary> /// Updates a record in the <c>Platform</c> table. /// </summary> /// <param name="value">The <see cref="PlatformRow"/> /// object used to update the table record.</param> /// <returns>true if the record was updated; otherwise, false.</returns> public virtual bool Update(PlatformRow value) { string sqlStr = "UPDATE [dbo].[Platform] SET " + "[location]=" + _db.CreateSqlParameterName("Location") + ", " + "[status]=" + _db.CreateSqlParameterName("Status") + ", " + "[platform_config]=" + _db.CreateSqlParameterName("Platform_config") + " WHERE " + "[platform_id]=" + _db.CreateSqlParameterName("Platform_id"); IDbCommand cmd = _db.CreateCommand(sqlStr); AddParameter(cmd, "Location", value.Location); AddParameter(cmd, "Status", value.Status); AddParameter(cmd, "Platform_config", value.Platform_config); AddParameter(cmd, "Platform_id", value.Platform_id); return(0 != cmd.ExecuteNonQuery()); }
// JRH v0.2.0 /// <summary> /// Sets the row passed in as a reference using the values contained in a Data parameter /// </summary> /// <param name="row"></param> /// <param name="data"></param> public void SetRow(ref PlatformRow row, RowData data) { // JRH v0.2.0: Set functionality to PlatformRow / gameObject row.gameObject.name += row.transform.GetSiblingIndex(); // JRH v0.2.0: Add the row's in-scene position relative to the other rows to the gameObject's name row.SetCode(data.CodeArray); // JRH v0.2.0: Set the row's code to the code array held in Data if (GameManager.Instance.PlatformManager.LastRow != null) { row.transform.position = new Vector3(0f, 0f, GameManager.Instance.PlatformManager.LastRow.transform.position.z - GameManager.Instance.LaneDistance); } // JRH v0.2.0: Move the new Row to one laneDistance unit behind the last row // JRH v0.2.0: Set functionality to each Platform component for (int i = 0; i < 3; i++) { row.Platforms[i].SetPlatform(data.CodeArray[i]); // JRH v0.2.0: Set the platform's code to the corresponding code in data row.Platforms[i].SetCritical(data.CritArray[i]); // JRH v0.2.0: Set the platform's critical value to the corresponding critical value in data if (ObstacleLibrary.DecipherCode(row.Platforms[i].Code, PlatformType.PIT)) { row.Platforms[i].SetPit(); } // JRH v0.2.0: If the code returns a pit, call the SetPit method in that platform to turn it into a pit if (GameManager.Instance.GhostMode) { if (row.Platforms[i].IsCritical && (row.Platforms[i].Code == 'p' || row.Platforms[i].Code == 'P')) { row.Platforms[i].transform.GetChild(0).GetComponent <Renderer>().material = ghostMaterial; } } } GenerateObstacles(row, data); for (int i = 0; i < 3; i++) { if (ObstacleLibrary.DecipherCode(row.Platforms[i].Code, PlatformType.REW)) { row.Platforms[i].SetReward(GenerateReward(row.Platforms[i])); } } }
//------------------------------- Private ---------------------------------------------- void init(NodeRow pNodeRow, int pIPAddress) { if (pNodeRow == null) { throw new Exception("Node: " + IPUtil.ToString(pIPAddress) + " NOT FOUND"); } nodeRow = pNodeRow; //-- get site using (var _db = new Rbr_Db()) { platformRow = _db.PlatformCollection.GetByPrimaryKey(nodeRow.Platform_id); } if (platformRow == null) { throw new Exception("Site: " + nodeRow.Platform_id + " NOT FOUND"); } }
/// <summary> /// Reads data from the provided data reader and returns /// an array of mapped objects. /// </summary> /// <param name="reader">The <see cref="System.Data.IDataReader"/> object to read data from the table.</param> /// <param name="startIndex">The index of the first record to map.</param> /// <param name="length">The number of records to map.</param> /// <param name="totalRecordCount">A reference parameter that returns the total number /// of records in the reader object if 0 was passed into the method; otherwise it returns -1.</param> /// <returns>An array of <see cref="PlatformRow"/> objects.</returns> protected virtual PlatformRow[] MapRecords(IDataReader reader, int startIndex, int length, ref int totalRecordCount) { if (0 > startIndex) { throw new ArgumentOutOfRangeException("startIndex", startIndex, "StartIndex cannot be less than zero."); } if (0 > length) { throw new ArgumentOutOfRangeException("length", length, "Length cannot be less than zero."); } int platform_idColumnIndex = reader.GetOrdinal("platform_id"); int locationColumnIndex = reader.GetOrdinal("location"); int statusColumnIndex = reader.GetOrdinal("status"); int platform_configColumnIndex = reader.GetOrdinal("platform_config"); System.Collections.ArrayList recordList = new System.Collections.ArrayList(); int ri = -startIndex; while (reader.Read()) { ri++; if (ri > 0 && ri <= length) { PlatformRow record = new PlatformRow(); recordList.Add(record); record.Platform_id = Convert.ToInt16(reader.GetValue(platform_idColumnIndex)); record.Location = Convert.ToString(reader.GetValue(locationColumnIndex)); record.Status = Convert.ToByte(reader.GetValue(statusColumnIndex)); record.Platform_config = Convert.ToInt32(reader.GetValue(platform_configColumnIndex)); if (ri == length && 0 != totalRecordCount) { break; } } } totalRecordCount = 0 == totalRecordCount ? ri + startIndex : -1; return((PlatformRow[])(recordList.ToArray(typeof(PlatformRow)))); }
internal static void CreateDefaultPlatform(Rbr_Db pDb) { //NOTE: HARDCODED VALUE - platform_id = 1 PlatformRow _firstPlatform = pDb.PlatformCollection.GetByPrimaryKey(1); if (_firstPlatform == null) { _firstPlatform = new PlatformRow { PlatformConfiguration = PlatformConfig.Standalone, Location = "Please Enter Real Location", Status = ((byte)Status.Active) }; addPlatform(pDb, _firstPlatform); } //add current node NodeManager.CreateCurrentNode(pDb, _firstPlatform.Platform_id); }
/// <summary> /// Adds a new record into the <c>Platform</c> table. /// </summary> /// <param name="value">The <see cref="PlatformRow"/> object to be inserted.</param> public virtual void Insert(PlatformRow value) { string sqlStr = "INSERT INTO [dbo].[Platform] (" + "[platform_id], " + "[location], " + "[status], " + "[platform_config]" + ") VALUES (" + _db.CreateSqlParameterName("Platform_id") + ", " + _db.CreateSqlParameterName("Location") + ", " + _db.CreateSqlParameterName("Status") + ", " + _db.CreateSqlParameterName("Platform_config") + ")"; IDbCommand cmd = _db.CreateCommand(sqlStr); AddParameter(cmd, "Platform_id", value.Platform_id); AddParameter(cmd, "Location", value.Location); AddParameter(cmd, "Status", value.Status); AddParameter(cmd, "Platform_config", value.Platform_config); cmd.ExecuteNonQuery(); }
// JRH v0.2.4 /// <summary> /// Compares and sets the values of this struct to the most recent piece of data in-game /// </summary> /// <returns></returns> public bool CritCheck(RowData?lastRow = null) { RowData lastData; List <int> unresolved = new List <int>() { 0, 1, 2 }; bool criticalResolution; int critCount = 0; if (lastRow == null) { PlatformRow lastInstance = GameManager.Instance.PlatformManager.LastRow; char[] codes = new char[3] { lastInstance.Platforms[0].Code, lastInstance.Platforms[1].Code, lastInstance.Platforms[2].Code }; bool[] crits = new bool[3] { lastInstance.Platforms[0].IsCritical, lastInstance.Platforms[1].IsCritical, lastInstance.Platforms[2].IsCritical }; lastData = new RowData(codes[0], codes[1], codes[2]); lastData.critArray = crits; } else { lastData = (RowData)lastRow; } for (int i = 0; i < 3; i++) { if (lastData.critArray[i]) { critArray[i] = !ObstacleLibrary.DecipherCode(codeArray[i]) || !ObstacleLibrary.DecipherCode(lastData.codeArray[i]) ? true : false; // JRH v0.2.0: If the last platform was on the critical path and this one is not an obstacle or pit, set it on the critical path } else { critArray[i] = lastData.critArray[i]; } // JRH v0.2.0: Otherwise, let it's critical path follow the platform previous to it's critical path //Debug.Log(i + ":" + lastCode[i] + "," + lastCrit[i] + "," + codeArray[i] + "," + critArray[i]); if (ObstacleLibrary.DecipherCode(lastData.codeArray[i], PlatformType.TALL)) { critArray[i] = false; } // JRH v0.2.9: If the current code is tall, remove the platform from the critical path. There is no way above a tall obstacle. } for (int i = 0; i < critArray.Length; i++) { if (critArray[i]) { unresolved.Remove(i); } } // JRH v0.2.0: If each platform is critical, whoohoo! We don't need to do anything with it in the next step criticalResolution = unresolved.Count < 1 ? true : false; // If there are any unresolved platforms, set the conditions for the next loop starting /* JRH v0.3.2: Due to the increase in time to switch lanes, * while (criticalResolution == false) * { * // While there are platforms unresolved, run this loop * criticalResolution = true; * // JRH v0.2.0: Resets the critical resolution pre-emptively, to be changed again if any platforms have their critical value changed * List<int> toResolve = new List<int>(); * * foreach (int i in unresolved) * { * bool leftCrit, rightCrit; * * leftCrit = i > 0 && !GameManager.Instance.PlatformGenerator.DecipherCode(codeArray[i - 1]) && critArray[i - 1] ? true : false; * rightCrit = i < critArray.Length - 1 && !GameManager.Instance.PlatformGenerator.DecipherCode(codeArray[i + 1]) && critArray[i + 1] ? true : false; * // JRH v0.2.0: Checks the platforms to the left and right of this platform (if they exist) and returns a bool for each if they can transfer critical value * * if ((leftCrit || rightCrit) && !GameManager.Instance.PlatformGenerator.DecipherCode(codeArray[i])) * { * // JRH v0.2.0: If critical value can be transfered (i.e. if the platform isn't a danger and the left or right platforms can transfer critical value * critArray[i] = true; * // JRH v0.2.0: Transfer the critical value * criticalResolution = false; * // JRH v0.2.0: Change the critical resolution so the loop repeats at least once more * toResolve.Add(i); * // JRH v0.2.0: Add the platform index to the list of platforms to resolve * } * } * * foreach (int i in toResolve) unresolved.Remove(i); * // JRH v0.2.0: Remove any platforms that have been resolved from the list of platforms needing to be resolved * }*/ List <int> toResolve = new List <int>(); foreach (int i in unresolved) { bool leftCrit, rightCrit; leftCrit = i > 0 && !ObstacleLibrary.DecipherCode(codeArray[i - 1]) && critArray[i - 1] ? true : false; rightCrit = i < critArray.Length - 1 && !ObstacleLibrary.DecipherCode(codeArray[i + 1]) && critArray[i + 1] ? true : false; // JRH v0.2.0: Checks the platforms to the left and right of this platform (if they exist) and returns a bool for each if they can transfer critical value if ((leftCrit || rightCrit) && !ObstacleLibrary.DecipherCode(codeArray[i])) { // JRH v0.2.0: If critical value can be transfered (i.e. if the platform isn't a danger and the left or right platforms can transfer critical value toResolve.Add(i); // JRH v0.2.0: Add the platform index to the list of platforms to resolve } } foreach (int i in toResolve) { critArray[i] = true; } foreach (bool b in critArray) { if (b) { critCount++; } } // JRH v0.2.0: Count the number of platforms that have had their critical value checked and are indeed part of the critical path return(critCount > 0 ? true : false); // JRH v0.2.0: Return true as long as there is one critical path available on this row, otherwise return false }
internal static void AddPlatform(Rbr_Db pDb, PlatformRow pPlatform) { pDb.PlatformCollection.Insert(pPlatform); }
internal static void UpdatePlatform(Rbr_Db pDb, PlatformRow pPlatform) { pDb.PlatformCollection.Update(pPlatform); }
// JRH v0.2.9: /// <summary> /// A terribly long and convoluted method that accurately decides on which obstacles to generate given the rowdata parameter /// </summary> /// <param name="row"></param> /// <param name="data"></param> void GenerateObstacles(PlatformRow row, RowData data) { //int rowCount = 0; List <Obstacle> obstacles = new List <Obstacle>(); List <int> obstacleLanes = new List <int>(); List <int> lanesNeedingObstacles = new List <int>() { 0, 1, 2 }; //int width, height; char[] codeArray = data.CodeArray; // JRH v0.2.9: For each lane that does require a an obstacle, remove it from the lane that requires obstacles REDUNDANCY HURR DURR for (int i = 0; i < data.CodeArray.Length; i++) { if (!ObstacleLibrary.DecipherCode(data.CodeArray[i], PlatformType.OBS)) { lanesNeedingObstacles.Remove(i); } } // JRH v0.2.9: Determine which obstacles are going to be put into the row and the leftmost lane they cover, and return it to the obstacles and obsLanes lists while (lanesNeedingObstacles.Count > 0) { int width = 1; int nextLaneCheck = 0; Obstacle nextObs; char code, nextCode; code = codeArray[lanesNeedingObstacles[0]]; // JRH v0.2.9: Using the next row needing an obstacle, get a code consisting of an upper and lower bool // JRH v0.2.9: Determine the width of the next obstacle through how many adjascent lane match codes with the current lane while (lanesNeedingObstacles.Count - nextLaneCheck > 1) { nextCode = codeArray[lanesNeedingObstacles[1]]; if (code == nextCode) { width++; nextLaneCheck++; } else { break; } } //height = ObstacleLibrary.DecipherCode(code, PlatformType.TALL) ? 2 : 1; // Determine the height of the next obstacle based on the code // JRH v0.2.9: Find a random obstacle that fits into the height and width requirements do { Obstacle ran = GetComponent <ObstacleLibrary>().LookUpObstacle(); nextObs = ObstacleLibrary.CompareCodes(code, ran.Code) && ran.Width <= width ? ran : null; //nextObs = ran.Height == height && ran.Width <= width ? ran : null; } while (nextObs == null); obstacles.Add(nextObs); // JRH v0.2.9: Add the current obstacle to the list of obstacles obstacleLanes.Add(lanesNeedingObstacles[0]); // JRH v0.2.9: Add the current lane to the list of lanes lanesNeedingObstacles.RemoveRange(0, nextObs.Width); // JRH v0.2.9: Remove the lanes that have just been resolved from the list of lanes that need obstacles } // JRH v0.2.9: For each obstacle rolled, instantiate it into the scene as appropriate for (int i = 0; i < obstacleLanes.Count; i++) { Obstacle obs = obstacles[i]; GameObject obj; float leftPos, rightPos; List <int> lanesCovered; obj = Instantiate(obs.gameObject); // JRH v0.2.9: Instantiate the obstacle object in-scene leftPos = obstacleLanes[i] - 1; rightPos = leftPos + obs.Width - 1; // JRH v0.2.9: Determine the leftmost and rightmost lane that the obstacle is meant to cover obj.transform.position = new Vector3(((leftPos + rightPos) / 2) * GameManager.Instance.LaneDistance, 0, row.transform.position.z); // JRH v0.2.9: Set the object's position to the midpoint of the left and right lanes covered and the row it's on's Z position for (int j = obstacleLanes[i]; j <= obstacleLanes[i] + obs.Width - 1; j++) { row.Platforms[j].SetObstacle(obj.GetComponent <Obstacle>()); } // JRH v0.2.9: Determine which platforms the object is meant to cover and assign them said obstacle obj.transform.SetParent(row.transform); // JRH v0.2.9: Finally, set the parent transform so it treadmills along with the row } }
/// <summary> /// Deletes the specified object from the <c>Platform</c> table. /// </summary> /// <param name="value">The <see cref="PlatformRow"/> object to delete.</param> /// <returns>true if the record was deleted; otherwise, false.</returns> public bool Delete(PlatformRow value) { return(DeleteByPrimaryKey(value.Platform_id)); }
static void addPlatform(Rbr_Db_Base pDb, PlatformRow pPlatform) { pDb.PlatformCollection.Insert(pPlatform); }