/// <summary> /// Prüft, ob das Teil mit anderen bereits gefallenen Segmenten kollidiert, wenn es entsprechend der Vorgabe verschoben wird /// </summary> /// <param name="t">Das fallende Teil</param> /// <param name="deltaSektor">Verschiebung im Sektor</param> /// <param name="deltaSchicht">Verschiebung in der Schicht</param> /// <returns><c>true</c> bei Kollision; <c>false</c> sonst</returns> private bool collidesWith(TTeil t, int deltaSektor, int deltaSchicht) { int positionSektor = calcNewSektor(t.PositionSektor, deltaSektor); int positionSchicht = t.PositionSchicht + deltaSchicht; for (int i = 0; i < TTeil.MaxBreite; i++) { for (int k = 0; k < TTeil.MaxHoehe; k++) { if (t.hasSegment(i, k)) //Das Teil hat an dieser Stelle ein Segment { int pos = calcNewSektor(positionSektor, i); int schicht = positionSchicht - k; if (schicht >= 0 && this.Spielfeld[pos, schicht]) //Überschneidung gefunden { return(true); } } } } //Keine Überschneidung gefunden return(false); }
/// <summary> /// Zeichnet das Teil mit allen seinen Segmenten /// </summary> /// <param name="g">Graphics-Objekt zum Zeichnen</param> /// <param name="t">Das zu zeichnende Teil</param> /// <param name="c">Die Farbe des Teils</param> /// <param name="segment">Das Segment-Objekt, mit dem gezeichnet wird</param> public static void drawTeil(Graphics g, TTeil t, Color c, TSegmentBase segment) { for (int i = 0; i < TTeil.MaxBreite; i++) { for (int k = 0; k < TTeil.MaxHoehe; k++) { if (t.hasSegment(i, k)) { int positionSektor = (t.PositionSektor + i) % TArena.AnzahlSektoren; int positionSchicht = t.PositionSchicht - k; segment.drawSegment(positionSektor, positionSchicht, g, c); } } } }
} //Ende Methode myPanel_Paint /// <summary> /// Speichert das Teil, das unten angekommen ist /// </summary> /// <param name="t">Das zu speichernde Teil</param> public void saveTeil(TTeil t) { for (int i = 0; i < TTeil.MaxBreite; i++) { for (int k = 0; k < TTeil.MaxHoehe; k++) { if (t.hasSegment(i, k)) //Das Teil hat an dieser Stelle ein Segment { int pos = this.myArena.calcNewSektor(t.PositionSektor, i); this.SpielfeldFarben[pos, t.PositionSchicht - k] = this._SharedData.FallingColor; } } } }
/// <summary> /// Löscht das Teil und alle seine Segmente /// </summary> /// <param name="g">Graphics-Objekt zum Zeichnen</param> /// <param name="t">Das zu zeichnende Teil</param> /// <param name="backColor">Hintergrundfarbe des Panels</param> /// <param name="arena">Verweis auf die Arena</param> /// <param name="segment">Verweis auf das Segment zum Zeichnen</param> public static void deleteTeil(Graphics g, TTeil t, Color backColor, TVisualArena arena, TSegmentBase segment) { for (int i = 0; i < TTeil.MaxBreite; i++) { for (int k = 0; k < TTeil.MaxHoehe; k++) { if (t.hasSegment(i, k)) { int positionSektor = (t.PositionSektor + i) % TArena.AnzahlSektoren; int positionSchicht = t.PositionSchicht - k; segment.deleteSegment(positionSektor, positionSchicht, g, backColor); arena.repairNachbarn(positionSektor, positionSchicht, g); } } } }
/// <summary> /// Speichert das Teil, das unten angekommen ist /// </summary> /// <param name="t">Das zu speichernde Teil</param> public void saveTeil(TTeil t) { for (int i = 0; i < TTeil.MaxBreite; i++) { for (int k = 0; k < TTeil.MaxHoehe; k++) { if (t.hasSegment(i, k)) //Das Teil hat an dieser Stelle ein Segment { int pos = calcNewSektor(t.PositionSektor, i); int schicht = t.PositionSchicht - k; if (schicht > 0) { this.Spielfeld[pos, schicht] = true; } } } } }