|
@ -40,7 +40,7 @@ public class GameManager : MonoBehaviour |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Easy access to IEnumerable in playerData so we can Enumerate through it
|
|
|
/// Easy access to IEnumerable in playerData so we can Enumerate through it
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
private IEnumerable<PlayerData> playerDataAsArray { get { return playerData.Values; } } |
|
|
|
|
|
|
|
|
private PlayerData[] playerDataAsArray { get { return playerData.Values.ToArray(); } } |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Easy access to GameMode value in CurrentGameMode reference
|
|
|
/// Easy access to GameMode value in CurrentGameMode reference
|
|
@ -80,6 +80,34 @@ public class GameManager : MonoBehaviour |
|
|
} |
|
|
} |
|
|
#endregion Unity Functions
|
|
|
#endregion Unity Functions
|
|
|
|
|
|
|
|
|
|
|
|
private IEnumerator GameRoutine() |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
//Allows game mode to instantiate anything it might need;
|
|
|
|
|
|
gameMode.PreGameStart(); |
|
|
|
|
|
|
|
|
|
|
|
//Spawn Characters and tell let the GameMode do anything with the characters it might want
|
|
|
|
|
|
SpawnCharacters(); |
|
|
|
|
|
gameMode.GameStart(playerDataAsArray); |
|
|
|
|
|
|
|
|
|
|
|
//Loop until the GameMode lets us know the game is over
|
|
|
|
|
|
while (!gameMode.isGameOver(playerDataAsArray)) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
//wait until we have recieved all player input
|
|
|
|
|
|
yield return StartCoroutine(WaitForPlayerInput()); |
|
|
|
|
|
|
|
|
|
|
|
//Routine for players movement
|
|
|
|
|
|
yield return StartCoroutine(RoundRoutine()); //it's pretty long so it gets it's own coroutine;
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Let the gamemode know that the game is over
|
|
|
|
|
|
gameMode.GameEnd(playerDataAsArray); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IEnumerator displayforSeconds(GameObject display, float time) |
|
|
IEnumerator displayforSeconds(GameObject display, float time) |
|
|
{ |
|
|
{ |
|
|
display.SetActive (true); |
|
|
display.SetActive (true); |
|
@ -87,63 +115,58 @@ public class GameManager : MonoBehaviour |
|
|
display.SetActive (false); |
|
|
display.SetActive (false); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void DoRoundRoutine() |
|
|
|
|
|
{ |
|
|
|
|
|
Debug.Log("Starting Round"); |
|
|
|
|
|
StartCoroutine(RoundRoutine()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void StartRound() |
|
|
|
|
|
|
|
|
private IEnumerator WaitForPlayerInput() |
|
|
{ |
|
|
{ |
|
|
gameMode.RoundStart(playerDataAsArray.ToArray()); |
|
|
|
|
|
LogicProtocols.FloatMsg RoundTime = new LogicProtocols.FloatMsg( gameMode.GetRoundTime()); |
|
|
|
|
|
bspawn.Spawn(); |
|
|
|
|
|
|
|
|
LogicProtocols.FloatMsg RoundTime = new LogicProtocols.FloatMsg(gameMode.GetRoundTime()); |
|
|
playerDataAsArray.ForEach(p => p.client.conn.Send(LogicProtocols.SendRoundTime, RoundTime)); |
|
|
playerDataAsArray.ForEach(p => p.client.conn.Send(LogicProtocols.SendRoundTime, RoundTime)); |
|
|
|
|
|
|
|
|
|
|
|
ClientList.ForEach(p => p.ChangeScene("ClientScene")); |
|
|
|
|
|
|
|
|
|
|
|
gameMode.InputStart(playerDataAsArray); |
|
|
|
|
|
yield return new WaitUntil(() => playerData.All(p => p.Value.recievedList)); |
|
|
|
|
|
|
|
|
|
|
|
//reset
|
|
|
|
|
|
playerDataAsArray.ForEach(p => p.recievedList = false); //reset all players list
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gameMode.InputEnd(playerDataAsArray); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private IEnumerator RoundRoutine() |
|
|
private IEnumerator RoundRoutine() |
|
|
{ |
|
|
{ |
|
|
playerDataAsArray.ForEach(p => p.recievedList = false); |
|
|
|
|
|
|
|
|
|
|
|
//Debug.Log("Doing Round Routine");
|
|
|
|
|
|
|
|
|
//Tell the gamemode that we are starting a round
|
|
|
|
|
|
gameMode.RoundStart(playerDataAsArray); |
|
|
|
|
|
|
|
|
|
|
|
//Loop until all players have finished moving
|
|
|
while (playerDataAsArray.Any(p => !p.blockReader.Finished)) |
|
|
while (playerDataAsArray.Any(p => !p.blockReader.Finished)) |
|
|
{ |
|
|
{ |
|
|
//Debug.Log("One Move");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Loop through all players
|
|
|
foreach (PlayerData player in playerDataAsArray) |
|
|
foreach (PlayerData player in playerDataAsArray) |
|
|
{ |
|
|
{ |
|
|
Debug.Log(player.client.Name); |
|
|
|
|
|
StartCoroutine(RunOnce(player)); |
|
|
|
|
|
yield return new WaitUntil(() => player.waiting); |
|
|
|
|
|
|
|
|
yield return StartCoroutine(MoveRoutine(player));//Move Player
|
|
|
|
|
|
gameMode.PlayerMoved(player);//LetGameModeKnow
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Let Gamemode know all players have moved
|
|
|
|
|
|
gameMode.AllPlayersMoved(playerDataAsArray.ToArray()); |
|
|
|
|
|
playerDataAsArray.ForEach(p => p.client.SendScore()); //Update the players score
|
|
|
|
|
|
|
|
|
//wait until all players have finished
|
|
|
|
|
|
//yield return new WaitUntil(() => playerArray.All(p => p.waiting));
|
|
|
|
|
|
|
|
|
|
|
|
gameMode.FinishedMove(playerDataAsArray.ToArray()); |
|
|
|
|
|
playerDataAsArray.ForEach(p => p.client.SendScore()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if Game is over break out of loop
|
|
|
|
|
|
if (gameMode.isGameOver(playerDataAsArray)) |
|
|
|
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (gameMode.isGameOver(playerDataAsArray.ToArray())) |
|
|
|
|
|
{ |
|
|
|
|
|
Debug.Log("Game Over"); |
|
|
|
|
|
SceneManager.LoadScene("ScoreBoards"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Let GameMode know that Round is Over
|
|
|
gameMode.RoundEnd(playerDataAsArray.ToArray()); |
|
|
gameMode.RoundEnd(playerDataAsArray.ToArray()); |
|
|
|
|
|
|
|
|
|
|
|
//Reset some player Data
|
|
|
foreach (PlayerData player in playerDataAsArray) |
|
|
foreach (PlayerData player in playerDataAsArray) |
|
|
{ |
|
|
{ |
|
|
player.blockReader.Reset(); |
|
|
player.blockReader.Reset(); |
|
|
player.waiting = false; |
|
|
|
|
|
player.client.SendInventory(); |
|
|
player.client.SendInventory(); |
|
|
player.client.ChangeScene("ClientScene"); |
|
|
|
|
|
} |
|
|
} |
|
|
//Debug.Log("Finished Moving");
|
|
|
|
|
|
|
|
|
|
|
|
StartRound(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void SpawnCharacters() |
|
|
private void SpawnCharacters() |
|
@ -223,28 +246,30 @@ public class GameManager : MonoBehaviour |
|
|
|
|
|
|
|
|
#endregion Networking Functions
|
|
|
#endregion Networking Functions
|
|
|
|
|
|
|
|
|
private IEnumerator RunOnce(PlayerData data) |
|
|
|
|
|
|
|
|
private IEnumerator MoveRoutine(PlayerData data) |
|
|
{ |
|
|
{ |
|
|
data.waiting = false; |
|
|
|
|
|
bool blockFinished = false; |
|
|
bool blockFinished = false; |
|
|
float waitTime; |
|
|
float waitTime; |
|
|
|
|
|
|
|
|
|
|
|
//Loop until the current block indicates or the reader indicates it has finished
|
|
|
while (!blockFinished && !data.blockReader.Finished) |
|
|
while (!blockFinished && !data.blockReader.Finished) |
|
|
{ |
|
|
{ |
|
|
//Debug.Log(data.client + "Moving once");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//If the current block hasn't already been removed, remove it from the player inventory
|
|
|
|
|
|
//We need to check if it has already been removed so loops don't eat an entire stack
|
|
|
if (data.blockReader.CurrentBlock != null && !data.blockReader.CurrentBlock.hasBeenRemoved) |
|
|
if (data.blockReader.CurrentBlock != null && !data.blockReader.CurrentBlock.hasBeenRemoved) |
|
|
{ |
|
|
{ |
|
|
data.client.Inventory.Remove(data.blockReader.CurrentBlock); |
|
|
data.client.Inventory.Remove(data.blockReader.CurrentBlock); |
|
|
data.blockReader.CurrentBlock.hasBeenRemoved = true; |
|
|
data.blockReader.CurrentBlock.hasBeenRemoved = true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Process the move
|
|
|
blockFinished = data.blockReader.Read(data.character, AnimationTime,out waitTime); |
|
|
blockFinished = data.blockReader.Read(data.character, AnimationTime,out waitTime); |
|
|
|
|
|
|
|
|
//Debug.Log("Waiting: " + waitTime);
|
|
|
|
|
|
|
|
|
//Wait for the animation to finish
|
|
|
yield return new WaitForSeconds(waitTime); |
|
|
yield return new WaitForSeconds(waitTime); |
|
|
gameMode.OnePlayerMoved(data); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
data.waiting = true; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -255,7 +280,6 @@ public class PlayerData |
|
|
public ClientData client; |
|
|
public ClientData client; |
|
|
|
|
|
|
|
|
public bool recievedList; |
|
|
public bool recievedList; |
|
|
public bool waiting; |
|
|
|
|
|
|
|
|
|
|
|
public PlayerData(Character character, ClientData client) |
|
|
public PlayerData(Character character, ClientData client) |
|
|
{ |
|
|
{ |
|
|