public void StartGame() { gameDesktop = new GameDesktop(); _player = new Player(); _enemy = new AINormal(); _player.OnThrow += (card) => gameDesktop.ThrowCard(PlayerType.Player, card); _player.OnPass += () => gameDesktop.Pass(PlayerType.Player); _player.OnGetAll += () => gameDesktop.GetAll(PlayerType.Player); _enemy.OnThrow += (card) => gameDesktop.ThrowCard(PlayerType.Enemy, card); _enemy.OnPass += () => gameDesktop.Pass(PlayerType.Enemy); _enemy.OnGetAll += () => gameDesktop.GetAll(PlayerType.Enemy); GameDesktop.OnDeckCreated += () => SpriteManager.ResetCardsOnWindow(GameDesktop.GetGameData().Deck);; GameDesktop.OnCardsHandOut += () => { RenewWindowHandler(); }; GameDesktop.OnThrowCard += (a, b) => { RenewWindowHandler(); }; GameDesktop.OnPass += (a) => { RenewWindowHandler(); }; GameDesktop.OnGetAll += (a) => { RenewWindowHandler(); }; GameDesktop.OnWhoseTurnChanged += (playerType) => { _player.GamePackage = gameDesktop.GetGameData(); _enemy.GamePackage = gameDesktop.GetGameData(); if (playerType == PlayerType.Player) { _player.TakeTheBaton(); } if (playerType == PlayerType.Enemy) { _enemy.TakeTheBaton(); } }; GameDesktop.OnActionRefused += (gameAction, gameError, message) => { MessageBox.Show(message); }; GameDesktop.OnGameError += (gameError, message) => { MessageBox.Show(message); }; GameDesktop.OnGameFinished += (result) => { string message = ""; switch (result) { case GameResult.Win: message = "Вы выиграли!"; break; case GameResult.Loose: message = "Вы проиграли :("; break; case GameResult.Draw: message = "Ничья."; break; default: message = "Что-то пошло не так.."; break; } if (OnGameFinished != null) { OnGameFinished(message); } }; // Connect UI and player instance SpriteManager.OnPlayerCardThrow = _player.Throw; SpriteManager.OnGameButtonClicked = (btnType) => { switch (btnType) { case ButtonType.Pass: case ButtonType.PassHovered: _player.Pass(); break; case ButtonType.GetAll: case ButtonType.GetAllHovered: _player.GetAll(); break; default: break; } }; // There we start game in game desktop GameDesktop.StartGame(); }
public void StartGame() { gameDesktop = new GameDesktop(); _player = new Player(); _enemy = new AINormal(); _player.OnThrow += (card) => gameDesktop.ThrowCard(PlayerType.Player, card); _player.OnPass += () => gameDesktop.Pass(PlayerType.Player); _player.OnGetAll += () => gameDesktop.GetAll(PlayerType.Player); _enemy.OnThrow += (card) => gameDesktop.ThrowCard(PlayerType.Enemy, card); _enemy.OnPass += () => gameDesktop.Pass(PlayerType.Enemy); _enemy.OnGetAll += () => gameDesktop.GetAll(PlayerType.Enemy); GameDesktop.OnDeckCreated += () => SpriteManager.ResetCardsOnWindow(GameDesktop.GetGameData().Deck); ; GameDesktop.OnCardsHandOut += () => { RenewWindowHandler(); }; GameDesktop.OnThrowCard += (a, b) => { RenewWindowHandler(); }; GameDesktop.OnPass += (a) => { RenewWindowHandler(); }; GameDesktop.OnGetAll += (a) => { RenewWindowHandler(); }; GameDesktop.OnWhoseTurnChanged += (playerType) => { _player.GamePackage = gameDesktop.GetGameData(); _enemy.GamePackage = gameDesktop.GetGameData(); if (playerType == PlayerType.Player) _player.TakeTheBaton(); if (playerType == PlayerType.Enemy) _enemy.TakeTheBaton(); }; GameDesktop.OnActionRefused += (gameAction, gameError, message) => { MessageBox.Show(message); }; GameDesktop.OnGameError += (gameError, message) => { MessageBox.Show(message); }; GameDesktop.OnGameFinished += (result) => { string message = ""; switch (result) { case GameResult.Win: message = "Вы выиграли!"; break; case GameResult.Loose: message = "Вы проиграли :("; break; case GameResult.Draw: message = "Ничья."; break; default: message = "Что-то пошло не так.."; break; } if (OnGameFinished != null) OnGameFinished(message); }; // Connect UI and player instance SpriteManager.OnPlayerCardThrow = _player.Throw; SpriteManager.OnGameButtonClicked = (btnType) => { switch (btnType) { case ButtonType.Pass: case ButtonType.PassHovered: _player.Pass(); break; case ButtonType.GetAll: case ButtonType.GetAllHovered: _player.GetAll(); break; default: break; } }; // There we start game in game desktop GameDesktop.StartGame(); }
private void RenewWindowHandler(PlayerType playerType) { _player.GamePackage = gameDesktop.GetGameData(); _enemy.GamePackage = gameDesktop.GetGameData(); SpriteManager.RenewWindowPackage(GameDesktop.GetGameData()); }