/// <summary> /// Select a valid tile and add it to snake /// </summary> /// <param name="tile"></param> public void TileSelection(Tile tile) { if (!isSelectionStarted) { return; } if (snake.GetCount().Equals(0)) { snake.Add(tile); grid.DimInvalidTiles(tile.GetTileColour()); } else { if (snake.IsTileValidToAdd(tile, grid)) { snake.Add(tile); } if (snake.IsTileValidToRemove(tile)) { snake.RemoveLast(); } } OnSnakeChanged?.Invoke(snake); }
public Game() { InitializeComponent(); //setts the parameters that can be coosen in settning for the game. speed = MenuOne.speed; accelerating = MenuOne.acc; wall = MenuOne.wall; //wall = true; //setts upp the music and setts the given size to the window simpleSound.PlayLooping(); pbCanvas.Height = 900; pbCanvas.Width = 900; // creats a head to the snake by clear any existing parts and givs it new coodinats Snake.Clear(); Coord head = new Coord(); head.X = 420; head.Y = 420; Snake.Add(head); //sett up a new timer for the game gameTimer.Interval = 1000 / speed; gameTimer.Start(); //creats a new start food GenerateFood(Snake); foodSpc.X = 1000; foodSpc.Y = 1000; stopGame = false; score = 0; }
/// <summary> /// přidává novou část a říká jestli smazat tu poslední /// </summary> /// <param name="zatoceniX"></param> /// <param name="zatoceniY"></param> /// <returns></returns> public bool NewHead(int zatoceniX, int zatoceniY) { var previousSnake = Snake.Last(); BodyPart newHead = new BodyPart(Snake.Last(), zatoceniX, zatoceniY); //zkontroluje, jestli žije Live = live(newHead); if (GameArray[newHead.X, newHead.Y] == Box.Food) {//kontroluje jestli snědl jídlo, případně vygeneruje další Snake.Add(newHead); GenerateFood(); return(false); } if (GameArray[newHead.X, newHead.Y] == Box.poisonedFood) {//kontroluje jestli snědl otrávené jídlo, případně vygeneruje další Snake.Add(newHead); GenerateFood(); DestroyLastBodyPart(); return(true); } else if (Snake.Count == 1) { Snake.Add(newHead); return(true); } else if (!(newHead.X == previousSnake.X && newHead.Y == previousSnake.Y)) { Snake.Add(newHead); return(true); } return(false); }
public PlayGroundViewModel() { Snake.Add(new SnakeBlockViewModel() { IsHead = true }); Snake.Add(new SnakeBlockViewModel() { IsHead = false }); }
public GameState(int width, int height, ConsoleRenderer renderer) { m_width = width; m_height = height; m_renderer = renderer; Apple = new Vector(3, 0); Snake.Add(new Vector(0, 0)); Direction = ConsoleKey.RightArrow; }
//Does actions when the timer has passed a certain tick-timer. //Switches snake direction, checks collision, and updates snake //and GUI according to what happens. private void Tick() { var newHead = PointFactory.Create(_snake.Last()); var tailToClear = PointFactory.Create(_snake.First()); var snakeDirection = _snake.GetDirection(); switch (snakeDirection) { case Directions.Up: newHead.Y -= 1; break; case Directions.Right: newHead.X += 1; break; case Directions.Down: newHead.Y += 1; break; case Directions.Left: newHead.X -= 1; break; } CheckCollision(newHead); //clears tail _snake.RemoveAt(0); _view.UpdatePoint(tailToClear); //prints tail foreach (Point part in _snake) { _view.UpdatePoint(part, "Tail"); } //prints new head _snake.Add(newHead); _view.UpdatePoint(_snake.Last(), "Head"); }
private void ProcessResponse(GameBoardDto gameBoardDto) { Snake.Clear(); foreach (Point point in gameBoardDto.Snake) { ViewPoint processPoint = new ViewPoint(ParseCoordinate(point.X), ParseCoordinate(point.Y), rectangleSize, margin); Snake.Add(processPoint); } Food.Clear(); foreach (Point point in gameBoardDto.Food) { ViewPoint processPoint = new ViewPoint(ParseCoordinate(point.X), ParseCoordinate(point.Y), rectangleSize, margin); Food.Add(processPoint); } GameException = String.Empty; }
//Updateds the GUI, and snake private void UpdatedGUI() { var tail = Factory.CreatePosition(location: snake.First()); if (!gameState.death) { //Test if not added new food if (!newFood) { //Remove the back of snek window.WriteRemove(tail); } else { //Prints new food window.WriteFood(food.GetLocation()); newFood = false; } //adds new head to the snake list snake.Add(newHead); //Prints new head window.WriteMove(head, newHead); } }
public void AddSnakePiece(SnakePiece piece) { snake.Add(piece); matrix[piece.Row, piece.Column] = piece; }