public int Update(NetworkInterface MasterNI) { NameEdit.Update(); PassEdit.Update(); Br.UpdateAnims(); if (Login.Update() == ButtonStates.CLICKED) { //DONE: Запрос на сервер IsRegistration = false; IsRequestSended = false; MasterNI.ConnectTo(Config.ServerIP); Log.SendMessage("Подключение к мастер-серверу"); ShowConnectingState(); } else if (Register.Update() == ButtonStates.CLICKED) { //DONE: Запрос на сервер IsRegistration = true; IsRequestSended = false; MasterNI.ConnectTo(Config.ServerIP); Log.SendMessage("Подключение к мастер-серверу"); ShowConnectingState(); } if (IsConnectingState) { Connecting_Icon.RotateOn(0.01f); if (MasterNI.IsConnected) { if (IsRequestSended) { string[] command = null; CommandParser.UpdateMasterServer(out command); if (command != null) { IsRequestSended = false; if (command[0] == "OK") { if (IsRegistration) { SetText("Успешно зарегестрирован"); ShowNormalState(); MasterNI.Disconnect(); } else { ShowNormalState(); _PlayerName = command[1]; _PlayerMoney = Convert.ToInt32(command[2]); Hide(true); return(1); } } else if (command[0] == "ERROR") { SetErrorText(Convert.ToInt32(command[1])); ShowNormalState(); MasterNI.Disconnect(); } } } else { IsRequestSended = true; if (IsRegistration) { CommandParser.SendCommandToMasterServer(new string[] { "REGISTER", NameEdit.Text, PassEdit.Text }); } else { CommandParser.SendCommandToMasterServer(new string[] { "LOGIN", NameEdit.Text, PassEdit.Text }); } } } else { if (MasterNI.IsError) { SetErrorText(ServerErrors.Length - 1); IsRequestSended = false; ShowNormalState(); MasterNI.Disconnect(); } } } return(0); }
public void Update(GameMenu Menu) { UpdateGameObjects(Menu); //Window.Title = Convert.ToString(Hand.Cards[0].Layer) + " " + Convert.ToString(Hand.Cards[1].Layer) + " " + Convert.ToString(Hand.Cards[2].Layer); // TODO: Add your update logic here //Window.Title = Convert.ToString(Mouse.GetState().X) + "||" + Convert.ToString(Mouse.GetState().Y); //Window.Title = Convert.ToString(ScreenWidth) + "||" + Convert.ToString(ScreenHeight); //Window.Title = Convert.ToString(Mouse.GetState().X) + "||" + Convert.ToString(Mouse.GetState().Y) + "|---|" + Convert.ToString(arrow.EndPoint.X) + "||" + Convert.ToString(arrow.EndPoint.Y) + "|---|" + Convert.ToString(arrow._Rotation); watch.Stop(); //Window.Title = CoordsConvert.WindowToWorldCoords(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), cam).ToString(); //if (MouseControl.IsLeftBtnClicked) // Window.Title = "Left"; //if (MouseControl.IsRightBtnClicked) // Window.Title = "Right"; //Window.Title = Hand.IsClick.ToString(); //Window.Title = Map.Tiles[0][0].NotSelectedFrame.ToString() + " || " + Map.Tiles[1][0].NotSelectedFrame.ToString(); /*PathFindingTest*/ // var Til = Map.GetTileIJByCoords(new Vector2(MouseControl.X, MouseControl.Y)); // List<Point> LastList = null; // if (Til != null) // { // int PL; // var TmpList = Map.PathFinding(1, 0, Til[0], Til[1], out PL); // Map.CreatePathArrows(TmpList); // if (TmpList != LastList) // { // LastList = new List<Point>(TmpList); // Window.Title = PL.ToString(); // } // } /*PathFindingTest End*/ watch.Reset(); UpdateCamera(); //cam.Position += new Vector2(0.5f, 0.5f); //cam.Zoom = 0.25f; //cam.Rotation -= 0.01f; string[] CN; CommandParser.UpdateGameServer(out CN); if (CN != null) { if (CN[0] == "WIN") { IsPlayerTurn = false; UI.SetEndGame(true); } else if (CN[0] == "LOSE" || CN[0] == "DRAW") { IsPlayerTurn = false; UI.SetEndGame(false); } else if (CN[0] == "REPLACE") { if (CN.Length == 1) { UI.ReplaceCards(null); } else { var CardsToReplace = new int[CN.Length - 1]; for (var i = 1; i < CN.Length; i++) { CardsToReplace[i - 1] = Convert.ToInt32(CN[i]); } UI.ReplaceCards(CardsToReplace); } } else if (CN[0] == "START") { UI.IterationReset(); } else if (CN[0] == "TURN") { foreach (var Tiles in Map.GetMap()) { foreach (var Tile in Tiles) { if (Tile != null) { if (Tile.UnitOnTile != null) { Tile.UnitOnTile.MovePointsLeft = Tile.UnitOnTile.Speed; Tile.UnitOnTile.CanAttack = true; } } } } if (CN[1] == "ENEMY") { UI.SetEnemyTurn(); UI.Opponent_Points = Convert.ToInt32(CN[2]); IsPlayerTurn = false; } else { var CardsToChoose = new int[CN.Length - 4]; UI.Player_Points = Convert.ToInt32(CN[2]); UI.Player_Money = Convert.ToInt32(CN[3]); if (UI.Player_Money_Inc < 10) { UI.Player_Money_Inc += 1; } for (var i = 4; i < CN.Length; i++) { CardsToChoose[i - 4] = Convert.ToInt32(CN[i]); } UI.SetPlayerTurn(Convert.ToInt32(CN[1]), CardsToChoose); IsPlayerTurn = true; } } else if (CN[0] == "CHOOSE") { if (CN[1] == "OK") { UI.ChooseCards(Hand); } } else if (CN[0] == "SPAWN") { if (IsPlayerTurn) { SetPlayerTurn(); UI.Player_Money -= GameContent.UnitCards[Convert.ToInt32(CN[2])].Cost; Hand.CalculateCardPosition(20, true); } if (CN[1] == "ALLIED") { Map.GetTile(Convert.ToInt32(CN[3]), Convert.ToInt32(CN[4])).SpawnUnit(new Unit(Vector2.Zero, GameContent.UnitCards[Convert.ToInt32(CN[2])].UnitTexture, GameContent.UI_Info_Allied, GameContent.UI_InfoFont, Color.White, 392, 20, GameContent.UnitCards[Convert.ToInt32(CN[2])].Name, GameContent.UnitCards[Convert.ToInt32(CN[2])].Speed, GameContent.UnitCards[Convert.ToInt32(CN[2])].Damage, GameContent.UnitCards[Convert.ToInt32(CN[2])].HP, GameContent.UnitCards[Convert.ToInt32(CN[2])].Armor, GameContent.UnitCards[Convert.ToInt32(CN[2])].AttackRadius, Side.PLAYER, GameContent.UnitCards[Convert.ToInt32(CN[2])].UnitAttackScript, UnitAttEngine, new Point(Convert.ToInt32(CN[3]), Convert.ToInt32(CN[4])), new Animation(8, 17, false), 0.4f), PlayerSide, Map.UI_VisibleState); } else { Map.GetTile(Convert.ToInt32(CN[3]), Convert.ToInt32(CN[4])).SpawnUnit(new Unit(Vector2.Zero, GameContent.UnitCards[Convert.ToInt32(CN[2])].UnitTexture, GameContent.UI_Info_Enemy, GameContent.UI_InfoFont, Color.White, 392, 20, GameContent.UnitCards[Convert.ToInt32(CN[2])].Name, GameContent.UnitCards[Convert.ToInt32(CN[2])].Speed, GameContent.UnitCards[Convert.ToInt32(CN[2])].Damage, GameContent.UnitCards[Convert.ToInt32(CN[2])].HP, GameContent.UnitCards[Convert.ToInt32(CN[2])].Armor, GameContent.UnitCards[Convert.ToInt32(CN[2])].AttackRadius, Side.OPPONENT, GameContent.UnitCards[Convert.ToInt32(CN[2])].UnitAttackScript, UnitAttEngine, new Point(Convert.ToInt32(CN[3]), Convert.ToInt32(CN[4])), new Animation(8, 17, false), 0.4f), (PlayerSide == MapZones.RIGHT) ? MapZones.LEFT : MapZones.RIGHT, Map.UI_VisibleState); } } else if (CN[0] == "MOVE") { if (IsPlayerTurn) { SetPlayerTurn(); } var first = CN[1].Split(); var last = CN[2].Split(); int PL; List <Point> Marked; var point = new Point(Convert.ToInt32(first[0]), Convert.ToInt32(first[1])); for (var i = 0; i < Map.CPTiles.Count(); i++) { if (Map.CPTiles[i] == point) { if (Map.GetTile(Convert.ToInt32(first[0]), Convert.ToInt32(first[1])).UnitOnTile.side == Side.PLAYER) { Map.SetCPState(i, CapturePointStates.NEUTRAL); UI.CPInfos[i].SetState(CapturePointStates.NEUTRAL); UI.Player_Points_Inc -= 1; } else { Map.SetCPState(i, CapturePointStates.NEUTRAL); UI.CPInfos[i].SetState(CapturePointStates.NEUTRAL); UI.Opponent_Points_Inc -= 1; } } } point = new Point(Convert.ToInt32(last[0]), Convert.ToInt32(last[1])); for (var i = 0; i < Map.CPTiles.Count(); i++) { if (Map.CPTiles[i] == point) { if (Map.GetTile(Convert.ToInt32(first[0]), Convert.ToInt32(first[1])).UnitOnTile.side == Side.PLAYER) { Map.SetCPState(i, CapturePointStates.ALLIED); UI.CPInfos[i].SetState(CapturePointStates.ALLIED); UI.Player_Points_Inc += 1; } else { Map.SetCPState(i, CapturePointStates.ENEMY); UI.CPInfos[i].SetState(CapturePointStates.ENEMY); UI.Opponent_Points_Inc += 1; } break; } } Map.UnitMove(Map.PathFinding(Convert.ToInt32(first[0]), Convert.ToInt32(first[1]), Convert.ToInt32(last[0]), Convert.ToInt32(last[1]), Map.GetTile(Convert.ToInt32(first[0]), Convert.ToInt32(first[1])).UnitOnTile.MovePointsLeft, out PL, out Marked, OpponentSide), Convert.ToInt32(CN[3])); } else if (CN[0] == "ATTACK") { if (IsPlayerTurn) { SetPlayerTurn(); } bool IsPlayer = false; if (Map.GetTile(Convert.ToInt32(CN[3]), Convert.ToInt32(CN[4])).UnitOnTile.side == Side.PLAYER) { IsPlayer = true; } Map.GetTile(Convert.ToInt32(CN[1]), Convert.ToInt32(CN[2])).UnitOnTile.Attack(Map.GetTile(Convert.ToInt32(CN[3]), Convert.ToInt32(CN[4])).UnitOnTile, Convert.ToInt32(CN[5])); if (Map.GetTile(Convert.ToInt32(CN[3]), Convert.ToInt32(CN[4])).UnitOnTile.HP <= Convert.ToInt32(CN[5])) { var point = new Point(Convert.ToInt32(CN[3]), Convert.ToInt32(CN[4])); for (var i = 0; i < Map.CPTiles.Count(); i++) { if (Map.CPTiles[i] == point) { Map.SetCPState(i, CapturePointStates.NEUTRAL); UI.CPInfos[i].SetState(CapturePointStates.NEUTRAL); if (IsPlayer) { UI.Player_Points_Inc -= 1; } else { UI.Opponent_Points_Inc -= 1; } break; } } } } //if(CN[0] == "2") //{ // //Map.GetTile(Convert.ToInt32(CN[1]), Convert.ToInt32(CN[2])).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, GameContent.UnitAttackScripts[0], UnitAttEngine, new Point(Convert.ToInt32(CN[1]), Convert.ToInt32(CN[2])), new Animation(8, 17, false), 0.4f), MapZones.RIGHT, Map.UI_VisibleState); //} } }