Kész!
This commit is contained in:
parent
d1585aff52
commit
f1f64a9b50
1
Hanoitornyai/Form1.Designer.cs
generated
1
Hanoitornyai/Form1.Designer.cs
generated
|
@ -40,6 +40,7 @@
|
||||||
this.JatekPanel.Size = new System.Drawing.Size(800, 450);
|
this.JatekPanel.Size = new System.Drawing.Size(800, 450);
|
||||||
this.JatekPanel.TabIndex = 0;
|
this.JatekPanel.TabIndex = 0;
|
||||||
this.JatekPanel.Paint += new System.Windows.Forms.PaintEventHandler(this.Paint);
|
this.JatekPanel.Paint += new System.Windows.Forms.PaintEventHandler(this.Paint);
|
||||||
|
this.JatekPanel.MouseClick += new System.Windows.Forms.MouseEventHandler(this.JatekPanel_MouseClick);
|
||||||
this.JatekPanel.Resize += new System.EventHandler(this.Form1_ResizeEnd);
|
this.JatekPanel.Resize += new System.EventHandler(this.Form1_ResizeEnd);
|
||||||
//
|
//
|
||||||
// InfoPanel
|
// InfoPanel
|
||||||
|
|
|
@ -5,6 +5,7 @@ using System.Data;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
@ -13,10 +14,12 @@ namespace Hanoitornyai
|
||||||
public partial class Form1 : Form
|
public partial class Form1 : Form
|
||||||
{
|
{
|
||||||
public Rud[] rudak;
|
public Rud[] rudak;
|
||||||
private Color[] kszinek = {Color.Red, Color.Orange, Color.Yellow, Color.Aqua, Color.Blue};
|
private Color[] kszinek = { Color.Red, Color.Orange, Color.Yellow, Color.Aqua, Color.Blue, };
|
||||||
|
Korong felvettkorong;
|
||||||
public Form1()
|
public Form1()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
felvettkorong = null;
|
||||||
rudak = new Rud[3];
|
rudak = new Rud[3];
|
||||||
for (int i = 0; i < rudak.Length; i++)
|
for (int i = 0; i < rudak.Length; i++)
|
||||||
{
|
{
|
||||||
|
@ -50,7 +53,30 @@ namespace Hanoitornyai
|
||||||
rudak[i].x = (rkoz*(i+1))+(i*rsz);
|
rudak[i].x = (rkoz*(i+1))+(i*rsz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void animation()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 1000; i++)
|
||||||
|
{
|
||||||
|
rudak[0].korongok[0].y -= 2f;
|
||||||
|
|
||||||
|
Thread.Sleep(1);
|
||||||
|
Graphics g = JatekPanel.CreateGraphics();
|
||||||
|
g.Clear(JatekPanel.BackColor);
|
||||||
|
Brush brush = new SolidBrush(rudak[0].szin);
|
||||||
|
rudakPozicioSzamitas();
|
||||||
|
|
||||||
|
for (int j = 0; j < rudak.Length; j++)
|
||||||
|
{
|
||||||
|
g.FillRectangle(brush, rudak[j].x, rudak[j].y, rudak[j].szelesseg, rudak[j].magassag);
|
||||||
|
foreach (Korong k in rudak[j].korongok)
|
||||||
|
{
|
||||||
|
Brush korongecset = new SolidBrush(k.szin);
|
||||||
|
g.FillRectangle(korongecset, k.x, k.y, k.szelesseg, k.magassag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
private void KorongSzamitas()
|
private void KorongSzamitas()
|
||||||
{
|
{
|
||||||
float km = rudak[0].szelesseg*1.5f;
|
float km = rudak[0].szelesseg*1.5f;
|
||||||
|
@ -61,7 +87,7 @@ namespace Hanoitornyai
|
||||||
{
|
{
|
||||||
rudak[i].korongok[j].magassag = km;
|
rudak[i].korongok[j].magassag = km;
|
||||||
int meret = rudak[i].korongok[j].meretjelzo;
|
int meret = rudak[i].korongok[j].meretjelzo;
|
||||||
rudak[i].korongok[j].szelesseg = rsz + (rsz*meret);
|
rudak[i].korongok[j].szelesseg = rsz + (rsz*meret)*1.2f;
|
||||||
float rx = rudak[i].x;
|
float rx = rudak[i].x;
|
||||||
rudak[i].korongok[j].x = rx - ((rudak[i].korongok[j].szelesseg - rsz) / 2);
|
rudak[i].korongok[j].x = rx - ((rudak[i].korongok[j].szelesseg - rsz) / 2);
|
||||||
rudak[i].korongok[j].y = JatekPanel.Height - ((j + 1) * km);
|
rudak[i].korongok[j].y = JatekPanel.Height - ((j + 1) * km);
|
||||||
|
@ -90,15 +116,53 @@ namespace Hanoitornyai
|
||||||
Brush brush = new SolidBrush(rudak[0].szin);
|
Brush brush = new SolidBrush(rudak[0].szin);
|
||||||
rudakPozicioSzamitas();
|
rudakPozicioSzamitas();
|
||||||
KorongSzamitas();
|
KorongSzamitas();
|
||||||
for (int i = 0; i < rudak.Length; i++)
|
for (int i = 0; i < rudak.Length; i++)
|
||||||
{
|
{
|
||||||
g.FillRectangle(brush, rudak[i].x, rudak[i].y, rudak[i].szelesseg, rudak[i].magassag);
|
g.FillRectangle(brush, rudak[i].x, rudak[i].y, rudak[i].szelesseg, rudak[i].magassag);
|
||||||
foreach(Korong k in rudak[i].korongok)
|
foreach (Korong k in rudak[i].korongok)
|
||||||
{
|
{
|
||||||
Brush korongecset = new SolidBrush(k.szin);
|
Brush korongecset = new SolidBrush(k.szin);
|
||||||
g.FillRectangle(korongecset, k.x, k.y, k.szelesseg, k.magassag);
|
g.FillRectangle(korongecset, k.x, k.y, k.szelesseg, k.magassag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (felvettkorong != null)
|
||||||
|
{
|
||||||
|
g.FillRectangle(new SolidBrush(felvettkorong.szin), felvettkorong.x, felvettkorong.y, felvettkorong.szelesseg, felvettkorong.magassag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void JatekPanel_MouseClick(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
//animation();
|
||||||
|
Rud valasztottRud = null;
|
||||||
|
foreach (var item in rudak)
|
||||||
|
{
|
||||||
|
if(e.X > item.x && e.X < item.x+item.szelesseg && e.Y > item.y)
|
||||||
|
{
|
||||||
|
valasztottRud = item;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (valasztottRud != null)
|
||||||
|
{
|
||||||
|
if (felvettkorong == null)
|
||||||
|
{
|
||||||
|
|
||||||
|
felvettkorong = valasztottRud.korongok[valasztottRud.korongok.Count - 1];
|
||||||
|
valasztottRud.korongok.Remove(felvettkorong);
|
||||||
|
felvettkorong.y -= 100;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(valasztottRud.korongok.Count == 0 || valasztottRud.korongok[valasztottRud.korongok.Count-1].meretjelzo > felvettkorong.meretjelzo)
|
||||||
|
{
|
||||||
|
felvettkorong.y += 100;
|
||||||
|
valasztottRud.korongok.Add(felvettkorong);
|
||||||
|
felvettkorong = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
JatekPanel.Refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user