public void Surrender() { if (NI.IsConnected) { CommandParser.SendCommandToGameServer(new string[] { "SURRENDER" }); } }
public void Update(ref bool IsMouseHandled, Map TiledMap, Camera cam, float CardAppearPos, bool IsPlayerTurn, MapZones PlayerZone, GameState state, int PlayerMoney) { ChooseArrow.Update(); for (var i = 0; i < KilledNonTargetCards.Count; i++) { if (KilledNonTargetCards[i] != null) { if (KilledNonTargetCards[i].CurrAnimName == "NONE") { KilledNonTargetCards.RemoveAt(i); i--; } else { KilledNonTargetCards[i].UpdateAnims(); } } } if (_ChoosedCard == -1) { for (var i = 0; i < Cards.Count; i++) { if (Cards[i] != null) { Cards[i].MoveUpdate(); Cards[i].UpdateAnims(); if (!IsMouseHandled && Cards[i].Update() != ButtonStates.NONE) { IsMouseHandled = true; _ChoosedCard = i; } else { Cards[i].StopAnimation(true); //Cards[i].IterationReset(); Cards[i].Down(); } } } } else if (Cards[_ChoosedCard] != null) { IsMouseHandled = true; for (var i = 0; i < Cards.Count; i++) { Cards[i].MoveUpdate(); Cards[i].UpdateAnims(); } if (MouseControl.IsLeftBtnClicked) { if (IsClick) { IsClick = false; Cards[_ChoosedCard].IsPressed = false; } else { IsClick = true; Cards[_ChoosedCard].IsPressed = true; } } var Upd = Cards[_ChoosedCard].Update(); if (IsPlayerTurn && (IsClick || Upd == ButtonStates.PRESSED)) { CalculateCardPosition(10, true, _ChoosedCard); Cards[_ChoosedCard].Down(); Cards[_ChoosedCard].SetUpLayer(); Cards[_ChoosedCard].Position = new Vector2(MouseControl.X - (Cards[_ChoosedCard].FrameSize.X * 0.25f), MouseControl.Y - (Cards[_ChoosedCard].FrameSize.Y * 0.25f)); if (MouseControl.Y < CardAppearPos) { IsMouseHandled = false; if (Cards[_ChoosedCard].IsTargeted) { if (!TiledMap.IsAnimsChanged) { TiledMap.ChangeTilesAnims(2, 1, new Animation(1, 1, true), TiledMap.GetTilesByAllowedZones(Cards[_ChoosedCard].AllowedZones, Cards[_ChoosedCard].AllowedTiles)); } Cards[_ChoosedCard].Disappear(); ChooseArrow.Appear(); ChooseArrow.BeginPoint = new Vector2((300 + CurrentScreenRes.X) / 2, CurrentScreenRes.Y + 20); ChooseArrow.EndPoint = new Vector2(MouseControl.X, MouseControl.Y); } else { Cards[_ChoosedCard].PlayAnimation("Choosed"); } } else { if (Cards[_ChoosedCard].IsTargeted) { TiledMap.SetDefault(); ChooseArrow.Disappear(); Cards[_ChoosedCard].Appear(); Cards[_ChoosedCard].IsDisappearing = false; } else { Cards[_ChoosedCard].CurrentFrame = 0; } } } else if (Upd != ButtonStates.NONE) { if (Upd == ButtonStates.CLICKED) { Cards[_ChoosedCard].Down(); if (Cards[_ChoosedCard].IsTargeted) { ChooseArrow.Disappear(); Cards[_ChoosedCard].Appear(); Cards[_ChoosedCard].IsDisappearing = false; } else { Cards[_ChoosedCard].StopAnimation(true); } if (MouseControl.Y < CardAppearPos) { var Tmp = TiledMap.GetTileIJByCoords(MouseControl.MouseToWorldCoords(cam)); Tile TmpTile; if (Tmp != null) { TmpTile = TiledMap.GetTile(Tmp[0], Tmp[1]); } else { TmpTile = null; } if (Cards[_ChoosedCard].IsTargeted) { if (TmpTile != null && PlayerMoney >= Convert.ToInt32(Cards[_ChoosedCard].MoneyInfo.Text) && TiledMap.CheckTileAllowed(new Point(Tmp[0], Tmp[1]), PlayerZone, Cards[_ChoosedCard].AllowedTiles)) //DONE: Убрать костыль TmpTile.NotSelectedFrame != 0, ввести тип Player для поиска правильной стороны { //TEST: Юниты //TmpTile.SpawnUnit(new Unit(Vector2.Zero, GameContent.UnitTextures[0], GameContent.UI_Info_Allied, GameContent.UI_InfoFont, Color.White, 392, 20, 5, 3, 6, 1, 2, Side.PLAYER, AttScript, ScrForUnit, new Point(Tmp[0], Tmp[1]), new Animation(8, 17, false), 0.4f), MapZones.RIGHT, TiledMap.UI_VisibleState); CommandParser.SendCommandToGameServer(new string[] { "SPAWN", _ChoosedCard.ToString(), Tmp[0].ToString(), Tmp[1].ToString() }); state.SetEnemyTurn(); Cards.RemoveAt(_ChoosedCard); } else { CalculateCardPosition(10, true); } } else { Cards[_ChoosedCard].StopAnimation(true); KilledNonTargetCards.Add(new Card(Cards[_ChoosedCard])); KilledNonTargetCards.Last().Disappear(); Cards.RemoveAt(_ChoosedCard); } TiledMap.SetDefault(); } else { CalculateCardPosition(10, true); } _ChoosedCard = -1; } } else { Cards[_ChoosedCard].Down(); //Cards[_ChoosedCard].IterationReset(); _ChoosedCard = -1; } } }
public void Update(ref bool IsMouseHandled, Map map, Hand hand, Camera cam, GameMenu Menu, MapZones Opponent) { EnemyTurnMoveProcess(); Br.UpdateAnims(); if (_IsEndGame) { if (iteration < 300) { iteration++; if (iteration >= 60 && iteration < 90) { EndGame.Visible = true; EndGame.Scale -= new Vector2(0.0333f); } } else { if (iteration == 300) { Parent.EndGame(); iteration++; } } } else if (_IsVs) { Cardchoose.Update(); if (ChooseConfirm.Update() == ButtonStates.CLICKED) { Parent.IsNotLockClick = false; ChooseConfirm.Visible = false; var replacedcards = Cardchoose.GetReplacedCards(); var command = new List <string>(); for (var i = 0; i < replacedcards.Length; i++) { if (replacedcards[i] == true) { command.Add(i.ToString()); } } if (command.Count == 0) { command.Add("NONE"); } CommandParser.SendCommandToGameServer(command.ToArray()); } IsMouseHandled = true; if (iteration < 120) { if (IsStartVs && iteration > 80) { PlayerIcon.Position += new Vector2((_DestinationPointPlayer.X - PlayerIcon.Position.X) / 8, 0); OpponentIcon.Position -= new Vector2((OpponentIcon.Position.X - _DestinationPointOpponent.X) / 8, 0); PlayerName.Position = new Vector2(PlayerIcon.Position.X + PlayerIcon.Texture.Width / 2 * PlayerIcon.Scale.X - PlayerName.Font.MeasureString(PlayerName.Text).X, PlayerIcon.Position.Y + PlayerIcon.Texture.Height * PlayerIcon.Scale.Y); OpponentName.Position = new Vector2(OpponentIcon.Position.X + OpponentIcon.Texture.Width / 2 * OpponentIcon.Scale.X - OpponentName.Font.MeasureString(OpponentName.Text).X, OpponentIcon.Position.Y + OpponentIcon.Texture.Height * OpponentIcon.Scale.Y); } if (IsStopVs && iteration > 80) { PlayerIcon.Position -= _TmpPlDistance; OpponentIcon.Position -= _TmpOpDistance; PlayerIcon.Scale -= _TmpIconScale; OpponentIcon.Scale -= _TmpIconScale; PlayerName.Position -= _TmpPlNameDistance; OpponentName.Position -= _TmpOpNameDistance; PlayerName.Scale -= _TmpTextScale; OpponentName.Scale -= _TmpTextScale; Vs.Visible = false; } if (iteration == 119) { if (IsStartVs) { IsStartVs = false; StopVS(); } else if (IsStopVs) { IsStopVs = false; PlayerIcon.Position = Vector2.Zero; OpponentIcon.Position = new Vector2(_CurrentScreenRes.X - OpponentIcon.Texture.Width * OpponentIcon.Scale.X, 0); PlayerIcon.Scale = new Vector2(0.4f); OpponentIcon.Scale = new Vector2(0.4f); PlayerName.Scale = Vector2.One; OpponentName.Scale = Vector2.One; PlayerName.Position = PlayerIcon.Position + new Vector2(PlayerIcon.Texture.Width * PlayerIcon.Scale.X + 10, 0); OpponentName.Position = OpponentIcon.Position - new Vector2(OpponentName.Font.MeasureString(OpponentName.Text).X + 10, 0); ChooseText.Visible = true; ChooseOrderText.Visible = true; ChooseConfirm.Visible = true; var Cards = new Card[ShowingCards.Length]; for (var i = 0; i < ShowingCards.Length; i++) { Cards[i] = new Card(Vector2.One, GameContent.CardTexture, GameContent.UnitCards[ShowingCards[i]].Card_Decoration, new Vector2(16, 9), 200, 10, 0, 13, new Animation(14, 16, true), new Animation(2, 6, false), new Animation(7, 12, false), new Animation(1, 1, true), 0, GameContent.UI_InfoFont, Color.White, GameContent.UnitCards[ShowingCards[i]].Name, GameContent.UnitCards[ShowingCards[i]].Damage.ToString(), GameContent.UnitCards[ShowingCards[i]].Armor.ToString(), GameContent.UnitCards[ShowingCards[i]].AttackRadius.ToString(), GameContent.UnitCards[ShowingCards[i]].Speed.ToString(), GameContent.UnitCards[ShowingCards[i]].HP.ToString(), GameContent.UnitCards[ShowingCards[i]].Cost.ToString(), 141, 315, 4, 4, 37, true, Parent.PlayerSide, Layer: 0.001f); } Cardchoose.ShowCards(true, Cards); } else { _IsVs = false; ChooseText.Visible = false; ChooseOrderText.Visible = false; ChooseText.Text = "Выберите карту"; ChooseText.Position = new Vector2((CurrentScreenRes.X - ChooseText.Font.MeasureString(ChooseText.Text).X) / 2, CurrentScreenRes.Y / 2 - 250); hand.AddCards(20, Cardchoose.GetCards(true).ToArray()); Cardchoose.ClearCardList(); Br.ScreenBrUp(); } } iteration++; } } else if (IsPlayerTurnStarted) { if (iteration < 100) { NewTurnText.Update(); if (iteration == 79) { NewTurnText.Disappear(); } iteration++; } else { if (!IsPlayerTurnCardShown) { IsPlayerTurnCardShown = true; ChooseText.Visible = true; var Cards = new Card[ShowingCards.Length]; for (var i = 0; i < ShowingCards.Length; i++) { Cards[i] = new Card(Vector2.One, GameContent.CardTexture, GameContent.UnitCards[ShowingCards[i]].Card_Decoration, new Vector2(16, 9), 200, 10, 0, 13, new Animation(14, 16, true), new Animation(2, 6, false), new Animation(7, 12, false), new Animation(1, 1, true), 0, GameContent.UI_InfoFont, Color.White, GameContent.UnitCards[ShowingCards[i]].Name, GameContent.UnitCards[ShowingCards[i]].Damage.ToString(), GameContent.UnitCards[ShowingCards[i]].Armor.ToString(), GameContent.UnitCards[ShowingCards[i]].AttackRadius.ToString(), GameContent.UnitCards[ShowingCards[i]].Speed.ToString(), GameContent.UnitCards[ShowingCards[i]].HP.ToString(), GameContent.UnitCards[ShowingCards[i]].Cost.ToString(), 141, 315, 4, 4, 37, true, Parent.PlayerSide, Layer: 0.001f); } Cardchoose.ShowCards(false, Cards); } var Upd = Cardchoose.Update(); if (Upd != -1) { Cardchoose.Enabled = false; //Отправить на серв данные CommandParser.SendCommandToGameServer(new string[] { "CHOOSE", Upd.ToString() }); } } } else { if (!IsMouseHandled) { if (MouseControl.X < UI_BottomLeft.Texture.Width) { if (MouseControl.Y > _CurrentScreenRes.Y - UI_BottomLeft.Texture.Height) { IsMouseHandled = true; } } else if (MouseControl.Y > _CurrentScreenRes.Y - UI_Bottom.Texture.Height) { IsMouseHandled = true; } else if (MouseControl.Y < UI_UpLeft.Texture.Height) { IsMouseHandled = true; } } var MoveUpd = Btn_Move.Update(); var AttackUpd = Btn_Attack.Update(); var EndTurnUpd = Btn_EndTurn.Update(); var StatsUpd = Btn_Stats.Update(); var ChatUpd = Btn_Chat.Update(); var GameMenuUpd = Btn_GameMenu.Update(); _ShowInf = false; if (!(map.IsPathFinding || map.IsAttack)) { Btn_EndTurn.Enabled = true; if (!map.IsPathFinding) { Btn_Attack.Enabled = true; } if (!map.IsAttack) { Btn_Move.Enabled = true; } for (var i = 0; i < hand.CardsCount; i++) { hand[i].Enabled = true; } } else { for (var i = 0; i < hand.CardsCount; i++) { hand[i].Enabled = false; } } if ((MoveUpd == ButtonStates.CLICKED || (Btn_Move.Enabled && KeyBindings.CheckKeyReleased("KEY_MOVEUNIT"))) && map.SelectedTile.X != -1) { if (map.IsPathFinding) { map.IsPathFinding = false; map.SetDefault(); map.UpdateAllTiles(cam); map.CreatePathArrows(null, cam); } else if ((map.GetTile(map.SelectedTile.X, map.SelectedTile.Y).TileContains == MapTiles.WITH_UNIT || map.GetTile(map.SelectedTile.X, map.SelectedTile.Y).TileContains == MapTiles.WITH_UNIT_AND_BUILDING) && map.GetTile(map.SelectedTile.X, map.SelectedTile.Y).UnitOnTile.side == Side.PLAYER) { Btn_Attack.Enabled = false; Btn_EndTurn.Enabled = false; map.IsPathFinding = true; map.ActionStartPoint = new Point(map.SelectedTile.X, map.SelectedTile.Y); map.HighLiteTilesWithPF(Opponent); map.UpdateAllTiles(cam); } } else if (MoveUpd == ButtonStates.ENTERED) { Inf.Appear(); Inf.Text = "Перемещение/ближний бой"; _ShowInf = true; } if ((AttackUpd == ButtonStates.CLICKED || (Btn_Attack.Enabled && KeyBindings.CheckKeyReleased("KEY_ATTACKUNIT"))) && map.SelectedTile.X != -1) { if (map.IsAttack) { map.IsAttack = false; map.SetDefault(); map.UpdateAllTiles(cam); map.CreatePathArrows(null, cam); } else if ((map.GetTile(map.SelectedTile.X, map.SelectedTile.Y).TileContains == MapTiles.WITH_UNIT || map.GetTile(map.SelectedTile.X, map.SelectedTile.Y).TileContains == MapTiles.WITH_UNIT_AND_BUILDING) && map.GetTile(map.SelectedTile.X, map.SelectedTile.Y).UnitOnTile.side == Side.PLAYER && map.GetTile(map.SelectedTile.X, map.SelectedTile.Y).UnitOnTile.CanAttack) { Btn_EndTurn.Enabled = false; Btn_Move.Enabled = false; map.IsAttack = true; map.ActionStartPoint = new Point(map.SelectedTile.X, map.SelectedTile.Y); map.HighLiteTilesWithEnemy(); map.UpdateAllTiles(cam); } } else if (AttackUpd == ButtonStates.ENTERED) { Inf.Appear(); Inf.Text = "Дальняя атака"; _ShowInf = true; } if (StatsUpd == ButtonStates.CLICKED || KeyBindings.CheckKeyReleased("KEY_STATS")) { if (map.UI_VisibleState) { map.HideUnitStats(); } else { map.ShowUnitStats(); } } else if (StatsUpd == ButtonStates.ENTERED) { Inf.Appear(); Inf.Text = "Скрыть/показать\n характ. юнитов"; _ShowInf = true; } if (ChatUpd == ButtonStates.ENTERED) { Inf.Appear(); Inf.Text = "Чат"; _ShowInf = true; } if (GameMenuUpd == ButtonStates.CLICKED) { Menu.Show(this, Parent, null); } else if (GameMenuUpd == ButtonStates.ENTERED) { Inf.Appear(); Inf.Text = "Игровое меню"; _ShowInf = true; } if (PlayerPoints.Update() == ButtonStates.ENTERED) { Inf.Appear(); Inf.Text = "Очки/Необходимо\nдля победы"; _ShowInf = true; } if (OpponentPoints.Update() == ButtonStates.ENTERED) { Inf.Appear(); Inf.Text = "Очки/Необходимо\nдля победы"; _ShowInf = true; } if (PlayerMoney.Update() == ButtonStates.ENTERED) { Inf.Appear(); Inf.Text = "Ресурсы"; _ShowInf = true; } if (RoundTime.Update() == ButtonStates.ENTERED) { Inf.Appear(); Inf.Text = "Время хода"; _ShowInf = true; } //*TEST if (EndTurnUpd == ButtonStates.CLICKED) { //if(IsEnemyTurn) // SetPlayerTurn(1); //else // SetEnemyTurn(); Parent.SetEnemyTurn(); CommandParser.SendCommandToGameServer(new string[] { "NEXTTURN" }); //DONE: Отправить на сервер команду смены хода } //*TEST if (!_ShowInf) { Inf.Disappear(); } else { Inf.Position = new Vector2(MouseControl.X + 10, MouseControl.Y); } Inf.Update(); if (map.ChoosedTileI != -1) { var tmptile = map.GetTile(map.ChoosedTileI, map.ChoosedTileJ); if (tmptile.UnitOnTile != null) { TileName.Text = tmptile.TileName + ", " + tmptile.UnitOnTile.Name; } else { TileName.Text = map.GetTile(map.ChoosedTileI, map.ChoosedTileJ).TileName; } TileName.Position = new Vector2(UI_BottomLeft.Position.X + UI_BottomLeft.Texture.Width / 2 - TileName.Font.MeasureString(TileName.Text).X / 2, UI_BottomLeft.Position.Y + 5); } } }
public void Update(ref bool IsMouseHandled, Hand hand, Camera cam, bool IsPlayerTurn, MapZones Opponent, GameState gameState) { if (MouseControl.IsRightBtnClicked) { if (IsPathFinding) { IsPathFinding = false; SetDefault(); UpdateAllTiles(cam); CreatePathArrows(null, cam); } else if (IsAttack) { IsAttack = false; SetDefault(); UpdateAllTiles(cam); CreatePathArrows(null, cam); } else { DeSelectTile(SelectedTile); } } if (_ChoosedTileI == -1 || _ChoosedTileJ == -1) { for (var i = 0; i < Tiles.Length; i++) { for (var j = 0; j < Tiles[0].Length; j++) { if (Tiles[i][j] != null) { Tiles[i][j].UpdateAnims(); if (!IsMouseHandled && Tiles[i][j].Update(cam: cam) != ButtonStates.NONE) { IsMouseHandled = true; _ChoosedTileI = i; _ChoosedTileJ = j; } else { Tiles[i][j].StopAnimation(true, Tiles[i][j].NotSelectedFrame); } Tiles[i][j].UpdateUnit(this, cam); } } } } else if (Tiles[_ChoosedTileI][_ChoosedTileJ] != null) { Tiles[_ChoosedTileI][_ChoosedTileJ].UpdateAnims(); var UpdateResult = Tiles[_ChoosedTileI][_ChoosedTileJ].Update(cam: cam); if (!IsMouseHandled && UpdateResult != ButtonStates.NONE) { IsMouseHandled = true; if (UpdateResult == ButtonStates.CLICKED) { if (IsPathFinding) { IsPathFinding = false; int PL; List <Point> Marked; var Path = PathFinding(ActionStartPoint.X, ActionStartPoint.Y, _ChoosedTileI, _ChoosedTileJ, Tiles[ActionStartPoint.X][ActionStartPoint.Y].UnitOnTile.MovePointsLeft, out PL, out Marked, Opponent); if (Path != null) { var Command = new string[Path.Count + 1]; Command[0] = "MOVE"; for (var i = 1; i < Command.Length; i++) { Command[i] = Path[i - 1].X.ToString() + " " + Path[i - 1].Y.ToString(); } CommandParser.SendCommandToGameServer(Command); gameState.SetEnemyTurn(); } //UnitMove(PathFinding(ActionStartPoint.X, ActionStartPoint.Y, _ChoosedTileI, _ChoosedTileJ, Tiles[ActionStartPoint.X][ActionStartPoint.Y].UnitOnTile.MovePointsLeft, out PL, out Marked, Opponent)); SetDefault(); UpdateAllTiles(cam); CreatePathArrows(null, cam); DeSelectTile(SelectedTile); SelectTile(new Point(_ChoosedTileI, _ChoosedTileJ)); //Переместить } else if (IsAttack) { IsAttack = false; if (EnemyFinding(ActionStartPoint.X, ActionStartPoint.Y, Tiles[ActionStartPoint.X][ActionStartPoint.Y].UnitOnTile.AttackDistance).Contains(new Point(_ChoosedTileI, _ChoosedTileJ))) { //Tiles[ActionStartPoint.X][ActionStartPoint.Y].UnitOnTile.Attack(Tiles[_ChoosedTileI][_ChoosedTileJ].UnitOnTile); CommandParser.SendCommandToGameServer(new string[] { "ATTACK", ActionStartPoint.X.ToString(), ActionStartPoint.Y.ToString(), _ChoosedTileI.ToString(), _ChoosedTileJ.ToString() }); gameState.SetEnemyTurn(); } SetDefault(); UpdateAllTiles(cam); CreatePathArrows(null, cam); } else { if (SelectedTile.X != -1) { DeSelectTile(SelectedTile); } if (IsPlayerTurn) { SelectTile(new Point(_ChoosedTileI, _ChoosedTileJ)); } } } if (IsPathFinding) { int PL; List <Point> Marked; CreatePathArrows(PathFinding(ActionStartPoint.X, ActionStartPoint.Y, _ChoosedTileI, _ChoosedTileJ, Tiles[ActionStartPoint.X][ActionStartPoint.Y].UnitOnTile.MovePointsLeft, out PL, out Marked, Opponent), cam); foreach (var Til in Marked) { if (!ChangedAnimTiles.Contains(Til)) { ChangedAnimTiles.Add(Til); } } foreach (var TilCoords in Marked) { ChangeTilesAnims(2, 1, new Animation(1, 1, true), TilCoords); } } else if (IsAttack) { Attack_Radius.Visible = true; var EnFind = EnemyFinding(ActionStartPoint.X, ActionStartPoint.Y, Tiles[ActionStartPoint.X][ActionStartPoint.Y].UnitOnTile.AttackDistance); foreach (var Til in EnFind) { if (!ChangedAnimTiles.Contains(Til)) { ChangedAnimTiles.Add(Til); } } foreach (var TilCoords in EnFind) { ChangeTilesAnims(2, 1, new Animation(1, 1, true), TilCoords); } if (EnFind.Contains(new Point(_ChoosedTileI, _ChoosedTileJ))) { var TmpList = new List <Point>(); TmpList.Add(new Point(ActionStartPoint.X, ActionStartPoint.Y)); TmpList.Add(new Point(_ChoosedTileI, _ChoosedTileJ)); CreatePathArrows(TmpList, cam); } else { CreatePathArrows(null, cam); } } if (hand.ChoosedCard == -1) { Info.Appear(); Info.Position = new Vector2(MouseControl.X - Info.Texture.Width / 2, MouseControl.Y + 20); Info.NeedMovePointsText = Tiles[_ChoosedTileI][_ChoosedTileJ].MovingPointsNeeded.ToString(); Info.DefenseText = Tiles[_ChoosedTileI][_ChoosedTileJ].GiveArmor.ToString(); } } else { Info.Disappear(); Tiles[_ChoosedTileI][_ChoosedTileJ].StopAnimation(true, Tiles[_ChoosedTileI][_ChoosedTileJ].NotSelectedFrame); _ChoosedTileI = -1; _ChoosedTileJ = -1; } for (var i = 0; i < Tiles.Length; i++) { for (var j = 0; j < Tiles[0].Length; j++) { if (Tiles[i][j] != null) { Tiles[i][j].UpdateUnit(this, cam); } } } } Info.Update(); FlyingTextProcessor.Update(); }