/// <summary> /// Create a new map instance with the given size. /// </summary> /// <param name="width">The width of the map in cells.</param> /// <param name="height">The height of the map in cells.</param> public Map(int width, int height) { // Initialize the array, generating a random map cells = new CellContent[width, height]; for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { if ((x > 1 || y > 1) && // We don't want a wall were we start World.Instance.RandomNumber(100) < WallProbability) { cells[y, x] = CellContent.Wall; } else { cells[y, x] = CellContent.Blank; } } } // Set a random goal position in the lower right quartile goalPosition = new Point(World.Instance.RandomNumber(Width * 3 / 4, Width), World.Instance.RandomNumber(Height * 3 / 4, Height)); cells[goalPosition.Y, goalPosition.X] = CellContent.Goal; goalPosition.X *= World.Instance.GridSize; goalPosition.Y *= World.Instance.GridSize; }
public Map(string filePath) { if (File.Exists(filePath)) { cells = ReadFile(filePath); } }
private void Awake() { m_map = new CellContent[8, 14]; for (int i = 0; i < 8; i++) { for (int j = 0; j < 14; j++) { m_map[i, j] = CellContent.FREE; } } }
/// <summary> /// 0... /// </summary> /// <param name="columnNumber"></param> /// <returns></returns> public int GetHeightOfColumn(CellContent[,] Cells, int columnNumber) { for (int i = 0; i < NumberOfRows; i++) { if (Cells[columnNumber, i] == CellContent.Empty) { return(i); } } //Column is full! return(NumberOfRows); }
/// <summary> /// Are there any spaces left to play? /// </summary> /// <returns></returns> public bool IsBoardFull(CellContent[,] Cells) { for (int colNumber = 0; colNumber < this.NumberOfColumns; colNumber++) { //Column has at least one free row if (this.GetHeightOfColumn(Cells, colNumber) < this.NumberOfRows) { return(false); } } //No empty columns return(true); }
public Game(string hash) { this.Cells = new CellContent[NUMBER_OF_COLUMNS, NUMBER_OF_ROWS]; var offset = 0; for (var c = 0; c < NUMBER_OF_COLUMNS; c++) { for (var r = 0; r < NUMBER_OF_ROWS; r++) { this.Cells[c, r] = (CellContent)int.Parse(hash.Substring(offset, 1)); offset++; } } }
//private void WriteFile(CellContent[,] cells) //{ // try // { // using (StreamWriter text = new StreamWriter("map.txt")) // { // for (int y = 0; y < Height; y++) // { // for (int x = 0; x < Width; x++) // { // text.Write(x + " " + y + " " + CellContentAtCell(new Point(x, y)) + " "); // } // text.Write("\r\n"); // } // } // } // catch (IOException IOE) // { // MessageBox.Show(IOE.Message, "Error IOException", MessageBoxButtons.OK, MessageBoxIcon.Error); // } //} //private CellContent[,] ReadFile(string filePath) //{ // if (File.Exists(filePath)) // { // string[] lines = File.ReadAllLines(filePath); // string[] splits = lines[0].Split(' '); // int countCellsForX = (splits.Length - 1) / 3; // int countCellsForY = lines.Length; // CellContent[,] cells = new CellContent[countCellsForX, countCellsForY]; // for (int y = 0; y < countCellsForY; y++) // { // splits = lines[y].Split(' '); // for (int x = 0; x < countCellsForX; x++) // { // Console.WriteLine(splits[(x * 3) + 2]); // switch (splits[(x * 3) + 2]) // { // case "Goal": // cells[x, y] = CellContent.Goal; // break; // case "Wall": // cells[x, y] = CellContent.Wall; // break; // case "Blank": // cells[x, y] = CellContent.Blank; // break; // } // } // } // return cells; // } // return null; //} #endregion /// <summary> /// Write the world map in a text file /// </summary> /// <param name="cells">List of cells' location</param> private void WriteFile(CellContent[,] cells) { using (StreamWriter text = new StreamWriter("map.txt")) { for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { text.Write("[" + x + "," + y + "]\t"); } text.WriteLine(""); for (int x = 0; x < Width; x++) { text.Write(CellContentAtCell(new Point(x, y)) + "\t"); } text.WriteLine("\r\n"); } } }
public bool IsMoveAllowed(CellContent[,] Cells, int columnNumber) { //Outside of the number of columns if (columnNumber < 0 || columnNumber + 1 > NumberOfColumns) { return(false); } //Is the column already full var columnHeight = GetHeightOfColumn(Cells, columnNumber); if (columnHeight == this.NumberOfRows) { return(false); } // All good return(true); }
/// <summary> /// Create a new map instance with the given size. /// </summary> /// <param name="width">The width of the map in cells.</param> /// <param name="height">The height of the map in cells.</param> /// <param name="fromFile">The bool from createNewMap</param> public Map(int width, int height, bool fromFile) { string filePath = "map.txt"; if (!fromFile && File.Exists(filePath)) { cells = ReadFile(filePath); } else { cells = new CellContent[width, height]; for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { if ((x > 1 || y > 1) && // We don't want a wall were we start World.Instance.RandomNumber(100) < WallProbability) { cells[x, y] = CellContent.Wall; } else { cells[x, y] = CellContent.Blank; } } } // Set a random goal position in the lower right quartile goalPosition = new Point(World.Instance.RandomNumber(Width * 3 / 4, Width), World.Instance.RandomNumber(Height * 3 / 4, Height)); cells[goalPosition.X, goalPosition.Y] = CellContent.Goal; goalPosition.X *= World.Instance.GridSize; goalPosition.Y *= World.Instance.GridSize; // Write this map in a text file WriteFile(cells); } }
/****************************************/ private void DisplayBoardHandler(Object sender, TurnChangedEventArgs e) { CellContent[,] board = _manager.GetBoard(); Console.WriteLine("\n - {0}'s Home - ",playerOneColor); Console.WriteLine("--13--14--15--16--17--18--***--19--20--21--22--23--24--"); //upper side for (int i = 0; i < 6; i++) { Console.Write("|"); for (int j = 0; j < 6; j++) { PrintBoardCell(board[i, j]); } Console.ResetColor(); //eaten stones zone if (_manager.GetEatenCheckers()?.Length > 0 && _manager.GetEatenCheckers()?.Length > i) { PrintEatenzone(_manager.GetEatenCheckers()[i]); } else { Console.Write("|///||"); //middle } for (int j = 6; j < 12; j++) { PrintBoardCell(board[i, j]); } Console.ResetColor(); Console.WriteLine(); } Console.WriteLine("======================================================="); //down side for (int i = 6; i < 12; i++) { Console.Write("|"); for (int j = 0; j < 6; j++) { PrintBoardCell(board[i, j]); } //eaten stones zone if (_manager.GetEatenCheckers()?.Length > 0 && _manager.GetEatenCheckers()?.Length > i) { PrintEatenzone(_manager.GetEatenCheckers()[i]); } else { Console.Write("|///||"); //middle } for (int j = 6; j < 12; j++) { PrintBoardCell(board[i, j]); } Console.ResetColor(); Console.WriteLine(); } Console.WriteLine("--12--11--10--9---8---7---***---6---5---4---3---2---1--"); Console.WriteLine(" - {0}'s Home - \n", playerTwoColor); Console.ResetColor(); }
public LayerData(CellContent[,] cells, LinkContent[,] rightLinks, LinkContent[,] bottomLinks) { Cells = cells; RightLinks = rightLinks; BottomLinks = bottomLinks; }
public void MakeMove(CellContent[,] Cells, int columnNumber, bool isYellow) { var columnHeight = GetHeightOfColumn(Cells, columnNumber); Cells[columnNumber, columnHeight] = isYellow ? CellContent.Yellow : CellContent.Red; }
public void MapSetter(CellContent[,] res) { m_map = res; }
/// <summary> /// Make the move before calling this method /// </summary> /// <param name="columnNumber"></param> /// <param name="isYellow"></param> /// <returns></returns> public bool WasWinningMove(CellContent[,] Cells, int columnNumber, bool isYellow) { //What colour is the player var playersColour = isYellow ? CellContent.Yellow : CellContent.Red; //Which row (0..) did the player put this counter in var rowNumber = this.GetHeightOfColumn(Cells, columnNumber) - 1; Debug.Assert(rowNumber >= 0); //Horizontal W-E var connectLength = 0; for (int c = 0; c < this.NumberOfColumns; c++) { if (Cells[c, rowNumber] == playersColour) { connectLength++; } else { connectLength = 0; } if (connectLength >= CONNECT_LENGTH) { return(true); } } //Vertical S-N connectLength = 0; for (int r = 0; r < this.NumberOfRows; r++) { if (Cells[columnNumber, r] == playersColour) { connectLength++; } else { connectLength = 0; } if (connectLength >= CONNECT_LENGTH) { return(true); } } //Diagonal SW-NE // Played col 0, so row =1, col=0, start is row=0, col=col-row+1 var startRow = rowNumber; var startColumn = columnNumber; while (startRow > 0 && startColumn > 0) { startRow--; startColumn--; } connectLength = 0; while (startRow < this.NumberOfRows && startColumn < this.NumberOfColumns) { if (Cells[startColumn, startRow] == playersColour) { connectLength++; } else { connectLength = 0; } if (connectLength >= CONNECT_LENGTH) { return(true); } startColumn++; startRow++; } //Diagonal SE-NW startRow = rowNumber; startColumn = columnNumber; while (startRow > 0 && startColumn < this.NumberOfColumns - 1) { startRow--; startColumn++; } connectLength = 0; while (startRow < this.NumberOfRows && startColumn >= 0) { if (Cells[startColumn, startRow] == playersColour) { connectLength++; } else { connectLength = 0; } if (connectLength >= CONNECT_LENGTH) { return(true); } startColumn--; startRow++; } return(false); }
protected override void OnExecuteEvent(VEntity entity) { CellContent[, ] _currLevel = levelToLoad.levelData; for (int i = 0; i < _currLevel.GetLength(0); i++) { for (int j = 0; j < _currLevel.GetLength(1); j++) { Coord c = new Coord(j, i); if (_currLevel[i, j].unitData != null) { EntityScriptableObject unitDataObject = _currLevel[i, j].unitData; ecsManager.CreateEvent("UnitCreate", component: new UnitCreateEvent { position = c, entityBlueprint = unitDataObject.entity }); } } } for (int i = 0; i < _currLevel.GetLength(0); i++) { for (int j = 0; j < _currLevel.GetLength(1); j++) { Coord c = new Coord(j, i); // create events for making cells ecsManager.CreateEvent("CellCreate", component: new CreateTerrainCellEvent { coord = c, movementCost = _currLevel[i, j].cellStruct.MovementCost, cellType = _currLevel[i, j].cellStruct.cellType }); } } //Initialize Deck /* foreach(string cardEntityId in deckListObject.decklist) { * //ecsManager.CreateEvent * }*/ CardZoneDataComponent cardZones = ecsManager.GetVSingletonComponent <CardZoneDataComponent>(); List <VEntity> cards = new List <VEntity>(); foreach (string cardName in deckList.cardNames) { // look up card in card database EntityScriptableObject cardEntity = cardDatabase.Cards.Find((scriptableObject) => scriptableObject.entity.GetVComponent <CardNameComponent>().name == cardName); Assert.IsNotNull(cardEntity); VEntity newCardEntity = ecsManager.InsantiateEntityFromBlueprint(cardEntity.entity); newCardEntity.GetVComponent <CardDisplayComponent>().cardDisplay = CardViewController.Instance.InitCard(newCardEntity); cards.Add(newCardEntity); ecsManager.ExecuteImmediateEvent("AddCardToZone", component: new CardZoneMoveEvent { source = Zone.NULL, destination = Zone.DECK, card = newCardEntity.id, }); } CardGameObject cantrip = GameObject.FindGameObjectWithTag("cantrip").GetComponent <CardGameObject>(); EntityScriptableObject cantripEntity = cardDatabase.Cards.Find((scriptableObject) => scriptableObject.entity.GetVComponent <CardNameComponent>().name == "Cantrip"); Assert.IsNotNull(cantripEntity); VEntity newCantripEntity = ecsManager.InsantiateEntityFromBlueprint(cantripEntity.entity); newCantripEntity.GetVComponent <CardDisplayComponent>().cardDisplay = CardViewController.Instance.InitCard(newCantripEntity); cards.Add(newCantripEntity); cantrip.cardEntityId = newCantripEntity.id; Debug.Log("Name: " + newCantripEntity.GetVComponent <CardNameComponent>().name); cantrip.cantrip = true; DeckHelper.Shuffle(cardZones.zones[Zone.DECK]); //HACK }