private void Form1_Click(object sender, EventArgs e) { if (currentPlayer == null || currentPlayer.IsBot()) { return; } int x = PointToClient(MousePosition).X *background.Width / ClientSize.Width; int y = PointToClient(MousePosition).Y *background.Height / ClientSize.Height; if (x <= 512) { selectedCardIndex = -1; } else if (x < 1396) // main table { if (selectedCardIndex >= 0) { int ix = (x - 512 - 38) / 256; int iy = (y - 38) / 316; if (table.PlaceIsFree(ix, iy)) { ((LocalPlayer)player1).PlayerMove(selectedCardIndex, ix, iy); } } selectedCardIndex = -1; } else //user cards { int index = (y / 316) * 2 + ((x - 1396) / 256); if (index < player1.GetCards().Count) { selectedCardIndex = index; } } Refresh(); }
private void Form1_Paint(object sender, PaintEventArgs e) { if (currentPlayer == null) { return; } Bitmap bitmap = new Bitmap(background); Graphics canvas = Graphics.FromImage(bitmap); //table cards for (int x = 0; x < 3; ++x) { for (int y = 0; y < 3; ++y) { if (table.PlaceIsFree(x, y)) { continue; } sTableCard tableCard = table.GetTableCardAt(x, y); Rectangle cardRect = new Rectangle(512 + 38 + 256 * tableCard.x, 38 + 316 * tableCard.y, 256, 316); if (tableCard.toBeFlipped) { if (animationPercent <= 50) { cardRect.X += 128 * animationPercent / 50; cardRect.Width -= 256 * animationPercent / 50; } else { cardRect.X += 128 * (100 - animationPercent) / 50; cardRect.Width -= 256 * (100 - animationPercent) / 50; } } DrawCard(canvas, tableCard.enemy, tableCard.card.image, cardRect); } } //enemy cards for (int i = 0; i < player2.GetCards().Count; ++i) { Rectangle destRect = new Rectangle((i % 2) * 256, i / 2 * 316, 256, 316); canvas.DrawImage(cardBackgroundBack, destRect); } //player cards List <sCard> playerCards = player1.GetCards(); for (int i = 0; i < playerCards.Count; ++i) { Rectangle destRect = new Rectangle((i % 2) * 256 + 512 + 844, i / 2 * 316, 256, 316); if (i == selectedCardIndex) { if (dragNDrop) { int x = PointToClient(MousePosition).X *background.Width / ClientSize.Width; int y = PointToClient(MousePosition).Y *background.Height / ClientSize.Height; destRect = new Rectangle(x - 128, y - 158, 256, 316); } else { destRect = new Rectangle((i % 2) * 256 + 512 + 844 - 10, i / 2 * 316 - 10, 256 + 20, 316 + 20); } } DrawCard(canvas, false, playerCards[i].image, destRect); } canvas.Dispose(); e.Graphics.DrawImage(bitmap, ClientRectangle); bitmap.Dispose(); }