コード例 #1
0
        public bool AddElement(string uiName, UIObject element, int collumn, int row)
        {
            bool throwFlag = false;

            if (collumn >= CollumnCount)
            {
                CONTENT_MANAGER.Log(string.Format("Collumn overflow : {0} at {1}", uiName ?? nameof(element), collumn));
                throwFlag = true;
            }
            if (row >= RowCount)
            {
                CONTENT_MANAGER.Log(string.Format("Row overflow : {0} at {1}", uiName ?? nameof(element), collumn));
                throwFlag = true;
            }
            if (throwFlag)
            {
                throw new ArgumentOutOfRangeException(string.Format("c: {0};r: {1}", collumn, row));
            }

            if (uiName == null || !CheckGridCellContainKey(uiName))
            {
                _cells[collumn, row].AddElement(uiName, element);
                return(true);
            }
            else
            {
                //log stuff
                CONTENT_MANAGER.Log("Duplicate UI element : " + uiName ?? nameof(element));
                return(false);
            }
        }
コード例 #2
0
        protected override void LoadContent()
        {
            CONTENT_MANAGER.LoadSpriteSheet("tank", 32, 32);
            CONTENT_MANAGER.LoadSpriteSheet("bullet", 32, 32);
            var terrain = CONTENT_MANAGER.LoadSpriteSheet("terrain", 16, 16);

            CONTENT_MANAGER.LoadFonts("default");

            var animdata = File.ReadAllText("Content/animdata/yellow_tank.json");

            CONTENT_MANAGER.LoadAnimation("yellow_tank", "tank", animdata);

            animdata = File.ReadAllText("Content/animdata/silver_tank.json");
            CONTENT_MANAGER.LoadAnimation("silver_tank", "tank", animdata);

            animdata = File.ReadAllText("Content/animdata/green_tank.json");
            CONTENT_MANAGER.LoadAnimation("green_tank", "tank", animdata);

            animdata = File.ReadAllText("Content/animdata/red_tank.json");
            CONTENT_MANAGER.LoadAnimation("red_tank", "tank", animdata);

            animdata = File.ReadAllText("Content/animdata/bullet.json");
            CONTENT_MANAGER.LoadAnimation("bullet", "bullet", animdata);

            InitScreen();
        }
コード例 #3
0
        public void InitCanvas()
        {
            canvas = new Canvas();

            ListView listView = new ListView(new Point(20, 20), new Vector2(300, 300), new Point(10, 40), new Vector2(50, 30));
            Button   button   = new Button("Add Item", new Point(400, 20), new Vector2(80, 30), CONTENT_MANAGER.Fonts["default"]);
            Label    label    = new Label("", new Point(400, 60), new Vector2(50, 30), CONTENT_MANAGER.Fonts["default"])
            {
                Origin = new Vector2(-2, -2)
            };

            button.MouseClick += (o, e) =>
            {
                listView.AddItem(count++.ToString());
            };

            listView.ItemSelected += (o, e) =>
            {
                label.Text = e.Text;
                CONTENT_MANAGER.Log(e.Text);
            };

            canvas.AddElement("listView", listView);
            canvas.AddElement("button", button);
            canvas.AddElement("label", label);
        }
コード例 #4
0
        /// <summary>
        /// Tells this entity to play an specific animation
        /// </summary>
        /// <param name="key">The name of the animation you want to play</param>
        public void PlayAnimation(string key)
        {
            if (string.IsNullOrEmpty(key) || !animations.ContainsKey(key))
            {
                CONTENT_MANAGER.Log(key + "not found");
                return;
            }

            //TODO find the meaning of the following code

            //if (currentAnimation != null)
            //{
            //    if (currentAnimation.Name == key)
            //    {
            //        if (animations.ContainsKey(key))
            //        {
            //            return;
            //        }
            //    }
            //}

            isPlaying = true;

            currentAnimation = animations[key];
            currentAnimation.Reset();
        }
コード例 #5
0
        public override void Draw(GameTime gameTime)
        {
            DrawMenuBackground(CONTENT_MANAGER.spriteBatch);

            CONTENT_MANAGER.spriteBatch.Draw(TitleBackground, new Vector2(0, -20), null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, LayerDepth.BackGround);

            canvas.Draw(CONTENT_MANAGER.spriteBatch);
            CONTENT_MANAGER.ShowFPS(gameTime);
        }
コード例 #6
0
        private void InitUI()
        {
            Button btn_create_room = new Button("Create Room", new Point(275, 150), new Vector2(170, 25), CONTENT_MANAGER.arcadefont);

            Button btn_goto_room = new Button("Go To Room", new Point(285, 200), new Vector2(150, 25), CONTENT_MANAGER.arcadefont);

            Label label_player_name = new Label(Player.Instance.Name, new Point(620, 0), null, CONTENT_MANAGER.arcadefont, 1);

            //bind event

            //Click to button go to room
            btn_goto_room.MouseClick += (sender, e) =>
            {
                enterRoom.ShowDialog();
            };

            //Click to button create room
            btn_create_room.MouseClick += (sender, e) =>
            {
                Player.Instance.CreateRoom();
            };

            //Click to ok button after enter room number
            enterRoom.button_OK.Click += (sender, e) =>
            {
                if (enterRoom.textBox_Input.Text != "")
                {
                    Player.Instance.GotoRoom(Convert.ToInt32(enterRoom.textBox_Input.Text));
                }
                else
                {
                    CONTENT_MANAGER.ShowMessageBox("You have't enter room number");
                }
            };

            //Cancel go to room
            enterRoom.button_Cancel.Click += (sender, e) =>
            {
                enterRoom.Hide();
            };

            //Event enter success
            Player.Instance.entered_succeed += (sender, e) =>
            {
                SCREEN_MANAGER.goto_screen("Room_Screen");
            };

            //Event create room success
            Player.Instance.created_room += (_sender, _e) =>
            {
                SCREEN_MANAGER.goto_screen("Room_Screen");
            };

            canvas.AddElement("btn_create_room", btn_create_room);
            canvas.AddElement("btn_goto_room", btn_goto_room);
            canvas.AddElement("label_player_name", label_player_name);
        }
コード例 #7
0
        static void Main(string[] args)
        {
            AppDomain currentDomain = AppDomain.CurrentDomain;

            currentDomain.UnhandledException += CurrentDomain_UnhandledException;

            CONTENT_MANAGER.ParseArguments(args);
            using (var game = new GameManager())
                game.Run();
        }
コード例 #8
0
 public void RemoveAnimation(string animationName)
 {
     if (animations.ContainsKey(animationName))
     {
         animations.Remove(animationName);
     }
     else
     {
         CONTENT_MANAGER.Log("animation doesn't exist : " + animationName);
     }
 }
コード例 #9
0
        protected override void LoadContent()
        {
            DrawingHelper.Initialize(GraphicsDevice);
            CONTENT_MANAGER.spriteBatch       = new SpriteBatch(GraphicsDevice);
            CONTENT_MANAGER.CurrentInputState = new InputState(Mouse.GetState(), Keyboard.GetState());

            CONTENT_MANAGER.LoadFonts("default");
            CONTENT_MANAGER.LoadSprites("Cats", "tank", "bullet");

            InitScreens();
        }
コード例 #10
0
 public T GetElementAs <T>(string uiName)
 {
     if (UIelements.ContainsKey(uiName))
     {
         return((T)(object)UIelements[uiName]);
     }
     else
     {
         //log stuff
         CONTENT_MANAGER.Log("UI element not found : " + uiName);
         return(default(T));
     }
 }
コード例 #11
0
 public UIObject GetElement(string uiName)
 {
     if (UIelements.ContainsKey(uiName))
     {
         return(UIelements[uiName]);
     }
     else
     {
         //log stuff
         CONTENT_MANAGER.Log("UI element not found : " + uiName);
         return(null);
     }
 }
コード例 #12
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            CONTENT_MANAGER.spriteBatch.Begin(SpriteSortMode.FrontToBack, transformMatrix: camera.TransformMatrix);
            {
                SCREEN_MANAGER.Draw(CONTENT_MANAGER.spriteBatch, gameTime);
                //DrawingHelper.Draw(CONTENT_MANAGER.spriteBatch);
                CONTENT_MANAGER.ShowFPS(gameTime);
            }
            CONTENT_MANAGER.spriteBatch.End();

            base.Draw(gameTime);
        }
コード例 #13
0
 public bool AddElement(string uiName, UIObject element)
 {
     if (uiName == null || !UIelements.ContainsKey(uiName))
     {
         UIelements.Add(uiName ?? nameof(element), element);
         element.Container = this;
         return(true);
     }
     else
     {
         //log stuff
         CONTENT_MANAGER.Log("Duplicate UI element : " + nameof(element));
         return(false);
     }
 }
コード例 #14
0
 /// <summary>
 /// Helper method to add Animations to this entity
 /// </summary>
 /// <param name="animation">The Animation we want to add</param>
 public void AddAnimation(Animation animation)
 {
     // Is this Animation already in the Dictionary?
     if (!animations.ContainsKey(animation.Name))
     {
         // If not we can safely add it
         animations.Add(animation.Name, animation);
     }
     else
     {
         // Otherwise we tell are computer to yell at us
         //log stuff
         CONTENT_MANAGER.Log("duplicate animation : " + animation.Name);
     }
 }
コード例 #15
0
        /* a map file data structure
         * basically it's a json file serialize from the class Map
         */

        public static Map LoadMap(string data)
        {
            data = CompressHelper.UnZip(data);

            var    mapdata  = data.Split('|');
            string majorver = string.Empty
            , minorver      = string.Empty;

            try
            {
                majorver = JsonConvert.DeserializeObject <string>(mapdata[0]);
                minorver = JsonConvert.DeserializeObject <string>(mapdata[1]);
            }
            catch (Exception e)
            {
                Utility.HelperFunction.Log(e);
            }

            if (string.Compare(majorver, VersionNumber.MajorVersion) != 0 ||
                string.Compare(minorver, VersionNumber.MinorVersion) != 0)
            {
                CONTENT_MANAGER.ShowMessageBox("Cant't load map" + Environment.NewLine + "Version not compatible" + Environment.NewLine + "Game version: " + VersionNumber.GetVersionNumber + Environment.NewLine + "Map version: " + majorver + "." + minorver);
                return(null);
            }

            Map output = new Map();

            try
            {
                output = JsonConvert.DeserializeObject <Map>(mapdata[2]);
            }
            catch (Exception er)
            {
                Utility.HelperFunction.Log(er);
                Environment.Exit(0);
            }

            if (output != null)
            {
                return(output);
            }
            else
            {
                HelperFunction.Log(new Exception(output?.ToString()));
                Environment.Exit(0);
                throw new NullReferenceException();
            }
        }
コード例 #16
0
        public override void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            CONTENT_MANAGER.BeginSpriteBatch(spriteBatch);

            canvas.Draw(spriteBatch, gameTime);

            MapRenderer.Draw(spriteBatch, map);
            foreach (var player in Players.Values)
            {
                player.Draw(gameTime, spriteBatch);
            }
            CONTENT_MANAGER.EndSpriteBatch(spriteBatch);

            drawBatch.Begin();
            world.DrawDebug(0, 0, 800, 600, DrawCell, DrawBox, DrawString);
            drawBatch.End();
        }
コード例 #17
0
        protected override void LoadContent()
        {
            CONTENT_MANAGER.spriteBatch = new SpriteBatch(GraphicsDevice);

            #region Load font
            CONTENT_MANAGER.LoadFont("default", "hack");
            #endregion

            #region Load spritesheet
            CONTENT_MANAGER.LoadSprites("animation", "spritesheet");
            #endregion

            #region Load audio
            CONTENT_MANAGER.LoadSound("door_close", "door_open", "footstep", "lever", "switch_pressed", "switch_released", "tele", "light_on", "light_off");
            #endregion

            InitScreen();
        }
コード例 #18
0
        public override void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            try
            {
                if (Font.MeasureString(textBuffer).X <= rect.Width)
                {
                    spriteBatch.DrawString(Font, textBuffer, rect.Location.ToVector2(), foregroundColor, Rotation, origin, scale, SpriteEffects.None, LayerDepth.GuiLower);
                }
                else
                {
                    spriteBatch.DrawString(Font, temp_text, rect.Location.ToVector2(), foregroundColor, Rotation, origin, scale, SpriteEffects.None, LayerDepth.GuiLower);
                }
            }
            catch (Exception e)
            {
                CONTENT_MANAGER.Log(e.Message);
            }

            //Draw text caret
            spriteBatch.DrawString(Font, IsFocused ? isCursor_flicker ? "" : "|" : "|", rect.Location.ToVector2() + new Vector2(CursorPosition * textSpacing - 5, -2), caretColor);

            DrawingHelper.DrawRectangle(rect, BackgroundColor, true);
        }
コード例 #19
0
        public override void Update(InputState inputState, InputState lastInputState)
        {
            base.Update(inputState, lastInputState);

            //Chau Van Sang adds isCursor for cursor flickering
            if (isFocused == true)
            {
                temp_speed_flicker += 1;
                if (temp_speed_flicker == speed_flick)
                {
                    isCursor_flicker   = !isCursor_flicker;
                    temp_speed_flicker = 0;
                }

                if (HelperFunction.IsKeyPress(Keys.Back))
                {
                    if (textBuffer.Length > 0)
                    {
                        if (font.MeasureString(textBuffer).X > rect.Width)
                        {
                            textBuffer.Remove(textBuffer.Length - 1, 1);
                            return;
                        }
                        textBuffer.Remove((CursorPosition - 1).Clamp(textBuffer.Length, 0), 1);
                        CursorPosition--;
                    }
                }

                if (inputState.keyboardState.IsKeyDown(Keys.LeftControl) && HelperFunction.IsKeyPress(Keys.V))
                {
                    string paste = CONTENT_MANAGER.GetClipboard();
                    textBuffer.Append(paste);
                    CursorPosition += paste.Length;
                }
            }
        }
コード例 #20
0
        //Notify another phayer that you are ready
        //( This method only use to phayer is no host )

        private void InitUI()
        {
            Button button_ready = new Button("Ready", new Point(127, 200), new Vector2(100, 25), CONTENT_MANAGER.arcadefont);

            Button button_selectmap = new Button(UISpriteSheetSourceRectangle.GetSpriteRectangle(SpriteSheetUI.Open), new Point(650, 20), 0.5f);

            Label label_this_ready = new Label("", new Point(50, 50), null, CONTENT_MANAGER.arcadefont, 1);

            Label label_another_ready = new Label("", new Point(490, 227), null, CONTENT_MANAGER.arcadefont, 1);

            Button separate = new Button("", new Point(355, 20), new Vector2(10, 480), CONTENT_MANAGER.arcadefont);

            Label player_name = new Label(Player.Instance.Name, new Point(130, 0), null, CONTENT_MANAGER.arcadefont, 1);

            Label another_player_name = new Label("", new Point(490, 0), null, CONTENT_MANAGER.arcadefont, 1);

            Label room_ID = new  Label(Player.Instance.RoomNumber.ToString(), new Point(360, 0), null, CONTENT_MANAGER.arcadefont, 1);

            // Bind event


            Player.Instance.another_goto_room += (sender, e) =>
            {
                another_player_name.Text = e;
            };

            //Khi chủ phòng load map và gửi cho người chơi khác
            //When select map
            button_selectmap.MouseClick += (sender, e) =>
            {
                try
                {
                    //If you are host, you can load map
                    if (Player.Instance.isHost)
                    {
                        string path = CONTENT_MANAGER.ShowFileOpenDialog(CONTENT_MANAGER.LocalRootPath + @"\map");

                        LoadMap(path);


                        //Send map to another phayer
                        string send = Path.GetFileName(path);

                        Player.Instance.Update(send);
                    }
                }
                catch (Exception er)
                {
                    Utility.HelperFunction.Log(er);
                    CONTENT_MANAGER.ShowMessageBox(er.Message);
                }
            };


            //Người chơi khác nhận map
            //Load map which host had been chosen
            Player.Instance.update += (sender, e) =>
            {
                string path = string.Format("{0}{1}{2}", CONTENT_MANAGER.LocalRootPath, @"\map\", e);
                if (File.Exists(path))
                {
                    loadPath  = path;
                    isLoadMap = true;
                }
            };

            //Event raise when another phayer ready
            Player.Instance.received_chat += (sender, e) =>
            {
                if (e == "Ready")
                {
                    is_another_ready         = true;
                    label_another_ready.Text = "Ready";
                }
                else
                {
                    is_another_ready         = false;
                    label_another_ready.Text = "NotReady";
                }
            };


            //Player is ready
            button_ready.MouseClick += (sender, e) =>
            {
                if (Player.Instance.isHost)
                {
                    if (map != null && is_another_ready)
                    {
                        is_this_ready = true;
                        Player.Instance.ChatWithAnother("Ready");
                    }
                }
                else
                {
                    //Tell another phayer, you start
                    if (!is_this_ready)
                    {
                        is_this_ready         = true;
                        label_this_ready.Text = "Ready";
                        Player.Instance.ChatWithAnother("Ready");
                    }
                    else
                    {
                        is_this_ready         = false;
                        label_this_ready.Text = "";
                        Player.Instance.ChatWithAnother("NotReady");
                    }
                }
            };

            //Add to canvas to draw to screen
            canvas.AddElement("button_selectmap", button_selectmap);
            canvas.AddElement("button_ready", button_ready);
            canvas.AddElement("label_this_ready", label_this_ready);
            canvas.AddElement("separate", separate);
            canvas.AddElement("label_another_ready", label_another_ready);
            canvas.AddElement("another_player_name", another_player_name);
            canvas.AddElement("room_ID", room_ID);
        }