using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing; namespace BilaPani { public static class Vykreslovani { private static Size ROZMERYPLATNA = new Size(500, 500); static Size rozmeryPolicek; private static Graphics g; static BufferedGraphicsContext currentContext; static BufferedGraphics myBuffer; private static Color[,] MapaJakoBarvy; public static void Init(Graphics graphics) { rozmeryPolicek = new Size(ROZMERYPLATNA.Width / mapa.dataMapy.GetLength(0), ROZMERYPLATNA.Height / mapa.dataMapy.GetLength(1)); MapaJakoBarvy = new Color[mapa.dataMapy.GetLength(0), mapa.dataMapy.GetLength(1)]; PrevestMapuDoPoleBarev(); g = graphics; currentContext = BufferedGraphicsManager.Current; myBuffer = currentContext.Allocate(g,new Rectangle(new Point(0,0),ROZMERYPLATNA)); } public static void Vykreslit() { myBuffer.Graphics.Clear(Color.Gray); for (int y = 0; y < mapa.dataMapy.GetLength(1); y++) { for (int x = 0; x < mapa.dataMapy.GetLength(0); x++) { myBuffer.Graphics.FillRectangle(new Pen(MapaJakoBarvy[x, y]).Brush, x * rozmeryPolicek.Width, y * rozmeryPolicek.Height, rozmeryPolicek.Width, rozmeryPolicek.Height); } } myBuffer.Render(); } public static void VykreslitCisla(int[,] cisla) { for (int y = 0; y < cisla.GetLength(1); y++) { for (int x = 0; x < cisla.GetLength(0); x++) { if (cisla[x, y] > 6400 || cisla[x, y] < 0) continue; myBuffer.Graphics.DrawString(cisla[x, y].ToString(), new Font(FontFamily.GenericSerif, 10), new Pen(Color.Orange).Brush, x * rozmeryPolicek.Width, y * rozmeryPolicek.Height); } } myBuffer.Render(); } public static void PrevestMapuDoPoleBarev() { for (int y = 0; y < mapa.dataMapy.GetLength(1); y++) { for (int x = 0; x < mapa.dataMapy.GetLength(0); x++) { MapaJakoBarvy[x, y] = ZiskatBarvuProPolicko(mapa.dataMapy[x, y]); } } MapaJakoBarvy[mapa.poziceCile.X, mapa.poziceCile.Y] = Color.Red; } private static Color ZiskatBarvuProPolicko(mapa.TypPole pole) { switch (pole) { case mapa.TypPole.BilaPani: return Color.WhiteSmoke; case mapa.TypPole.Nic: return Color.Gray; case mapa.TypPole.Televize: return Color.Red; case mapa.TypPole.Zed: return Color.Black; case mapa.TypPole.Zved: return Color.Green; default: return Color.White; } } } }