public void PaintCell(Graphics g, bool sw) { Pen pen1; //if (this.status == false) // pen1 = new Pen(Color.Red, 2); //else pen1 = new Pen(Color.Aqua, 2); g.DrawRectangle(pen1, this.x, this.y, 30, 30); if (sw == true && this.s != null) { s.SetX(this.x); s.SetY(this.y); s.PaintShip(g); } Point p = new Point(this.x + 3, this.y + 3); if (this.hit == 1) { this.pic = Image.FromFile("splash.png"); } else if (this.hit == 2) { this.pic = Image.FromFile("boom.png"); } g.DrawImage(pic, p); }
private void Game1_MouseUp(object sender, MouseEventArgs e) { if (boardCreated == false) { g = CreateGraphics(); int x = e.X; int y = e.Y; if (x >= 400 && x <= 700 && y >= 270 && y <= 570)//האם הלחיצה הייתה בגבולות המשחק { int i = (y - 150) / 30; int j = (x - 280) / 30; if (game1.IsAvilable(i, j, s) == true)//התא פנוי { x = game1.GetBoard()[i, j].GetX(); y = game1.GetBoard()[i, j].GetY(); s.SetX(x); s.SetY(y); game1.GetBoard()[i, j].SetShip(s); game1.SetShipOnBoard(i, j); } Refresh(); } } s = null; }
private void newGameToolStripMenuItem_Click_1(object sender, EventArgs e) { boardCreated = false; battle.Show(); explain.Show(); game1 = new Board(280, 150); game2 = new Board(650, 150); s1 = new Ship(); s1.SetX(753); s1.SetY(307); s1.SetSize(5); s2 = new Ship(); s2.SetX(856); s2.SetY(328); s2.SetSize(4); s3 = new Ship(); s3.SetX(753); s3.SetY(470); s3.SetSize(3); s4 = new Ship(); s4.SetX(856); s4.SetY(470); s4.SetSize(3); s5 = new Ship(); s5.SetX(941); s5.SetY(500); s5.SetSize(2); s = null; countC = 0; //מספר התאים שפוצצו-מחשב sizeC = 0; //מחשב-גודל הצוללת posC = true; //מנח הצוללת-מחשב firstIC = 0; //השורה של התא הראשון בצוללת-מחשב firstJC = 0; //העמודה של התא הראשון בצוללת-מחשב countP = 0; //מספר התאים שפוצצו-שחקן sizeP = 0; //גודל הצוללת-שחקן posP = true; //מנח הצוללת-שחקן firstIP = 0; // השורה של התא הראשון בצוללת -שחקן firstJP = 0; //העמודה של התא הראשון בצוללת-שחקן ifFound = false; countFoundsC = 0; //מספר הצוללות שגילה המחשב countFoundsP = 0; //מספר הצוללות שגילה השחקן Refresh(); }
private void Game1_Load(object sender, EventArgs e) { game1 = new Board(280, 150); s1 = new Ship(); s1.SetX(753); s1.SetY(307); s1.SetSize(5); s2 = new Ship(); s2.SetX(856); s2.SetY(328); s2.SetSize(4); s3 = new Ship(); s3.SetX(753); s3.SetY(470); s3.SetSize(3); s4 = new Ship(); s4.SetX(856); s4.SetY(470); s4.SetSize(3); s5 = new Ship(); s5.SetX(941); s5.SetY(500); s5.SetSize(2); }