public ActionResult DeleteConfirmed(int id) { Souris souris = db.Souris.Find(id); db.Souris.Remove(souris); db.SaveChanges(); return(RedirectToAction("Index")); }
/// <summary> /// Allows each screen to run logic. /// </summary> public override void Update(GameTime gameTime) { // Read the keyboard and gamepad. _input.Update(); Souris.Get().Update(Mouse.GetState()); Clavier.Get().Update(Keyboard.GetState()); // Make a copy of the master screen list, to avoid confusion if // the process of updating one screen adds or removes others. _screensToUpdate.Clear(); foreach (GameScreen screen in _screens) { _screensToUpdate.Add(screen); } bool otherScreenHasFocus = !Game.IsActive; bool coveredByOtherScreen = false; // Loop as long as there are screens waiting to be updated. while (_screensToUpdate.Count > 0) { // Pop the topmost screen off the waiting list. GameScreen screen = _screensToUpdate[_screensToUpdate.Count - 1]; _screensToUpdate.RemoveAt(_screensToUpdate.Count - 1); // Update the screen. screen.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); if (screen.ScreenState == ScreenState.TransitionOn || screen.ScreenState == ScreenState.Active) { // If this is the first active screen we came across, // give it a chance to handle input. if (!otherScreenHasFocus) { screen.HandleInput(_input); otherScreenHasFocus = true; } // If this is an active non-popup, inform any subsequent // screens that they are covered by it. if (!screen.IsPopup) { coveredByOtherScreen = true; } } } // Print debug trace? if (_traceEnabled) { TraceScreens(); } }
public ActionResult Edit([Bind(Include = "Id,Categorie,Type,Prix,Nom,Description")] Souris souris) { if (ModelState.IsValid) { db.Entry(souris).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(souris)); }
public ActionResult Create([Bind(Include = "Id,Type,Prix,Nom,Description")] Souris souris) { if (ModelState.IsValid) { db.Souris.Add(souris); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(souris)); }
// GET: Souris/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Souris souris = db.Souris.Find(id); if (souris == null) { return(HttpNotFound()); } return(View(souris)); }
private void SetContextMenu(string context, params string[] menus) { _contextMenuContext = context; _contextMenus = menus; _showContextMenu = true; _contextMenuPos = new Point(Souris.Get().X + (int)_camera.X, Souris.Get().Y + (int)_camera.Y); _contextMaxWidth = 0; foreach (var m in menus) { var len = (int)_fontPopup.MeasureString(m).X; if (len > _contextMaxWidth) { _contextMaxWidth = len; } } }
/// <summary> /// Draws the gameplay screen. /// </summary> public override void Draw(GameTime gameTime) { var graphics = ScreenManager.GraphicsDevice; var spriteBatch = ScreenManager.SpriteBatch; graphics.Clear(ClearOptions.Target, Color.CornflowerBlue, 0, 0); spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend); spriteBatch.Draw(_backgroundTexture, new Rectangle(0, 0, graphics.Viewport.Width, graphics.Viewport.Height), Color.White); // Draw terrain and bridges for (var y = 0; y < _mapHeight; ++y) { for (var x = 0; x < _mapWidth; ++x) { var terrain = _mapTerrains[y, x]; var tex = terrain.Type == "Mist" || terrain.Type == "BridgeSea" ? _terrains[6].Texture : (terrain.Type == "BridgeRiver" ? _terrains[9].Texture : (terrain.Type == "Road" ? _terrains[0].Texture : terrain.Texture)); var number = 0; if (terrain.Type == "Sea" || terrain.Type == "BridgeSea") { number = (y > 0 && !_mapTerrains[y - 1, x].IsSea() ? 8 : 0) + (x < _mapWidth - 1 && !_mapTerrains[y, x + 1].IsSea() ? 4 : 0) + (y < _mapHeight - 1 && !_mapTerrains[y + 1, x].IsSea() ? 2 : 0) + (x > 0 && !_mapTerrains[y, x - 1].IsSea() ? 1 : 0); } else if (terrain.Type == "River" || terrain.Type == "BridgeRiver") { number = (y > 0 && !_mapTerrains[y - 1, x].IsRiver() ? 8 : 0) + (x < _mapWidth - 1 && !_mapTerrains[y, x + 1].IsRiver() ? 4 : 0) + (y < _mapHeight - 1 && !_mapTerrains[y + 1, x].IsRiver() ? 2 : 0) + (x > 0 && !_mapTerrains[y, x - 1].IsRiver() ? 1 : 0); } tex.Draw( spriteBatch, y / 100f + 0.1f, new Vector2( _gridWidth * x - _camera.X, _gridHeight * y - _camera.Y + _gridHeight - _mapTerrains[y, x].Texture.Height), number); if ((terrain.Type == "Mist" || terrain.Type == "BridgeSea" || terrain.Type == "BridgeRiver" || terrain.Type == "Road") && _mapBuildings[y, x] == null) { _mapTerrains[y, x].Texture.Draw( spriteBatch, y / 100f + 0.101f, new Vector2( _gridWidth * x - _camera.X, _gridHeight * y - _camera.Y + _gridHeight - _mapTerrains[y, x].Texture.Height), terrain.Type == "Road" || terrain.Type == "BridgeSea" || terrain.Type == "BridgeRiver" ? (y > 0 && !_mapTerrains[y - 1, x].IsRoad() ? 8 : 0) + (x < _mapWidth - 1 && !_mapTerrains[y, x + 1].IsRoad() ? 4 : 0) + (y < _mapHeight - 1 && !_mapTerrains[y + 1, x].IsRoad() ? 2 : 0) + (x > 0 && !_mapTerrains[y, x - 1].IsRoad() ? 1 : 0) : 0); } } } // Draw buildings for (var y = 0; y < _mapHeight; ++y) { for (var x = 0; x < _mapWidth; ++x) { if (_mapBuildings[y, x] != null) { var texture = _texturesBuildings[_mapBuildings[y, x].Type]; var pos = new Vector2( _gridWidth * x - _camera.X + (int)Math.Floor((double)(_gridWidth + texture.Width) / 2) - _gridWidth, _gridHeight * y - texture.Height + _gridHeight - _camera.Y); texture.Draw( spriteBatch, y / 100f + 0.103f, pos, _mapBuildings[y, x].Player == null ? 0 : _mapBuildings[y, x].Player.Version); if (_mapBuildings[y, x].CaptureStatus < 20) { _capturing.Draw(spriteBatch, 0.91f, pos + new Vector2(0, texture.Height - 8)); } } } } // Draw units foreach (var u in _units) { _texturesUnitsPreview[u.Type].Draw( spriteBatch, u.Position.Y / 100f + 0.106f, _gridWidth * u.Position - _camera, u.Player.Version - 1, Color.White, u.Player.Number == 1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None); } // User Interface (15px per number) // Context menu (popup) if (_showContextMenu) { for (var i = 0; i < _contextMenus.Length; ++i) { var on = new Rectangle(_contextMenuPos.X + 2 - (int)_camera.X, _contextMenuPos.Y + 2 + 16 * i - (int)_camera.Y, _contextMaxWidth + 2 + _popupLeft.Width + _popupRight.Width, 16).Contains(Souris.Get().Position); var dec = on ? 0.001f : 0; (on ? _popupLeftOn : _popupLeft).Draw(spriteBatch, 0.94f + dec, new Vector2(_contextMenuPos.X, _contextMenuPos.Y + 16 * i) - _camera); for (var j = 0; j < _contextMaxWidth + 2; ++j) { (on ? _popupMidOn : _popupMid).Draw(spriteBatch, 0.94f + dec, new Vector2(_contextMenuPos.X + j + _popupLeft.Width, _contextMenuPos.Y + 16 * i) - _camera); } (on ? _popupRightOn : _popupRight).Draw(spriteBatch, 0.94f + dec, new Vector2(_contextMenuPos.X + _contextMaxWidth + 2 + _popupLeft.Width, _contextMenuPos.Y + 16 * i) - _camera); spriteBatch.DrawString(_fontPopup, _contextMenus[i], new Vector2(_contextMenuPos.X + 9, _contextMenuPos.Y + 16 * i + 3) - _camera, Color.Black, 0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.95f); spriteBatch.DrawString(_fontPopup, _contextMenus[i], new Vector2(_contextMenuPos.X + 8, _contextMenuPos.Y + 16 * i + 2) - _camera, Color.White, 0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.96f); } } // Cursor if (_cursorPos != _nullCursor) { _cursor.Draw(spriteBatch, 0.899f, _cursorPos * _gridWidth - _camera); } spriteBatch.End(); // If the game is transitioning on or off, fade it out to black. if (TransitionPosition > 0 || _pauseAlpha > 0) { ScreenManager.FadeBackBufferToBlack(MathHelper.Lerp(1f - TransitionAlpha, 1f, _pauseAlpha / 2)); } }
/// <summary> /// Updates the state of the game. This method checks the GameScreen.IsActive /// property, so the game will stop updating when the pause menu is active, /// or if you tab away to a different application. /// </summary> public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { base.Update(gameTime, otherScreenHasFocus, false); // Gradually fade in or out depending on whether we are covered by the pause screen. _pauseAlpha = coveredByOtherScreen ? Math.Min(_pauseAlpha + 1f / 32, 1) : Math.Max(_pauseAlpha - 1f / 32, 0); if (!IsActive) { return; } // Update textures for animations for (var i = 0; i < _terrains.GetLength(0); ++i) { _terrains[i].Texture.Update(gameTime); } for (var i = 0; i < _texturesBuildings.Count; ++i) { _texturesBuildings.Values.ElementAt(i).Update(gameTime); } for (var i = 0; i < _texturesUnitsBig.Count; ++i) { _texturesUnitsBig.Values.ElementAt(i).Update(gameTime); } for (var i = 0; i < _texturesUnitsPreview.Count; ++i) { _texturesUnitsPreview.Values.ElementAt(i).Update(gameTime); } for (var i = 0; i < _texturesUnitsSmall.Count; ++i) { _texturesUnitsSmall.Values.ElementAt(i).Update(gameTime); } _cursor.Update(gameTime); // Context menu var oldShow = _showContextMenu; var noSelect = false; if (_showContextMenu && Souris.Get().Clicked(MouseButton.Left)) { var rect = new Rectangle(_contextMenuPos.X + 2 - (int)_camera.X, _contextMenuPos.Y + 2 - (int)_camera.Y, _contextMaxWidth + 2 + _popupLeft.Width + _popupRight.Width, 16 * _contextMenus.Length); if (rect.Contains(Souris.Get().Position)) { var index = (int)Math.Floor((double)(Souris.Get().Y - rect.Y) / 16f); var selected = _contextMenus[index]; } _showContextMenu = false; noSelect = true; } // Update cursor position if (!_showContextMenu) { var curPos = new Vector2((int)((Souris.Get().X + _camera.X) / _gridWidth), (int)((Souris.Get().Y + _camera.Y) / _gridHeight)); _cursorPos = Souris.Get().X + _camera.X >= 0 && Souris.Get().Y + _camera.Y >= 0 && curPos.X < _mapWidth && curPos.Y < _mapHeight ? curPos : _nullCursor; } // Mouse click if (Souris.Get().Clicked(MouseButton.Left) && _cursorPos != _nullCursor && !noSelect) { var unitUnder = _units.FirstOrDefault(t => Math.Abs(t.Position.X - _cursorPos.X) < 0.1 && Math.Abs(t.Position.Y - _cursorPos.Y) < 0.1); var buildingUnder = _mapBuildings[(int)_cursorPos.Y, (int)_cursorPos.X]; } }