private void AddCard(sTableCard tcard) { table.AddCard(tcard); animationPercent = 0; //start animation timer1.Start(); ChangePlayer(); }
public void AddCard(sCard card, int x, int y, bool enemy) { sTableCard tcard = new sTableCard(card, enemy, x, y); ChangeOwnerNearCard(tcard); cards.Add(tcard); }
public void FlipCardsMarkedToBeFlipped() { for (int i = 0; i < cards.Count; ++i) { sTableCard tcard = cards[i]; if (tcard.toBeFlipped) { tcard.enemy = !tcard.enemy; cards[i] = tcard; } } }
public void EndFlippingAnimation() { for (int i = 0; i < cards.Count; ++i) { sTableCard tcard = cards[i]; if (tcard.toBeFlipped) { tcard.toBeFlipped = false; cards[i] = tcard; } } }
private void SendData(sTableCard tcard) { if (!connection.Connected) { return; } byte[] bytes = new byte[13]; BitConverter.GetBytes(cards.FindIndex(item => item.Equals(tcard.card))).CopyTo(bytes, 0); BitConverter.GetBytes(tcard.x).CopyTo(bytes, 4); BitConverter.GetBytes(tcard.y).CopyTo(bytes, 8); bytes[12] = Convert.ToByte(tcard.enemy); NetworkStream stream = connection.GetStream(); stream.Write(bytes, 0, 13); stream.Flush(); }
public sTableCard MakeMove(Table table) { while (!moveHasBeenMade) { Thread.Sleep(10); } sTableCard card = new sTableCard(); card.card = cards[moveCardIndex]; card.enemy = false; card.toBeFlipped = false; card.x = moveX; card.y = moveY; moveHasBeenMade = false; cards.RemoveAt(moveCardIndex); return(card); }
private void ChangeOwnerNearCard(sTableCard tCard) { for (int i = 0; i < cards.Count; ++i) { int deltaX = Math.Abs(cards[i].x - tCard.x); int deltaY = Math.Abs(cards[i].y - tCard.y); if (cards[i].enemy != tCard.enemy && ((deltaX == 1 && deltaY == 0) || (deltaX == 0 && deltaY == 1))) { if ((cards[i].x > tCard.x && cards[i].card.left < tCard.card.right) || (cards[i].x < tCard.x && cards[i].card.right < tCard.card.left) || (cards[i].y > tCard.y && cards[i].card.top < tCard.card.bottom) || (cards[i].y < tCard.y && cards[i].card.bottom < tCard.card.top)) { sTableCard tc = cards[i]; tc.toBeFlipped = true; cards[i] = tc; } } } }
public sTableCard MakeMove(Table table) { for (int x = 0; x < 3; ++x) { for (int y = 0; y < 3; ++y) { if (table.PlaceIsFree(x, y)) { sTableCard card = new sTableCard(); card.card = cards[0]; card.enemy = iAmEnemy; card.toBeFlipped = false; card.x = x; card.y = y; cards.RemoveAt(0); return(card); } } } return(new sTableCard()); }
public sTableCard MakeMove(Table table) { sTableCard card = new sTableCard(); if (!client.Connected) { return(card); } NetworkStream stream = client.GetStream(); byte[] inStream = new byte[13]; stream.Read(inStream, 0, 13); int index = Convert.ToInt32(inStream[0]); card.card = cards[index]; card.x = Convert.ToInt32(inStream[4]); card.y = Convert.ToInt32(inStream[8]); card.enemy = !Convert.ToBoolean(inStream[12]); cardsLeft--; return(card); }
public sTableCard MakeMove(Table table) { sCard bestCard = new sCard(); double bestScore = -1; int bestX = -1; int bestY = -1; for (int i = 0; i < cards.Count; i++) { for (int x = 0; x < 3; ++x) { for (int y = 0; y < 3; ++y) { if (table.PlaceIsFree(x, y)) { Sort(x, y); double score = Calculate(i, x, y, table); if (score > bestScore) { bestCard = cards[i]; bestX = x; bestY = y; bestScore = score; } } } } } sTableCard card = new sTableCard(); card.card = bestCard; card.enemy = iAmEnemy; card.toBeFlipped = false; card.x = bestX; card.y = bestY; cards.Remove(bestCard); return(card); }
private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { while (true) { if (backgroundWorker1.CancellationPending) { return; } while (currentPlayer == null || timer1.Enabled || table.GetNumberOfCards() == 9) { Thread.Sleep(10); } sTableCard tcard = currentPlayer.MakeMove(table); if (connection != null && currentPlayer.Equals(player1)) { SendData(tcard); } if (tcard.card == null) { continue; } Invoke(new AddCardDelegate(AddCard), tcard); } }
public void AddCard(sTableCard tcard) { ChangeOwnerNearCard(tcard); cards.Add(tcard); }
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(); }