public timerGame(snake _game, int time) { game = _game; lastTime = time; game.stata.time = (time > 0 ? time : 0); }
public void newGame() { field.sizeOfCell = sizeOfCell; field.DrawField(); widthField = field.GetWidth(); heigthField = field.GetHeigth(); snake1 = new snake(widthField / 2, heigthField / 2, sizeOfCell); field.Controls.Add(snake1.Head); score = 0; CreateFood(); timer1.Enabled = true; isGameEnd = false; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); try { Snake = new snake(this.Content.Load <Texture2D>("res/snake_block.png")); } catch (Microsoft.Xna.Framework.Content.ContentLoadException e) { Debug.WriteLine(e.Message); //throw; } // TODO: use this.Content to load your game content here }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); try { Snake = new snake(this.Content.Load<Texture2D>("res/snake_block.png")); } catch (Microsoft.Xna.Framework.Content.ContentLoadException e) { Debug.WriteLine(e.Message); //throw; } // TODO: use this.Content to load your game content here }
public void checkPos(snake _game) { foreach (int[] point in game.table) { if (point[2] == 0 && point[0] == _game.snakeBody[_game.snakeBody.Count - 1][0] && point[1] == _game.snakeBody[_game.snakeBody.Count - 1][1]) { _game.gameOver = true; } else if (point[2] == 1 && _game.stata.score < point[3] && point[0] == _game.snakeBody[_game.snakeBody.Count - 1][0] && point[1] == _game.snakeBody[_game.snakeBody.Count - 1][1]) { _game.gameOver = true; } else if (point[2] == 3 && _game.stata.score >= game.scoreWin && point[0] == _game.snakeBody[_game.snakeBody.Count - 1][0] && point[1] == _game.snakeBody[_game.snakeBody.Count - 1][1]) { _game.winGame = true; } } }
private void newGame(int[] numCells, int cellSize, bool barrier, int direction) { snakeClass = null; Random rnd = new Random(); if (levelClass != null) { while (numCells[0] * cellSize > Screen.PrimaryScreen.Bounds.Width - 80 || numCells[1] * cellSize > Screen.PrimaryScreen.Bounds.Height - 240) { cellSize -= 1; } levelClass.game.cellSize = cellSize; foreach (int[] startPos in levelClass.game.table) { if (startPos[2] == 2) { snakeClass = new snake(numCells[0], numCells[1], cellSize, direction, Graphics.FromHwnd(tableSnakePanel.Handle), barrier, new int[] { startPos[0], startPos[1] }); } } } else { snakeClass = new snake(numCells[0], numCells[1], cellSize, 2, Graphics.FromHwnd(tableSnakePanel.Handle), barrier, new int[] { 0, 0 }); } this.Width = cellSize * numCells[0] + 42; this.Height = cellSize * numCells[1] + 170; this.Left = Screen.PrimaryScreen.Bounds.Width / 2 - this.Width / 2; this.Top = Screen.PrimaryScreen.Bounds.Height / 2 - this.Height / 2 - 25; snakeClass.drawLines(); updateData.Enabled = true; }