Commit 5b4574a7 authored by 18강현모's avatar 18강현모

X, Y index 순서 변경 및 그에 따른 주석 변경 완료. 이제 머지 가능.

parent 931bd96e
...@@ -11,12 +11,13 @@ public class LifeCrystalUI : MonoBehaviour ...@@ -11,12 +11,13 @@ public class LifeCrystalUI : MonoBehaviour
////////////////////////////////////////////////// Private variables ////////////////////////////////////////////////// Private variables
/// <summary> /// <summary>
/// Enum for cell types /// Enum for cell types
/// <para/> [Empty = 0, Life = 1, Gold = 2, Ame = 3]
/// </summary> /// </summary>
public enum CellType{Empty, Life, Gold, Ame }; public enum CellType{Empty, Life, Gold, Ame };
/// <summary> /// <summary>
/// Image renderers of cells /// Image renderers of cells
/// <para/> First index = vertical position (0 on the bottom) /// <para/> First index = horizontal position (0 on the bottom)
/// <para/> Second index = horizontal position (0 on the left) /// <para/> Second index = vertical position (0 on the left)
/// </summary> /// </summary>
Image[][] cellImg; Image[][] cellImg;
/// <summary> /// <summary>
...@@ -29,8 +30,8 @@ public class LifeCrystalUI : MonoBehaviour ...@@ -29,8 +30,8 @@ public class LifeCrystalUI : MonoBehaviour
Vector3 pivotPosition; Vector3 pivotPosition;
/// <summary> /// <summary>
/// Current cell state (enum Color) /// Current cell state (enum Color)
/// <para/> First index = vertical position (0 on the bottom) /// <para/> First index = horizontal position (0 on the bottom)
/// <para/> Second index = horizontal position (0 on the left) /// <para/> Second index = vertical position (0 on the left)
/// </summary> /// </summary>
CellType[][] cell; CellType[][] cell;
////////////////////////////////////////////////// Public variables ////////////////////////////////////////////////// Public variables
...@@ -47,7 +48,7 @@ public class LifeCrystalUI : MonoBehaviour ...@@ -47,7 +48,7 @@ public class LifeCrystalUI : MonoBehaviour
/// </summary> /// </summary>
public GameObject rowObj; public GameObject rowObj;
/// <summary> /// <summary>
/// LifeCrystal enabled? /// LifeCrystal enabled if isDead == false
/// </summary> /// </summary>
public bool isDead; public bool isDead;
/// <summary> /// <summary>
...@@ -89,15 +90,15 @@ public class LifeCrystalUI : MonoBehaviour ...@@ -89,15 +90,15 @@ public class LifeCrystalUI : MonoBehaviour
{ {
if (isDead) return; if (isDead) return;
for (int i = height - 1; i >= 0; i--) for (int y = height - 1; y >= 0; y--)
{ {
for (int j = 2; j >= 0; j--) for (int x = 2; x >= 0; x--)
{ {
if (dmg > 0 && lifeCount > 0 && cell[i][j] != CellType.Empty) if (dmg > 0 && lifeCount > 0 && cell[x][y] != CellType.Empty)
{ {
if (cell[i][j] == CellType.Gold) if (cell[x][y] == CellType.Gold)
goldCount--; goldCount--;
updateCell(j, i, CellType.Empty); updateCell(x, y, CellType.Empty);
dmg--; dmg--;
lifeCount--; lifeCount--;
} }
...@@ -138,13 +139,13 @@ public class LifeCrystalUI : MonoBehaviour ...@@ -138,13 +139,13 @@ public class LifeCrystalUI : MonoBehaviour
} }
int redLifeIndex = 0; int redLifeIndex = 0;
for (int i = 0; i < height; i++) for (int y = 0; y < height; y++)
for (int j = 0; j < 3; j++) for (int x = 0; x < 3; x++)
{ {
if (cell[i][j] == CellType.Life) if (cell[x][y] == CellType.Life)
{ {
if (mixer[redLifeIndex] == 1) if (mixer[redLifeIndex] == 1)
updateCell(j, i, CellType.Gold); updateCell(x, y, CellType.Gold);
redLifeIndex++; redLifeIndex++;
} }
} }
...@@ -191,11 +192,11 @@ public class LifeCrystalUI : MonoBehaviour ...@@ -191,11 +192,11 @@ public class LifeCrystalUI : MonoBehaviour
if (goldCount < gold) if (goldCount < gold)
return false; return false;
goldCount -= gold; goldCount -= gold;
for (int i = height - 1; i >= 0; i--) for (int y = height - 1; y >= 0; y--)
for (int j = 2; j >= 0; j--) for (int x = 2; x >= 0; x--)
if (cell[i][j] == CellType.Gold && gold > 0) if (cell[x][y] == CellType.Gold && gold > 0)
{ {
updateCell(j, i, CellType.Life); updateCell(x, y, CellType.Life);
gold--; gold--;
} }
return true; return true;
...@@ -214,19 +215,13 @@ public class LifeCrystalUI : MonoBehaviour ...@@ -214,19 +215,13 @@ public class LifeCrystalUI : MonoBehaviour
height = 8; height = 8;
lifeCount = 24; lifeCount = 24;
goldCount = 0; goldCount = 0;
cell = new CellType[height][]; cell = new CellType[3][] { new CellType[height], new CellType[height], new CellType[height] };
for (int i = 0; i < height; i++) for (int y = 0; y < height; y++)
cell[i] = new CellType[3]; for (int x = 0; x < 3; x++)
for (int i = 0; i < height; i++) cell[x][y] = CellType.Life;
for (int j = 0; j < 3; j++) cellImg = new Image[3][] { new Image[height], new Image[height], new Image[height] };
cell[i][j] = CellType.Life;
cellImg = new Image[height][];
for (int i = 0; i < height; i++)
cellImg[i] = new Image[3];
for (int i = 0; i < 3 * height; i++) for (int i = 0; i < 3 * height; i++)
{ cellImg[i % 3][i / 3] = transform.Find("Cells").Find("LC" + (i + 1).ToString("00")).GetComponent<Image>();
cellImg[i / 3][i % 3] = transform.Find("Cells").Find("LC" + (i + 1).ToString("00")).GetComponent<Image>();
}
} }
/// <summary> /// <summary>
/// Runs each frame /// Runs each frame
...@@ -244,10 +239,10 @@ public class LifeCrystalUI : MonoBehaviour ...@@ -244,10 +239,10 @@ public class LifeCrystalUI : MonoBehaviour
/// <param name="value"></param> /// <param name="value"></param>
void updateCell(int x, int y, CellType value) void updateCell(int x, int y, CellType value)
{ {
cell[y][x] = value; cell[x][y] = value;
cellImg[y][x].sprite = cellSprites[(int)value]; cellImg[x][y].sprite = cellSprites[(int)value];
cellImg[y][x].transform.localPosition = pivotPosition + gridSize * new Vector3(x, y, 0); cellImg[x][y].transform.localPosition = pivotPosition + gridSize * new Vector3(x, y, 0);
cellImg[y][x].enabled = value == CellType.Empty ? false : true; cellImg[x][y].enabled = value == CellType.Empty ? false : true;
} }
/// <summary> /// <summary>
/// Runs when life goes below zero /// Runs when life goes below zero
...@@ -260,7 +255,7 @@ public class LifeCrystalUI : MonoBehaviour ...@@ -260,7 +255,7 @@ public class LifeCrystalUI : MonoBehaviour
/// Simulates a block drop and find where to drop it /// Simulates a block drop and find where to drop it
/// </summary> /// </summary>
/// <param name="grid">Shape of the dropping block /// <param name="grid">Shape of the dropping block
/// <para/> grid[Y][X] /// <para/> grid[X][Y]
/// <para/> X: 0~2 (0 on the bottom) /// <para/> X: 0~2 (0 on the bottom)
/// <para/> Y: 0~(height-1) (0 on the left)</param> /// <para/> Y: 0~(height-1) (0 on the left)</param>
/// <returns>Vector2(drop position(0~2), drop depth(0~height))</returns> /// <returns>Vector2(drop position(0~2), drop depth(0~height))</returns>
...@@ -286,41 +281,37 @@ public class LifeCrystalUI : MonoBehaviour ...@@ -286,41 +281,37 @@ public class LifeCrystalUI : MonoBehaviour
depth = 0; depth = 0;
blockTexture[x] = depth; blockTexture[x] = depth;
} }
for (int j = 0; j <= 2; j++) for (int x = 0; x <= 2; x++)
{ {
int depth = 0; int depth = 0;
for (int i = height - 1; i >= 0; i--) for (int y = height - 1; y >= 0; y--)
{ {
if (cell[i][j] == 0) if (cell[x][y] == 0)
depth++; depth++;
else else
break; break;
} }
emptyTexture[j] = depth; emptyTexture[x] = depth;
} }
for (int k = 0; k < 3; k++)
print("k=" + k + ", " + emptyTexture[k]);
for (int k = 0; k < bWidth; k++)
print("k=" + k + ", " + emptyTexture[k]);
///////////////////////////////calculates possible drops ///////////////////////////////calculates possible drops
int[] dropDepth = new int[4 - bWidth]; int[] dropDepth = new int[4 - bWidth];
for (int i = 0; i < 4 - bWidth; i++) for (int x = 0; x < 4 - bWidth; x++)
{ {
int maxDepth = emptyTexture[i] + blockTexture[0]; int maxDepth = emptyTexture[x] + blockTexture[0];
for (int x = 1; x < bWidth; x++) for (int bx = 1; bx < bWidth; bx++)
{ {
if (maxDepth > emptyTexture[i + x] + blockTexture[x]) if (maxDepth > emptyTexture[x + bx] + blockTexture[bx])
maxDepth = emptyTexture[i + x] + blockTexture[x]; maxDepth = emptyTexture[x + bx] + blockTexture[bx];
} }
dropDepth[i] = maxDepth; dropDepth[x] = maxDepth;
} }
int realPosition = 0, realDepth = dropDepth[0]; int realPosition = 0, realDepth = dropDepth[0];
for (int i = 1; i < 4 - bWidth; i++) for (int x = 1; x < 4 - bWidth; x++)
if (realDepth < dropDepth[i]) if (realDepth < dropDepth[x])
{ {
realPosition = i; realPosition = x;
realDepth = dropDepth[i]; realDepth = dropDepth[x];
} }
return new Vector2Int(realPosition, realDepth); return new Vector2Int(realPosition, realDepth);
...@@ -333,7 +324,6 @@ public class LifeCrystalUI : MonoBehaviour ...@@ -333,7 +324,6 @@ public class LifeCrystalUI : MonoBehaviour
/// <returns>Null</returns> /// <returns>Null</returns>
IEnumerator DropBlock(LifeCrystal frag, Vector2Int dropxy) IEnumerator DropBlock(LifeCrystal frag, Vector2Int dropxy)
{ {
print(dropxy);
int bWidth = frag.grid.Length; int bWidth = frag.grid.Length;
int bHeight = frag.grid[0].Length; int bHeight = frag.grid[0].Length;
List<Vector2Int> droppingCells = new List<Vector2Int>(0); List<Vector2Int> droppingCells = new List<Vector2Int>(0);
...@@ -344,13 +334,13 @@ public class LifeCrystalUI : MonoBehaviour ...@@ -344,13 +334,13 @@ public class LifeCrystalUI : MonoBehaviour
if (frag.grid[x][y] != CellType.Empty) if (frag.grid[x][y] != CellType.Empty)
{ {
updateCell(dropxy.x + x, height - dropxy.y + y, frag.grid[x][y]); updateCell(dropxy.x + x, height - dropxy.y + y, frag.grid[x][y]);
droppingCells.Add(new Vector2Int(height - dropxy.y + y, dropxy.x + x)); droppingCells.Add(new Vector2Int(dropxy.x + x, height - dropxy.y + y));
lifeCount++; lifeCount++;
} }
} }
foreach (Vector2Int block in droppingCells) foreach (Vector2Int block in droppingCells)
{ {
cellImg[block.x][block.y].transform.localPosition = pivotPosition + gridSize * new Vector3(block.y, block.x + dropxy.y, 0); cellImg[block.x][block.y].transform.localPosition = pivotPosition + gridSize * new Vector3(block.x, block.y + dropxy.y, 0);
} }
yield return new WaitForSeconds(0.05f); yield return new WaitForSeconds(0.05f);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment