private void deck2PictureBox_MouseMove(object sender, MouseEventArgs e) { if (GraphicContext.GetCoorX(this, deck2PictureBox) != -1 && GraphicContext.GetCoorY(this, deck2PictureBox) != -1) { // Con trỏ di chuyển qua ô khác chưa ? if (GraphicContext.GetCell(GraphicContext.GetCoorX(this, deck2PictureBox)) != mouseCellX || GraphicContext.GetCell(GraphicContext.GetCoorY(this, deck2PictureBox)) != mouseCellY) { // Đặt lại tọa độ con trỏ mouseCellX = GraphicContext.GetCell(GraphicContext.GetCoorX(this, deck2PictureBox)); mouseCellY = GraphicContext.GetCell(GraphicContext.GetCoorY(this, deck2PictureBox)); deck2PictureBox.Refresh(); // Vẽ outline ô đã chọn GraphicContext.DrawOuterFrameCell(mouseCellX, mouseCellY, 5, this, deck2PictureBox); } } else { // Con trỏ rời bàn cờ mouseCellX = 0; mouseCellY = 0; // Repaint deck2PictureBox.Refresh(); } }
private void deck2PictureBox_Paint(object sender, PaintEventArgs e) { GraphicContext.DrawDeckStatus(player2.RevealedCells, player2.ShipSet, e); if (player2.LastCells[0] != -1 && player2.LastCells[1] != -1) { GraphicContext.DrawOuterFrameCell(player2.LastCells[0], player2.LastCells[1], 6, e); } }
private void deckPictureBox_MouseMove(object sender, MouseEventArgs e) { if (currentShip != -1) { // Check xem con trỏ có ở trên bàn cờ không ? if (GraphicContext.GetCoorX(this, deckPictureBox) != -1 && GraphicContext.GetCoorY(this, deckPictureBox) != -1) { // Xét ô mà con trỏ đang nằm if (GraphicContext.GetCell(GraphicContext.GetCoorX(this, deckPictureBox)) != mouseCellX || GraphicContext.GetCell(GraphicContext.GetCoorY(this, deckPictureBox)) != mouseCellY) { // Đặt lại tọa độ mouseCellX = GraphicContext.GetCell(GraphicContext.GetCoorX(this, deckPictureBox)); mouseCellY = GraphicContext.GetCell(GraphicContext.GetCoorY(this, deckPictureBox)); // Vẽ lại bàn, tránh hiện tượng vẽ full ô deckPictureBox.Refresh(); // Nằm ngang if (shipRotation) { // Vẽ tàu với độ dài tương ứng. for (int i = 0; i < Game.shipLengths[currentShip]; i++) { // Nếu không chạm rìa bàn cờ if (mouseCellX + i <= 9) { //Tô outline cell GraphicContext.DrawInnerFrameCell(mouseCellX + i, mouseCellY, currentShip, this, deckPictureBox); } else { break; } } } else { // Nằm dọc. for (int i = 0; i < Game.shipLengths[currentShip]; i++) { if (mouseCellY + i <= 9) { GraphicContext.DrawInnerFrameCell(mouseCellX, mouseCellY + i, currentShip, this, deckPictureBox); } else { break; } } } } } else { // Ra ngoài rìa bàn cờ if (mouseCellX != 0 || mouseCellY != 0) { mouseCellX = 0; mouseCellY = 0; deckPictureBox.Refresh(); } } } }
// Sự kiện tô tàu trên deck private void DeckPictureBoxPaint(object sender, PaintEventArgs e) { GraphicContext.DrawShipSet(player.ShipSet, e); }