private void refreshAvailabeNewArmy() { AvailabeNewArmy = Math.Max(3, (int)(playerManager.GetPlayer(ActivePlayerId).CountryNum / 1.5)); }
public void UpdateMessage(StateManager stateManager, PlayerManager playerManager, RiskMap map) { this.stateManager = stateManager; //TODO: stupid... string msg; switch (stateManager.State) { case GameState.ChooseCountry: msg = "Pick one country. "; break; case GameState.AddArmy: msg = "Add your army! (" + stateManager.AvailabeNewArmy.ToString() + " left)"; break; case GameState.AttackChooseSource: msg = "Choose your army to attack! "; break; case GameState.AttackChooseDest: msg = "Where will you attack? "; break; case GameState.AttackPickArmy: msg = "Pick more army to defense your new territory!"; break; default: msg = null; break; } if (stateManager.State == GameState.AttackWaitDice) { Player attacker = playerManager.GetPlayer(stateManager.ActivePlayerId); Player defender = playerManager.GetPlayer(map.GetArmyViz(stateManager.AttackDest).PlayerId); string attackerDice = stateManager.AttackerMaxDiceNum > 1 ? "dices" : "dice"; string defenderDice = stateManager.DefenderMaxDiceNum > 1 ? "dices" : "dice"; msgTextBlock.Text = string.Format("Player {0}: Throw {1} {2}! \n Player {3}: Throw {4} {5}! ", attacker.PlayerId, stateManager.AttackerMaxDiceNum, attackerDice, defender.PlayerId, stateManager.DefenderMaxDiceNum, defenderDice); msgTextBlock.Foreground = new SolidColorBrush(attacker.MainColor); } else if (stateManager.State == GameState.AttackAnimation) { Player attacker = playerManager.GetPlayer(stateManager.ActivePlayerId); Player defender = playerManager.GetPlayer(map.GetArmyViz(stateManager.AttackDest).PlayerId); msgTextBlock.Text = string.Format("Player {0}: {1} Lost; Player {2}: {3} Lost. \n Battle {4}!", attacker.PlayerId, stateManager.AttackerLost, defender.PlayerId, stateManager.DefenderLost, stateManager.IsAttackerWin ? "Win" : "Failed"); msgTextBlock.Foreground = new SolidColorBrush(attacker.MainColor); } else if (msg != null) { Player player = playerManager.GetPlayer(stateManager.ActivePlayerId); msgTextBlock.Text = "Player " + player.PlayerId + ": \n" + msg; msgTextBlock.Foreground = new SolidColorBrush(player.MainColor); } else { msgTextBlock.Text = ""; } if (msgTextBlock.Text.Length == 0) { msgTextBlock.Opacity = 0; } else { msgTextBlock.Opacity = 1; //animation double inTime = 0.5, holdTime = 4, outTime = 0.5; DoubleAnimation opacityInAnim = new DoubleAnimation(0, 1, new Duration(TimeSpan.FromSeconds(inTime))); DoubleAnimation motionInAnim = new DoubleAnimation(-20, 0, new Duration(TimeSpan.FromSeconds(inTime))); DoubleAnimation opacityOutAnim = new DoubleAnimation(1, 0, new Duration(TimeSpan.FromSeconds(outTime))) { BeginTime = TimeSpan.FromSeconds(inTime + holdTime) }; DoubleAnimation motionOutAnim = new DoubleAnimation(0, 10, new Duration(TimeSpan.FromSeconds(outTime))) { BeginTime = TimeSpan.FromSeconds(inTime + holdTime) }; motionOutAnim.Completed += new EventHandler(motionOutAnim_Completed); msgTextBlock.BeginAnimation(TextBlock.OpacityProperty, opacityInAnim, HandoffBehavior.SnapshotAndReplace); textMotionTrans.BeginAnimation(TranslateTransform.YProperty, motionInAnim, HandoffBehavior.SnapshotAndReplace); if (stateManager.State == GameState.AttackAnimation) { msgTextBlock.BeginAnimation(TextBlock.OpacityProperty, opacityOutAnim, HandoffBehavior.Compose); textMotionTrans.BeginAnimation(TranslateTransform.YProperty, motionOutAnim, HandoffBehavior.Compose); } } }
private void refreshViews() { playerInfo1.Update(playerManager.GetPlayer(1), stateManager.ActivePlayerId == 1); playerInfo2.Update(playerManager.GetPlayer(2), stateManager.ActivePlayerId == 2); //udpate messages msgControl.UpdateMessage(stateManager, playerManager, riskMap); //update buttons ControlButton activeButtons = stateManager.ActivePlayerId == 1 ? controlButton1 : controlButton2; ControlButton inactiveButtons = stateManager.ActivePlayerId == 1 ? controlButton2 : controlButton1; activeButtons.HideAllButtons(); switch (stateManager.State) { case GameState.AttackChooseSource: activeButtons.NextButtonVisible = true; break; case GameState.AttackChooseDest: case GameState.AttackWaitDice: activeButtons.CancelButtonVisible = true; break; default: activeButtons.HideAllButtons(); break; } inactiveButtons.HideAllButtons(); //stop attacking if (stateManager.State == GameState.AttackChooseSource && stateManager.AttackSource != null) { riskMap.GetArmyViz(stateManager.AttackSource).IsAttacking = false; } //attack line if (stateManager.State == GameState.AttackWaitDice && !stateManager.IsErrored) { riskMap.DrawAttackLine(stateManager.AttackSource, stateManager.AttackDest); } else if (stateManager.State != GameState.AttackWaitDice) { riskMap.HideAttackLine(); } //wizardOz if (stateManager.State == GameState.AttackWaitDice) { wizardOzWindow.RequestDice(); } //dice viz if (stateManager.State != GameState.AttackWaitDice || stateManager.IsErrored) { diceViz.ClearDices(); } //card CardHolder cardHolder = stateManager.ActivePlayerId == 1 ? cardHolder1 : cardHolder2; if (stateManager.State == GameState.AddArmy && previousState != GameState.AddArmy) { cardHolder.Show(); wizardOzWindow.RequestCard(); } else if (stateManager.State == GameState.AttackChooseSource) { cardHolder.Hide(); wizardOzWindow.CancelCard(); } previousState = stateManager.State; }
public void UpdateMessage(StateManager stateManager, PlayerManager playerManager, RiskMap map) { this.stateManager = stateManager; //TODO: stupid... string msg; switch (stateManager.State) { case GameState.ChooseCountry: msg = "Pick one country. "; break; case GameState.AddArmy: msg = "Add your army! (" + stateManager.AvailabeNewArmy.ToString() + " left)"; break; case GameState.AttackChooseSource: msg = "Choose your army to attack! "; break; case GameState.AttackChooseDest: msg = "Where will you attack? "; break; case GameState.AttackPickArmy: msg = "Pick more army to defense your new territory!"; break; default: msg = null; break; } if (stateManager.State == GameState.AttackWaitDice) { Player attacker = playerManager.GetPlayer(stateManager.ActivePlayerId); Player defender = playerManager.GetPlayer(map.GetArmyViz(stateManager.AttackDest).PlayerId); string attackerDice = stateManager.AttackerMaxDiceNum > 1 ? "dices" : "dice"; string defenderDice = stateManager.DefenderMaxDiceNum > 1 ? "dices" : "dice"; msgTextBlock.Text = string.Format("Player {0}: Throw {1} {2}! \n Player {3}: Throw {4} {5}! ", attacker.PlayerId, stateManager.AttackerMaxDiceNum, attackerDice, defender.PlayerId, stateManager.DefenderMaxDiceNum, defenderDice); msgTextBlock.Foreground = new SolidColorBrush(attacker.MainColor); } else if (stateManager.State == GameState.AttackAnimation) { Player attacker = playerManager.GetPlayer(stateManager.ActivePlayerId); Player defender = playerManager.GetPlayer(map.GetArmyViz(stateManager.AttackDest).PlayerId); msgTextBlock.Text = string.Format("Player {0}: {1} Lost; Player {2}: {3} Lost. \n Battle {4}!", attacker.PlayerId, stateManager.AttackerLost, defender.PlayerId, stateManager.DefenderLost, stateManager.IsAttackerWin ? "Win" : "Failed"); msgTextBlock.Foreground = new SolidColorBrush(attacker.MainColor); } else if (msg != null) { Player player = playerManager.GetPlayer(stateManager.ActivePlayerId); msgTextBlock.Text = "Player " + player.PlayerId + ": \n" + msg; msgTextBlock.Foreground = new SolidColorBrush(player.MainColor); } else { msgTextBlock.Text = ""; } if (msgTextBlock.Text.Length == 0) { msgTextBlock.Opacity = 0; } else { msgTextBlock.Opacity = 1; //animation double inTime = 0.5, holdTime = 4, outTime = 0.5; DoubleAnimation opacityInAnim = new DoubleAnimation(0, 1, new Duration(TimeSpan.FromSeconds(inTime))); DoubleAnimation motionInAnim = new DoubleAnimation(-20, 0, new Duration(TimeSpan.FromSeconds(inTime))); DoubleAnimation opacityOutAnim = new DoubleAnimation(1, 0, new Duration(TimeSpan.FromSeconds(outTime))) { BeginTime = TimeSpan.FromSeconds(inTime + holdTime) }; DoubleAnimation motionOutAnim = new DoubleAnimation(0, 10, new Duration(TimeSpan.FromSeconds(outTime))) { BeginTime = TimeSpan.FromSeconds(inTime + holdTime) }; motionOutAnim.Completed += new EventHandler(motionOutAnim_Completed); msgTextBlock.BeginAnimation(TextBlock.OpacityProperty, opacityInAnim, HandoffBehavior.SnapshotAndReplace); textMotionTrans.BeginAnimation(TranslateTransform.YProperty, motionInAnim, HandoffBehavior.SnapshotAndReplace); if (stateManager.State == GameState.AttackAnimation) { msgTextBlock.BeginAnimation(TextBlock.OpacityProperty, opacityOutAnim, HandoffBehavior.Compose); textMotionTrans.BeginAnimation(TranslateTransform.YProperty, motionOutAnim, HandoffBehavior.Compose); } } }