void KetGolyoCserejePalyan(Golyo golyo1, Golyo golyo2) { ConsoleColor golyo1Szine = golyo1.Szine; Palya.Jatekter[golyo1.SorIndex, golyo1.OszlopIndex] = new Golyo(golyo1.SorIndex, golyo1.OszlopIndex, golyo2.Szine); Palya.Jatekter[golyo2.SorIndex, golyo2.OszlopIndex] = new Golyo(golyo2.SorIndex, golyo2.OszlopIndex, golyo1Szine); }
/// <summary> /// A megadott sorindextől felfele (a sorindexet is beleértve) minden üres helyet a tetejére visz, és a színes golyókat pedig az aljához "szorítja" /// </summary> /// <param name="sorIndextolFelfele"></param> /// <param name="y"></param> void FuggolegesSzetvalogatasHelybenCserevel(int sorIndextolFelfele, int y) { Golyo[,] palya = Palya.Jatekter; int belsoSorindex = int.MaxValue; for (int x = sorIndextolFelfele; x >= 0; x--) { if (palya[x, y] == null) { belsoSorindex = x - 1; for (int j = belsoSorindex; j >= 0; j--) { if (palya[j, y] != null) { belsoSorindex = j; j = -1; } } if (belsoSorindex >= 0 && palya[belsoSorindex, y] != null) { palya[x, y] = new Golyo(x, y, palya[belsoSorindex, y].Szine); palya[belsoSorindex, y] = null; } } } }
public Golyo[] GolyokKoordinatainakBekerese() { Golyo golyo1 = Palya[SorszamBeker(1), OszlopszamBeker(1)]; Golyo golyo2 = Palya[SorszamBeker(2), OszlopszamBeker(2)]; return(new Golyo[] { golyo1, golyo2 }); }
/// <summary> /// UnitTest-hez /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Equals(object obj) { if (obj == null || obj.GetType() != typeof(Golyo)) { return(false); } Golyo golyo2 = (Golyo)obj; if (SorIndex != golyo2.SorIndex || OszlopIndex != golyo2.OszlopIndex || Szine != golyo2.Szine) { return(false); } return(true); }
/// <summary> /// Ha a megadott két golyó egymás mellett, vagy felett van, és az így kialakult cserével (1-es rész) egymás mellé vagy fölé kerül /// minimum a Palya osztályban beállított egyszínű golyó, akkor eltünteti azokat, pontokat ad utánuk és a helyükre /// a fölöttük lévő golyó, vagy random színű kerül, majd a módosult sortól újraindul az 1-es rész /// </summary> /// <param name="golyo1"></param> /// <param name="golyo2"></param> protected void Lepes(Golyo golyo1, Golyo golyo2) { var egymasMellett = EgymasMellettE(golyo1, golyo2); var egymasFelett = EgymasFelettE(golyo1, golyo2); if (egymasMellett || egymasFelett) { int legalsoModositottSorindex = (golyo1.SorIndex > golyo2.SorIndex) ? golyo1.SorIndex: golyo2.SorIndex; KetGolyoCserejePalyan(golyo1, golyo2); do { legalsoModositottSorindex = AzonosSzinuGolyokEltuntetese(Palya, Jatekos, legalsoModositottSorindex); UresHelyekreGolyokLehozasa(legalsoModositottSorindex); legalsoModositottSorindex--; } while (legalsoModositottSorindex >= 0); } }
/// <summary> /// A megadott oszlopban a megadott sortól felfele (a sor indexét is beleértve) minden üres helyre egy olyan színű golyót rak be, ami se az üres hely jobb, sem a bal oldalán nincs /// </summary> /// <param name="sorIndex"></param> /// <param name="y"></param> void OszlopUresHelyeireRandomGolyok(int sorIndex, int y) { var palya = Palya.Jatekter; int oszlopokSzama = palya.GetLength(1); for (int x = 0; x <= sorIndex; x++) { if (palya[x, y] == null) { var generaltGolyo = Golyo.RandomSzinuGolyo(x, y); while (y > 0 && palya[x, (y - 1)] != null && generaltGolyo.Szine == palya[x, (y - 1)].Szine || y < oszlopokSzama - 2 && palya[x, (y + 1)] != null && generaltGolyo.Szine == palya[x, (y + 1)].Szine) { generaltGolyo = Golyo.RandomSzinuGolyo(x, y); } palya[x, y] = generaltGolyo; } } }
bool EgymasFelettE(Golyo golyo1, Golyo golyo2) { return(golyo1.OszlopIndex == golyo2.OszlopIndex && Math.Abs(golyo1.SorIndex - golyo2.SorIndex) == 1); }