Esempio n. 1
0
        public Form1()
        {
            LayerValueToColorMapping = new Dictionary <int, Color>()
            {
                // background
                { 1, Color.Beige },
                { 2, Color.AliceBlue },
                { 3, Color.Orange },

                // seabottom
                { 11, Color.Gray },

                // seasurface
                { 21, Color.Black },

                // animations
                { 31, Color.RosyBrown },
                { 32, Color.Yellow },
                { 33, Color.OrangeRed },
                { 34, Color.Green }
            };

            Pixels = new SortedDictionary <string, PictureBox>();

            InitializeComponent();

            CreateGrid();

            Game = new GameEngine(this);

            LastGridState = null;
        }
Esempio n. 2
0
        private void DrawGrid(ConcreteLayer gridstate)
        {
            foreach (var displayValue in gridstate)
            {
                var key = displayValue.Key;
                int x   = key.Item1;
                int y   = key.Item2;

                string naam = GetPixelNaam(x, y);

                PictureBox pixel = this.Pixels[naam];
                pixel.BackColor = this.LayerValueToColorMapping[displayValue.Value];
            }
        }
        public static ConcreteLayer CaluculateDiff(ConcreteLayer oldLayer, ConcreteLayer newLayer)
        {
            var diff = new ConcreteLayer();

            foreach (var displayvalue in oldLayer)
            {
                var key = displayvalue.Key;
                if (oldLayer[key] != newLayer[key])
                {
                    diff.Add(key, newLayer[key]);
                }
            }

            return(diff);
        }
Esempio n. 4
0
        public ConcreteLayer GetGrid()
        {
            var gridstate = new ConcreteLayer();

            for (int i = 0; i <= Sea.GridWidth; i++)
            {
                for (int j = 0; j <= Sea.GridHeight; j++)
                {
                    int value = GetDisplayValue(i, j);
                    var key   = new Tuple <int, int>(i, j);

                    gridstate.Add(key, value);
                }
            }

            return(gridstate);
        }
Esempio n. 5
0
        public void RepaintGrid()
        {
            ViewModel     vm         = this.Game.GetViewModel();
            ConcreteLayer gridToDraw = null;

            // Reset or start state
            if (this.LastGridState == null)
            {
                this.LastGridState = vm.GetGrid();
                DrawGrid(this.LastGridState);
            }

            else
            {
                ConcreteLayer newGridState     = this.Game.GetViewModel().GetGrid();
                ConcreteLayer newGridStateDiff = ConcreteLayer.CaluculateDiff(this.LastGridState, newGridState);
                this.LastGridState = newGridState;
                DrawGrid(newGridStateDiff);
            }
        }