public async Task <IActionResult> Onpost() { if (ModelState.IsValid) { GameEngine.Game gameEngine = new GameEngine.Game(_context); gameEngine.Settings = new GameSettings(); gameEngine.InitializeNewBoard(Options.BoardWidth, Options.BoardHeight); var entity = new Domain.GameSave() { SaveName = Options.SaveName, BoardHeight = Options.BoardHeight, BoardWidth = Options.BoardWidth, NumberOfMines = Options.NumberOfMines, BoardState = gameEngine.GetSerializedGameState() }; _context.GameSave.Add(entity); await _context.SaveChangesAsync(); return(RedirectToPage("./PlayGame", new{ GameId = entity.GameSaveId })); } return(Page()); }
public IActionResult OnGetLoadGame(int id) { var savedGame = GetSavedGames().First(sg => sg.SavedGameId == id); var game = new GameEngine.Game(Difficulty.Easy, savedGame); HttpContext.Session.SetString("Game", JsonConvert.SerializeObject(game)); return(Redirect("./Game")); }
// Singleton utilized public static Game GetInstance() { lock (lockobj) { if (instance == null) { instance = new Game(); } } return instance; }
private void startButton_Click(object sender, RoutedEventArgs e) { this.gameEngine = new Game(); var matrix = new bool[5,5]; matrix[3, 3] = true; matrix[3, 2] = true; matrix[2, 1] = true; this.horst.GameMatrix = matrix; this.horst.InitCanvas(); }
public View() { // Delegate for updating the view (Game is running on different thread) _drawView = new DrawView(this.drawView); _pen = new Pen(_brush, 2); _renderer = new RenderSystem(this); InitializeComponent(); this.SetStyle( ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true); // Start game thread _game = new Game(this); ThreadStart start = new ThreadStart(_game.Start); _thread = new Thread(start); _thread.Start(); }
public void OnGet() { if (NewGame) { ClearGame(); } if (string.IsNullOrWhiteSpace(DifficultyString)) { return; } if (!Enum.TryParse <Difficulty>(DifficultyString, true, out var difficulty)) { return; } var game = new GameEngine.Game(difficulty); SerializeGame(game); return; }
/// <summary> /// Удалить игру из списка игр /// </summary> /// <param name="game"></param> /// <returns></returns> public bool RemoveGame(Game game) { Engine.Instance.Games.Remove(game); GameRemoved(this, new EntityRemovedEventArgs() { Id = game.Id }); return true; }
/// <summary> /// Создать игру /// </summary> /// <param name="gameName"></param> /// <param name="playerName"></param> /// <param name="turnDuration"></param> /// <param name="victoryLimit"></param> public Guid CreateGame(string gameName, string playerName, int turnDuration, int victoryLimit) { Player player = GetPlayer(playerName); player.Points = 0; Game game = new Game(gameName, turnDuration, victoryLimit, player); game.Players.Add(player); player.CurrentGame = game; player.HintUsed = false; Games.Add(game); GameAdded(this, new GameAddedEventArgs() { Id = game.Id, Name = game.Name, AuthorName = playerName, Date = game.CreatedOn.ToShortDateString(), State = "Waiting" }); return game.Id; }
public MainWindow() { InitializeComponent(); _game = new Game(); }
public PlayGameModel(GameSaveDbContext context) { _context = context; GameEngine = new GameEngine.Game(_context); }
public async Task <ActionResult> OnPost() { if (FieldSize == "Back to Main Menu") { return(RedirectToPage("./MainMenu")); } if (ModelState.IsValid) { if (FieldSize == "Small Field") { GameOptions.Height = 9; GameOptions.Width = 9; GameOptions.Bombs = 10; } if (FieldSize == "Medium Field") { GameOptions.Height = 16; GameOptions.Width = 16; GameOptions.Bombs = 40; } if (FieldSize == "Large Field") { GameOptions.Height = 16; GameOptions.Width = 30; GameOptions.Bombs = 99; } if (GameOptions.Bombs > GameOptions.Height * GameOptions.Width - 1) { BombAmount = false; } foreach (GameSettings settings in _context.GameSettingses) { if (settings.GameName == GameOptions.GameName) { isCorrect = false; } } if (!isCorrect || !BombAmount) { return(RedirectToPage("./StartGame", new { correct = isCorrect, bombAmount = BombAmount })); } var game = new GameEngine.Game(GameOptions.Height, GameOptions.Width); game.PlaceBomb(GameOptions.Height, GameOptions.Width, GameOptions.Bombs); string gameCells = ""; foreach (CellState variable in game.GetBoard()) { gameCells += Convert.ToInt32(variable) + ","; } gameCells = gameCells.Remove(gameCells.Length - 1); var gameState = new GameSettings() { BoardWidth = GameOptions.Width, BoardHeight = GameOptions.Height, GameName = GameOptions.GameName, BombAmount = GameOptions.Bombs, GameState = gameCells }; _context.GameSettingses.Add(gameState); await _context.SaveChangesAsync(); return(RedirectToPage("./PlayGame", new { gameId = gameState.GameId })); } return(Page()); }
public async Task <ActionResult> OnGet(int?gameId, int?col, int?row, bool?over, bool?win) { if (win != null) { WinGame = win.Value; } if (over != null) { GameOver = over.Value; } GameSettings = await _context.GameSettingses.ToListAsync(); if (gameId == null) { return(RedirectToPage("./StartGame")); } var match = false; foreach (GameSettings settings in _context.GameSettingses) { if (settings.GameId == gameId) { match = true; } } if (!match) { return(RedirectToPage("./MainMenu")); } GameId = gameId.Value; BoardHeight = GameSettings.First(a => a.GameId == gameId).BoardHeight; BoardWidth = GameSettings.First(a => a.GameId == gameId).BoardWidth; var game = new GameEngine.Game(GameSettings.First(a => a.GameId == gameId).BoardHeight, GameSettings.First(a => a.GameId == gameId).BoardWidth); var indexOfList = 0; var gameCells = GameSettings.First(a => a.GameId == gameId) .GameState.ToString(); var gameCallsList = gameCells.Split(","); for (var i = 0; i < GameSettings.First(a => a.GameId == gameId).BoardHeight; i++) { for (var j = 0; j < GameSettings.First(a => a.GameId == gameId).BoardWidth; j++) { game.Board[i, j] = (CellState)int.Parse(gameCallsList[indexOfList]); indexOfList++; } } Board = game.Board; if (col != null && row != null) { game.Move(row.Value, col.Value); if (game.GetValue(row.Value, col.Value) == CellState.B) { return(RedirectToPage("./PlayGame", new { over = true, gameId = GameId })); } var emptyCellCount = 0; foreach (CellState cellState in Board) { if (NotOpenValues.Contains(cellState)) { emptyCellCount++; } } string gameState = ""; foreach (CellState variable in Board) { gameState += Convert.ToInt32(variable) + ","; } gameState = gameState.Remove(gameState.Length - 1); _context.GameSettingses.First(a => a.GameId == gameId).GameState = gameState; await _context.SaveChangesAsync(); if (emptyCellCount == GameSettings.First(a => a.GameId == gameId).BombAmount) { return(RedirectToPage("./PlayGame", new { win = true, gameId = GameId })); } } return(Page()); }
private void Form1_Load(object sender, EventArgs e) { game = new Game(); game.Initialize(panel1, panel1.DisplayRectangle.Size); game.InitializeGraphics(); game.InitializeSound(); game.InitializeResources(); game.InternalUpdate(); this.Show(); gameTickTimer.Enabled = true; animationTimer.Enabled = true; control = new GameController(game, new GameMap(new Size(32, 32), new Size(24, 24))); hoverTile = new GameEntity(); hoverTile.AddSprite("hover", new GameSprite(new SpriteFrame(new SpriteImage("resources/images/hover_tile.png", Color.Transparent), 1))); hoverTile.SetSprite("hover"); hoverTile.ZIndex = 200; // * Hold den nær jorden ift. infantry som er på 100 hoverTile.IsSelectable = false; RifleInfantry testUnit1 = new RifleInfantry(); RifleInfantry testUnit2 = new RifleInfantry(); RifleInfantry testUnit3 = new RifleInfantry(); RifleInfantry testUnit4 = new RifleInfantry(); testUnit1.WorldPosition = new Point(2, 2); testUnit2.WorldPosition = new Point(4, 1); testUnit3.WorldPosition = new Point(4, 2); testUnit4.WorldPosition = new Point(4, 3); testUnit1.MoveSpeed = 20; testUnit2.MoveSpeed = 50; testUnit3.MoveSpeed = 50; testUnit4.MoveSpeed = 40; control.PlaceEntity(testUnit1); control.PlaceEntity(testUnit2); control.PlaceEntity(testUnit3); control.PlaceEntity(testUnit4); control.PlaceEntity(hoverTile); // * Lav lidt skov Random rand = new Random(); for(int i = 0; i < 15; i++) { GameEntity tree = new GameEntity(); tree.AddSprite("idle", new GameSprite(new SpriteFrame(new SpriteImage( GameController.resourceRoot + "/images/trees/" + rand.Next(1, 6) + ".png", Color.Transparent), 1)) ); tree.OccupationMatrix = new bool[2, 2] { { false, true }, { false, false } }; tree.IsSelectable = false; tree.SetSprite("idle"); tree.WorldPosition = new Point( rand.Next(0, control.map.GetSize().Width), rand.Next(0, control.map.GetSize().Height) ); control.PlaceEntity(tree); } shouldRun = true; /* RenderThread renderThread = new RenderThread(new RenderDelegate(this.RenderGame)); ThreadStart threadStart = new ThreadStart(renderThread.Start); new Thread(threadStart).Start(); // * Start renderingstråden */ }
public ActionResult OnPost() { if (ModelState.IsValid) { var savedGames = new List <string>(); foreach (var gameSave in _context.GameSave) { savedGames.Add(gameSave.SaveName); } if (savedGames.Contains(SaveFileName)) { return(RedirectToPage(new { dif = Difficulty, SaveFileName })); } GameEngine.Game gameEngine = new GameEngine.Game(_context); //you need to fix the functions, maybe remove them entirely. switch (Difficulty) { case "1": gameEngine.Settings = new GameSettings(); break; case "2": gameEngine.Settings = new GameSettings() { BoardHeight = 16, BoardWidth = 16, NumberOfMines = 40 }; break; case "3": gameEngine.Settings = new GameSettings() { BoardHeight = 24, BoardWidth = 24, NumberOfMines = 99 }; break; default: gameEngine.Settings = new GameSettings(); break; } gameEngine.InitializeNewBoard(gameEngine.Settings.BoardWidth, gameEngine.Settings.BoardHeight); var entity = new Domain.GameSave() { SaveName = gameEngine.Settings.SaveName, BoardHeight = gameEngine.Settings.BoardHeight, BoardWidth = gameEngine.Settings.BoardWidth, NumberOfMines = gameEngine.Settings.NumberOfMines, BoardState = gameEngine.GetSerializedGameState() }; _context.GameSave.Add(entity); _context.SaveChangesAsync(); return(RedirectToPage("./PlayGame", new { GameId = entity.GameSaveId })); } return(RedirectToPage("../Index")); }
private void SerializeGame(GameEngine.Game game) { HttpContext.Session.SetString("Game", JsonConvert.SerializeObject(game)); }