/// <summary> /// Setzt die Schiffsteile an den jeweiligen Positionen fest (Bei einem MouseClick-Event) /// </summary> /// <param name="tmp">Das Panel welches das MouseClick-Event ausgelöst hat (als Referenz)</param> private void setShips(ref Panel_DoubleBuffered tmp) { String positionString = tmp.Name; // pb_ aus dem String entfernen positionString = positionString.Remove(0, 3); // x und y Position String[] position = positionString.Split(':'); int x = int.Parse(position[0]); int y = int.Parse(position[1]); switch (ships) { // galley case shipModels.galley: if (horizontal) { // Horizontal // galley ist 4 Fleder groß, wenn Feld 7 erreicht, dann Schiff in gegengesetzte Richtung aufbauen if (x >= 7) { if ((int)tmp.Tag != (int)1 && (int)pb[x - 1, y].Tag != (int)1 && (int)pb[x - 2, y].Tag != (int)1 && (int)pb[x - 3, y].Tag != (int)1) { tmp.BackgroundImage = Battleships.Properties.Resources.galley4h; pb[x - 1, y].BackgroundImage = Battleships.Properties.Resources.galley3h; pb[x - 2, y].BackgroundImage = Battleships.Properties.Resources.galley2h; pb[x - 3, y].BackgroundImage = Battleships.Properties.Resources.galley1h; tmp.Tag = 1; pb[x - 1, y].Tag = 1; pb[x - 2, y].Tag = 1; pb[x - 3, y].Tag = 1; galleyRef.name = "Galley"; galleyRef.posHeckX = x; galleyRef.posHeckY = y; galleyRef.shipDestryoed = false; galleyRef.Heck = false; galleyRef.Front = false; galleyRef.middle1 = false; galleyRef.middle2 = false; galleyRef.horizontal = horizontal; pb_Store[x, y].Name = galleyRef.name + "_" + "Front"; pb_Store[x - 1, y].Name = galleyRef.name + "_" + "Middle2"; pb_Store[x - 2, y].Name = galleyRef.name + "_" + "Middle1"; pb_Store[x - 3, y].Name = galleyRef.name + "_" + "Heck"; // Schiffsauswahl auf nothing setzen ships = shipModels.nothing; } else { // Anzeigen, dass hier kein Schiff plaziert werden kann (entsprechende Felder rot blinken lassen) tmp.BackColor = collisionColor; pb[x - 1, y].BackColor = collisionColor; pb[x - 2, y].BackColor = collisionColor; pb[x - 3, y].BackColor = collisionColor; Application.DoEvents(); System.Threading.Thread.Sleep(500); tmp.BackColor = Color.Transparent; pb[x - 1, y].BackColor = Color.Transparent; pb[x - 2, y].BackColor = Color.Transparent; pb[x - 3, y].BackColor = Color.Transparent; return; } } // Ansonsten galley in normaler Richtung zusammenbauen (4 Felder) else { if ((int)tmp.Tag != (int)1 && (int)pb[x + 1, y].Tag != (int)1 && (int)pb[x + 2, y].Tag != (int)1 && (int)pb[x + 3, y].Tag != (int)1) { tmp.BackgroundImage = Battleships.Properties.Resources.galley1h; pb[x + 1, y].BackgroundImage = Battleships.Properties.Resources.galley2h; pb[x + 2, y].BackgroundImage = Battleships.Properties.Resources.galley3h; pb[x + 3, y].BackgroundImage = Battleships.Properties.Resources.galley4h; tmp.Tag = 1; pb[x + 1, y].Tag = 1; pb[x + 2, y].Tag = 1; pb[x + 3, y].Tag = 1; galleyRef.name = "Galley"; galleyRef.posHeckX = x; galleyRef.posHeckY = y; galleyRef.shipDestryoed = false; galleyRef.Heck = false; galleyRef.Front = false; galleyRef.middle1 = false; galleyRef.middle2 = false; galleyRef.horizontal = horizontal; pb_Store[x, y].Name = galleyRef.name + "_" + "Heck"; pb_Store[x + 1, y].Name = galleyRef.name + "_" + "Middle1"; pb_Store[x + 2, y].Name = galleyRef.name + "_" + "Middle2"; pb_Store[x + 3, y].Name = galleyRef.name + "_" + "Front"; // Schiffsauswahl auf nothing setzen ships = shipModels.nothing; } else { // Anzeigen, dass hier kein Schiff plaziert werden kann (entsprechende Felder rot blinken lassen) tmp.BackColor = collisionColor; pb[x + 1, y].BackColor = collisionColor; pb[x + 2, y].BackColor = collisionColor; pb[x + 3, y].BackColor = collisionColor; Application.DoEvents(); System.Threading.Thread.Sleep(500); tmp.BackColor = Color.Transparent; pb[x + 1, y].BackColor = Color.Transparent; pb[x + 2, y].BackColor = Color.Transparent; pb[x + 3, y].BackColor = Color.Transparent; return; } } } else { // Vertikal // galley ist 4 Fleder groß, wenn Feld 7 erreicht, dann Schiff in gegengesetzte Richtung aufbauen if (y >= 7) { if ((int)tmp.Tag != 1 && (int)pb[x, y - 1].Tag != 1 && (int)pb[x, y - 2].Tag != 1 && (int)pb[x, y - 3].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.galley4v; pb[x, y - 1].BackgroundImage = Battleships.Properties.Resources.galley3v; pb[x, y - 2].BackgroundImage = Battleships.Properties.Resources.galley2v; pb[x, y - 3].BackgroundImage = Battleships.Properties.Resources.galley1v; tmp.Tag = 1; pb[x, y - 1].Tag = 1; pb[x, y - 2].Tag = 1; pb[x, y - 3].Tag = 1; galleyRef.name = "Galley"; galleyRef.posHeckX = x; galleyRef.posHeckY = y; galleyRef.shipDestryoed = false; galleyRef.Heck = false; galleyRef.Front = false; galleyRef.middle1 = false; galleyRef.middle2 = false; galleyRef.horizontal = horizontal; pb_Store[x, y].Name = galleyRef.name + "_" + "Front"; pb_Store[x, y - 1].Name = galleyRef.name + "_" + "Middle2"; pb_Store[x, y - 2].Name = galleyRef.name + "_" + "Middle1"; pb_Store[x, y - 3].Name = galleyRef.name + "_" + "Heck"; // Schiffsauswahl auf nothing setzen ships = shipModels.nothing; } else { // Anzeigen, dass hier kein Schiff plaziert werden kann (entsprechende Felder rot blinken lassen) tmp.BackColor = collisionColor; pb[x, y - 1].BackColor = collisionColor; pb[x, y - 2].BackColor = collisionColor; pb[x, y - 3].BackColor = collisionColor; Application.DoEvents(); System.Threading.Thread.Sleep(500); tmp.BackColor = Color.Transparent; pb[x, y - 1].BackColor = Color.Transparent; pb[x, y - 2].BackColor = Color.Transparent; pb[x, y - 3].BackColor = Color.Transparent; return; } } // Ansonsten galley in normaler Richtung zusammenbauen (4 Felder) else { if ((int)tmp.Tag != 1 && (int)pb[x, y + 1].Tag != 1 && (int)pb[x, y + 2].Tag != 1 && (int)pb[x, y + 3].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.galley1v; pb[x, y + 1].BackgroundImage = Battleships.Properties.Resources.galley2v; pb[x, y + 2].BackgroundImage = Battleships.Properties.Resources.galley3v; pb[x, y + 3].BackgroundImage = Battleships.Properties.Resources.galley4v; tmp.Tag = 1; pb[x, y + 1].Tag = 1; pb[x, y + 2].Tag = 1; pb[x, y + 3].Tag = 1; galleyRef.name = "Galley"; galleyRef.posHeckX = x; galleyRef.posHeckY = y; galleyRef.shipDestryoed = false; galleyRef.Heck = false; galleyRef.Front = false; galleyRef.middle1 = false; galleyRef.middle2 = false; galleyRef.horizontal = horizontal; pb_Store[x, y].Name = galleyRef.name + "_" + "Heck"; pb_Store[x, y + 1].Name = galleyRef.name + "_" + "Middle1"; pb_Store[x, y + 2].Name = galleyRef.name + "_" + "Middle2"; pb_Store[x, y + 3].Name = galleyRef.name + "_" + "Front"; // Schiffsauswahl auf nothing setzen ships = shipModels.nothing; } else { // Anzeigen, dass hier kein Schiff plaziert werden kann (entsprechende Felder rot blinken lassen) tmp.BackColor = collisionColor; pb[x, y + 1].BackColor = collisionColor; pb[x, y + 2].BackColor = collisionColor; pb[x, y + 3].BackColor = collisionColor; Application.DoEvents(); System.Threading.Thread.Sleep(500); tmp.BackColor = Color.Transparent; pb[x, y + 1].BackColor = Color.Transparent; pb[x, y + 2].BackColor = Color.Transparent; pb[x, y + 3].BackColor = Color.Transparent; return; } } } break; // battleship case shipModels.battleship: if (horizontal) { // Horizontal // battleship ist 4 Fleder groß, wenn Feld 7 erreicht, dann Schiff in gegengesetzte Richtung aufbauen if (x >= 7) { if ((int)tmp.Tag != 1 && (int)pb[x - 1, y].Tag != 1 && (int)pb[x - 2, y].Tag != 1 && (int)pb[x - 3, y].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.z41; pb[x - 1, y].BackgroundImage = Battleships.Properties.Resources.z31; pb[x - 2, y].BackgroundImage = Battleships.Properties.Resources.z21; pb[x - 3, y].BackgroundImage = Battleships.Properties.Resources.z11; tmp.Tag = 1; pb[x - 1, y].Tag = 1; pb[x - 2, y].Tag = 1; pb[x - 3, y].Tag = 1; // Schiffsauswahl auf nothing setzen ships = shipModels.nothing; battleshipRef.name = "Battleship"; battleshipRef.posHeckX = x; battleshipRef.posHeckY = y; battleshipRef.shipDestryoed = false; battleshipRef.Heck = false; battleshipRef.Front = false; battleshipRef.middle1 = false; battleshipRef.middle2 = false; battleshipRef.horizontal = horizontal; pb_Store[x, y].Name = battleshipRef.name + "_" + "Front"; pb_Store[x - 1, y].Name = battleshipRef.name + "_" + "Middle2"; pb_Store[x - 2, y].Name = battleshipRef.name + "_" + "Middle1"; pb_Store[x - 3, y].Name = battleshipRef.name + "_" + "Heck"; } else { // Anzeigen, dass hier kein Schiff plaziert werden kann (entsprechende Felder rot blinken lassen) tmp.BackColor = collisionColor; pb[x - 1, y].BackColor = collisionColor; pb[x - 2, y].BackColor = collisionColor; pb[x - 3, y].BackColor = collisionColor; Application.DoEvents(); System.Threading.Thread.Sleep(500); tmp.BackColor = Color.Transparent; pb[x - 1, y].BackColor = Color.Transparent; pb[x - 2, y].BackColor = Color.Transparent; pb[x - 3, y].BackColor = Color.Transparent; return; } } // Ansonsten battleship in normaler Richtung zusammenbauen (5 Felder) else { if ((int)tmp.Tag != 1 && (int)pb[x + 1, y].Tag != 1 && (int)pb[x + 2, y].Tag != 1 && (int)pb[x + 3, y].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.z11; pb[x + 1, y].BackgroundImage = Battleships.Properties.Resources.z21; pb[x + 2, y].BackgroundImage = Battleships.Properties.Resources.z31; pb[x + 3, y].BackgroundImage = Battleships.Properties.Resources.z41; tmp.Tag = 1; pb[x + 1, y].Tag = 1; pb[x + 2, y].Tag = 1; pb[x + 3, y].Tag = 1; battleshipRef.name = "Battleship"; battleshipRef.posHeckX = x; battleshipRef.posHeckY = y; battleshipRef.shipDestryoed = false; battleshipRef.Heck = false; battleshipRef.Front = false; battleshipRef.middle1 = false; battleshipRef.middle2 = false; battleshipRef.horizontal = horizontal; pb_Store[x, y].Name = battleshipRef.name + "_" + "Heck"; pb_Store[x + 1, y].Name = battleshipRef.name + "_" + "Middle1"; pb_Store[x + 2, y].Name = battleshipRef.name + "_" + "Middle2"; pb_Store[x + 3, y].Name = battleshipRef.name + "_" + "Front"; // Schiffsauswahl auf nothing setzen ships = shipModels.nothing; } else { // Anzeigen, dass hier kein Schiff plaziert werden kann (entsprechende Felder rot blinken lassen) tmp.BackColor = collisionColor; pb[x + 1, y].BackColor = collisionColor; pb[x + 2, y].BackColor = collisionColor; pb[x + 3, y].BackColor = collisionColor; Application.DoEvents(); System.Threading.Thread.Sleep(500); tmp.BackColor = Color.Transparent; pb[x + 1, y].BackColor = Color.Transparent; pb[x + 2, y].BackColor = Color.Transparent; pb[x + 3, y].BackColor = Color.Transparent; return; } } } else { // Vertikal // battleship ist 4 Fleder groß, wenn Feld 7 erreicht, dann Schiff in gegengesetzte Richtung aufbauen if (y >= 7) { if ((int)tmp.Tag != 1 && (int)pb[x, y - 1].Tag != 1 && (int)pb[x, y - 2].Tag != 1 && (int)pb[x, y - 3].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.z4v1; pb[x, y - 1].BackgroundImage = Battleships.Properties.Resources.z3v1; pb[x, y - 2].BackgroundImage = Battleships.Properties.Resources.z2v1; pb[x, y - 3].BackgroundImage = Battleships.Properties.Resources.z1v1; tmp.Tag = 1; pb[x, y - 1].Tag = 1; pb[x, y - 2].Tag = 1; pb[x, y - 3].Tag = 1; battleshipRef.name = "Battleship"; battleshipRef.posHeckX = x; battleshipRef.posHeckY = y; battleshipRef.shipDestryoed = false; battleshipRef.Heck = false; battleshipRef.Front = false; battleshipRef.middle1 = false; battleshipRef.middle2 = false; battleshipRef.horizontal = horizontal; pb_Store[x, y].Name = battleshipRef.name + "_" + "Front"; pb_Store[x, y - 1].Name = battleshipRef.name + "_" + "Middle2"; pb_Store[x, y - 2].Name = battleshipRef.name + "_" + "Middle1"; pb_Store[x, y - 3].Name = battleshipRef.name + "_" + "Heck"; // Schiffsauswahl auf nothing setzen ships = shipModels.nothing; } else { // Anzeigen, dass hier kein Schiff plaziert werden kann (entsprechende Felder rot blinken lassen) tmp.BackColor = collisionColor; pb[x, y - 1].BackColor = collisionColor; pb[x, y - 2].BackColor = collisionColor; pb[x, y - 3].BackColor = collisionColor; Application.DoEvents(); System.Threading.Thread.Sleep(500); tmp.BackColor = Color.Transparent; pb[x, y - 1].BackColor = Color.Transparent; pb[x, y - 2].BackColor = Color.Transparent; pb[x, y - 3].BackColor = Color.Transparent; return; } } // Ansonsten battleship in normaler Richtung zusammenbauen (5 Felder) else { if ((int)tmp.Tag != 1 && (int)pb[x, y + 1].Tag != 1 && (int)pb[x, y + 2].Tag != 1 && (int)pb[x, y + 3].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.z1v1; pb[x, y + 1].BackgroundImage = Battleships.Properties.Resources.z2v1; pb[x, y + 2].BackgroundImage = Battleships.Properties.Resources.z3v1; pb[x, y + 3].BackgroundImage = Battleships.Properties.Resources.z4v1; tmp.Tag = 1; pb[x, y + 1].Tag = 1; pb[x, y + 2].Tag = 1; pb[x, y + 3].Tag = 1; battleshipRef.name = "Battleship"; battleshipRef.posHeckX = x; battleshipRef.posHeckY = y; battleshipRef.shipDestryoed = false; battleshipRef.Heck = false; battleshipRef.Front = false; battleshipRef.middle1 = false; battleshipRef.middle2 = false; battleshipRef.horizontal = horizontal; pb_Store[x, y].Name = battleshipRef.name + "_" + "Heck"; pb_Store[x, y + 1].Name = battleshipRef.name + "_" + "Middle1"; pb_Store[x, y + 2].Name = battleshipRef.name + "_" + "Middle2"; pb_Store[x, y + 3].Name = battleshipRef.name + "_" + "Front"; // Schiffsauswahl auf nothing setzen ships = shipModels.nothing; } else { // Anzeigen, dass hier kein Schiff plaziert werden kann (entsprechende Felder rot blinken lassen) tmp.BackColor = collisionColor; pb[x, y + 1].BackColor = collisionColor; pb[x, y + 2].BackColor = collisionColor; pb[x, y + 3].BackColor = collisionColor; Application.DoEvents(); System.Threading.Thread.Sleep(500); tmp.BackColor = Color.Transparent; pb[x, y + 1].BackColor = Color.Transparent; pb[x, y + 2].BackColor = Color.Transparent; pb[x, y + 3].BackColor = Color.Transparent; return; } } } break; // Cruiser case shipModels.cruiser: if (horizontal) { // Horizontal // Cruiser ist 3 Fleder groß, wenn Feld 8 erreicht, dann Schiff in gegengesetzte Richtung aufbauen if (x >= 8) { if ((int)tmp.Tag != 1 && (int)pb[x - 1, y].Tag != 1 && (int)pb[x - 2, y].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.cruiser3h; pb[x - 1, y].BackgroundImage = Battleships.Properties.Resources.cruiser2h; pb[x - 2, y].BackgroundImage = Battleships.Properties.Resources.cruiser1h; tmp.Tag = 1; pb[x - 1, y].Tag = 1; pb[x - 2, y].Tag = 1; cruiserRef[zaehler_cruiser].name = "Cruiser_" + zaehler_cruiser.ToString(); cruiserRef[zaehler_cruiser].posHeckX = x; cruiserRef[zaehler_cruiser].posHeckY = y; cruiserRef[zaehler_cruiser].shipDestryoed = false; cruiserRef[zaehler_cruiser].Front = false; cruiserRef[zaehler_cruiser].Heck = false; cruiserRef[zaehler_cruiser].middle = false; cruiserRef[zaehler_cruiser].horizontal = horizontal; pb_Store[x, y].Name = cruiserRef[zaehler_cruiser].name + "_" + "Front"; pb_Store[x - 1, y].Name = cruiserRef[zaehler_cruiser].name + "_" + "Middle"; pb_Store[x - 2, y].Name = cruiserRef[zaehler_cruiser].name + "_" + "Heck"; // Schiffsauswahl auf nothing setzen ships = shipModels.nothing; } else { // Anzeigen, dass hier kein Schiff plaziert werden kann (entsprechende Felder rot blinken lassen) tmp.BackColor = collisionColor; pb[x - 1, y].BackColor = collisionColor; pb[x - 2, y].BackColor = collisionColor; Application.DoEvents(); System.Threading.Thread.Sleep(500); tmp.BackColor = Color.Transparent; pb[x - 1, y].BackColor = Color.Transparent; pb[x - 2, y].BackColor = Color.Transparent; return; } } // Ansonsten Cruiser in normaler Richtung zusammenbauen (3 Felder) else { if ((int)tmp.Tag != 1 && (int)pb[x + 1, y].Tag != 1 && (int)pb[x + 2, y].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.cruiser1h; pb[x + 1, y].BackgroundImage = Battleships.Properties.Resources.cruiser2h; pb[x + 2, y].BackgroundImage = Battleships.Properties.Resources.cruiser3h; tmp.Tag = 1; pb[x + 1, y].Tag = 1; pb[x + 2, y].Tag = 1; cruiserRef[zaehler_cruiser].name = "Cruiser_" + zaehler_cruiser.ToString(); cruiserRef[zaehler_cruiser].posHeckX = x; cruiserRef[zaehler_cruiser].posHeckY = y; cruiserRef[zaehler_cruiser].shipDestryoed = false; cruiserRef[zaehler_cruiser].Front = false; cruiserRef[zaehler_cruiser].Heck = false; cruiserRef[zaehler_cruiser].middle = false; cruiserRef[zaehler_cruiser].horizontal = horizontal; pb_Store[x, y].Name = cruiserRef[zaehler_cruiser].name + "_" + "Heck"; pb_Store[x + 1, y].Name = cruiserRef[zaehler_cruiser].name + "_" + "Middle"; pb_Store[x + 2, y].Name = cruiserRef[zaehler_cruiser].name + "_" + "Front"; // Schiffsauswahl auf nothing setzen ships = shipModels.nothing; } else { // Anzeigen, dass hier kein Schiff plaziert werden kann (entsprechende Felder rot blinken lassen) tmp.BackColor = collisionColor; pb[x + 1, y].BackColor = collisionColor; pb[x + 2, y].BackColor = collisionColor; Application.DoEvents(); System.Threading.Thread.Sleep(500); tmp.BackColor = Color.Transparent; pb[x + 1, y].BackColor = Color.Transparent; pb[x + 2, y].BackColor = Color.Transparent; return; } } } else { // Vertikal // Cruiser ist 5 Fleder groß, wenn Feld 8 erreicht, dann Schiff in gegengesetzte Richtung aufbauen if (y >= 8) { if ((int)tmp.Tag != 1 && (int)pb[x, y - 1].Tag != 1 && (int)pb[x, y - 2].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.cruiser3v; pb[x, y - 1].BackgroundImage = Battleships.Properties.Resources.cruiser2v; pb[x, y - 2].BackgroundImage = Battleships.Properties.Resources.cruiser1v; tmp.Tag = 1; pb[x, y - 1].Tag = 1; pb[x, y - 2].Tag = 1; cruiserRef[zaehler_cruiser].name = "Cruiser_" + zaehler_cruiser.ToString(); cruiserRef[zaehler_cruiser].posHeckX = x; cruiserRef[zaehler_cruiser].posHeckY = y; cruiserRef[zaehler_cruiser].shipDestryoed = false; cruiserRef[zaehler_cruiser].Front = false; cruiserRef[zaehler_cruiser].Heck = false; cruiserRef[zaehler_cruiser].middle = false; cruiserRef[zaehler_cruiser].horizontal = horizontal; pb_Store[x, y].Name = cruiserRef[zaehler_cruiser].name + "_" + "Front"; pb_Store[x, y - 1].Name = cruiserRef[zaehler_cruiser].name + "_" + "Middle"; pb_Store[x, y - 2].Name = cruiserRef[zaehler_cruiser].name + "_" + "Heck"; // Schiffsauswahl auf nothing setzen ships = shipModels.nothing; } else { // Anzeigen, dass hier kein Schiff plaziert werden kann (entsprechende Felder rot blinken lassen) tmp.BackColor = collisionColor; pb[x, y - 1].BackColor = collisionColor; pb[x, y - 2].BackColor = collisionColor; Application.DoEvents(); System.Threading.Thread.Sleep(500); tmp.BackColor = Color.Transparent; pb[x, y - 1].BackColor = Color.Transparent; pb[x, y - 2].BackColor = Color.Transparent; return; } } // Ansonsten Cruiser in normaler Richtung zusammenbauen (3 Felder) else { if ((int)tmp.Tag != 1 && (int)pb[x, y + 1].Tag != 1 && (int)pb[x, y + 2].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.cruiser1v; pb[x, y + 1].BackgroundImage = Battleships.Properties.Resources.cruiser2v; pb[x, y + 2].BackgroundImage = Battleships.Properties.Resources.cruiser3v; tmp.Tag = 1; pb[x, y + 1].Tag = 1; pb[x, y + 2].Tag = 1; cruiserRef[zaehler_cruiser].name = "Cruiser_" + zaehler_cruiser.ToString(); cruiserRef[zaehler_cruiser].posHeckX = x; cruiserRef[zaehler_cruiser].posHeckY = y; cruiserRef[zaehler_cruiser].shipDestryoed = false; cruiserRef[zaehler_cruiser].Front = false; cruiserRef[zaehler_cruiser].Heck = false; cruiserRef[zaehler_cruiser].middle = false; cruiserRef[zaehler_cruiser].horizontal = horizontal; pb_Store[x, y].Name = cruiserRef[zaehler_cruiser].name + "_" + "Heck"; pb_Store[x, y + 1].Name = cruiserRef[zaehler_cruiser].name + "_" + "Middle"; pb_Store[x, y + 2].Name = cruiserRef[zaehler_cruiser].name + "_" + "Front"; // Schiffsauswahl auf nothing setzen ships = shipModels.nothing; } else { // Anzeigen, dass hier kein Schiff plaziert werden kann (entsprechende Felder rot blinken lassen) tmp.BackColor = collisionColor; pb[x, y + 1].BackColor = collisionColor; pb[x, y + 2].BackColor = collisionColor; Application.DoEvents(); System.Threading.Thread.Sleep(500); tmp.BackColor = Color.Transparent; pb[x, y + 1].BackColor = Color.Transparent; pb[x, y + 2].BackColor = Color.Transparent; return; } } } break; // boat case shipModels.boat: if (horizontal) { // Horizontal // boat ist 1 Fled groß, wenn Feld 9 erreicht, dann Schiff in gegengesetzte Richtung aufbauen if (x >= 9) { if ((int)tmp.Tag != 1 && (int)pb[x - 1, y].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.boat2h; pb[x - 1, y].BackgroundImage = Battleships.Properties.Resources.boat1h; tmp.Tag = 1; pb[x - 1, y].Tag = 1; // Position sowie name des Schiffes speichern boatRef[zaehler_boat].name = "Boat_" + zaehler_boat.ToString(); boatRef[zaehler_boat].posHeckX = x; boatRef[zaehler_boat].posHeckY = y; boatRef[zaehler_boat].posFrontX = x - 1; boatRef[zaehler_boat].posFrontY = y; boatRef[zaehler_boat].shipDestryoed = false; boatRef[zaehler_boat].Front = false; boatRef[zaehler_boat].Heck = false; boatRef[zaehler_boat].horizontal = horizontal; pb_Store[x, y].Name = boatRef[zaehler_boat].name + "_" + "Front"; pb_Store[x - 1, y].Name = boatRef[zaehler_boat].name + "_" + "Heck"; // Schiffsauswahl auf nothing setzen ships = shipModels.nothing; } else { // Anzeigen, dass hier kein Schiff plaziert werden kann (entsprechende Felder rot blinken lassen) tmp.BackColor = collisionColor; pb[x - 1, y].BackColor = collisionColor; Application.DoEvents(); System.Threading.Thread.Sleep(500); tmp.BackColor = Color.Transparent; pb[x - 1, y].BackColor = Color.Transparent; return; } } // Ansonsten boat in normaler Richtung zusammenbauen (2 Felder) else { if ((int)tmp.Tag != 1 && (int)pb[x + 1, y].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.boat1h; pb[x + 1, y].BackgroundImage = Battleships.Properties.Resources.boat2h; tmp.Tag = 1; pb[x + 1, y].Tag = 1; // Position sowie name des schiffes speichern boatRef[zaehler_boat].name = "Boat_" + zaehler_boat.ToString(); boatRef[zaehler_boat].posHeckX = x; boatRef[zaehler_boat].posHeckY = y; boatRef[zaehler_boat].posFrontX = x + 1; boatRef[zaehler_boat].posFrontY = y; ; boatRef[zaehler_boat].shipDestryoed = false; boatRef[zaehler_boat].Front = false; boatRef[zaehler_boat].Heck = false; boatRef[zaehler_boat].horizontal = horizontal; pb_Store[x, y].Name = boatRef[zaehler_boat].name + "_" + "Heck"; pb_Store[x + 1, y].Name = boatRef[zaehler_boat].name + "_" + "Front"; // Schiffsauswahl auf nothing setzen ships = shipModels.nothing; } else { // Anzeigen, dass hier kein Schiff plaziert werden kann (entsprechende Felder rot blinken lassen) tmp.BackColor = collisionColor; pb[x + 1, y].BackColor = collisionColor; Application.DoEvents(); System.Threading.Thread.Sleep(500); tmp.BackColor = Color.Transparent; pb[x + 1, y].BackColor = Color.Transparent; return; } } } else { // Vertikal // boat ist 2 Fleder groß, wenn Feld 9 erreicht, dann Schiff in gegengesetzte Richtung aufbauen if (y >= 8) { if ((int)tmp.Tag != 1 && (int)pb[x, y - 1].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.boat2v; pb[x, y - 1].BackgroundImage = Battleships.Properties.Resources.boat1v; tmp.Tag = 1; pb[x, y - 1].Tag = 1; // Position sowie name des schiffes speichern boatRef[zaehler_boat].name = "Boat_" + zaehler_boat.ToString(); boatRef[zaehler_boat].posHeckX = x; boatRef[zaehler_boat].posHeckY = y; boatRef[zaehler_boat].posFrontX = x; boatRef[zaehler_boat].posFrontY = y - 1; boatRef[zaehler_boat].shipDestryoed = false; boatRef[zaehler_boat].Front = false; boatRef[zaehler_boat].Heck = false; boatRef[zaehler_boat].horizontal = horizontal; pb_Store[x, y].Name = boatRef[zaehler_boat].name + "_" + "Front"; pb_Store[x, y - 1].Name = boatRef[zaehler_boat].name + "_" + "Heck"; // Schiffsauswahl auf nothing setzen ships = shipModels.nothing; } else { // Anzeigen, dass hier kein Schiff plaziert werden kann (entsprechende Felder rot blinken lassen) tmp.BackColor = collisionColor; pb[x, y - 1].BackColor = collisionColor; Application.DoEvents(); System.Threading.Thread.Sleep(500); tmp.BackColor = Color.Transparent; pb[x, y - 1].BackColor = Color.Transparent; return; } } // Ansonsten boat in normaler Richtung zusammenbauen (2 Felder) else { if ((int)tmp.Tag != 1 && (int)pb[x, y + 1].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.boat1v; pb[x, y + 1].BackgroundImage = Battleships.Properties.Resources.boat2v; tmp.Tag = 1; pb[x, y + 1].Tag = 1; // Position sowie name des schiffes speichern boatRef[zaehler_boat].name = "Boat_" + zaehler_boat.ToString(); boatRef[zaehler_boat].posHeckX = x; boatRef[zaehler_boat].posHeckY = y; boatRef[zaehler_boat].posFrontX = x; boatRef[zaehler_boat].posFrontY = y + 1; boatRef[zaehler_boat].shipDestryoed = false; boatRef[zaehler_boat].Front = false; boatRef[zaehler_boat].Heck = false; boatRef[zaehler_boat].horizontal = horizontal; pb_Store[x, y].Name = boatRef[zaehler_boat].name + "_" + "Heck"; pb_Store[x, y + 1].Name = boatRef[zaehler_boat].name + "_" + "Front"; // Schiffsauswahl auf nothing setzen ships = shipModels.nothing; } else { // Anzeigen, dass hier kein Schiff plaziert werden kann (entsprechende Felder rot blinken lassen) tmp.BackColor = collisionColor; pb[x, y + 1].BackColor = collisionColor; Application.DoEvents(); System.Threading.Thread.Sleep(500); tmp.BackColor = Color.Transparent; pb[x, y + 1].BackColor = Color.Transparent; return; } } } break; } }
/// <summary> /// Zeichnet die Schiffe an die entsprechende Stelle (Bei einem MouseEnter-Event auf ein Panel) /// </summary> /// <param name="tmp">Das Panel welches das MouseEnter-Event ausgelöst hat (Als Referenz)</param> private void drawShips(ref Panel_DoubleBuffered tmp) { String positionString = tmp.Name; // pb_ aus dem String entfernen positionString = positionString.Remove(0, 3); // x und y Position String[] position = positionString.Split(':'); int x = int.Parse(position[0]); int y = int.Parse(position[1]); switch (ships) { // galley case shipModels.galley: if (horizontal) { // Horizontal // galley ist 4 Fleder groß, wenn Feld 7 erreicht, dann Schiff in gegengesetzte Richtung aufbauen if (x >= 7) { if ((int)tmp.Tag != 1 && (int)pb[x - 1, y].Tag != 1 && (int)pb[x - 2, y].Tag != 1 && (int)pb[x - 3, y].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.galley4h; pb[x - 1, y].BackgroundImage = Battleships.Properties.Resources.galley3h; pb[x - 2, y].BackgroundImage = Battleships.Properties.Resources.galley2h; pb[x - 3, y].BackgroundImage = Battleships.Properties.Resources.galley1h; } } // Ansonsten galley in normaler Richtung zusammenbauen (4 Felder) else { if ((int)tmp.Tag != 1 && (int)pb[x + 1, y].Tag != 1 && (int)pb[x + 2, y].Tag != 1 && (int)pb[x + 3, y].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.galley1h; pb[x + 1, y].BackgroundImage = Battleships.Properties.Resources.galley2h; pb[x + 2, y].BackgroundImage = Battleships.Properties.Resources.galley3h; pb[x + 3, y].BackgroundImage = Battleships.Properties.Resources.galley4h; } } } else { // Vertikal // galley ist 4 Fleder groß, wenn Feld 7 erreicht, dann Schiff in gegengesetzte Richtung aufbauen if (y >= 7) { if ((int)tmp.Tag != 1 && (int)pb[x, y - 1].Tag != 1 && (int)pb[x, y - 2].Tag != 1 && (int)pb[x, y - 3].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.galley4v; pb[x, y - 1].BackgroundImage = Battleships.Properties.Resources.galley3v; pb[x, y - 2].BackgroundImage = Battleships.Properties.Resources.galley2v; pb[x, y - 3].BackgroundImage = Battleships.Properties.Resources.galley1v; } } // Ansonsten galley in normaler Richtung zusammenbauen (4 Felder) else { if ((int)tmp.Tag != 1 && (int)pb[x, y + 1].Tag != 1 && (int)pb[x, y + 2].Tag != 1 && (int)pb[x, y + 3].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.galley1v; pb[x, y + 1].BackgroundImage = Battleships.Properties.Resources.galley2v; pb[x, y + 2].BackgroundImage = Battleships.Properties.Resources.galley3v; pb[x, y + 3].BackgroundImage = Battleships.Properties.Resources.galley4v; } } } break; // battleship case shipModels.battleship: if (horizontal) { // Horizontal // battleship ist 5 Fleder groß, wenn Feld 6 erreicht, dann Schiff in gegengesetzte Richtung aufbauen if (x >= 6) { if ((int)tmp.Tag != 1 && (int)pb[x - 1, y].Tag != 1 && (int)pb[x - 2, y].Tag != 1 && (int)pb[x - 3, y].Tag != 1 && (int)pb[x - 4, y].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.z41; pb[x - 1, y].BackgroundImage = Battleships.Properties.Resources.z31; pb[x - 2, y].BackgroundImage = Battleships.Properties.Resources.z21; pb[x - 3, y].BackgroundImage = Battleships.Properties.Resources.z11; } } // Ansonsten battleship in normaler Richtung zusammenbauen (5 Felder) else { if ((int)tmp.Tag != 1 && (int)pb[x + 1, y].Tag != 1 && (int)pb[x + 2, y].Tag != 1 && (int)pb[x + 3, y].Tag != 1 && (int)pb[x + 4, y].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.z11; pb[x + 1, y].BackgroundImage = Battleships.Properties.Resources.z21; pb[x + 2, y].BackgroundImage = Battleships.Properties.Resources.z31; pb[x + 3, y].BackgroundImage = Battleships.Properties.Resources.z41; } } } else { // Vertikal // battleship ist 5 Fleder groß, wenn Feld 6 erreicht, dann Schiff in gegengesetzte Richtung aufbauen if (y >= 6) { if ((int)tmp.Tag != 1 && (int)pb[x, y - 1].Tag != 1 && (int)pb[x, y - 2].Tag != 1 && (int)pb[x, y - 3].Tag != 1 && (int)pb[x, y - 4].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.z4v1; pb[x, y - 1].BackgroundImage = Battleships.Properties.Resources.z3v1; pb[x, y - 2].BackgroundImage = Battleships.Properties.Resources.z2v1; pb[x, y - 3].BackgroundImage = Battleships.Properties.Resources.z1v1; } } // Ansonsten battleship in normaler Richtung zusammenbauen (5 Felder) else { if ((int)tmp.Tag != 1 && (int)pb[x, y + 1].Tag != 1 && (int)pb[x, y + 2].Tag != 1 && (int)pb[x, y + 3].Tag != 1 && (int)pb[x, y + 4].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.z1v1; pb[x, y + 1].BackgroundImage = Battleships.Properties.Resources.z2v1; pb[x, y + 2].BackgroundImage = Battleships.Properties.Resources.z3v1; pb[x, y + 3].BackgroundImage = Battleships.Properties.Resources.z4v1; } } } break; // Cruiser case shipModels.cruiser: if (horizontal) { // Horizontal // Cruiser ist 3 Fleder groß, wenn Feld 8 erreicht, dann Schiff in gegengesetzte Richtung aufbauen if (x >= 8) { if ((int)tmp.Tag != 1 && (int)pb[x - 1, y].Tag != 1 && (int)pb[x - 2, y].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.cruiser3h; pb[x - 1, y].BackgroundImage = Battleships.Properties.Resources.cruiser2h; pb[x - 2, y].BackgroundImage = Battleships.Properties.Resources.cruiser1h; } } // Ansonsten Cruiser in normaler Richtung zusammenbauen (3 Felder) else { if ((int)tmp.Tag != 1 && (int)pb[x + 1, y].Tag != 1 && (int)pb[x + 2, y].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.cruiser1h; pb[x + 1, y].BackgroundImage = Battleships.Properties.Resources.cruiser2h; pb[x + 2, y].BackgroundImage = Battleships.Properties.Resources.cruiser3h; } } } else { // Vertikal // Cruiser ist 5 Fleder groß, wenn Feld 8 erreicht, dann Schiff in gegengesetzte Richtung aufbauen if (y >= 8) { if ((int)tmp.Tag != 1 && (int)pb[x, y - 1].Tag != 1 && (int)pb[x, y - 2].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.cruiser3v; pb[x, y - 1].BackgroundImage = Battleships.Properties.Resources.cruiser2v; pb[x, y - 2].BackgroundImage = Battleships.Properties.Resources.cruiser1v; } } // Ansonsten Cruiser in normaler Richtung zusammenbauen (3 Felder) else { if ((int)tmp.Tag != 1 && (int)pb[x, y + 1].Tag != 1 && (int)pb[x, y + 2].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.cruiser1v; pb[x, y + 1].BackgroundImage = Battleships.Properties.Resources.cruiser2v; pb[x, y + 2].BackgroundImage = Battleships.Properties.Resources.cruiser3v; } } } break; // boat case shipModels.boat: if (horizontal) { // Horizontal // boat ist 1 Fled groß, wenn Feld 9 erreicht, dann Schiff in gegengesetzte Richtung aufbauen if (x >= 9) { if ((int)tmp.Tag != 1 && (int)pb[x - 1, y].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.boat2h; pb[x - 1, y].BackgroundImage = Battleships.Properties.Resources.boat1h; } } // Ansonsten boat in normaler Richtung zusammenbauen (2 Felder) else { if ((int)tmp.Tag != 1 && (int)pb[x + 1, y].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.boat1h; pb[x + 1, y].BackgroundImage = Battleships.Properties.Resources.boat2h; } } } else { // Vertikal // boat ist 2 Fleder groß, wenn Feld 9 erreicht, dann Schiff in gegengesetzte Richtung aufbauen if (y >= 8) { if ((int)tmp.Tag != 1 && (int)pb[x, y - 1].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.boat2v; pb[x, y - 1].BackgroundImage = Battleships.Properties.Resources.boat1v; } } // Ansonsten boat in normaler Richtung zusammenbauen (2 Felder) else { if ((int)tmp.Tag != 1 && (int)pb[x, y + 1].Tag != 1) { tmp.BackgroundImage = Battleships.Properties.Resources.boat1v; pb[x, y + 1].BackgroundImage = Battleships.Properties.Resources.boat2v; } } } break; } }