public void ActionCommand(int commandRotate, IGenericGameArea gameArea) { //TODO: return cell, not only type Coordinate targetPosition = AnalyzePosition(commandRotate); IBaseCell cellOnWay = gameArea.GetCellOnPosition(targetPosition); if (cellOnWay == null) { return; } PointType cellType = cellOnWay.GetPointType(); if (cellType == PointType.Food) { gameArea.TryEat(this, targetPosition); return; } if (cellType == PointType.Cell) { //Attack? } if (cellType == PointType.Trap) { Health = 0; } }
public void DrawPoints(IBaseCell[,] cells) { var pixels = new byte[Size, Size, 4]; PrintBackgroundWithBlack(pixels); for (var y = 0; y < Configuration.FieldSize; y++) { for (var x = 0; x < Configuration.FieldSize; x++) { IBaseCell cell = cells[y, x]; if (cell == null) { continue; } for (var addX = 0; addX < Configuration.ScaleSize; addX++) { for (var addY = 0; addY < Configuration.ScaleSize; addY++) { PutPixel(pixels, cell.Position.X * Configuration.ScaleSize + addX, cell.Position.Y * Configuration.ScaleSize + addY, cell); } } } } PrintPixels(pixels); }
private static void PutPixel(byte[,,] pixels, int positionX, int positionY, IBaseCell cell) { Color color = CellColorGenerator.GetCellColor(cell); pixels[positionY, positionX, 0] = color.B; pixels[positionY, positionX, 1] = color.G; pixels[positionY, positionX, 2] = color.R; }
public void CheckingIfYouCanMoveFromAnyGroundOfTheMazeToAnyOtherGroundOfTheMaze(/*int width, int height, IGeneration algo*/ TestingMazeConstructor ts) { var _maze = new Maze(ts.height, ts.width, ts.generation); IList <IBaseCell> neighbs = new List <IBaseCell>(); IBaseCell ground = _maze[0, 0]; //while (!(ground is Ground)) //{ // Random random = new Random(); // int randY = random.Next(0, ts.height); // int randX = random.Next(0, ts.height); // ground = _maze[randX, randY]; //} neighbs.Add(ground); //ничего не потеряем, т.к. ground 100 пудов объект класса Ground //будем добавлять соседей клеток в общий список //делаем это пока не закончатся все клетки int k = 0; while (k < neighbs.Count) { ground = neighbs[k]; IEnumerable <IBaseCell> neibghsOfGr = new List <IBaseCell> { _maze[ground.X - 1, ground.Y], _maze[ground.X + 1, ground.Y], _maze[ground.X, ground.Y - 1], _maze[ground.X, ground.Y + 1] }; foreach (var ne in neibghsOfGr) { if (ne is Ground) { if (!ItemIsInList(neighbs, ne)) { neighbs.Add(ne); } } } k++; } //теперь у нас в neighbs содержатся все доступные //для проходов из одной точки в другую клетки //смотрим являются ли все Ground-ы в лабиринте доступными для хода for (int i = 0; i < ts.width; i++) { for (int j = 0; j < ts.height; j++) { if (_maze[i, j] is Ground) { Assert.IsTrue(ItemIsInList(neighbs, _maze[i, j])); } } } }
private bool ItemIsInList(IList <IBaseCell> items, IBaseCell item) { foreach (var it in items) { if (it == item) { return(true); } } return(false); }
public void MoveCommand(int commandRotate, IGenericGameArea gameArea) { ActionCommand(commandRotate, gameArea); Coordinate targetPosition = AnalyzePosition(commandRotate); IBaseCell targetCell = gameArea.GetCellOnPosition(targetPosition); if (targetCell == null) { Position = targetPosition; } }
public void TryEat(IGenericCell sender, Coordinate foodPosition) { IBaseCell cellOnWay = GetCellOnPosition(foodPosition); PointType cellType = cellOnWay.GetPointType(); if (cellType != PointType.Food) { throw new ArgumentException(); } sender.Health += ((FoodCell)cellOnWay).HealthIncome(); RemoveCell(cellOnWay); }
public static PointType GetPointType(this IBaseCell cell) { switch (cell) { case FoodCell _: return(PointType.Food); case WallCell _: return(PointType.Wall); case IGenericCell lc: return(lc.IsAlive() ? PointType.Cell : PointType.DeadCell); default: throw new ArgumentException(); } }
public static Color GetCellColor(IBaseCell cell) { switch (cell) { case FoodCell _: return(Colors.GreenYellow); case TrapCell _: return(Colors.IndianRed); case IGenericCell _: return(Colors.AliceBlue); case WallCell _: return(Colors.Gold); default: throw new ArgumentException($"{cell.GetType()}"); } }
public void RemoveCell(IBaseCell cell) { Cells[cell.Position.Y, cell.Position.X] = null; }
public void AddCell(IBaseCell cell) { Cells[cell.Position.Y, cell.Position.X] = cell; }
public void RemoveCell(IBaseCell cell) { RemoveCell(cell.Position); }
public void CleanField(int[,] cells) { Cells = new IBaseCell[Configuration.FieldSize, Configuration.FieldSize]; GenerateGameField(cells); }
public void CleanField() { Cells = new IBaseCell[AreaSize, AreaSize]; GenerateRandomWall(); }