public long DenfenseScore(int currentRow, int currentColumn, Cells[,] arrayCells) { long score = DenfenseVertical(currentRow, currentColumn, arrayCells) + DenfenseHorizal(currentRow, currentColumn, arrayCells) + DenfenseMainDiagonal(currentRow, currentColumn, arrayCells) + DenfenseSecondDiagonal(currentRow, currentColumn, arrayCells); return(score); }
/// <summary> /// The Constructor Making the Grid and the Cells that are inside of it /// </summary> /// <param name="form"></param> public Grid(Form form) { _form = form; //Set the Hold Block to NULL BlockThatIsHeld = TypeOfBlock.Null; //Allow the user to Hold a Block at the start of the game _allowBlockToBeHeld = true; //Setting up Number of Cells _cells = new Cells[Properties.Settings.Default.Number_Of_Columns, Properties.Settings.Default.Number_Of_Rows]; //Setting up a grid to hold all the Cells Left = Properties.Settings.Default.Left_Grid_Margin; Top = Properties.Settings.Default.Top_Grid_Margin; Width = Properties.Settings.Default.Number_Of_Columns * Properties.Settings.Default.Cell_Width; Height = Properties.Settings.Default.Number_Of_Rows * Properties.Settings.Default.Cell_Height; form.Controls.Add(this); //Setting Up the Cells and assigning them an location int ColumnAdjuster = Left; int RowAdjuster = Top; for (int i = 0; i < Properties.Settings.Default.Number_Of_Columns; i++) { for (int j = 0; j < Properties.Settings.Default.Number_Of_Rows; j++) { _cells[i, j] = new Cells(i, j) { Width = Properties.Settings.Default.Cell_Width, Height = Properties.Settings.Default.Cell_Height, Left = ColumnAdjuster + (i * Properties.Settings.Default.Cell_Width), Top = RowAdjuster + (j * Properties.Settings.Default.Cell_Height) }; form.Controls.Add(_cells[i, j]); } } }
//kiểm tra kết thúc theo chiều ngang private bool isEndGameInHorizal(int currentRow, int currenCol, int owner, Cells[,] arrayCells) { int countLeft = 0; int countRight = 0; int temp = currenCol; for (int i = currenCol; i >= 0; i--) { if (arrayCells[currentRow, currenCol--].Owned == owner) { countLeft++; } else { break; } } currenCol = temp; for (int j = currenCol; j < board.NoOfColumn; j++) { if (arrayCells[currentRow, currenCol++].Owned == owner) { countRight++; } else { break; } } return(countLeft + countRight >= 6); }
// duyệt đường chéo xuôi private bool isMainDiagonal(int currentRow, int currentCol, int owner, Cells[,] arrayCells) { int countUp = 0; int countDown = 0; for (int i = 1; i < 6 && currentRow - i >= 0 && currentCol - i >= 0; i++) { if (owner == arrayCells[currentRow - i, currentCol - i].Owned) { countUp++; } else { break; } } for (int i = 0; i < 6 && currentRow + i < board.NoOfRows && currentCol + i < board.NoOfColumn; i++) { if (owner == arrayCells[currentRow + i, currentCol + i].Owned) { countDown++; } else { break; } } return((countUp + countDown) >= 5); }
public void RestartGame() //перезапуск игры { this.cellsContainer = new Cells[this.cellsCount, this.cellsCount]; this.copyCellsContainer = new Cells[this.cellsCount, this.cellsCount]; for (int i = 0; i < this.cellsCount; i++) { for (int j = 0; j < this.cellsCount; j++) { this.cellsContainer[i, j] = new Cells(0); this.copyCellsContainer[i, j] = new Cells(0); } } //обнуляем массив поля int x = -1; int y = -1; //будут хранить координаты зарандомленных ячеек, нужны чтоб просто передать что-то в функцию добавления новой ячейки, т.к. лень писать для неё перегрузку без параметров this.AddRandomCell(ref x, ref y); this.AddRandomCell(ref x, ref y); //рандомим ячейки и записываем в х и у их координаты this.steps = 0; //обнуляем счётчик ходов this.score = 0; //обнуляем счёт for (int i = 0; i < Skill.skillCount; i++) { this.skills[i].ResetPrice(); } this.skillActivated = false; //переводим в положение пока нельзя использовать скилы this.lose = false; }
public long AttackScore(int currentRow, int currentColumn, Cells[,] arrayCells) { long score = AttackVertical(currentRow, currentColumn, arrayCells) + AttackHorizal(currentRow, currentColumn, arrayCells) + AttackMainDiagonal(currentRow, currentColumn, arrayCells) + AttackSecondDiagonal(currentRow, currentColumn, arrayCells); return(score); }
private bool isEndGameInVertical(int currentRow, int currentCol, int owner, Cells[,] arrayCells) { int countTop = 0; int countBottom = 0; int temp = currentRow; for (int i = currentRow; i >= 0; i--) { if (arrayCells[currentRow--, currentCol].Owned == owner) { countTop++; } else { break; } } currentRow = temp; for (int j = currentRow; j < board.NoOfRows; j++) { if (arrayCells[currentRow++, currentCol].Owned == owner) { countBottom++; } else { break; } } return(countTop + countBottom >= 6); }
public Board(int rows, int columns) { field = new Cells[rows, columns]; InitField(); lines = 0; score = 0; }
public bool isEndGame(int currentRow, int currenCol, int owner, Cells[,] arrayCells) { if (isEndGameInVertical(currentRow, currenCol, owner, arrayCells) || isEndGameInHorizal(currentRow, currenCol, owner, arrayCells) || isMainDiagonal(currentRow, currenCol, owner, arrayCells) || isSecondDiagonal(currentRow, currenCol, owner, arrayCells)) { return(true); } return(false); }
public Board() { Cell = new Cells[12, 12]; for (int i = 0; i < 12; i++) for (int j = 0; j < 12; j++) { Cell[i, j] = Cells.None; } }
private static Board BoardSeed(Cells[,] SourceBoard, int Variant) { Board Seed = new Board(); Seed.SBoard = new Cells[9, 9]; Array.Copy(SourceBoard, Seed.SBoard, 81); Seed.SetMessage(""); Seed.SetVariant(Variant); return(Seed); }
// khởi tạo mảng ô cờ public void InitArrayCells() { arrayCells = new Cells[board.NoOfRows, board.NoOfColumn]; for (int i = 0; i < board.NoOfRows; i++) { for (int j = 0; j < board.NoOfColumn; j++) { arrayCells[i, j] = new Cells(i, j, new Point(j * Cells.WIDTH, i * Cells.HEIGHT), 0); } } }
void addSlots() { cells = new Cells [columns, rows]; for (int x = 0; x < columns; x++) { for (int y = 0; y < columns; y++) { Debug.Log("NewCell"); } } }
public Map(int width, int height, List <MapPosition> livingCells = null) { _map = new Cells[width, height]; for (int w = 0; w < width; w++) { for (int h = 0; h < height; h++) { _map[w, h] = new Cells((livingCells != null && livingCells.Contains(new MapPosition(w, h)))); } } }
public static Cells[,] copy_cells(Cells[,] mas) { Cells[,] poles = new Cells[8, 8]; for (int x = 0; x < 8; x++) { for (int y = 0; y < 8; y++) { poles[x, y] = new Cells(mas[x, y]); } } return(poles); }
void Start() { load = GameObject.Find("Loading").GetComponent <Loading>(); labAlim = this.gameObject.GetComponent <LabAlim>(); i = Random.Range(0, (int)a); id = Random.Range(0, (int)b); available = ((int)a * (int)b) - 1; cells = new Cells[a, b]; lab = GameObject.Find("Labyrinth"); checkCell = cells[i, id]; CreateWalls(); }
public string PrepareForNewGame() { // create new board of cells this.board = new Cells[width, height]; // set initial positions for snakes and next pending positions if (!SetInitialPositionsAndActions()) { return("Could not set initial positions"); } // set food this.food = null; GenerateFood(true); return(string.Empty); }
public void UpdateBoard(int x, int y, int _currentcell, Cells[,] Cell, Ellipse elip) { SolidColorBrush _color = null; elip.Width = _cellWidth; elip.Height = _cellHeight; if (Cell[x, y] == CaroChess_1312229.Models.Board.Cells.Player1) { _color = Brushes.SteelBlue; } if (Cell[x, y] == CaroChess_1312229.Models.Board.Cells.Player2) { _color = Brushes.Black; } elip.Fill = _color; }
public Grid(int nbCells, List <Coords> AliveCellsCoords) { this.n = nbCells; this.TabCells = new Cells[n, n]; for (int x = 0; x < n; x++) { for (int y = 0; y < n; y++) { if (AliveCellsCoords.Contains(new Coords(x, y))) { TabCells[x, y] = new Cells(true); } else { TabCells[x, y] = new Cells(false); } } } }
public int ktBeforePlayer(Cells[,] Cell)//kt nguoi nao danh truoc { int dem = 0;//so so o la cua nguoi choi 1 hay nguoi choi 2 for (int i = 0; i < _Row; i++) { for (int j = 0; j < _Col; j++) { if (Cell[i, j] == Cells.Player1 || Cell[i, j] == Cells.Player2) { dem++; } } } if (dem % 2 == 0) return 1; else return 2; }
private long AttackHorizal(int currentRow, int currentColumn, Cells[,] arrayCells) { int countPlayer = 0; int countComputer = 0; long score = 0; for (int Dem = 1; Dem < 6 && currentColumn + Dem < board.NoOfRows; Dem++) { if (arrayCells[currentRow, currentColumn + Dem].Owned == 1) { countComputer++; } else if (arrayCells[currentRow, currentColumn + Dem].Owned == 2) { countPlayer++; break; } else { break; } } for (int Dem = 1; Dem < 6 && currentColumn - Dem >= 0; Dem++) { if (arrayCells[currentRow, currentColumn - Dem].Owned == 1) { countComputer++; } else if (arrayCells[currentRow, currentColumn - Dem].Owned == 2) { countPlayer++; break; } else { break; } } score -= DENFENSE_SCORE[countPlayer + 1]; score += ATTACK_SCORE[countComputer]; return(score); }
private long DenfenseSecondDiagonal(int currentRow, int currentColumn, Cells[,] arrayCells) // "/" { int countPlayer = 0; int countComputer = 0; long score = 0; for (int Dem = 1; Dem < 6 && currentColumn - Dem >= 0 && currentRow + Dem < board.NoOfRows; Dem++) { if (arrayCells[currentRow + Dem, currentColumn - Dem].Owned == 1) { countComputer++; break; } else if (arrayCells[currentRow + Dem, currentColumn - Dem].Owned == 2) { countPlayer++; } else { break; } } for (int Dem = 1; Dem < 6 && currentColumn + Dem < board.NoOfColumn && currentRow - Dem >= 0; Dem++) { if (arrayCells[currentRow - Dem, currentColumn + Dem].Owned == 1) { countComputer++; break; } else if (arrayCells[currentRow - Dem, currentColumn + Dem].Owned == 2) { countPlayer++; } else { break; } } score += DENFENSE_SCORE[countPlayer]; return(score); }
public int ktHoa(Cells[,] Board) { int kt = 2; for (int i = 0; i < _Row; i++) { for (int j = 0; j < _Col; j++) { if (Board[i, j] != Cells.None) { kt = 1;//hoa } else { kt = 0;//KHONG hoa return kt; } } } return kt; }
public Map(int mapHight, int mapLength, int spawnWallChance) { _mapHight = mapHight; _mapLength = mapLength; mapArray = new Cells[_mapHight, _mapLength]; _spawnWallChance = spawnWallChance; float modularMapHight = _mapHight / 5; float modularMapLength = _mapLength / 5; hightStart = (int)modularMapHight; lengthStart = (int)modularMapLength; hightEnd = _mapHight - hightStart; lengthEnd = _mapLength - lengthStart; maxHight = _mapHight; maxHight--; maxLength = _mapLength; maxLength--; maxRightEdge = maxLength; maxRightEdge--; _mapFirstBlock = random.Next(1, (int)maxHight / 5); }
public static void DownloadMap() { string fileName = ""; Console.WriteLine("Введите название карты"); do { fileName = Console.ReadLine(); if (File.Exists(fileName)) { break; } else { Console.WriteLine("Error. There is no map"); } } while (true); try { string[] textMap = File.ReadAllLines(fileName); MapWidth = textMap[0].Length; Field = new Cells[MapWidth, MapWidth]; for (int i = 0; i < MapWidth; i++) { for (int j = 0; j < MapWidth; j++) { Field[i, j] = (Cells)textMap[i][j]; } } } catch (Exception error) { Console.WriteLine("Map read error: \n{0}", error); } }
public bool checkTrueBlock(Cells[,] Cell, int x, int y) { if (Cell[x, y] == Cells.None) return true; return false; }
public Iteration(int x, int y) { cells = new Cells[x, y]; }
public bool ktWin(Cells[,] Cell, int row, int col) { int kt1 = 0; int kt2 = 0; int kt3 = 0; int kt4 = 0; int k = row; int l = col; int dem1 = 0; int dem2 = 0; int dem3 = 0; int dem4 = 0; //kt duong cheo thư nhất int currPlayer = 0; currPlayer = ktBeforePlayer(Cell); //kt duong cheo 1 while (Cell[row, col] == Cells.Player2) { while (Cell[row, col] == Cells.Player2) { dem1++; row++; col++; if (!checkHopLe(row, col)) break; } row = k; col = l; dem1--; while (Cell[row, col] == Cells.Player2) { dem1++; row--; col--; if (!checkHopLe(row, col)) { kt1 = 1; break; } } if (kt1 == 1) break; } row = k;//set lai i j ban dau col = l; //kt duong cheo thứ hai while (Cell[row, col] == Cells.Player2) { while (Cell[row, col] == Cells.Player2) { dem2++; row--; col++; if (!checkHopLe(row, col)) break; } row = k; col = l; dem2--; while (Cell[row, col] == Cells.Player2) { dem2++; row++; col--; if (!checkHopLe(row, col)) { kt2 = 1; break; } } if (kt2 == 1) break; } row = k;//set lai i j ban dau col = l; //kt hang ngang while (Cell[row, col] == Cells.Player2) { while (Cell[row, col] == Cells.Player2) { dem3++; col++; if (!checkHopLe(row, col)) break; } row = k; col = l; dem3--; while (Cell[row, col] == Cells.Player2) { dem3++; col--; if (!checkHopLe(row, col)) { kt3 = 1; break; } } if (kt3 == 1) break; } row = k;//set lai i j ban dau col = l; //kt hang doc while (Cell[row, col] == Cells.Player2) { while (Cell[row, col] == Cells.Player2) { dem4++; row++; if (!checkHopLe(row, col)) break; } row = k; col = l; dem4--; while (Cell[row, col] == Cells.Player2) { dem4++; row--; if (!checkHopLe(row, col)) { kt4 = 1; break; } } if (kt4 == 1) break; } //------------------------------------------------- //------------------------------------------------- row = k; col = l; while (Cell[row, col] == Cells.Player1) { while (Cell[row, col] == Cells.Player1) { dem1++; row++; col++; if (!checkHopLe(row, col)) break; } row = k; col = l; dem1--; while (Cell[row, col] == Cells.Player1) { dem1++; row--; col--; if (!checkHopLe(row, col)) { kt1 = 1; break; } } if (kt1 == 1) break; } row = k;//set lai i j ban dau col = l; //kt duong cheo thứ hai while (Cell[row, col] == Cells.Player1) { while (Cell[row, col] == Cells.Player1) { dem2++; row--; col++; if (!checkHopLe(row, col)) break; } row = k; col = l; dem2--; while (Cell[row, col] == Cells.Player1) { dem2++; row++; col--; if (!checkHopLe(row, col)) { kt2 = 1; break; } } if (kt2 == 1) break; } row = k;//set lai i j ban dau col = l; //kt hang ngang while (Cell[row, col] == Cells.Player1) { while (Cell[row, col] == Cells.Player1) { dem3++; col++; if (!checkHopLe(row, col)) break; } row = k; col = l; dem3--; while (Cell[row, col] == Cells.Player1) { dem3++; col--; if (!checkHopLe(row, col)) { kt3 = 1; break; } } if (kt3 == 1) break; } row = k;//set lai i j ban dau col = l; //kt hang doc while (Cell[row, col] == Cells.Player1) { while (Cell[row, col] == Cells.Player1) { dem4++; row++; if (!checkHopLe(row, col)) break; } row = k; col = l; dem4--; while (Cell[row, col] == Cells.Player1) { dem4++; row--; if (!checkHopLe(row, col)) { kt4 = 1; break; } } if (kt4 == 1) break; } if ((dem1 >= 5) || (dem2 >= 5) || (dem3 >= 5) || (dem4 >= 5))//6 con lien tiep can dc phep thang return true;//tra ve ket qua thang return false; }
private void initialize() { int name = PlayerPrefs.GetInt(("Player")); mazeGrid = new Cells[rows, columns]; float wallSize = wall.transform.localScale.x; floorClone = Instantiate(floor, new Vector3(rows * 2 - 1.5f, 0.5f, -(columns * 2) + 1.5f), Quaternion.identity); //correct //makes the water a bit bigger than the maze if (rows % 2 == 0) { floor.transform.localScale = new Vector3((rows / 2) + .5f, 0.0001f, (columns / 2) + .5f); //floor.transform.localScale = new Vector3((rows + wallSize ) * rows, 0.0001f, (columns + wallSize) * columns); } else { floor.transform.localScale = new Vector3((rows / 2) + 1.5f, 0.0001f, (columns / 2) + 1.5f); //floor.transform.localScale = new Vector3((rows * wallSize) * rows, 0.0001f, (columns * wallSize) * columns); } //spawn boat the player choose if (name == 2) { player2.transform.localScale = new Vector3(.0019f, 0.003f, .0019f); player2 = Instantiate(player2, new Vector3(-0.5f, -1000f, 0), Quaternion.Euler(0, -90, 0)); player2.transform.position = new Vector3(0, .9f, 0); player2.GetComponent <Movement>().enabled = true; player2.GetComponent <ChestCollision>().enabled = true; //player2.GetComponent<BoatFloater>().enabled = true; currentLevel = player2.GetComponent <ChestCollision>().levelCounter; player2.transform.parent = floorClone.transform; } else if (name == 3) { player3.transform.localScale = new Vector3(.0009f, 0.001f, .0009f); player3 = Instantiate(player3, new Vector3(-0.5f, -1000f, 0), Quaternion.Euler(0, -90, 0)); player3.transform.position = new Vector3(0, .5f, 0); player3.GetComponent <Movement>().enabled = true; player3.GetComponent <ChestCollision>().enabled = true; //player3.GetComponent<BoatFloater>().enabled = true; currentLevel = player3.GetComponent <ChestCollision>().levelCounter; player3.transform.parent = floorClone.transform; } else if (name == 4) { player4.transform.localScale = new Vector3(.0009f, 0.001f, .0009f); player4 = Instantiate(player4, new Vector3(-0.5f, -1000f, 0), Quaternion.Euler(0, -90, 0)); player4.transform.position = new Vector3(0, .5f, 0); player4.GetComponent <Movement>().enabled = true; player4.GetComponent <ChestCollision>().enabled = true; // player4.GetComponent<BoatFloater>().enabled = true; currentLevel = player4.GetComponent <ChestCollision>().levelCounter; player4.transform.parent = floorClone.transform; } else if (name == 5) { player5.transform.localScale = new Vector3(.0009f, 0.001f, .0009f); player5 = Instantiate(player5, new Vector3(-0.5f, -1000f, 0), Quaternion.Euler(0, -90, 0)); player5.transform.position = new Vector3(0, .5f, 0); player5.GetComponent <Movement>().enabled = true; player5.GetComponent <ChestCollision>().enabled = true; //player5.GetComponent<BoatFloater>().enabled = true; currentLevel = player5.GetComponent <ChestCollision>().levelCounter; player5.transform.parent = floorClone.transform; } else { player1.transform.localScale = new Vector3(.0009f, 0.001f, .0009f); player1 = Instantiate(player1, new Vector3(-0.5f, -1000f, 0), Quaternion.Euler(0, -90, 0)); player1.transform.position = new Vector3(0, .5f, 0); player1.GetComponent <Movement>().enabled = true; player1.GetComponent <ChestCollision>().enabled = true; //player1.GetComponent<BoatFloater>().enabled = true; currentLevel = player1.GetComponent <ChestCollision>().levelCounter; player1.transform.parent = floorClone.transform; } //spawn chest if (rows == columns) { chest = Instantiate(chest, new Vector3((rows - 1) * wallSize, 1.75f, (-columns + 1) * wallSize), Quaternion.identity); } else { chest = Instantiate(chest, new Vector3((rows - 2) * wallSize, 1.75f, (-columns) * wallSize), Quaternion.identity); } for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { //Initializes each cell with a cell object, each cell containing four wall game objects mazeGrid[i, j] = new Cells(); //spawns coins coin = Instantiate(coin, new Vector3(j * wallSize, 1.75f, -i * wallSize), Quaternion.identity); coin.GetComponent <CoinCollision>().enabled = true; coin.GetComponent <AudioSource>().enabled = true; //coin.GetComponent<Coinglow>().enabled = true; coin.transform.parent = transform; //Creates the upper wall of the maze walls //GameObject northWall = Instantiate(wall, new Vector3(j*wallSize, 1.75f, -i*wallSize + 2.25f), Quaternion.identity); GameObject northWall = Instantiate(wall, new Vector3(j * wallSize, 1.75f, -i * wallSize + 2.25f), Quaternion.identity); northWall.name = "North Wall Row: " + i + " Column: " + j; //Creates the lower wall of the maze walls GameObject southWall = Instantiate(wall, new Vector3(j * wallSize, 1.75f, -i * wallSize - 2.25f), Quaternion.identity); southWall.name = "South Wall Row: " + i + " Column: " + j; //Creates the left wall of the maze walls GameObject westWall = Instantiate(wall, new Vector3(j * wallSize - 2.145f, 1.75f, -i * wallSize), Quaternion.Euler(0, 90, 0)); westWall.name = "West Wall Row: " + i + " Column: " + j; //Creates the right wall of the maze walls GameObject eastWall = Instantiate(wall, new Vector3(j * wallSize + 1.25f + .48861f, 1.75f, -i * wallSize), Quaternion.Euler(0, 90, 0)); eastWall.name = "East Wall Row: " + i + " Column: " + j; //Sets references to each wall in the Cells object mazeGrid[i, j].northWall = northWall; mazeGrid[i, j].southWall = southWall; mazeGrid[i, j].westWall = westWall; mazeGrid[i, j].eastWall = eastWall; //Hierarchy stuff northWall.transform.parent = transform; southWall.transform.parent = transform; westWall.transform.parent = transform; eastWall.transform.parent = transform; /* * if(i == 0 && j == 0) * { * Destroy(westWall); * } * * if (i == rows-1 && j == columns-1) * { * Destroy(eastWall); * } */ } } //Destroy(coin); //destroyWalls(); }