public void changeLocationOfLocation(CswPrimaryKey PrevLocationId, CswPrimaryKey CurrentLocationId) { Collection <CswNbtObjClassInventoryLevel> PrevLevels; Collection <CswNbtObjClassInventoryLevel> CurrentLevels; _getInventoryLevelCollections(out PrevLevels, out CurrentLevels, PrevLocationId, CurrentLocationId); Collection <CswNbtObjClassInventoryLevel> AppliesToLevels = new Collection <CswNbtObjClassInventoryLevel>(); foreach (CswNbtObjClassInventoryLevel Prev in PrevLevels) { if (false == CurrentLevels.Contains(Prev)) { AppliesToLevels.Add(Prev); } } foreach (CswNbtObjClassInventoryLevel Current in CurrentLevels) { if (false == PrevLevels.Contains(Current) && false == AppliesToLevels.Contains(Current)) { AppliesToLevels.Add(Current); } } foreach (CswNbtObjClassInventoryLevel LevelToUpdate in AppliesToLevels) { CswNbtSdInventoryLevelMgr Mgr = new CswNbtSdInventoryLevelMgr(_CswNbtResources); LevelToUpdate.CurrentQuantity.Quantity = Mgr.getCurrentInventoryLevel(LevelToUpdate); LevelToUpdate.postChanges(true); } }
/// <summary> /// Updates the currently active levels and their entities. /// </summary> /// <param name="gameTime">Game time.</param> public void Update(GameTime gameTime) { if (CurrentLevels.Count() == 0) { Parent.ChangeState(GameState.GameOver); } foreach (Level lv in CurrentLevels) { lv.Update(gameTime); } }
// LEVEL SETTINGS public void SaveLevel(int gridIndex, int levelIndex) { BinaryFormatter binaryFormatter = new BinaryFormatter(); FileStream file = File.Create(Application.persistentDataPath + "/levelSettings.dat"); CurrentLevels data = new CurrentLevels(); data.levelIndex = levelIndex; data.gridIndex = gridIndex; binaryFormatter.Serialize(file, data); file.Close(); }
public bool EndScope(int[] expectedScope) { if (CurrentLevels.SequenceEqual(expectedScope)) { var currentLevel = CurrentLevels.Pop(); NextLevel = currentLevel + 1; return(true); } else { return(false); } }
public int LoadLevel() { if (File.Exists(Application.persistentDataPath + "/levelSettings.dat")) { BinaryFormatter binaryFormatter = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/levelSettings.dat", FileMode.Open); CurrentLevels data = (CurrentLevels)binaryFormatter.Deserialize(file); file.Close(); return(data.levelIndex); } else { return(0); } }
public bool changeLocationOfQuantity(double Quantity, CswPrimaryKey UnitId, string Reason, CswPrimaryKey MaterialId, CswPrimaryKey PrevLocationId, CswPrimaryKey CurrentLocationId) { bool Ret = false; if (CswTools.IsPrimaryKey(MaterialId) && CswTools.IsPrimaryKey(PrevLocationId) && CswTools.IsPrimaryKey(CurrentLocationId)) { Collection <CswNbtObjClassInventoryLevel> PrevLevels; Collection <CswNbtObjClassInventoryLevel> CurrentLevels; _getInventoryLevelCollections(out PrevLevels, out CurrentLevels, PrevLocationId, CurrentLocationId, MaterialId); Collection <CswNbtObjClassInventoryLevel> AppliesToPrevLevels = new Collection <CswNbtObjClassInventoryLevel>(); foreach (CswNbtObjClassInventoryLevel Prev in PrevLevels) { if (false == CurrentLevels.Contains(Prev)) { AppliesToPrevLevels.Add(Prev); } } //These Inventory Levels are losing inventory _applyQuantityToInventoryLevels(AppliesToPrevLevels, -(Quantity), UnitId, Reason); Collection <CswNbtObjClassInventoryLevel> AppliesToCurrentLevels = new Collection <CswNbtObjClassInventoryLevel>(); foreach (CswNbtObjClassInventoryLevel Current in CurrentLevels) { if (false == PrevLevels.Contains(Current)) { AppliesToCurrentLevels.Add(Current); } } //These Inventory Levels are gaining inventory _applyQuantityToInventoryLevels(AppliesToCurrentLevels, Quantity, UnitId, Reason); Ret = true; } return(Ret); }
/// <summary> /// Draws current active levels and their entities. /// </summary> /// <param name="gameTime">Game time.</param> public void Draw(GraphicsDevice graphicsDevice, GameTime gameTime, SpriteBatch spriteBatch, Rectangle clientBounds) { Vector2?cameraPos = null; if (!CurrentLevels.Any()) { return; } var split = CurrentLevels.Count() > 1; if (!split) { var level = CurrentLevels.First(); if (level.Players.Count() > 1) { var p1 = level.Players.First(); var p2 = level.Players.Last(); var p1Pos = p1.CenterPosition; var p2Pos = p2.CenterPosition; var dist = p1Pos - p2Pos; if (dist.X > clientBounds.Width - p1.CollisionRect.Width - p2.CollisionRect.Width || dist.Y > clientBounds.Height - p1.CollisionRect.Height - p2.CollisionRect.Height || p1.TransitioningToLevel != 0 || p2.TransitioningToLevel != 0) { split = true; } else { cameraPos = (p2Pos + p1Pos) / 2; } } } if (split) { var oldViewport = graphicsDevice.Viewport; Rectangle?pBounds = null; foreach (var pInfo in CurrentLevels.SelectMany(l => l.Players.Select(p => new { Player = p, Level = l })).OrderBy(p => p.Player.DisplayName)) { if (pBounds == null) { pBounds = new Rectangle(0, 0, clientBounds.Width / 2, clientBounds.Height); } else { pBounds = new Rectangle(clientBounds.Width / 2, 0, clientBounds.Width / 2, clientBounds.Height); } graphicsDevice.Viewport = new Viewport(pBounds.Value); var transformMatrix = Matrix.CreateScale(new Vector3(1, 1, 0)); spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null, transformMatrix); var lv = pInfo.Level; if (pInfo.Player.TransitioningToLevel != 0) { SlideScreen(gameTime, spriteBatch, pBounds.Value, lv, pInfo.Player); } else { Vector2 camera = GetCameraPosition(pInfo.Player.CenterPosition, lv.Map.PixelSize, pBounds.Value); lv.Draw(gameTime, spriteBatch, camera); } #region GUI Drawing int guiSize = 100; Rectangle GUIRect = new Rectangle(pBounds.Value.X, pBounds.Value.Y, pBounds.Value.Width, guiSize); _gui.Draw(spriteBatch, GUIRect, new[] { pInfo.Player }, clientBounds); #endregion GUI Drawing //Title Card if (_cards.ContainsKey(pInfo.Player)) { _cards[pInfo.Player].Draw(gameTime, spriteBatch, pBounds.Value); } spriteBatch.End(); } graphicsDevice.Viewport = oldViewport; } else { spriteBatch.Begin(); var lv = CurrentLevels.First(); var player = lv.Players.First(); if (player.TransitioningToLevel == 0) { Vector2 camera = GetCameraPosition(cameraPos ?? lv.Players.First().CenterPosition, lv.Map.PixelSize, clientBounds); lv.Draw(gameTime, spriteBatch, camera); } else { SlideScreen(gameTime, spriteBatch, clientBounds, lv, player); } #region GUI Drawing int guiSize = 100; Rectangle GUIRect = new Rectangle(clientBounds.X, clientBounds.Y, clientBounds.Width, guiSize); _gui.Draw(spriteBatch, GUIRect, Players, clientBounds); #endregion GUI Drawing //Title Card if (_cards.ContainsKey(player)) { _cards[player].Draw(gameTime, spriteBatch, clientBounds); } spriteBatch.End(); } }
public int[] BeginScope() { CurrentLevels.Push(NextLevel); NextLevel = 0; return(CurrentLevels.ToArray()); }