using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Hanoitornyai { public partial class Form1 : Form { public Rud[] rudak; private Color[] kszinek = {Color.Red, Color.Orange, Color.Yellow, Color.Aqua, Color.Blue}; public Form1() { InitializeComponent(); rudak = new Rud[3]; for (int i = 0; i < rudak.Length; i++) { rudak[i] = new Rud(Color.Black); } for (int i = 0;i < kszinek.Length;i++) { rudak[0].korongok.Add(new Korong(kszinek[i], 5-i)); } rudakPozicioSzamitas(); } private void Form1_ResizeEnd(object sender, EventArgs e) { //Initialize(); } private void rudakPozicioSzamitas() { float psz = JatekPanel.Width; float pm = JatekPanel.Height; float rm = pm * 0.75f; float rsz = rm / 12; float rkoz = (psz - (3 * rsz)) / 4; for (int i = 0; i < rudak.Length; i++) { rudak[i].magassag = rm; rudak[i].szelesseg = rsz; rudak[i].y = pm / 4; rudak[i].x = (rkoz*(i+1))+(i*rsz); } } private void KorongSzamitas() { float km = rudak[0].szelesseg*1.5f; float rsz = rudak[0].szelesseg; for (int i = 0; i < 3; i++) { for (int j = 0; j < rudak[i].korongok.Count; j++) { rudak[i].korongok[j].magassag = km; int meret = rudak[i].korongok[j].meretjelzo; rudak[i].korongok[j].szelesseg = rsz + (rsz*meret); float rx = rudak[i].x; rudak[i].korongok[j].x = rx - ((rudak[i].korongok[j].szelesseg - rsz) / 2); rudak[i].korongok[j].y = JatekPanel.Height - ((j + 1) * km); } } } /* public void Initialize() { Graphics g = JatekPanel.CreateGraphics(); g.Clear(Color.White); Pen toll = new Pen(Color.Black); Brush brush = new SolidBrush(Color.Black); int egynegyed = JatekPanel.Width / 4; int ketharmad = (JatekPanel.Height / 3) * 2; g.FillRectangle(brush, new Rectangle(egynegyed - 10, JatekPanel.Height - ketharmad, 20, ketharmad)); g.FillRectangle(brush, new Rectangle(egynegyed * 2 - 10, JatekPanel.Height - ketharmad, 20, ketharmad)); g.FillRectangle(brush, new Rectangle(egynegyed * 3 - 10, JatekPanel.Height - ketharmad, 20, ketharmad)); g.FillRectangle(brush, new Rectangle(0, JatekPanel.Height - 20, JatekPanel.Width, 20)); }*/ private void Paint(object sender, PaintEventArgs e) { Graphics g = JatekPanel.CreateGraphics(); g.Clear(JatekPanel.BackColor); Brush brush = new SolidBrush(rudak[0].szin); rudakPozicioSzamitas(); KorongSzamitas(); for (int i = 0; i < rudak.Length; i++) { g.FillRectangle(brush, rudak[i].x, rudak[i].y, rudak[i].szelesseg, rudak[i].magassag); foreach(Korong k in rudak[i].korongok) { Brush korongecset = new SolidBrush(k.szin); g.FillRectangle(korongecset, k.x, k.y, k.szelesseg, k.magassag); } } } } }