public void SnakeIsTypeAnimalAndReptile() { Snakes sox = new Snakes(false, true); Assert.IsAssignableFrom <Animal>(sox); Assert.IsAssignableFrom <Reptile>(sox); }
private void AssembleMap() { Map = new List <List <Piece> >(); for (int y = 0; y < Height; y++) { Map.Add(new List <Piece>()); for (int x = 0; x < Width; x++) { if (Walls.Any(p => p.X == x && p.Y == y)) { Map[y].Add(new Piece(x, y, PieceType.Wall, Color.Blue)); } else if (Snakes.Any(s => s.snakePieces.Any(p => p.X == x && p.Y == y && p.Type == PieceType.SnakePiece))) { Map[y].Add(new Piece(x, y, PieceType.SnakePiece, Snakes.Where(s => s.IsAtPos(x, y)).FirstOrDefault().snakePieces.Where(p => p.X == x && p.Y == y).FirstOrDefault().Color)); } else if (Snakes.Any(s => s.snakePieces.Any(p => p.X == x && p.Y == y && p.Type == PieceType.HeadPiece))) { Map[y].Add(new Piece(x, y, PieceType.HeadPiece, Snakes.Where(s => s.IsAtPos(x, y)).FirstOrDefault().snakePieces.Where(p => p.X == x && p.Y == y).FirstOrDefault().Color)); } else if (FoodPieces.Any(p => p.X == x && p.Y == y)) { Piece piece = FoodPieces.Where(p => p.X == x && p.Y == y).FirstOrDefault(); Map[y].Add(piece); } else { Map[y].Add(new Piece(x, y, PieceType.Empty)); } } } }
private static void CheckIfCurrentCellPositionIsSnakeHead(Player player) { if (Snakes.CheckIfCurrentCellPostionIsSnakeHead(player.GetCurrentCellPosition())) { player.SetCurrentCellPosition(Snakes.GetSnakeTailForSnakeHead(player.GetCurrentCellPosition())); } }
private void MoveSnakes() { foreach (var snake in Snakes.ToArray()) { if (snake.TurnsHasNotEaten == Params.SnakeTurnToDie) { Snakes.Remove(snake); } if (snake.IsStarving) { var isDead = snake.StarvingSnakeTurn(); if (isDead) { Snakes.Remove(snake); } } else { var headLocation = snake.HeadLocation; snake.MoveSnake(GetRandomGrassCell(headLocation)); } if (snake.ShouldSplit) { Snakes.Add(snake.SplitSnake()); } } }
/// <summary> /// Reaction on left. Deactivate the rating write and the snake. /// </summary> /// <param name="otherPlayer"></param> public override void OnPlayerLeftRoom(Player otherPlayer) { if (gameOver) { return; } var actorID = (int)otherPlayer.CustomProperties[PlayerOptionKeys.ActorID]; for (var i = 0; i < Snakes.Count; i++) { if (Snakes[i].GetActorIDOfCreator() == actorID) { Snakes[i].Clear(); Snakes[i].Disconnect = true; rating.PlayerLeft(actorID); //End game if need if (Snakes.Count(s => !s.Disconnect) < 2) { CompleteGame(timeIsEnd: false); } return; } } }
private bool SnakeBirth(SnakeItem snake) { // once 7 nodes is contained in our snake, it birth count += 1; bool found = false; int snakeValue = snake.SnakeValue; if (!Snakes.ContainsKey(snakeValue)) { // created a new node into the dictionary if its value does not exist List <SnakeItem> snakesSameValue = new List <SnakeItem>() { snake }; Snakes.Add(snakeValue, snakesSameValue); } else { // if the same value were found, a new snake is add to a list of the same value foreach (var item in Snakes[snakeValue]) { if (!snake.Equals(item)) { // comparing all snakes with same value, // found if each node from a snake differs from the other SnakesFound = new List <SnakeItem>(); SnakesFound.Add(snake); SnakesFound.Add(item); return(true); } } Snakes[snake.SnakeValue].Add(snake); } return(found); }
public void AddPlayerSnake() { Snake newPlayerSnake = GetRandomSnake(); Snakes.Add(newPlayerSnake); PlayerSnake = newPlayerSnake; }
public void AddPlayerSnake(int x, int y, Direction direction, Color headColor, Color bodyColor) { Snake newPlayerSnake = new Snake(x, y, direction, headColor, bodyColor); Snakes.Add(newPlayerSnake); PlayerSnake = newPlayerSnake; }
public void ChangeDirection(Snake snake) { Snakes.TryGetValue(snake.id, out Snake exists); if(exists == null) return; exists.direction = snake.direction; SendSnakes(); }
public void SnakesImplementsIEatPeopleAndIVenomous() { Snakes snake = new Snakes(true, true); string expected = "I'm just on a plane, minding my own business"; Assert.True(snake.EatPeople); Assert.True(snake.Venomous); Assert.Equal(expected, snake.EatingPeople()); }
private static void ParseSnakesFromInput() { int numberOfSnakes = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfSnakes; i++) { var snakeHeadAndTailPositionAsString = Console.ReadLine(); var snakeHeadAndTailPositionAsStringArray = snakeHeadAndTailPositionAsString.Split(' '); Snakes.PopulateSnakesHeadAndTailPositions(int.Parse(snakeHeadAndTailPositionAsStringArray[0]), int.Parse(snakeHeadAndTailPositionAsStringArray[1])); } }
public void DeleteSnake(SnakeProfile currentSnake) { Snakes.Remove(currentSnake); if (Snakes.Count > 0) { SelectedSnake = Snakes[0]; } else { SelectedSnake = null; } }
public void AddSnake() { var snake = new Snake(Params); var grassCells = GrassBoard.GrassCells[0]; snake.Locations.Enqueue(grassCells[0]); snake.Locations.Enqueue(grassCells[1]); snake.Locations.Enqueue(grassCells[2]); snake.HeadLocation = grassCells[2]; Snakes.Add(snake); }
public void SwitchPlayer() { if (hasPlayer == false) { AddPlayerSnake(); hasPlayer = true; } else { Snakes.Remove(PlayerSnake); hasPlayer = false; } }
public void RunTurn() { if (!Snakes.Any()) { HasEnded = true; } else { TurnsCount++; GrassBoard.UpdateGrass(); MoveSnakes(); } }
public void Restart() { GenerateWalls(); Snakes.Clear(); AddAISnake(); if (hasPlayer == true) { AddPlayerSnake(); } GenerateFoodPiece(); AssembleMap(); Running = true; Score = 0; }
public void DerivedClassesHaveSoundFromAnimalAndIsOverriden() { HouseCat sox = new HouseCat("Black&White", 10); Sunfish sox2 = new Sunfish(); Snakes sox3 = new Snakes(false, true); Tiger socks = new Tiger(); Bird skcos = new Bird(); Frog frog = new Frog(); Assert.Equal("Meow meow", sox.Sound()); Assert.Equal("glug glug", sox2.Sound()); Assert.Equal("Croaaaak", frog.Sound()); Assert.Equal("hissssss", sox3.Sound()); Assert.Equal("Rawwwwr", socks.Sound()); Assert.Equal("Tweet tweet", skcos.Sound()); }
/// <summary> /// Register the snake in the Snakes list /// </summary> /// <param name="snake"></param> /// <returns></returns> public static bool RegisterSnakeScript(Snake snake) { if (Snakes == null) { Snakes = new List <Snake>(4); } if (snake == null || Snakes.Contains(snake)) { return(false); } Snakes.Add(snake); Snakes = Snakes.OrderBy(s => s.GetActorIDOfCreator()).ToList(); return(true); }
void Start() { //Save Time timeLastStep = PhotonNetwork.Time; //Apply game speed byte gameSpeed = (byte)PhotonNetwork.CurrentRoom.CustomProperties[RoomOptionKeys.GameSpeed]; timeBetweenStep = 0.9d - gameSpeed / 10d; //0.9d just magic number (works normal for ping 100ms and less in max speed) //Clear data from old game Snakes?.Clear(); Fruit = null; //Set TimeLeft to start value timeLeft = (byte)PhotonNetwork.CurrentRoom.CustomProperties[RoomOptionKeys.GameTimeInSeconds]; timeLeftText.text = TimePrefix + math.round(timeLeft); }
private void SetSnakesOnGame(List <List <int> > snakeIndices) { foreach (var snakeIndex in snakeIndices) { if (Snakes.Any(x => x.Head == snakeIndex[0])) { //Skipping two snake heads at same point continue; } var snake = new Snake() { Head = snakeIndex[0], Tail = snakeIndex[1] }; Snakes.Add(snake); } }
static void Main(string[] args) { Console.Clear(); Console.CursorVisible = false; var snake = Snakes.First(); snake.Position = Vector2.One; snake.Draw(); UpdateScore(snake); Thread inputThread = new Thread(InputLoop); inputThread.Start(); CreateNewFood(); }
public void Add(Snake snake, Canvas canvas) { Canvas = canvas; if (Snakes == null) { Snakes = new ConcurrentDictionary<string, Snake>(); Timer = new Timer(onMove, null, 0, 1000/30); AddFood(); } if (Snakes.ContainsKey(snake.id)) { return; } Snakes.TryAdd(snake.id, snake); SendSnakes(); }
/// <summary> /// Send everyone the command for make a step (authoritarian) /// </summary> void MakeStepGlobal() { var directions = Snakes.Select(s => s.GetCurrentInputDirection()).ToArray(); RaiseEventOptions raiseEventOptions = new RaiseEventOptions { Receivers = ReceiverGroup.All }; SendOptions sendOptions = new SendOptions { Reliability = true }; PhotonNetwork.RaiseEvent(RemoteEventNames.RegularStep, directions, raiseEventOptions, sendOptions); //Try respawn for deactivate snakes foreach (var snake in Snakes.Where(s => !s.Disconnect)) { if (snake.GetCurrentLenght() == 0) { snake.CreateRespawnEvent(); } } }
// Objects public void RegisterObject(Entity o) { objects.Add(o); if (o.GetType().GetTypeInfo().IsSubclassOf(typeof(Foliage)) || o.GetType() == typeof(Foliage)) { foliage.Add((Foliage)o); } else if (o.GetType().GetTypeInfo().IsSubclassOf(typeof(Actor)) || o.GetType() == typeof(Actor)) { actors.Add((Actor)o); } if (o.GetType().GetTypeInfo().IsSubclassOf(typeof(ShopKeeper)) || o.GetType() == typeof(ShopKeeper)) { MatchShopKeeper = (ShopKeeper)o; } if (o.GetType().GetTypeInfo().IsSubclassOf(typeof(Snake)) || o.GetType() == typeof(Snake)) { Snakes.Add((Snake)o); } }
public void OnTick() { AssembleMap(); if (Running) { foreach (ComputerSnake snake in Snakes.Where(s => s.GetType() == typeof(ComputerSnake))) { snake.Map = Map; snake.Move(); } // HACK foreach (Snake snake in Snakes.Where(s => s.GetType() != typeof(ComputerSnake))) { snake.Move(); } } CheckCollisions(); }
public Map(int width, int height, int worldTick, SnakePlayer mySnake, IEnumerable <SnakePlayer> snakeInfos, IEnumerable <MapCoordinate> foodPositions, IEnumerable <MapCoordinate> obstaclePositions) { Tick = worldTick; MySnake = mySnake; FoodPositions = new HashSet <MapCoordinate>(foodPositions); ObstaclePositions = new HashSet <MapCoordinate>(obstaclePositions); Snakes = snakeInfos.ToList(); OpponentSnakes = Snakes.Where(s => s.Id != MySnake.Id).ToList(); TileGrid = new TileGridBuilder(width, height) .WithFood(FoodPositions) .WithObstacles(ObstaclePositions) .WithMySnake(MySnake) .WithOpponentSnakes(OpponentSnakes) .WithOpponentHeadNeighbors(OpponentSnakes) .Build(); OpponentsTailsPositions = OpponentSnakes.Where(s => s.IsAlive) .ToDictionary(s => s.TailPosition, s => s); Width = width; Height = height; }
static void InputLoop() { while (Run) { float speedModifier = 1; var key = Console.ReadKey(true); var snake = Snakes.First(); foreach (var food in Foods) { food.Draw(); } UpdateScore(snake); switch (key.Key) { case ConsoleKey.W: snake.Move(new Vector2(0, -1) * speedModifier); break; case ConsoleKey.A: snake.Move(new Vector2(-1, 0) * speedModifier); break; case ConsoleKey.D: snake.Move(new Vector2(1, 0) * speedModifier); break; case ConsoleKey.S: snake.Move(new Vector2(0, 1) * speedModifier); break; } } }
public override void ApplyTo(SimpleGameServer server) { Snakes = server.GetObjectsByName("Snake").Where(@object => @object.ObjectName == "SnakeHead").ToList(); Apples = server.GetObjectsByName("Apple").ToList(); Snakes.ForEach(snake => { SnakeProperties properties = (SnakeProperties)snake.ObjectProperties; Apples.ForEach(apple => { if (apple.Position == properties.Head.Position) { LoggingService.LogMessage($"Player picked up an Apple.{snake.Owner.ClientHashCode}"); server.RemoveObject(apple); properties.Length += 1; properties.Score += 1; if (server.TickInterval - 20 > 0) { server.SetTickInterval(server.TickInterval - 20); } } }); }); }
public void ChangeSnake(int step) { SelectedSnake = Snakes[Snakes.IndexOf(SelectedSnake) + step]; }
public void CreateSnake() { Snakes.Add(new SnakeProfile(DefaultResources.RandomSkin().SkinName)); SelectedSnake = Snakes[Snakes.Count - 1]; }