private void AssertCollectedFileItems(CollectedObject collectedObject, WmiObject[] expectedFiles) { string UNEXPECTED_ITEM_ATTRIBUTE_VALUE = "Unexpected value for a file_item attribute was found: {0}"; SystemCharacteristics::ReferenceType[] objectReferences = collectedObject.ObjectType.reference.ToArray(); IList <ItemType> fileItems = (IList <ItemType>)collectedObject.SystemData; Assert.AreEqual(expectedFiles.Count(), objectReferences.Count(), "Unexpected number of item references was found."); Assert.AreEqual(objectReferences.Count(), fileItems.Count, "Unexpected number of generated items type was found."); int i = 0; foreach (var expectedFile in expectedFiles) { Dictionary <string, object> fileItemFields = expectedFile.GetValues(); Assert.IsInstanceOfType(fileItems[i], typeof(file_item), "The generated ItemType must be a instance of file_item class."); file_item fileItem = (file_item)fileItems[i]; Assert.AreEqual(objectReferences[i].item_ref, fileItem.id, "The generated ItemType ID must be equal to collected object ID."); Assert.AreEqual(StatusEnumeration.exists, fileItem.status, "A generated ItemType with unexpected OVAL Status was found."); Assert.AreEqual(fileItemFields[FILE_SIZE].ToString(), fileItem.size.Value, string.Format(UNEXPECTED_ITEM_ATTRIBUTE_VALUE, FILE_SIZE)); Assert.AreEqual(ConvertWmiTimeToFileTime(fileItemFields[C_DATE].ToString()), fileItem.c_time.Value, string.Format(UNEXPECTED_ITEM_ATTRIBUTE_VALUE, C_DATE)); Assert.AreEqual(ConvertWmiTimeToFileTime(fileItemFields[M_DATE].ToString()), fileItem.m_time.Value, string.Format(UNEXPECTED_ITEM_ATTRIBUTE_VALUE, M_DATE)); Assert.AreEqual(ConvertWmiTimeToFileTime(fileItemFields[A_DATE].ToString()), fileItem.a_time.Value, string.Format(UNEXPECTED_ITEM_ATTRIBUTE_VALUE, A_DATE)); Assert.AreEqual(fileItemFields[VERSION], fileItem.version.Value, string.Format(UNEXPECTED_ITEM_ATTRIBUTE_VALUE, VERSION)); Assert.AreEqual(fileItemFields[FILE_TYPE], fileItem.type.Value, string.Format(UNEXPECTED_ITEM_ATTRIBUTE_VALUE, FILE_SIZE)); Assert.AreEqual(fileItemFields[COMPANY], fileItem.company.Value, string.Format(UNEXPECTED_ITEM_ATTRIBUTE_VALUE, COMPANY)); i++; } }
protected virtual ProbeResultBuilder CollectInformation(CollectInfo collectInfo) { CollectedObject collectedObject = null; var probeResultBuilder = new ProbeResultBuilder(); int idOfItems = 1; // var objectsOfAnEspecificType = this.GetObjectsOfType(collectInfo.ObjectTypes); ObjectCollector.PrepareCollectionOfObjects(collectInfo.ObjectTypes, collectInfo.Variables); foreach (var ovalObject in collectInfo.ObjectTypes) { ExecutionLogBuilder.CollectingInformationFrom(ovalObject.id); if (this.ObjectTypeHasSet(ovalObject)) { collectedObject = this.ProcessSet(ovalObject, collectInfo); } else { collectedObject = this.ProcessCollect(ovalObject, collectInfo, probeResultBuilder, ref idOfItems); } probeResultBuilder.AddCollectedObject(collectedObject); } return(probeResultBuilder); }
private static IEnumerable <CollectedObject> CreateCollectedObjectsForSpecificObjectTypes(IEnumerable <OVAL.Definitions.ObjectType> objectTypes, List <string> resultsForObjects) { List <CollectedObject> collectedObjects = new List <CollectedObject>(); IEnumerable <family_object> familyObjects = objectTypes.OfType <family_object>(); int id = 1; foreach (var familyObject in familyObjects) { string existId = resultsForObjects.Where(x => x.Equals(familyObject.id)).SingleOrDefault(); if (string.IsNullOrEmpty(existId)) { CollectedObject collectedObject = new CollectedObject(familyObject.id); ItemType familyItem = CreateFamilySpecificItem(id.ToString()); collectedObject.AddItemToSystemData(familyItem); collectedObjects.Add(collectedObject); id++; } else { resultsForObjects.Remove(existId); } } return(collectedObjects); }
/// <summary> /// This method executes the process of a setElement in the ObjectType. /// For the objectType that has a setElement the process is a some different. /// Actually, the setElement uses the objectType already was collected. /// In this process the setElement process uses a systemCharacteristics for the get a reference for the objectType /// collected and makes the references are used in the new CollectedObject of the process. /// </summary> /// <param name="ovalObject">The Oval Object.</param> /// <param name="collectInfo">The collect info.</param> /// <returns></returns> private CollectedObject ProcessSet(Definitions.ObjectType ovalObject, CollectInfo collectInfo) { CollectedObject collectedObject = null; try { var setElement = this.GetSetElement(ovalObject); var setEvaluator = new SetEvaluator(collectInfo.SystemCharacteristics, collectInfo.States, collectInfo.Variables); var resultOfSet = setEvaluator.Evaluate(setElement); var objectReferences = resultOfSet.Result; if (objectReferences.Count() > 0) { collectedObject = new CollectedObject(ovalObject.id); foreach (string reference in objectReferences) { var itemType = collectInfo.SystemCharacteristics.GetSystemDataByReferenceId(reference); collectedObject.AddItemToSystemData(itemType); } collectedObject.SetEspecificObjectStatus(resultOfSet.ObjectFlag); } return(collectedObject); } catch (Exception ex) { collectedObject = new CollectedObject(ovalObject.id); collectedObject.SetEspecificObjectStatus(FlagEnumeration.error); collectedObject.ObjectType.message = MessageType.FromErrorString(String.Format("An error occurred while set processing: '{0}'", ex.Message)); return(collectedObject); } }
public void Should_be_possible_to_create_a_relation_between_objectType_and_systemData_through_of_referenceData() { CollectedObject collectObject = new CollectedObject("oval:org.mitre.oval:obj:6000"); ItemType registryItem1 = new registry_item() { status = StatusEnumeration.exists, id = "1" }; ItemType registryItem2 = new registry_item() { status = StatusEnumeration.doesnotexist, id = "2" }; collectObject.AddItemToSystemData(registryItem1); collectObject.AddItemToSystemData(registryItem2); Assert.AreEqual(2, collectObject.ObjectType.reference.Count(), "the quantity of reference is not expected"); Assert.AreEqual("1", collectObject.ObjectType.reference[0].item_ref, "the first element of reference not has the id expected"); Assert.AreEqual("2", collectObject.ObjectType.reference[1].item_ref, "the second element of reference not has the id expected"); CollectedObject otherCollectedObject = new CollectedObject("oval:org.mitre.oval:obj:6001"); ItemType registryItem3 = new registry_item() { status = StatusEnumeration.exists, id = "3" }; otherCollectedObject.AddItemToSystemData(registryItem3); Assert.AreEqual(1, otherCollectedObject.ObjectType.reference.Count(), "the quantity of reference is not expected for the second collectedObject"); Assert.AreEqual("3", otherCollectedObject.ObjectType.reference[0].item_ref, "the referece id of element is not expected"); }
private static IEnumerable <CollectedObject> CreateCollectedObjectsForSpecificObjectTypes(IEnumerable <definitions.ObjectType> objectTypes, List <string> resultsForObjects) { List <CollectedObject> collectedObjects = new List <CollectedObject>(); IEnumerable <registry_object> registryObjects = objectTypes.OfType <registry_object>(); int id = 1; foreach (var registryObject in registryObjects) { CollectedObject collectedObject = new CollectedObject(registryObject.id); string existId = resultsForObjects.Where(x => x.Equals(registryObject.id)).SingleOrDefault(); if (string.IsNullOrEmpty(existId)) { ItemType registryItem = CreateRegistryItem( registryObject.GetItemValue(registry_object_ItemsChoices.hive).ToString(), id.ToString(), "", registryObject.GetItemValue(registry_object_ItemsChoices.key).ToString(), registryObject.GetItemValue(registry_object_ItemsChoices.name).ToString(), "default" ); collectedObject.AddItemToSystemData(registryItem); collectedObjects.Add(collectedObject); id++; } else { resultsForObjects.Remove(existId); } } return(collectedObjects); }
private void assertCollectedItemsReferences(CollectedObject collectedObject, IList <ItemType> collectedItems) { int collectedObjectCount = collectedObject.ObjectType.reference.Count(); Assert.AreEqual(collectedItems.Count(), collectedObjectCount, "Unexpected number of item references was found."); Assert.AreEqual(collectedObjectCount, collectedItems.Count, "Unexpected number of generated items type was found."); }
private static IEnumerable <CollectedObject> CreateCollectedResultsForFamilyCollect() { List <CollectedObject> collectedObjects = new List <CollectedObject>(); CollectedObject registry = CreateFamilyCollectedObject("oval:org.mitre.oval:obj:99", 1); collectedObjects.Add(registry); return(collectedObjects); }
private static CollectedObject CreateFamilyCollectedObject(string ovalId, int quantidadeDeItems) { CollectedObject collectedObject = new CollectedObject(ovalId); ItemType familyItem = CreateFamilyItem("windows"); collectedObject.AddItemToSystemData(familyItem); return(collectedObject); }
private static IEnumerable <CollectedObject> CreateCollectedResultsForRegistryCollect() { List <CollectedObject> collectedObjects = new List <CollectedObject>(); CollectedObject registry = CreateRegistryCollectedObject(ID_REGISTRY_OBJECT, 2); collectedObjects.Add(registry); return(collectedObjects); }
public void AddCollectedObject(CollectedObject collectedObject) { if (collectedObject == null) { return; } ((List <CollectedObject>) this.probeResult.CollectedObjects).Add(collectedObject); }
/// <summary> /// This method returns the CollectedObjects from the ProbeResult. /// </summary> /// <param name="probeResult">The probe result.</param> /// <returns></returns> private ObjectType[] GetCollectedObjects(ProbeResult probeResult) { ObjectType[] objectTypes = new ObjectType[probeResult.CollectedObjects.Count()]; for (int i = 0; i <= (probeResult.CollectedObjects.Count() - 1); i++) { CollectedObject collectedObject = probeResult.CollectedObjects.ElementAt(i); objectTypes[i] = collectedObject.ObjectType; } return(objectTypes); }
public void Should_not_possible_to_add_a_item_type_if_it_already_exists_in_the_collected_object() { oval_system_characteristics systemCharacteristics = new LoadOvalDocument().GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml"); CollectedObject collectedObject = new CollectedObject("oval:org.mitre.oval:obj:1000"); ItemType registryItem1 = new registry_item() { status = StatusEnumeration.exists, id = "1" }; ItemType registryItem2 = systemCharacteristics.GetSystemDataByReferenceId("2"); }
public ProbeResult CreateCollectedObjectForNotSupportedObjects( IEnumerable <Definitions.ObjectType> objectNotSupported) { ProbeResultBuilder probeResultBuilder = new ProbeResultBuilder(); foreach (var objectType in objectNotSupported) { var collectedObject = new CollectedObject(objectType.id); collectedObject.SetEspecificObjectStatus(FlagEnumeration.notcollected); probeResultBuilder.AddCollectedObject(collectedObject); } return(probeResultBuilder.ProbeResult); }
public static ProbeResult CreateProbeResultForRegistryCollectWithSytemDataDuplicated() { ProbeResult probeResult = new ProbeResult(); CollectedObject registryCollect = CreateRegistryCollectedObject(ID_REGISTRY_OBJECT, 2); CollectedObject otherRegistryCollect = CreateRegistryCollectedObject(ID_OTHER_REGISTRY_OBJECT, 2); List <CollectedObject> collectedObjects = new List <CollectedObject>() { registryCollect, otherRegistryCollect }; probeResult.CollectedObjects = collectedObjects; probeResult.ExecutionLog = CreateAnExecutionLogForRegistry(); return(probeResult); }
public static ProbeResult CreateProbeResultForRegistryCollectWithVariables() { ProbeResult probeResult = new ProbeResult(); CollectedObject registryCollect = CreateRegistryCollectedObject(ID_REGISTRY_OBJECT, 2); registryCollect.AddVariableReference(CreateVariableReference()); List <CollectedObject> collectedObjects = new List <CollectedObject>() { registryCollect }; probeResult.CollectedObjects = collectedObjects; probeResult.ExecutionLog = CreateAnExecutionLogForRegistry(); return(probeResult); }
private void AssertCollectedFileItems(Definitions::ObjectType sourceObject, CollectedObject collectedObject, IEnumerable <CollectedItem> expectedItems) { SystemCharacteristics.ReferenceType[] objectReferences = collectedObject.ObjectType.reference.ToArray(); IList <ItemType> collectedItems = (IList <ItemType>)collectedObject.SystemData; this.assertCollectedItemsReferences(collectedObject, collectedItems); for (int i = 0; i < expectedItems.Count(); i++) { CollectedItem expectedFileItem = expectedItems.ElementAt(i); ItemType collectedItem = collectedItems[i]; this.assertCollectedItemStatus(objectReferences[i], collectedItem); this.assertFileEffectiveRightsInitialEntities(sourceObject, collectedItem); this.assertFileEffectiveRightsCollectedItems(expectedFileItem, collectedItem); } }
public void Should_be_possible_to_execute_a_collect_for_RegKeyEffectiveRights_with_referenced_variable_on_key_entity() { var fakeObjects = new Definitions.ObjectType[] { ProbeHelper.GetDefinitionObjectTypeByID("definitionsSimple", "770") }; string fakeVariableValue = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion"; var fakeEvaluatedVariables = VariableHelper.CreateVariableWithOneValue("oval:modulo:obj:770", "oval:modulo:var:770", fakeVariableValue); var fakeCollectInfo = ProbeHelper.CreateFakeCollectInfo(fakeObjects, fakeEvaluatedVariables, null); var fakeCollectedItems = new CollectedItem[] { ProbeHelper.CreateFakeCollectedItem(new regkeyeffectiverights_item()) }; var prober = this.GetMockedRegKeyEffectiveRightsProber(fakeCollectedItems, null); var proberExecutionResult = prober.Execute(FakeContext, FakeTargetInfo, fakeCollectInfo); this.doBasicProbeResultAssert(proberExecutionResult); CollectedObject collectedObject = proberExecutionResult.CollectedObjects.Single(obj => obj.ObjectType.id.Equals("oval:modulo:obj:770")); this.assertCollectedItemsReferences(collectedObject, (IList <ItemType>)collectedObject.SystemData); Assert.AreEqual(1, collectedObject.SystemData.Count, "Unexpected system data count."); this.assertCollectedItemStatus(collectedObject.ObjectType.reference.ElementAt(0), collectedObject.SystemData[0]); }
public void Should_be_possible_to_add_reference_for_variables_in_the_ObjectType() { List <string> variableValues = new List <string>() { "Multiprocessor Free" }; VariableValue variable = new VariableValue("oval:org.mitre.oval:obj:6000", "oval:com.hp:var:1", variableValues); IEnumerable <VariableValue> variables = new List <VariableValue>() { variable }; CollectedObject collectedObject = new CollectedObject("oval:org.mitre.oval:obj:6000"); collectedObject.AddVariableReference(variables); Assert.IsNotNull(collectedObject.ObjectType.variable_value, "the variables was not set"); Assert.IsTrue(collectedObject.ObjectType.variable_value.Count() == 1, "the quantity of the variable_value is not expected"); Assert.AreEqual(collectedObject.ObjectType.variable_value[0].Value, "Multiprocessor Free", "the value is not expected"); }
public void Should_be_possible_to_update_status_of_an_objectType_to_doesnotexists_based_on_in_systemData() { CollectedObject collectObject = new CollectedObject("oval:org.mitre.oval:obj:6000"); ItemType registryItem1 = new registry_item() { status = StatusEnumeration.exists, id = "1" }; ItemType registryItem2 = new registry_item() { status = StatusEnumeration.doesnotexist, id = "2" }; collectObject.AddItemToSystemData(registryItem1); collectObject.AddItemToSystemData(registryItem2); collectObject.UpdateCollectedObjectStatus(); Assert.AreEqual(FlagEnumeration.doesnotexist, collectObject.ObjectType.flag); }
public void Should_be_possible_to_execute_a_registry_collect_with_Set_element() { var fakeDefinitions = ProbeHelper.GetFakeOvalDefinitions("definitionsWithSet.xml"); var fakeObjects = fakeDefinitions.objects.OfType <registry_object>().ToArray(); oval_system_characteristics fakeSystemCharacteristics = new LoadOvalDocument().GetFakeOvalSystemCharacteristics("system_characteristics_with_sets.xml"); CollectInfo fakeCollectedInfo = ProbeHelper.CreateFakeCollectInfo(fakeObjects, null, fakeSystemCharacteristics); registry_item fakeRegistryItem = this.GetFakeRegistryItem(@"Software\Microsoft\Windows NT\CurrentVersion", "CurrentVersion", eValueTypes.STRING, "6.0"); RegistryProber registryProber = this.GetMockedRegistryProber(fakeRegistryItem); IEnumerable <CollectedObject> result = registryProber.Execute(fakeContext, fakeTarget, fakeCollectedInfo).CollectedObjects; Assert.IsNotNull(result, "the result is not expected"); CollectedObject collectedObject = result.Where <CollectedObject>(obj => obj.ObjectType.id == "oval:org.mitre.oval:obj:6000").SingleOrDefault(); Assert.IsNotNull(collectedObject, "the element was not found"); Assert.AreEqual(collectedObject.ObjectType.reference.Count(), 3, "the quantity of object referenced is not expected"); }
public void Should_be_possible_to_execute_a_simple_collect_for_RegKeyEffectiveRights_object() { var prober = new RegKeyEffectiveRightsProber(); ProberBehaviorCreator .CreateBehaviorForNormalFlowExecution( prober, FakeItemsToReturnByItemTypeGenerator, FakeCollectedItems); var probeExecutionResult = prober.Execute(FakeContext, FakeTargetInfo, FakeCollectInfo); DoAssertForSingleCollectedObject(probeExecutionResult, typeof(regkeyeffectiverights_item)); this.doBasicProbeResultAssert(probeExecutionResult); CollectedObject collectedObject = probeExecutionResult.CollectedObjects.ElementAt(0); this.assertCollectedItemsReferences(collectedObject, (IList <ItemType>)collectedObject.SystemData); this.assertCollectedItemStatus(collectedObject.ObjectType.reference.ElementAt(0), collectedObject.SystemData[0]); }
private void AssertProbeResultItem(CollectedObject collectedObject, string objectID, string[] expectedVariables, List <registry_item> expectedItems) { SystemCharacteristics::ObjectType createdObjectType = collectedObject.ObjectType; List <ItemType> createdItemsType = (List <ItemType>)collectedObject.SystemData; Assert.AreEqual(objectID, createdObjectType.id); if (expectedVariables != null) { Assert.IsNotNull(createdObjectType.variable_value, "There is no variable values for this collected object"); Assert.AreEqual(expectedVariables.Count(), createdObjectType.variable_value.Count(), "The number of variable values for this collected object is unexpected."); for (int i = 0; i < expectedVariables.Count(); i++) { Assert.AreEqual(expectedVariables[i], createdObjectType.variable_value[i].Value, "An unexpected variable value was found."); } } Assert.AreEqual(expectedItems.Count, createdObjectType.reference.Count()); Assert.AreEqual(expectedItems.Count, createdItemsType.Count); for (int i = 0; i < createdItemsType.Count; i++) { registry_item createdRegistryItem = (registry_item)createdItemsType[i]; Assert.AreEqual(expectedItems[i].status, createdRegistryItem.status); Assert.AreEqual(expectedItems[i].message.First().Value, createdRegistryItem.message.First().Value); Assert.AreEqual(expectedItems[i].hive.Value, createdRegistryItem.hive.Value); Assert.AreEqual(expectedItems[i].key.Value, createdRegistryItem.key.Value); Assert.AreEqual(expectedItems[i].name.Value, createdRegistryItem.name.Value); Assert.AreEqual(expectedItems[i].type.Value, createdRegistryItem.type.Value); Assert.AreEqual(expectedItems[i].value.Count(), createdRegistryItem.value.Count()); for (int j = 0; j < expectedItems[i].value.Count(); j++) { Assert.AreEqual(expectedItems[i].value[j].Value, createdRegistryItem.value[j].Value); } } }
public void Should_be_possible_to_execute_a_simple_file_collect() { // Arrange file_item fakeFileItem = this.CreateFakeFileItem("c:\\windows\\ODBC.ini", null, null); CollectInfo fakeCollectInfo = this.getFakeCollectInfo("definitionsWithOnlyObjects.xml"); FileProber fileProber = this.GetMockedFileProber(fakeFileItem); // Act ProbeResult collectResult = fileProber.Execute(fakeContext, fakeTargetInfo, fakeCollectInfo); // Assert Assert.IsNotNull(collectResult, "The result of probe execution cannot be null."); Assert.IsNotNull(collectResult.CollectedObjects, "There are no collected objects."); Assert.AreEqual(2, collectResult.CollectedObjects.Count(), "Unexpected quantity of collected objects"); CollectedObject fileObjectToAssert = collectResult.CollectedObjects.ElementAt(0); Assert.IsNotNull(fileObjectToAssert.ObjectType, "The first collected object cannot null."); Assert.AreEqual("oval:modulo:obj:9000", fileObjectToAssert.ObjectType.id, "The identificator of [collected object] and [definitions object] must be equal."); Assert.AreEqual(FlagEnumeration.complete, fileObjectToAssert.ObjectType.flag, "A successfully gathering must generate a collected object with flag equal to 'complete'."); Assert.IsNotNull(fileObjectToAssert.ObjectType.reference, "A successfully gathering must generate at least one item referenced"); Assert.AreEqual(1, fileObjectToAssert.ObjectType.reference.Count(), "Unexpected number of generated items for this object collected"); Assert.AreEqual(fileObjectToAssert.SystemData.Count(), fileObjectToAssert.ObjectType.reference.Count(), "The number of referenced items in collected object should be equal to generated items quantity."); }
/// <summary> /// Executes a normal collect, using the system datasource for data collecting. /// </summary> /// <param name="ovalComponent">The oval component.</param> /// <param name="collectInfo">The collect info.</param> /// <param name="id">The id parameter is 'a sequencial number controlled by external scope.</param> /// <returns></returns> private CollectedObject ProcessCollect(Definitions.ObjectType ovalComponent, CollectInfo collectInfo, ProbeResultBuilder probeResultBuilder, ref int id) { CollectedObject collectedObject = null; var allItemsToCollect = this.TryToGetItemsToCollect(ovalComponent, collectInfo.Variables); if (allItemsToCollect.Count() > 0) { collectedObject = new CollectedObject(ovalComponent.id); foreach (var itemToCollect in allItemsToCollect) { var collectedItems = ObjectCollector.CollectDataForSystemItem(itemToCollect); foreach (var collectedItem in collectedItems) { var itemType = probeResultBuilder.GetItemType(collectedItem.ItemType); if (itemType == null) { collectedItem.ItemType.id = id.ToString(); id++; } else { collectedItem.ItemType = itemType; } collectedObject.AddItemToSystemData(collectedItem.ItemType); var variables = collectInfo.GetVariableValueForOvalComponent(collectedObject.ObjectType.id); collectedObject.AddVariableReference(variables); ExecutionLogBuilder.AddDetailInformation(collectedItem.ExecutionLog); } } collectedObject.UpdateCollectedObjectStatus(); } return(collectedObject); }
private static CollectedObject CreateRegistryCollectedObject(string ovalId, int quantidadeDeItems) { CollectedObject collectedObject = new CollectedObject(ovalId); ItemType currentVersion = CreateRegistryItem("HKEY_LOCAL_MACHINE", "1", "", "Microsoft\\WindowsNT\\", "CDSVersion", "Service Pack 1"); collectedObject.AddItemToSystemData(currentVersion); ItemType systemRoot = CreateRegistryItem("HKEY_LOCAL_MACHINE", "2", "", "Microsoft\\WindowsNT\\", "SystemRoot", @"c:\Windows"); collectedObject.AddItemToSystemData(systemRoot); return(collectedObject); }
public void Run() { plane.Print(); while (!settings.GameOver) { // adding chance to spawn @ 25% int chanceToSpawn = rnd.Next(0, 100); status.ClearStatus(); status.PrintStatus(); if (chanceToSpawn <= 80) { int objXPosition = 1; int objYPosition = rnd.Next(0, settings.Width - 2); destroyObject = new DestroyObject(new Point(objXPosition, objYPosition)); gameObjectsList.AddLast(destroyObject); } if (chanceToSpawn <= 15) { int objXPosition = 1; int objYPosition = rnd.Next(0, settings.Width); collectObject = new CollectedObject(new Point(objXPosition, objYPosition)); gameObjectsList.AddLast(collectObject); } while (gameObjectsList.Count > 0) { current = gameObjectsList.First; gameObjectsList.RemoveFirst(); if (!current.Value.HaveCollision) { PrintGameObject.PrintObject(current.Value); newGameObjectsList.AddLast(current.Value); } } gameObjectsList = newGameObjectsList; newGameObjectsList = new LinkedList<GameObject>(); while (Console.KeyAvailable) { ConsoleKeyInfo keyPressed = Console.ReadKey(); plane.Clear(); if (keyPressed.Key == ConsoleKey.UpArrow) { plane.Position.X--; if (plane.Position.X < 1) { plane.Position.X = 1; } } if (keyPressed.Key == ConsoleKey.DownArrow) { plane.Position.X++; if (plane.Position.X > settings.Height - plane.PlaneHeight) { plane.Position.X = settings.Height - plane.PlaneHeight; } } if (keyPressed.Key == ConsoleKey.LeftArrow) { plane.Position.Y--; if (plane.Position.Y < 0) { plane.Position.Y = 0; } } if (keyPressed.Key == ConsoleKey.RightArrow) { plane.Position.Y++; if (plane.Position.Y > settings.Width - plane.PlaneWidth) { plane.Position.Y = settings.Width - plane.PlaneWidth; } } if (keyPressed.Key == ConsoleKey.Spacebar) { projectile = new Projectile(new Point(plane.Position.X - 1, plane.Position.Y + plane.PlaneWidth / 2)); projectilesFired.AddLast(projectile); PrintGameObject.PrintObject(projectile); } if (keyPressed.Key == ConsoleKey.P) { PauseScreenPage pause = new PauseScreenPage(); pause.PauseMain(); settings.Pause = !settings.Pause; Console.ReadKey(); Console.Clear(); } plane.Print(); } while (projectilesFired.Count > 0) { Projectile current = (projectilesFired.First).Value; projectilesFired.RemoveFirst(); PrintGameObject.ClearObject(current); current.Move(); if (!current.HaveCollision) { PrintGameObject.PrintObject(current); projectilesInAir.AddLast(current); } } projectilesFired = projectilesInAir; projectilesInAir = new LinkedList<Projectile>(); //foreach (var projectile in projectilesFired) //{ // if (projectile.UpLeftCorner.X >= 0) // { // PrintGameObject.ClearObject(projectile); // projectile.Move(); // if (projectile.UpLeftCorner.X > 0) // { // PrintGameObject.PrintObject(projectile); // } // } //} while (gameObjectsList.Count > 0) { current = gameObjectsList.First; gameObjectsList.RemoveFirst(); PrintGameObject.ClearObject(current.Value); current.Value.Move(); if (!current.Value.HaveCollision) { PrintGameObject.PrintObject(current.Value); newGameObjectsList.AddLast(current); } } gameObjectsList = newGameObjectsList; newGameObjectsList = new LinkedList<GameObject>(); status.Score += 1; Thread.Sleep(sleepTime); } Settings.PrintGameOver(); }
public void Should_be_possible_to_create_an_objectType_with_status_not_collected() { CollectedObject collectObject = new CollectedObject("oval:org.mitre.oval:obj:6000"); Assert.AreEqual(Modulo.Collect.OVAL.SystemCharacteristics.FlagEnumeration.notcollected, collectObject.ObjectType.flag, "the objectType not has the expected flag"); }
public void Run() { plane.Print(); if (FermiInTheAir.Utility.OpeningPage.playTutorial) { Settings.Tutorial(); // plays only one time when opening application } plane.Print(); FermiInTheAir.Utility.OpeningPage.playTutorial = false; //set plane point coordinates to true while (!settings.GameOver) { // chance to spawn objects, adjust below for collectables / destroyables int chanceToSpawn = rnd.Next(0, 100); status.ClearStatus(); status.PrintStatus(); if (Convert.ToInt32(difficultyTimer.ElapsedMilliseconds) > 30000) { destroyObjectSpawnFrequency = 40; } if (chanceToSpawn <= destroyObjectSpawnFrequency) // previously = 40 { int objXPosition = 1; int objYPosition = rnd.Next(11, settings.Width - 11); // previously = rnd.Next(0, settings.Width - 2); destroyObject = new DestroyObject(new Point(objXPosition, objYPosition)); foreach (var point in destroyObject.PositionsCoordinates) { if (CheckCollisionWithPlane(destroyObject, plane)) { destroyObject.HaveCollision = true; plane.Lives--; sounds.Crash(); break; } if (CheckCollisionWhitOtherObject(point)) { destroyObject.HaveCollision = true; } } if (!destroyObject.HaveCollision) { gameObjectsList.Add(destroyObject); destroyObject.SetPositionsCoordinates(); } } if (chanceToSpawn <= 15) { int objXPosition = 1; int objYPosition = rnd.Next(7, settings.Width - 7); // previously = rnd.Next(0, settings.Width); collectObject = new CollectedObject(new Point(objXPosition, objYPosition)); if (CheckCollisionWithPlane(collectObject, plane)) { collectObject.HaveCollision = true; settings.Score += 5; //TODO : regulate score } if (CheckCollisionWhitOtherObject(collectObject.UpLeftCorner)) { destroyObject.HaveCollision = true; } if (!destroyObject.HaveCollision) { gameObjectsList.Add(collectObject); collectObject.SetPositionsCoordinates(); } } while (gameObjectsList.Count > 0) { current = gameObjectsList[gameObjectsList.Count - 1]; gameObjectsList.RemoveAt(gameObjectsList.Count - 1); if (!current.HaveCollision) { PrintGameObject.PrintObject(current); newGameObjectsList.Add(current); } } if (plane.Lives < 0) { settings.GameOver = true; sounds.GameOver(); break; } gameObjectsList = newGameObjectsList; newGameObjectsList = new List<GameObject>(); while (Console.KeyAvailable) { plane.Clear(); ConsoleKeyInfo keyPressed = Console.ReadKey(true); if (keyPressed.Key == ConsoleKey.UpArrow) { plane.Position.X--; if (plane.Position.X < 1) { plane.Position.X = 1; } } if (keyPressed.Key == ConsoleKey.DownArrow) { plane.Position.X++; if (plane.Position.X > settings.Height - plane.PlaneHeight) { plane.Position.X = settings.Height - plane.PlaneHeight; } } if (keyPressed.Key == ConsoleKey.LeftArrow) { plane.Position.Y--; if (plane.Position.Y < 0) { plane.Position.Y = 0; } } if (keyPressed.Key == ConsoleKey.RightArrow) { plane.Position.Y++; if (plane.Position.Y > settings.Width - plane.PlaneWidth) { plane.Position.Y = settings.Width - plane.PlaneWidth; } } if (keyPressed.Key == ConsoleKey.Spacebar) { projectile = new Projectile(new Point(plane.Position.X - 1, plane.Position.Y + plane.PlaneWidth / 2)); if (CheckCollisionWhitOtherObject(projectile.UpLeftCorner)) { projectile.HaveCollision = true; sounds.DestroyObject(); settings.Score += 5; } else { gameObjectsList.Add(projectile); } PrintGameObject.PrintObject(projectile); } if (keyPressed.Key == ConsoleKey.P) { PauseScreenPage pause = new PauseScreenPage(); pause.PauseMain(); settings.Pause = !settings.Pause; Console.ReadKey(); Console.Clear(); } plane.SetPlaneCoordinates(); bool haveCollision = CheckPlaneCollision(); if (haveCollision) { plane.Lives--; sounds.Crash(); } if (plane.Lives < 0) { settings.GameOver = true; sounds.GameOver(); break; } plane.Print(); } while (gameObjectsList.Count > 0) { current = gameObjectsList[gameObjectsList.Count - 1]; gameObjectsList.RemoveAt(gameObjectsList.Count - 1); PrintGameObject.ClearObject(current); current.Move(); current.SetPositionsCoordinates(); if (CheckCollisionWithPlane(current, plane)) { current.HaveCollision = true; if (current.Symbol != '$' && current.Symbol!= '^') { plane.Lives--; } else if (current.Symbol == '$') { settings.Score += 10; } sounds.Crash(); } else if (CheckCollisionWhitOtherObject(current.UpLeftCorner)) { current.HaveCollision = true; sounds.DestroyObject(); settings.Score += 5; } else { PrintGameObject.PrintObject(current); newGameObjectsList.Add(current); } } gameObjectsList = newGameObjectsList; newGameObjectsList = new List<GameObject>(); status.Score = settings.Score; status.Lives = plane.Lives; Thread.Sleep(sleepTime); } Settings.PrintGameOver(status.Score); }
public void RemoveObject(CollectedObject obj) { GameObject.Destroy(obj.gameObject); }