Skip to content

Commit

Permalink
added reverse bool in checker.cs to do checking from right to left
Browse files Browse the repository at this point in the history
  • Loading branch information
robertoguazon committed Nov 4, 2016
1 parent 487419b commit 7bc66c3
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 13 deletions.
Binary file not shown.
Binary file not shown.
Binary file modified Project1_Borais-Francisco-Mabasa-Guazon/Assets/scenes/Game.unity
Binary file not shown.
56 changes: 43 additions & 13 deletions Project1_Borais-Francisco-Mabasa-Guazon/Assets/scripts/Checker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ public class Checker : MonoBehaviour {
[SerializeField]
private int[] checkerRows;

//EXPERIMENTAL
[SerializeField]
private bool reverse = false;
//END OF EXPERIMENTAL

private Sprite _currentChipSprite;

private int _currentRow;
Expand Down Expand Up @@ -39,6 +44,7 @@ public void Start() {
public void CheckPlacedCells(Grid grid, List<GameObject> placedCells) {

int orig = placedCells.Count;

for (int i = 0; i < placedCells.Count; i++) {
GameObject cellObject = placedCells[i];
Cell cell = cellObject.GetComponent<Cell>();
Expand Down Expand Up @@ -68,25 +74,49 @@ public bool CheckCell(Grid grid, Cell cell) {
{

if ((checkerRow + cell.Row) >= grid.GetRows()) return false;
for (int checkerCol = 0; (checkerCol < checkerRows[checkerRow]); checkerCol++)
{

if (reverse) {
for (int checkerCol = checkerRows[checkerRow] - 1; (checkerCol >= 0); checkerCol--)
{

if ((checkerCol + cell.Col) >= grid.GetCols()) return false;
// Debug.Log("checker row,col (: " + checkerRow + ", " + checkerCol + ")");
if ((cell.Col - checkerCol) < 0) return false;
// Debug.Log("checker row,col (: " + checkerRow + ", " + checkerCol + ")");


GameObject cellObject = grid.GetCellAt(cell.Row + checkerRow, cell.Col + checkerCol);
Cell checkCell = cellObject.GetComponent<Cell>();
if (checkCell.isChecked()) return false;
GameObject cellObject = grid.GetCellAt(cell.Row + checkerRow, cell.Col - checkerCol);
Cell checkCell = cellObject.GetComponent<Cell>();
if (checkCell.isChecked()) return false;

// Debug.Log("Final(" + (cell.Row + checkerRow) + ", " + (cell.Col + checkerCol) + ")");
if (_currentChipSprite != grid.GetChipSpriteAt(checkerRow + cell.Row, checkerCol + cell.Col))
{
return false;
// Debug.Log("Final(" + (cell.Row + checkerRow) + ", " + (cell.Col + checkerCol) + ")");
if (_currentChipSprite != grid.GetChipSpriteAt(cell.Row + checkerRow, cell.Col - checkerCol))
{
return false;
}

vertices.Add(cellObject.transform.position);
cellsToCheck.Add(checkCell);
}
} else {
for (int checkerCol = 0; (checkerCol < checkerRows[checkerRow]); checkerCol++)
{

if ((checkerCol + cell.Col) >= grid.GetCols()) return false;
// Debug.Log("checker row,col (: " + checkerRow + ", " + checkerCol + ")");


vertices.Add(cellObject.transform.position);
cellsToCheck.Add(checkCell);
GameObject cellObject = grid.GetCellAt(cell.Row + checkerRow, cell.Col + checkerCol);
Cell checkCell = cellObject.GetComponent<Cell>();
if (checkCell.isChecked()) return false;

// Debug.Log("Final(" + (cell.Row + checkerRow) + ", " + (cell.Col + checkerCol) + ")");
if (_currentChipSprite != grid.GetChipSpriteAt(checkerRow + cell.Row, checkerCol + cell.Col))
{
return false;
}

vertices.Add(cellObject.transform.position);
cellsToCheck.Add(checkCell);
}
}
}

Expand Down
Binary file modified Project1_Borais-Francisco-Mabasa-Guazon/Library/CurrentLayout.dwlt
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Project1_Borais-Francisco-Mabasa-Guazon/Library/assetDatabase3
Binary file not shown.
Binary file modified Project1_Borais-Francisco-Mabasa-Guazon/Library/expandedItems
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 7bc66c3

Please sign in to comment.