Mi a hiba a kóddal? (C#)
A progi eddigi részének az lenen a lényeg h lerakjon véletlenszerűen 20 pictureboxot. Viszont néha rárakja az egyik pb re a másikat így csak 19 picturebox látható. NEM mindig csinálja csak úgy 01 ből 5 ször. Nem tudom mi a hiba. A kód elég rondára és bonyolultra sikeredett ezért elnézést kérek. Ha valaki tudja mi a hiba eben az kérem írja le. Köszönöm előre.
public partial class Form1 : Form
{
Random pozicio = new Random();
int szaz = 100;
int egy;
Point kep;
public void KepLerakas()
{
egy = pozicio.Next(1, 6);
kep.X = egy * szaz;
egy = pozicio.Next(1, 6);
kep.Y = egy * szaz;
label1.Text = Convert.ToString(kep);
}
public void Kep1()
{
KepLerakas();
kartya.Location=kep;
}
public void Kep2()
{
KepLerakas();
kartya2.Location = kep;
while (kartya2.Location == kartya.Location)
{
KepLerakas();
kartya2.Location = kep;
}
}
public void Kep3()
{
KepLerakas();
kartya3.Location = kep;
while (kartya3.Location == kartya2.Location || kartya3.Location == kartya.Location)
{
KepLerakas();
kartya3.Location = kep;
}
}
public void Kep4()
{
KepLerakas();
kartya4.Location = kep;
while (kartya4.Location == kartya3.Location || kartya4.Location == kartya2.Location || kartya4.Location == kartya.Location)
{
KepLerakas();
kartya4.Location = kep;
}
}
public void Kep5()
{
KepLerakas();
kartya5.Location = kep;
while (kartya5.Location == kartya4.Location || kartya5.Location == kartya3.Location || kartya5.Location == kartya2.Location || kartya5.Location == kartya.Location)
{
KepLerakas();
kartya5.Location = kep;
}
}
public void Kep6()
{
KepLerakas();
kartya6.Location = kep;
while (kartya6.Location == kartya5.Location || kartya6.Location == kartya4.Location || kartya6.Location == kartya3.Location || kartya6.Location == kartya2.Location || kartya6.Location == kartya.Location)
{
KepLerakas();
kartya6.Location = kep;
}
}
public void Kep7()
{
KepLerakas();
kartya7.Location = kep;
while (kartya7.Location == kartya6.Location || kartya7.Location == kartya5.Location || kartya7.Location == kartya4.Location || kartya7.Location == kartya3.Location || kartya7.Location == kartya2.Location || kartya7.Location == kartya.Location)
{
KepLerakas();
kartya7.Location = kep;
}
}
public void Kep8()
{
KepLerakas();
kartya8.Location = kep;
while (kartya8.Location == kartya7.Location || kartya8.Location == kartya6.Location || kartya8.Location == kartya5.Location || kartya8.Location == kartya4.Location || kartya8.Location == kartya3.Location || kartya8.Location == kartya2.Location || kartya8.Location == kartya.Location)
{
KepLerakas();
kartya8.Location = kep;
}
}
public void Kep9()
{
KepLerakas();
kartya9.Location = kep;
while (kartya9.Location == kartya8.Location || kartya9.Location == kartya7.Location || kartya9.Location == kartya6.Location || kartya9.Location == kartya5.Location || kartya9.Location == kartya4.Location || kartya9.Location == kartya3.Location || kartya9.Location == kartya2.Location||kartya9.Location == kartya.Location)
{
KepLerakas();
kartya9.Location = kep;
}
}
public void Kep10()
{
KepLerakas();
kartya10.Location = kep;
while (kartya10.Location == kartya9.Location || kartya10.Location == kartya8.Location || kartya10.Location == kartya7.Location || kartya10.Location == kartya6.Location || kartya10.Location == kartya5.Location || kartya10.Location == kartya4.Location || kartya10.Location == kartya3.Location || kartya10.Location == kartya2.Location || kartya10.Location == kartya.Location)
{
KepLerakas();
kartya10.Location = kep;
}
}
public void Kep11()
{
KepLerakas();
kartya11.Location = kep;
while (kartya11.Location == kartya10.Location || kartya11.Location == kartya9.Location || kartya11.Location == kartya8.Location || kartya11.Location == kartya7.Location || kartya11.Location == kartya6.Location || kartya11.Location == kartya5.Location || kartya11.Location == kartya4.Location || kartya11.Location == kartya3.Location || kartya11.Location == kartya2.Location || kartya11.Location == kartya.Location)
{
KepLerakas();
kartya11.Location = kep;
}
}
public void Kep12()
{
KepLerakas();
kartya12.Location = kep;
while (kartya12.Location == kartya11.Location || kartya12.Location == kartya10.Location || kartya12.Location == kartya9.Location || kartya12.Location == kartya8.Location || kartya12.Location == kartya7.Location || kartya12.Location == kartya6.Location || kartya12.Location == kartya5.Location || kartya12.Location == kartya4.Location || kartya12.Location == kartya3.Location || kartya12.Location == kartya2.Location || kartya12.Location == kartya.Location)
{
KepLerakas();
kartya12.Location = kep;
}
}
public void Kep13()
{
KepLerakas();
kartya13.Location = kep;
while (kartya13.Location == kartya12.Location || kartya13.Location == kartya10.Location || kartya13.Location == kartya9.Location || kartya13.Location == kartya8.Location || kartya13.Location == kartya7.Location || kartya13.Location == kartya6.Location || kartya13.Location == kartya5.Location || kartya13.Location == kartya5.Location || kartya13.Location == kartya4.Location || kartya13.Location == kartya3.Location || kartya13.Location == kartya2.Location || kartya13.Location == kartya.Location)
{
KepLerakas();
kartya13.Location = kep;
}
}
public void Kep14()
{
KepLerakas();
kartya14.Location = kep;
while (kartya14.Location == kartya13.Location || kartya14.Location == kartya12.Location || kartya14.Location == kartya10.Location || kartya14.Location == kartya9.Location || kartya14.Location == kartya8.Location || kartya14.Location == kartya7.Location || kartya14.Location == kartya6.Location || kartya14.Location == kartya5.Location || kartya14.Location == kartya5.Location || kartya14.Location == kartya4.Location || kartya14.Location == kartya3.Location || kartya14.Location == kartya2.Location || kartya14.Location == kartya.Location)
{
KepLerakas();
kartya14.Location = kep;
}
}
public void Kep15()
{
KepLerakas();
kartya15.Location = kep;
while (kartya15.Location == kartya14.Location ||kartya15.Location == kartya13.Location || kartya15.Location == kartya12.Location || kartya15.Location == kartya10.Location || kartya15.Location == kartya9.Location || kartya15.Location == kartya8.Location || kartya15.Location == kartya7.Location || kartya15.Location == kartya6.Location || kartya15.Location == kartya5.Location || kartya15.Location == kartya5.Location || kartya15.Location == kartya4.Location || kartya15.Location == kartya3.Location || kartya15.Location == kartya2.Location || kartya15.Location == kartya.Location)
{
KepLerakas();
kartya15.Location = kep;
}
}
public void Kep16()
{
KepLerakas();
kartya16.Location = kep;
while (kartya16.Location == kartya15.Location || kartya16.Location == kartya14.Location || kartya16.Location == kartya13.Location || kartya16.Location == kartya12.Location || kartya16.Location == kartya10.Location || kartya16.Location == kartya9.Location || kartya16.Location == kartya8.Location || kartya16.Location == kartya7.Location || kartya16.Location == kartya6.Location || kartya16.Location == kartya5.Location || kartya16.Location == kartya5.Location || kartya16.Location == kartya4.Location || kartya16.Location == kartya3.Location || kartya16.Location == kartya2.Location || kartya16.Location == kartya.Location)
{
KepLerakas();
kartya16.Location = kep;
}
}
public void Kep17()
{
KepLerakas();
kartya17.Location = kep;
while (kartya17.Location == kartya16.Location || kartya17.Location == kartya15.Location || kartya17.Location == kartya14.Location || kartya17.Location == kartya13.Location || kartya17.Location == kartya12.Location || kartya17.Location == kartya10.Location || kartya17.Location == kartya9.Location || kartya17.Location == kartya8.Location || kartya17.Location == kartya7.Location || kartya17.Location == kartya6.Location || kartya17.Location == kartya5.Location || kartya17.Location == kartya5.Location || kartya17.Location == kartya4.Location || kartya17.Location == kartya3.Location || kartya17.Location == kartya2.Location || kartya17.Location == kartya.Location)
{
KepLerakas();
kartya17.Location = kep;
}
}
public void Kep18()
{
KepLerakas();
kartya18.Location = kep;
while (kartya18.Location == kartya17.Location || kartya18.Location == kartya16.Location || kartya18.Location == kartya15.Location || kartya18.Location == kartya14.Location || kartya18.Location == kartya13.Location || kartya18.Location == kartya12.Location || kartya18.Location == kartya10.Location || kartya18.Location == kartya9.Location || kartya18.Location == kartya8.Location || kartya18.Location == kartya7.Location || kartya18.Location == kartya6.Location || kartya18.Location == kartya5.Location || kartya18.Location == kartya5.Location || kartya18.Location == kartya4.Location || kartya18.Location == kartya3.Location || kartya18.Location == kartya2.Location || kartya18.Location == kartya.Location)
{
KepLerakas();
kartya18.Location = kep;
}
}
public void Kep19()
{
KepLerakas();
kartya19.Location = kep;
while (kartya19.Location == kartya18.Location || kartya19.Location == kartya17.Location || kartya19.Location == kartya16.Location || kartya19.Location == kartya15.Location || kartya19.Location == kartya14.Location || kartya19.Location == kartya13.Location || kartya19.Location == kartya12.Location || kartya19.Location == kartya10.Location || kartya19.Location == kartya9.Location || kartya19.Location == kartya8.Location || kartya19.Location == kartya7.Location || kartya19.Location == kartya6.Location || kartya19.Location == kartya5.Location || kartya19.Location == kartya5.Location || kartya19.Location == kartya4.Location || kartya19.Location == kartya3.Location || kartya19.Location == kartya2.Location || kartya19.Location == kartya.Location)
{
KepLerakas();
kartya19.Location = kep;
}
}
public void Kep20()
{
KepLerakas();
kartya20.Location = kep;
while (kartya20.Location == kartya19.Location || kartya20.Location == kartya18.Location || kartya20.Location == kartya17.Location || kartya20.Location == kartya16.Location || kartya20.Location == kartya15.Location || kartya20.Location == kartya14.Location || kartya20.Location == kartya13.Location || kartya20.Location == kartya12.Location || kartya20.Location == kartya10.Location || kartya20.Location == kartya9.Location || kartya20.Location == kartya8.Location || kartya20.Location == kartya7.Location || kartya20.Location == kartya6.Location || kartya20.Location == kartya5.Location || kartya20.Location == kartya5.Location || kartya20.Location == kartya4.Location || kartya20.Location == kartya3.Location || kartya20.Location == kartya2.Location || kartya20.Location == kartya.Location)
{
KepLerakas();
kartya20.Location = kep;
}
}
public Form1()
{
InitializeComponent();
timer1.Interval = 400;
timer1.Enabled = true;
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
Kep1();
Kep2();
Kep3();
Kep4();
Kep5();
Kep6();
Kep7();
Kep8();
Kep9();
Kep10();
Kep11();
Kep12();
Kep13();
Kep14();
Kep15();
Kep16();
Kep17();
Kep18();
Kep19();
Kep20();
timer1.Enabled = false;
}
}
}
Bocs, de ez a kód egy hulladék. Nem is fogom végigolvasni. Az a fogalom mond neked valamit, hogy heterogén kollekció (C#-os néven gyűjtemény)? Vagy az, hogy tömb? Ha nem, akkor tanuld meg. Ha igen, akkor használd. Bocsi a hangnemért, de ezt így tudtam megfogalmazni.
System.Collections.Generic -ből nézd meg a listát (List).
"Bocs, de ez a kód egy hulladék" :D
Még finoman fogalmaztál.. Bazze, kell neki 20 képet kirakni, erre ír 20 külön függvényt,Kép1, Kép2.. XDDDD
Kérdező, mennyiért csinálsz meg egy programot, ami 5000 képet rak ki véletlenszerűen? :D:D
Így van.
Amik neked kellenek:
Tömb, lista, paraméter átadás, globális változók
Kapcsolódó kérdések:
Minden jog fenntartva © 2025, www.gyakorikerdesek.hu
GYIK | Szabályzat | Jogi nyilatkozat | Adatvédelem | Cookie beállítások | WebMinute Kft. | Facebook | Kapcsolat: info(kukac)gyakorikerdesek.hu
Ha kifogással szeretne élni valamely tartalommal kapcsolatban, kérjük jelezze e-mailes elérhetőségünkön!