169 lines
6.1 KiB
C#
169 lines
6.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
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, };
|
|
Korong felvettkorong;
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
felvettkorong = null;
|
|
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 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()
|
|
{
|
|
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)*1.2f;
|
|
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);
|
|
}
|
|
}
|
|
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();
|
|
}
|
|
}
|
|
}
|