/// <summary> /// Send current gameState /// </summary> private void BroadcastGameboard() { var gs = GameManager.Export(); OthelloPlayer1.UpdateGameboard(gs); OthelloPlayer2.UpdateGameboard(gs); }
private void GameManager_OnGameFinished(object sender, GameState gameState) { var gameManager = sender as GameManager; // Send the final state BroadcastGameboard(); // Notifiy the end of the game OthelloPlayer1.GameEnded(); OthelloPlayer2.GameEnded(); }
/// <summary> /// Start the game /// </summary> private void StartGame() { // Start the game GameManager.Start(); // Get initial gameState var gs = GameManager.Export(); // Informs the players that the game is starting OthelloPlayer1.GameStarted(gs); OthelloPlayer2.GameStarted(gs); }
public void Init() { // Init gameManager GameManager = new GameManager(); GameManager.OnGameFinished += GameManager_OnGameFinished; // Update clients OthelloPlayer1.SetColor(Color.Black); OthelloPlayer1.SetAvatarID(0); OthelloPlayer2.SetColor(Color.White); OthelloPlayer2.SetAvatarID(19); // Game is ready OthelloPlayer1.GameReady(); OthelloPlayer2.GameReady(); }
/// <summary> /// Send avatardID from both client after this function /// </summary> /// <param name="game"></param> public void Load(SaveFile saveFile) { // Init gameManager GameManager = new GameManager(); GameManager.OnGameFinished += GameManager_OnGameFinished; // Load the game GameManager.Load(saveFile.States); // Update clients OthelloPlayer1.SetColor((Color)saveFile.Player1Color); OthelloPlayer1.SetAvatarID(saveFile.Player1AvatarID); OthelloPlayer2.SetColor((Color)saveFile.Player2Color); OthelloPlayer2.SetAvatarID(saveFile.Player2AvatarID); // Notify clients of opponent avatar OthelloPlayer1.OpponentAvatarChanged(saveFile.Player2AvatarID); OthelloPlayer2.OpponentAvatarChanged(saveFile.Player1AvatarID); // Immediatly start the game StartGame(); }