Exemplo n.º 1
0
        public GameState(NetworkInterface NI, Game1 Parent, int ScreenWidth, int ScreenHeight, GraphicsDevice gr_Device)
        {
            this.Parent = Parent;
            this.NI     = NI;

            gr_Dev = gr_Device;

            int[][] mass = null;
            while (true)
            {
                var msg = NI.GetNextMsg();
                if (msg != null)
                {
                    var masss = (mass as object);
                    Serialization.DeSerialize(msg, ref masss, typeof(int[][]));
                    mass = masss as int[][];
                    break;
                }
            }

            var CP = new List <Point>();

            while (true)
            {
                var msg = NI.GetNextMsg();
                if (msg != null)
                {
                    string[] str;
                    var      masss = (mass as object);
                    Serialization.DeSerialize(msg, ref masss, typeof(string[]));
                    str = masss as string[];
                    foreach (var point in str)
                    {
                        var split = point.Split(' ');
                        CP.Add(new Point(Convert.ToInt32(split[0]), Convert.ToInt32(split[1])));
                    }
                    break;
                }
            }

            Log.SendMessage("Ожидание команды начала игры");

            var player1_name = "";
            var player2_name = "";
            var player_money = "";
            var player1_icon = 0;
            var player2_icon = 0;

            string[] tmpmsg = null;
            int[]    Cards  = null;
            while (true)
            {
                var msg = NI.GetNextMsg();
                if (msg != null)
                {
                    var masss = (tmpmsg as object);
                    Serialization.DeSerialize(msg, ref masss, typeof(string[]));
                    tmpmsg = masss as string[];

                    player1_name = tmpmsg[0];
                    player2_name = tmpmsg[1];
                    player_money = tmpmsg[2];
                    PlayerSide   = (tmpmsg[3] == "RIGHT") ? MapZones.RIGHT : MapZones.LEFT;
                    OpponentSide = (PlayerSide == MapZones.LEFT) ? MapZones.RIGHT : MapZones.LEFT;
                    player1_icon = Convert.ToInt32(tmpmsg[4]);
                    player2_icon = Convert.ToInt32(tmpmsg[5]);
                    Cards        = new int[tmpmsg.Length - 6];
                    for (var i = 6; i < tmpmsg.Length; i++)
                    {
                        Cards[i - 6] = Convert.ToInt32(tmpmsg[i]);
                    }
                    break;
                }
            }

            watch = new Stopwatch();//ДЫБГ
            var MapArr = new Tile[8][];
            var Rnd    = new Random();

            for (var i = 0; i < 8; i++)
            {
                MapArr[i] = new Tile[15];
                for (var j = 0; j < 15; j++)
                {
                    if (j % 2 == 0)
                    {
                        MapArr[i][j] = new Tile(new Vector2(j * 294, i * 339), GameContent.TileBorder, GameContent.TileBorder_HL, GameContent.TileTypes[mass[i][j]].Tile_Decoration, 392, 20, 0, new Animation(1, 1, true), 1, GameContent.TileTypes[mass[i][j]].SpeedNeeded, GameContent.TileTypes[mass[i][j]].Armor, GameContent.TileTypes[mass[i][j]].Name, LAYER_MAP);
                    }
                    else
                    if (i != MapArr.GetLength(0) - 1)
                    {
                        MapArr[i][j] = new Tile(new Vector2(j * 294, i * 339 + 169.5f), GameContent.TileBorder, GameContent.TileBorder_HL, GameContent.TileTypes[mass[i][j]].Tile_Decoration, 392, 20, 0, new Animation(1, 1, true), 1, GameContent.TileTypes[mass[i][j]].SpeedNeeded, GameContent.TileTypes[mass[i][j]].Armor, GameContent.TileTypes[mass[i][j]].Name, LAYER_MAP);
                    }
                    else
                    {
                        MapArr[i][j] = null;
                    }
                }
            }


            Map = new Map(MapArr, 0, 1, new Animation(1, 1, true), GameContent.ArrowSegment, GameContent.ArrowEnd, GameContent.UI_TileInfo, GameContent.Tile_ControlPoint_Neutral, GameContent.Tile_ControlPoint_Allied, GameContent.Tile_ControlPoint_Enemy, GameContent.Unit_AttackRadius, GameContent.UI_InfoFont, Color.White, CP.ToArray());
            //foreach (var Til in Map)
            //    if (Til != null)
            //    {
            //        Til.Scale = new Vector2(2, 2);
            //        Til.Position = new Vector2(Til.Position.X * Til.Scale.X, Til.Position.Y * Til.Scale.Y);
            //    }
            char a = Convert.ToChar(12);

            //var Arr = new Card[10];
            //Arr[0] = new Card(new Vector2(100, 300), Content.Load<Texture2D>(@"Textures\Card"), Content.Load<Texture2D>(@"Textures\Tiger"), new Vector2(16, 9), 200, 10, 0, 13, new Animation(0, 0, true), new Animation(2, 6, false), new Animation(7, 9, false), new Animation(1, 1, true), 0, Content.Load<SpriteFont>(@"Fonts\TileInfoFont"), Color.White, "Pz. VI H \"Tiger\"", "3", "1", "5", "5", "6", 141, 315, 4, 4, 37, false, Layer: LAYER_CARDS)
            //{
            //    Scale = new Vector2(0.5f, 0.5f)
            //};
            //for (var i = 1; i < Arr.Length; i++)
            //{
            //    Arr[i] = new Card(new Vector2(100 + i * 60, 300), Content.Load<Texture2D>(@"Textures\Card"), Content.Load<Texture2D>(@"Textures\Tiger"), new Vector2(16, 9), 200, 10, 0, 13, new Animation(0, 0, true), new Animation(2, 6, false), new Animation(7, 12, false), new Animation(1, 1, true), 0, Content.Load<SpriteFont>(@"Fonts\TileInfoFont"), Color.White, "Pz. VI H \"Tiger\"", "3", "1", "5", "5", "6", 141, 315, 4, 4, 37, true, Layer: LAYER_CARDS + 0.001f * i)
            //    {
            //        Scale = new Vector2(0.5f, 0.5f),
            //        AllowedZones = MapZones.RIGHT
            //    };
            //}
            Hand = new Hand(new Vector2(ScreenWidth / 2, ScreenHeight - 175), null, new Vector2(ScreenWidth, ScreenHeight), GameContent.ArrowSegment, GameContent.ArrowEnd, LAYER_CARDS);

            UI = new MainUI
                 (
                new Vector2(ScreenWidth, ScreenHeight), GameContent.UI_Main_Bottom,
                GameContent.UI_Main_Bottom_Left, GameContent.UI_Main_Up,
                GameContent.UI_Main_Up_Left, GameContent.UI_Main_Up_Right,
                GameContent.UI_Btn_NewTurn, GameContent.UI_Btn_Move,
                GameContent.UI_Btn_Attack, GameContent.UI_Btn_Menu,
                GameContent.UI_Btn_Chat, GameContent.UI_Btn_Stats,
                GameContent.UI_Player_Icons[player1_icon], GameContent.UI_Player_Icons[player2_icon],
                GameContent.UI_Flag_Player, GameContent.UI_Flag_Enemy,
                GameContent.UI_Money, GameContent.UI_HourGlass,
                GameContent.UI_Vs, GameContent.UI_AlliedPoint,
                GameContent.UI_EnemyPoint, GameContent.UI_NeutralPoint, GameContent.UI_EnemyTurn,
                GameContent.UI_VictoryImage, GameContent.UI_LoseImage,
                GameContent.UI_ButtonFont,
                GameContent.UI_MiniFont,
                GameContent.UI_NewTurnFont,
                gr_Device, this,
                player1_name, player2_name,
                0, 1, 0, 1, 50,
                Convert.ToInt32(player_money), 1,
                "1:30", new string[] { "A", "B", "C" },
                Cards, (Cards.Length == 3) ? true : false,
                LAYER_UI_FAR);
            // TODO: use this.Content to load your game content here
            cam       = new Camera(new Vector2(ScreenWidth, ScreenHeight));
            cam.Zoom  = 0.25f;
            laststate = 0;

            KeyBindings.Init();
            KeyBindings.RegisterKeyBind("KEY_MOVEUNIT", Keys.M);
            KeyBindings.RegisterKeyBind("KEY_ATTACKUNIT", Keys.F);
            KeyBindings.RegisterKeyBind("KEY_STATS", Keys.T);
            KeyBindings.RegisterKeyBind("KEY_CAMMOVE_UP", Keys.W);
            KeyBindings.RegisterKeyBind("KEY_CAMMOVE_DOWN", Keys.S);
            KeyBindings.RegisterKeyBind("KEY_CAMMOVE_LEFT", Keys.A);
            KeyBindings.RegisterKeyBind("KEY_CAMMOVE_RIGHT", Keys.D);

            UnitAttEngine = new Script("", "GameCursachProject", false);

            //TEST
            //Map.GetTile(4, 6).SpawnUnit(new Unit(Vector2.Zero, GameContent.UnitTextures[0], GameContent.UI_Info_Enemy, GameContent.UI_InfoFont, Color.White, 392, 20, 5, 3, 6, 1, 2, Side.OPPONENT, GameContent.UnitAttackScripts[0], UnitAttEngine, new Point(4, 6), new Animation(8, 17, false), 0.4f), MapZones.RIGHT, Map.UI_VisibleState);
            //TEST
            SetEnemyTurn();
        }
Exemplo n.º 2
0
        public void Update()
        {
            var Upd = base.Update();

            if (Visible)
            {
                if (MouseControl.IsLeftBtnClicked)
                {
                    if (Upd == ButtonStates.CLICKED)
                    {
                        if (!Focused)
                        {
                            Focused    = true;
                            base.Text += "|";
                        }
                    }
                    else
                    if (Focused)
                    {
                        Focused   = false;
                        base.Text = base.Text.Remove(base.Text.Length - 1);
                    }
                }

                if (Focused)
                {
                    var    IsKeyFinded = false;
                    string Symbol      = "";

                    if (RealText.Length < MaxLength)
                    {
                        for (var i = 48; i < 58; i++)
                        {
                            if (KeyBindings.CheckKeyReleased((Keys)i) == true)
                            {
                                IsKeyFinded = true;
                                Symbol      = char.ConvertFromUtf32(i);
                                break;
                            }
                        }
                        if (!IsKeyFinded)
                        {
                            for (var i = 65; i < 91; i++)
                            {
                                if (KeyBindings.CheckKeyReleased((Keys)i) == true)
                                {
                                    IsKeyFinded = true;
                                    Symbol      = char.ConvertFromUtf32(i);
                                    break;
                                }
                            }
                        }
                        if (!IsKeyFinded)
                        {
                            for (var i = 96; i < 106; i++)
                            {
                                if (KeyBindings.CheckKeyReleased((Keys)i) == true)
                                {
                                    IsKeyFinded = true;
                                    Symbol      = char.ConvertFromUtf32(i - 48);
                                    break;
                                }
                            }
                        }
                        if (IsKeyFinded)
                        {
                            base.Text = base.Text.Remove(base.Text.Length - 1);
                            if (!(KeyBindings.CheckKeyPressed(Keys.LeftShift) || KeyBindings.CheckKeyPressed(Keys.RightShift)))
                            {
                                Symbol = Symbol.ToLower();
                            }
                            RealText += Symbol;
                            if (IsMasked)
                            {
                                base.Text += "*";
                            }
                            else
                            {
                                base.Text += Symbol;
                            }
                            base.Text += "|";
                        }
                    }

                    if (KeyBindings.CheckKeyReleased(Keys.Back))
                    {
                        base.Text = base.Text.Remove(base.Text.Length - 1);
                        if (base.Text.Length > 0)
                        {
                            base.Text = base.Text.Remove(base.Text.Length - 1);
                        }
                        if (RealText.Length > 0)
                        {
                            RealText = RealText.Remove(RealText.Length - 1);
                        }
                        base.Text += "|";
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void Update(MainUI UI, GameState State, MainMenu menu)
        {
            if (KeyBindings.CheckKeyReleased("KEY_MENU"))
            {
                if (IsOptions)
                {
                    ChangeOptionsState();
                }
                else
                {
                    if (_IsShown)
                    {
                        Hide(UI, State, menu);
                    }
                    else
                    {
                        Show(UI, State, menu);
                    }
                }
            }

            if (_IsShown)
            {
                if (IsOptions)
                {
                    if (Resolutions.Update() == false)
                    {
                        if (ScreenMode.Update() == ButtonStates.CLICKED)
                        {
                            if (Config.FullScreen)
                            {
                                Config.FullScreen = false;
                                ScreenMode.Text   = "Оконный";
                            }
                            else
                            {
                                Config.FullScreen = true;
                                ScreenMode.Text   = "Полноэкранный";
                            }
                            Parent.ApplyChanges();
                        }
                    }
                }
                else
                {
                    if (Continue.Update() == ButtonStates.CLICKED)
                    {
                        Hide(UI, State, menu);
                    }
                    else
                    if (Surrender.Update() == ButtonStates.CLICKED)
                    {
                        //DONE: Surrender
                        if (Parent.GlobalState == GlobalGameState.Game)
                        {
                            State.Surrender();
                        }
                        Hide(UI, State, menu);
                    }
                    else
                    if (Options.Update() == ButtonStates.CLICKED)
                    {
                        ChangeOptionsState();
                    }
                    else
                    if (Quit.Update() == ButtonStates.CLICKED)
                    {
                        if (CommandParser.GameServerInterface != null)
                        {
                            CommandParser.GameServerInterface.Disconnect();
                        }
                        if (CommandParser.MasterServerInterface != null)
                        {
                            CommandParser.MasterServerInterface.Disconnect();
                        }
                        Parent.Exit();
                    }
                }
            }
        }