Beispiel #1
0
        /// <summary>
        /// For each regiment ensure a texture exists and is up to date
        /// </summary>
        /// <param name="abgame"></param>
        internal static void UpdateAllRegimentalTextures(IAleaBelliGame abgame, GraphicsDevice GraphicsDevice, SpriteBatch spriteBatch, SpriteFont CounterFont)
        {
            foreach (Regiment r in abgame.AllRegiments)
            {
                RenderTarget2D renderTarget;
                // does the texture exists or is the regiment 'dirty'
                if (regimentTextures.TryGetValue(r.RegimentId, out renderTarget) == false)
                {
                    // create the texture
                    renderTarget = new RenderTarget2D(
                        GraphicsDevice,
                        200,
                        200,
                        false,
                        GraphicsDevice.PresentationParameters.BackBufferFormat,
                        DepthFormat.Depth24);

                    // add to the structure
                    regimentTextures[r.RegimentId] = renderTarget;

                    // redraw
                    r.IsDirty = false;

                    UpdateRegimentalTexture(r, renderTarget, GraphicsDevice, spriteBatch, CounterFont);
                }
                else if (r.IsDirty)
                {
                    // redraw
                    r.IsDirty = false;

                    UpdateRegimentalTexture(r, renderTarget, GraphicsDevice, spriteBatch, CounterFont);
                }
            }
        }
Beispiel #2
0
        public MapVisualHost(IAleaBelliGame game, Controller controller)
        {
            this.game         = game;
            this.ClipToBounds = false;
            this.controller   = controller;
            UpdateGameVisuals();

            // Add the event handler for MouseLeftButtonUp.
///            this.MouseLeftButtonUp += new System.Windows.Input.MouseButtonEventHandler(OnMouseLeftButtonDown);
        }
        public static string ReadStringResource(IAleaBelliGame g, string filename)
        {
            List <string> list = ReadTextResource(g, filename);
            StringBuilder sb   = new StringBuilder();

            foreach (string s in list)
            {
                sb.AppendLine(s);
            }

            return(sb.ToString());
        }
        public static void LoadNations(IAleaBelliGame g)
        {
            List <string> nations = ReadTextResource(g, "nations.txt");

            foreach (string s in nations)
            {
                // id,name
                string[] a         = s.Split(',');
                int      id        = int.Parse(a[0].Trim());
                string   name      = a[1].Trim();
                string   baseColor = a[2].Trim();
                Nation   n         = new Nation()
                {
                    ShortName = name, NationId = id, BaseColour = baseColor
                };
                g.AddNation(n);
            }
        }
        public static List <string> ReadTextFileResource(IAleaBelliGame g, string filename)
        {
            List <string> lines = new List <string>();

            // Open the text file using a stream reader.
            using (StreamReader reader = new StreamReader(filename))
            {
                while (reader.Peek() >= 0)
                {
                    string line = reader.ReadLine();
                    if (!string.IsNullOrEmpty(line) && !line.StartsWith("#"))
                    {
                        lines.Add(line);
                    }
                }
            }
            return(lines);
        }
        public static List <string> ReadTextResource(IAleaBelliGame g, string filename)
        {
            List <string> lines = new List <string>();

            if (defaultUseFile)
            {
                return(ReadTextFileResource(g, baseFilePath + filename));
            }

            var assembly = g.GetType().Assembly;
            var names    = g.GetType().Assembly.GetManifestResourceNames();

            foreach (string name in names)
            {
                if (name.EndsWith(filename))
                {
                    // var resource = assembly.GetManifestResourceStream(name);
                    using (Stream stream = assembly.GetManifestResourceStream(name))
                    {
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            while (reader.Peek() >= 0)
                            {
                                string line = reader.ReadLine();
                                if (!string.IsNullOrEmpty(line) && !line.StartsWith("#"))
                                {
                                    lines.Add(line);
                                }
                            }
                        }
                    }
                }
            }

            return(lines);
        }