Recode finished version 1
This commit is contained in:
@@ -4,8 +4,104 @@ using UnityEngine;
|
||||
|
||||
public class Bishop : Character
|
||||
{
|
||||
public static readonly Vector2[,] moves =
|
||||
{
|
||||
{
|
||||
//up, right
|
||||
new Vector2(1, 1),
|
||||
new Vector2(2, 2),
|
||||
new Vector2(3, 3),
|
||||
new Vector2(4, 4),
|
||||
new Vector2(5, 5),
|
||||
new Vector2(6, 6),
|
||||
new Vector2(7, 7),
|
||||
new Vector2(8.5f, 8.5f),
|
||||
},
|
||||
|
||||
{
|
||||
//up, left
|
||||
new Vector2(-1, 1),
|
||||
new Vector2(-2, 2),
|
||||
new Vector2(-3, 3),
|
||||
new Vector2(-4, 4),
|
||||
new Vector2(-5, 5),
|
||||
new Vector2(-6, 6),
|
||||
new Vector2(-7, 7),
|
||||
new Vector2(-8.5f, 8.5f),
|
||||
},
|
||||
|
||||
{
|
||||
//down, right
|
||||
new Vector2(1, -1),
|
||||
new Vector2(2, -2),
|
||||
new Vector2(3, -3),
|
||||
new Vector2(4, -4),
|
||||
new Vector2(5, -5),
|
||||
new Vector2(6, -6),
|
||||
new Vector2(7, -7),
|
||||
new Vector2(8.5f, -8.5f),
|
||||
},
|
||||
|
||||
{
|
||||
//down, left
|
||||
new Vector2(-1, -1),
|
||||
new Vector2(-2, -2),
|
||||
new Vector2(-3, -3),
|
||||
new Vector2(-4, -4),
|
||||
new Vector2(-5, -5),
|
||||
new Vector2(-6, -6),
|
||||
new Vector2(-7, -7),
|
||||
new Vector2(-8.5f, -8.5f),
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public override bool[,] GetValidMoves(Cell[,] cells, Game game)
|
||||
{
|
||||
return null;
|
||||
bool[,] result = new bool[8, 8];
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
for (int j = 0; j < 8; j++)
|
||||
{
|
||||
Vector3 testPosition = transform.position + (Vector3)moves[i, j];
|
||||
Cell testCell = game.GetCellOnPosition(testPosition);
|
||||
|
||||
if (testCell != null)
|
||||
{
|
||||
if (testCell.connected == null)
|
||||
{
|
||||
int x, y;
|
||||
|
||||
string nameX = testCell.gameObject.name.Substring(5, 1);
|
||||
string nameY = testCell.gameObject.name.Substring(7, 1);
|
||||
|
||||
x = int.Parse(nameX);
|
||||
y = int.Parse(nameY);
|
||||
|
||||
result[x, y] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (testCell.connected.team != game.currentTeam)
|
||||
{
|
||||
int x, y;
|
||||
|
||||
string nameX = testCell.gameObject.name.Substring(5, 1);
|
||||
string nameY = testCell.gameObject.name.Substring(7, 1);
|
||||
|
||||
x = int.Parse(nameX);
|
||||
y = int.Parse(nameY);
|
||||
|
||||
result[x, y] = true;
|
||||
}
|
||||
|
||||
j = 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ public class Game : MonoBehaviour
|
||||
Destroy(tempCell.connected.gameObject);
|
||||
}
|
||||
tempCell.connected = clickedCell.connected;
|
||||
tempCell.connected.gameObject.transform.position = (tempCell.gameObject.transform.position);
|
||||
tempCell.connected.gameObject.transform.position = (tempCell.gameObject.transform.position + Vector3.back);
|
||||
|
||||
clickedCell.connected = null;
|
||||
DeColorAllCells();
|
||||
|
||||
@@ -4,8 +4,62 @@ using UnityEngine;
|
||||
|
||||
public class King : Character
|
||||
{
|
||||
public static readonly Vector2[] moves =
|
||||
{
|
||||
//up
|
||||
new Vector2(0, 1),
|
||||
//down
|
||||
new Vector2(0, -1),
|
||||
//right
|
||||
new Vector2(1, 0),
|
||||
//left
|
||||
new Vector2(-1, 0),
|
||||
//up, right
|
||||
new Vector2(1, 1),
|
||||
//up, left
|
||||
new Vector2(-1, 1),
|
||||
//down, right
|
||||
new Vector2(1, -1),
|
||||
//down, left
|
||||
new Vector2(-1, -1)
|
||||
};
|
||||
|
||||
public override bool[,] GetValidMoves(Cell[,] cells, Game game)
|
||||
{
|
||||
return null;
|
||||
bool[,] result = new bool[8, 8];
|
||||
|
||||
foreach (Vector2 move in moves)
|
||||
{
|
||||
Vector3 testPosition = transform.position + (Vector3)move;
|
||||
|
||||
Cell testCell = game.GetCellOnPosition(testPosition + Vector3.back);
|
||||
|
||||
if (testCell != null)
|
||||
{
|
||||
int x, y;
|
||||
|
||||
string nameX = testCell.gameObject.name.Substring(5, 1);
|
||||
string nameY = testCell.gameObject.name.Substring(7, 1);
|
||||
|
||||
x = int.Parse(nameX);
|
||||
y = int.Parse(nameY);
|
||||
|
||||
|
||||
if (testCell.connected == null)
|
||||
{
|
||||
result[x, y] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Character testCharacter = testCell.connected;
|
||||
if (testCharacter.team != game.currentTeam)
|
||||
{
|
||||
result[x, y] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,18 +20,18 @@ public class Knight : Character
|
||||
new Vector2(-2, 1),
|
||||
new Vector2(-2, -1),
|
||||
};
|
||||
|
||||
|
||||
public override bool[,] GetValidMoves(Cell[,] cells, Game game)
|
||||
{
|
||||
bool[,] result = new bool[8, 8];
|
||||
|
||||
|
||||
foreach (Vector2 move in moves)
|
||||
{
|
||||
Vector3 testPosition = transform.position + (Vector3)move;
|
||||
|
||||
Cell testCell = game.GetCellOnPosition(testPosition + Vector3.back);
|
||||
|
||||
if(testCell != null)
|
||||
if (testCell != null)
|
||||
{
|
||||
int x, y;
|
||||
|
||||
@@ -40,25 +40,23 @@ public class Knight : Character
|
||||
|
||||
x = int.Parse(nameX);
|
||||
y = int.Parse(nameY);
|
||||
|
||||
if (IsPositionInGrid(x, y))
|
||||
|
||||
|
||||
if (testCell.connected == null)
|
||||
{
|
||||
if (testCell.connected == null)
|
||||
result[x, y] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Character testCharacter = testCell.connected;
|
||||
if (testCharacter.team != game.currentTeam)
|
||||
{
|
||||
result[x, y] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Character testCharacter = testCell.connected;
|
||||
if (testCharacter.team != game.currentTeam)
|
||||
{
|
||||
result[x, y] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,151 @@ using UnityEngine;
|
||||
|
||||
public class Queen : Character
|
||||
{
|
||||
public static readonly Vector2[,] moves =
|
||||
{
|
||||
{
|
||||
//up
|
||||
new Vector2(0, 1),
|
||||
new Vector2(0, 2),
|
||||
new Vector2(0, 3),
|
||||
new Vector2(0, 4),
|
||||
new Vector2(0, 5),
|
||||
new Vector2(0, 6),
|
||||
new Vector2(0, 7),
|
||||
new Vector2(0, 8.5f), //.5 because of calculation error in game ^^
|
||||
},
|
||||
|
||||
{
|
||||
//down
|
||||
new Vector2(0, -1),
|
||||
new Vector2(0, -2),
|
||||
new Vector2(0, -3),
|
||||
new Vector2(0, -4),
|
||||
new Vector2(0, -5),
|
||||
new Vector2(0, -6),
|
||||
new Vector2(0, -7),
|
||||
new Vector2(0, -8.5f),
|
||||
},
|
||||
|
||||
{
|
||||
//right
|
||||
new Vector2(1, 0),
|
||||
new Vector2(2, 0),
|
||||
new Vector2(3, 0),
|
||||
new Vector2(4, 0),
|
||||
new Vector2(5, 0),
|
||||
new Vector2(6, 0),
|
||||
new Vector2(7, 0),
|
||||
new Vector2(8.5f, 0)
|
||||
},
|
||||
|
||||
{
|
||||
//left
|
||||
new Vector2(-1, 0),
|
||||
new Vector2(-2, 0),
|
||||
new Vector2(-3, 0),
|
||||
new Vector2(-4, 0),
|
||||
new Vector2(-5, 0),
|
||||
new Vector2(-6, 0),
|
||||
new Vector2(-7, 0),
|
||||
new Vector2(-8.5f, 0)
|
||||
},
|
||||
|
||||
{
|
||||
//up, right
|
||||
new Vector2(1, 1),
|
||||
new Vector2(2, 2),
|
||||
new Vector2(3, 3),
|
||||
new Vector2(4, 4),
|
||||
new Vector2(5, 5),
|
||||
new Vector2(6, 6),
|
||||
new Vector2(7, 7),
|
||||
new Vector2(8.5f, 8.5f),
|
||||
},
|
||||
|
||||
{
|
||||
//up, left
|
||||
new Vector2(-1, 1),
|
||||
new Vector2(-2, 2),
|
||||
new Vector2(-3, 3),
|
||||
new Vector2(-4, 4),
|
||||
new Vector2(-5, 5),
|
||||
new Vector2(-6, 6),
|
||||
new Vector2(-7, 7),
|
||||
new Vector2(-8.5f, 8.5f),
|
||||
},
|
||||
|
||||
{
|
||||
//down, right
|
||||
new Vector2(1, -1),
|
||||
new Vector2(2, -2),
|
||||
new Vector2(3, -3),
|
||||
new Vector2(4, -4),
|
||||
new Vector2(5, -5),
|
||||
new Vector2(6, -6),
|
||||
new Vector2(7, -7),
|
||||
new Vector2(8.5f, -8.5f),
|
||||
},
|
||||
|
||||
{
|
||||
//down, left
|
||||
new Vector2(-1, -1),
|
||||
new Vector2(-2, -2),
|
||||
new Vector2(-3, -3),
|
||||
new Vector2(-4, -4),
|
||||
new Vector2(-5, -5),
|
||||
new Vector2(-6, -6),
|
||||
new Vector2(-7, -7),
|
||||
new Vector2(-8.5f, -8.5f),
|
||||
}
|
||||
};
|
||||
|
||||
public override bool[,] GetValidMoves(Cell[,] cells, Game game)
|
||||
{
|
||||
return null;
|
||||
bool[,] result = new bool[8, 8];
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
for (int j = 0; j < 8; j++)
|
||||
{
|
||||
Vector3 testPosition = transform.position + (Vector3)moves[i, j];
|
||||
Cell testCell = game.GetCellOnPosition(testPosition);
|
||||
|
||||
if(testCell != null)
|
||||
{
|
||||
if (testCell.connected == null)
|
||||
{
|
||||
int x, y;
|
||||
|
||||
string nameX = testCell.gameObject.name.Substring(5, 1);
|
||||
string nameY = testCell.gameObject.name.Substring(7, 1);
|
||||
|
||||
x = int.Parse(nameX);
|
||||
y = int.Parse(nameY);
|
||||
|
||||
result[x, y] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (testCell.connected.team != game.currentTeam)
|
||||
{
|
||||
int x, y;
|
||||
|
||||
string nameX = testCell.gameObject.name.Substring(5, 1);
|
||||
string nameY = testCell.gameObject.name.Substring(7, 1);
|
||||
|
||||
x = int.Parse(nameX);
|
||||
y = int.Parse(nameY);
|
||||
|
||||
result[x, y] = true;
|
||||
}
|
||||
|
||||
j = 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ public class Rook : Character
|
||||
{
|
||||
private static readonly Vector2[,] moves =
|
||||
{
|
||||
|
||||
{
|
||||
//up
|
||||
new Vector2(0, 1),
|
||||
@@ -55,13 +54,53 @@ public class Rook : Character
|
||||
new Vector2(-8.5f, 0)
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public override bool[,] GetValidMoves(Cell[,] cells, Game game)
|
||||
{
|
||||
bool[,] result = new bool[8, 8];
|
||||
|
||||
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
for (int j = 0; j < 8; j++)
|
||||
{
|
||||
Vector3 testPosition = transform.position + (Vector3)moves[i, j];
|
||||
Cell testCell = game.GetCellOnPosition(testPosition);
|
||||
|
||||
if(testCell != null)
|
||||
{
|
||||
if (testCell.connected == null)
|
||||
{
|
||||
int x, y;
|
||||
|
||||
string nameX = testCell.gameObject.name.Substring(5, 1);
|
||||
string nameY = testCell.gameObject.name.Substring(7, 1);
|
||||
|
||||
x = int.Parse(nameX);
|
||||
y = int.Parse(nameY);
|
||||
|
||||
result[x, y] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (testCell.connected.team != game.currentTeam)
|
||||
{
|
||||
int x, y;
|
||||
|
||||
string nameX = testCell.gameObject.name.Substring(5, 1);
|
||||
string nameY = testCell.gameObject.name.Substring(7, 1);
|
||||
|
||||
x = int.Parse(nameX);
|
||||
y = int.Parse(nameY);
|
||||
|
||||
result[x, y] = true;
|
||||
}
|
||||
|
||||
j = 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user