public bool IsAvilable(int i, int j, Ship s) { if (s != null) { //הפעולה מקבלת צוללת, שורה ועמודה ובודקת האם אפשר להניח שם את הצוללת הרצויה if (s.GetPosition() == true) { if ((i - 4) + s.GetSize() <= 10) { if (this.GetBoard()[i, j].GetStatus() == true)//התא פנוי { return(true); } } } else if ((j - 4) + s.GetSize() <= 10) { if (this.GetBoard()[i, j].GetStatus() == true)//התא פנוי { return(true); } } return(false); } return(false); }
public bool CheckShip(Ship s, int i, int j) { // הפעולה מקבלת צוללת ושורה ןעמודה רצויים לראש צוללת //הפעולה תחזיר שקר אם הצוללת חורגת מגבולות המטריצה bool position = s.GetPosition(); int size = s.GetSize(); int i1 = i; int j1 = j; //משתני עזר כדי לא "לקלקל" את המשתנים המקוריים if (position == true) //אם הצוללת מונחת במאונך { if (i1 + size >= 14) { return(false); } } else if (j1 + size >= 14) { return(false); } //הפעולה תחזיר שקר אם הצוללת מונחת על גבי צוללת אחרת //הפעולה מחזירה אמת אם הצוללת מונחת באופן חוקי על הלוח - אחרת מחזירה שקר if (position == true)//אם הצוללת מונחת במאונך { for (int k = i - 1; k <= i + size; k++) { for (int l = j - 1; l < j + 2; l++) { if (board[k, l].GetStatus() == false) { return(false); } } } } else // הצוללת מונחת במאוזן { for (int k = i - 1; k < i + 2; k++) { for (int l = j - 1; l <= j + size; l++) { if (board[k, l].GetStatus() == false) { return(false); } } } } return(true); }
private void Game1_MouseDown(object sender, MouseEventArgs e) { s = null; if (boardCreated == false) { g = CreateGraphics(); int x = e.X; int y = e.Y; if (s1.GetPosition() == true) { if (x >= s1.GetX() && x <= s1.GetX() + 22 && y >= s1.GetY() && y <= s1.GetY() + 125)//ship5 { s = this.s1; } } else if (x >= s1.GetX() && x <= s1.GetX() + 125 && y >= s1.GetY() && y <= s1.GetY() + 22) { s = this.s1; } if (s2.GetPosition() == true) { if (x >= s2.GetX() && x <= s2.GetX() + 22 && y >= s2.GetY() && y <= s2.GetY() + 105)//ship4 { s = this.s2; } } else if (x >= s2.GetX() && x <= s2.GetX() + 105 && y >= s2.GetY() && y <= s2.GetY() + 22) { s = this.s2; } if (s3.GetPosition() == true) { if (x >= s3.GetX() && x <= s3.GetX() + 22 && y >= s3.GetY() && y <= s3.GetY() + 85)//ship3 { s = this.s3; } } else if (x >= s3.GetX() && x <= s3.GetX() + 85 && y >= s3.GetY() && y <= s3.GetY() + 22) { s = this.s3; } if (s4.GetPosition() == true) { if (x >= s4.GetX() && x <= s4.GetX() + 22 && y >= s4.GetY() && y <= s4.GetY() + 85)//ship3(2) { s = this.s4; } } else if (x >= s4.GetX() && x <= s4.GetX() + 85 && y >= s4.GetY() && y <= s4.GetY() + 22) { s = this.s4; } if (s5.GetPosition() == true) { if (x >= s5.GetX() && x <= s5.GetX() + 22 && y >= s5.GetY() && y <= s5.GetY() + 65)//ship2 { s = this.s5; } } else if (x >= s5.GetX() && x <= s5.GetX() + 65 && y >= s5.GetY() && y <= s5.GetY() + 22) { s = this.s5; } if (s != null) { if (x >= 400 && x <= 700 && y >= 270 && y <= 570)//האם הלחיצה הייתה בגבולות המשחק { int oldI = (s.GetY() - 150) / 30; int oldJ = (s.GetX() - 280) / 30; if (game1.GetBoard()[oldI, oldJ].GetShip() != null) { game1.RemoveShipOfBoard(oldI, oldJ); } } } } }