Esempio n. 1
0
        private void AiClickButton(string coord_tip)
        {
            Button clicked_button = (Button)PlayerShipTable.FindName(coord_tip);

            if (PlayerHitsaShip(clicked_button.Name, player1))
            {
                LastCoordThatHit = coord_tip;
                if (aiplayer.PlayerHits.Contains(clicked_button.Name))
                {
                    AiTurns();
                    return;
                }
                else
                {
                    clicked_button.Content = (Image)FindResource(partHitAi);
                    aiplayer.updatePlayerHits(clicked_button.Name);
                    player1.updateEnemyHits(clicked_button.Name);
                    lastShipHitAi.ShipPartsHit += 1;
                }
                if (lastShipHitAi.ShipPartsHit > 1)
                {
                    if (GameObjects.Functions.CheckIfAllShipCoordsHit(lastShipHitAi, player1) == null)
                    {
                        LastCoordThatHit = null;
                        GameObjects.Functions.UpdateRemainingShips(NumberofHitsEnemy, player_remaining_ships, aiplayer, player1, false);
                        CheckAiWins();
                    }
                }
            }
            else
            {
                if (clicked_button.Content != null)
                {
                    AiTurns();
                    return;
                }
                else
                {
                    clicked_button.Content = (Image)FindResource("NotHit");
                }
            }
            SetTurnData(0);
        }
Esempio n. 2
0
        private void DrawBoat(GameObjects.Ship ship, bool isAi)
        {
            Image front, mid, mid2, mid3, back;

            if (player1.RemainingShips.Count <= 5 && aiplayer.RemainingShips.Count <= 5)
            {
                //PlayerTargetTable
                if (!isAi)
                {
                    if (ship.rotated == true)
                    {
                        if (ship.shipType.Equals("PatrolBoat"))
                        {
                            front = (Image)FindResource("LeftShipFront");
                            back  = (Image)FindResource("LeftShipBack");

                            Button toDrawStart = (Button)PlayerShipTable.FindName(ship.getCoords()[0, 0] + ship.getCoords()[0, 1]);
                            toDrawStart.Content = front;
                            Button toDrawEnd = (Button)PlayerShipTable.FindName(ship.getCoords()[1, 0] + ship.getCoords()[1, 1]);
                            toDrawEnd.Content = back;
                        }
                        else if (ship.shipType.Equals("Submarine") || ship.shipType.Equals("Destroyer"))
                        {
                            front = (Image)FindResource("LeftShipFront");
                            mid   = (Image)FindResource("LeftShipMid");
                            back  = (Image)FindResource("LeftShipBack");

                            Button toDrawStart = (Button)PlayerShipTable.FindName(ship.getCoords()[0, 0] + "" + ship.getCoords()[0, 1]);
                            toDrawStart.Content = front;
                            Button toDrawMid = (Button)PlayerShipTable.FindName(ship.getCoords()[1, 0] + "" + ship.getCoords()[1, 1]);
                            toDrawMid.Content = mid;
                            Button toDrawEnd = (Button)PlayerShipTable.FindName(ship.getCoords()[2, 0] + "" + ship.getCoords()[2, 1]);
                            toDrawEnd.Content = back;
                        }
                        else if (ship.shipType.Equals("Battleship"))
                        {
                            front = (Image)FindResource("LeftShipFront");
                            mid   = (Image)FindResource("LeftShipMid");
                            mid2  = (Image)FindResource("LeftShipMid");
                            back  = (Image)FindResource("LeftShipBack");

                            Button toDrawStart = (Button)PlayerShipTable.FindName(ship.getCoords()[0, 0] + "" + ship.getCoords()[0, 1]);
                            toDrawStart.Content = front;
                            Button toDrawMid = (Button)PlayerShipTable.FindName(ship.getCoords()[1, 0] + "" + ship.getCoords()[1, 1]);
                            toDrawMid.Content = mid;
                            Button toDrawMid2 = (Button)PlayerShipTable.FindName(ship.getCoords()[2, 0] + "" + ship.getCoords()[2, 1]);
                            toDrawMid2.Content = mid2;
                            Button toDrawEnd = (Button)PlayerShipTable.FindName(ship.getCoords()[3, 0] + "" + ship.getCoords()[3, 1]);
                            toDrawEnd.Content = back;
                        }
                        else if (ship.shipType.Equals("Carrier"))
                        {
                            front = (Image)FindResource("LeftShipFront");
                            mid   = (Image)FindResource("LeftShipMid");
                            mid2  = (Image)FindResource("LeftShipMid");
                            mid3  = (Image)FindResource("LeftShipMid");
                            back  = (Image)FindResource("LeftShipBack");

                            Button toDrawStart = (Button)PlayerShipTable.FindName(ship.getCoords()[0, 0] + "" + ship.getCoords()[0, 1]);
                            toDrawStart.Content = front;
                            Button toDrawMid = (Button)PlayerShipTable.FindName(ship.getCoords()[1, 0] + "" + ship.getCoords()[1, 1]);
                            toDrawMid.Content = mid;
                            Button toDrawMid2 = (Button)PlayerShipTable.FindName(ship.getCoords()[2, 0] + "" + ship.getCoords()[2, 1]);
                            toDrawMid2.Content = mid2;
                            Button toDrawMid3 = (Button)PlayerShipTable.FindName(ship.getCoords()[3, 0] + "" + ship.getCoords()[3, 1]);
                            toDrawMid3.Content = mid3;
                            Button toDrawEnd = (Button)PlayerShipTable.FindName(ship.getCoords()[4, 0] + "" + ship.getCoords()[4, 1]);
                            toDrawEnd.Content = back;
                        }
                    }
                    else
                    {
                        if (ship.shipType.Equals("PatrolBoat"))
                        {
                            front = (Image)FindResource("ShipFront");
                            back  = (Image)FindResource("ShipBack");

                            Button toDrawStart = (Button)PlayerShipTable.FindName(ship.getCoords()[0, 0] + ship.getCoords()[0, 1]);
                            toDrawStart.Content = front;
                            Button toDrawEnd = (Button)PlayerShipTable.FindName(ship.getCoords()[1, 0] + ship.getCoords()[1, 1]);
                            toDrawEnd.Content = back;
                        }
                        else if (ship.shipType.Equals("Submarine") || ship.shipType.Equals("Destroyer"))
                        {
                            front = (Image)FindResource("ShipFront");
                            mid   = (Image)FindResource("ShipMid");
                            back  = (Image)FindResource("ShipBack");

                            Button toDrawStart = (Button)PlayerShipTable.FindName(ship.getCoords()[0, 0] + "" + ship.getCoords()[0, 1]);
                            toDrawStart.Content = front;
                            Button toDrawMid = (Button)PlayerShipTable.FindName(ship.getCoords()[1, 0] + "" + ship.getCoords()[1, 1]);
                            toDrawMid.Content = mid;
                            Button toDrawEnd = (Button)PlayerShipTable.FindName(ship.getCoords()[2, 0] + "" + ship.getCoords()[2, 1]);
                            toDrawEnd.Content = back;
                        }
                        else if (ship.shipType.Equals("Battleship"))
                        {
                            front = (Image)FindResource("ShipFront");
                            mid   = (Image)FindResource("ShipMid");
                            mid2  = (Image)FindResource("ShipMid");
                            back  = (Image)FindResource("ShipBack");
                            Button toDrawStart = (Button)PlayerShipTable.FindName(ship.getCoords()[0, 0] + "" + ship.getCoords()[0, 1]);
                            toDrawStart.Content = front;
                            Button toDrawMid = (Button)PlayerShipTable.FindName(ship.getCoords()[1, 0] + "" + ship.getCoords()[1, 1]);
                            toDrawMid.Content = mid;
                            Button toDrawMid2 = (Button)PlayerShipTable.FindName(ship.getCoords()[2, 0] + "" + ship.getCoords()[2, 1]);
                            toDrawMid2.Content = mid2;
                            Button toDrawEnd = (Button)PlayerShipTable.FindName(ship.getCoords()[3, 0] + "" + ship.getCoords()[3, 1]);
                            toDrawEnd.Content = back;
                        }
                        else if (ship.shipType.Equals("Carrier"))
                        {
                            front = (Image)FindResource("ShipFront");
                            mid   = (Image)FindResource("ShipMid");
                            mid2  = (Image)FindResource("ShipMid");
                            mid3  = (Image)FindResource("ShipMid");
                            back  = (Image)FindResource("ShipBack");

                            Button toDrawStart = (Button)PlayerShipTable.FindName(ship.getCoords()[0, 0] + "" + ship.getCoords()[0, 1]);
                            toDrawStart.Content = front;
                            Button toDrawMid = (Button)PlayerShipTable.FindName(ship.getCoords()[1, 0] + "" + ship.getCoords()[1, 1]);
                            toDrawMid.Content = mid;
                            Button toDrawMid2 = (Button)PlayerShipTable.FindName(ship.getCoords()[2, 0] + "" + ship.getCoords()[2, 1]);
                            toDrawMid2.Content = mid2;
                            Button toDrawMid3 = (Button)PlayerShipTable.FindName(ship.getCoords()[3, 0] + "" + ship.getCoords()[3, 1]);
                            toDrawMid3.Content = mid3;
                            Button toDrawEnd = (Button)PlayerShipTable.FindName(ship.getCoords()[4, 0] + "" + ship.getCoords()[4, 1]);
                            toDrawEnd.Content = back;
                        }
                    }
                }

                //if its ai
                else
                {
                    if (ship.rotated == true)
                    {
                        if (ship.shipType.Equals("PatrolBoat"))
                        {
                            front = (Image)FindResource("LeftShipFront");
                            back  = (Image)FindResource("LeftShipBack");

                            Button toDrawStart = (Button)PlayerTargetTable.FindName(ship.getCoords()[0, 0] + ship.getCoords()[0, 1] + "_t");
                            toDrawStart.Content = front;
                            Button toDrawEnd = (Button)PlayerTargetTable.FindName(ship.getCoords()[1, 0] + ship.getCoords()[1, 1] + "_t");
                            toDrawEnd.Content = back;
                        }
                        else if (ship.shipType.Equals("Submarine") || ship.shipType.Equals("Destroyer"))
                        {
                            front = (Image)FindResource("LeftShipFront");
                            mid   = (Image)FindResource("LeftShipMid");
                            back  = (Image)FindResource("LeftShipBack");

                            Button toDrawStart = (Button)PlayerTargetTable.FindName(ship.getCoords()[0, 0] + "" + ship.getCoords()[0, 1] + "_t");
                            toDrawStart.Content = front;
                            Button toDrawMid = (Button)PlayerTargetTable.FindName(ship.getCoords()[1, 0] + "" + ship.getCoords()[1, 1] + "_t");
                            toDrawMid.Content = mid;
                            Button toDrawEnd = (Button)PlayerTargetTable.FindName(ship.getCoords()[2, 0] + "" + ship.getCoords()[2, 1] + "_t");
                            toDrawEnd.Content = back;
                        }
                        else if (ship.shipType.Equals("Battleship"))
                        {
                            front = (Image)FindResource("LeftShipFront");
                            mid   = (Image)FindResource("LeftShipMid");
                            mid2  = (Image)FindResource("LeftShipMid");
                            back  = (Image)FindResource("LeftShipBack");

                            Button toDrawStart = (Button)PlayerTargetTable.FindName(ship.getCoords()[0, 0] + "" + ship.getCoords()[0, 1] + "_t");
                            toDrawStart.Content = front;
                            Button toDrawMid = (Button)PlayerTargetTable.FindName(ship.getCoords()[1, 0] + "" + ship.getCoords()[1, 1] + "_t");
                            toDrawMid.Content = mid;
                            Button toDrawMid2 = (Button)PlayerTargetTable.FindName(ship.getCoords()[2, 0] + "" + ship.getCoords()[2, 1] + "_t");
                            toDrawMid2.Content = mid2;
                            Button toDrawEnd = (Button)PlayerTargetTable.FindName(ship.getCoords()[3, 0] + "" + ship.getCoords()[3, 1] + "_t");
                            toDrawEnd.Content = back;
                        }
                        else if (ship.shipType.Equals("Carrier"))
                        {
                            front = (Image)FindResource("LeftShipFront");
                            mid   = (Image)FindResource("LeftShipMid");
                            mid2  = (Image)FindResource("LeftShipMid");
                            mid3  = (Image)FindResource("LeftShipMid");
                            back  = (Image)FindResource("LeftShipBack");

                            Button toDrawStart = (Button)PlayerTargetTable.FindName(ship.getCoords()[0, 0] + "" + ship.getCoords()[0, 1] + "_t");
                            toDrawStart.Content = front;
                            Button toDrawMid = (Button)PlayerTargetTable.FindName(ship.getCoords()[1, 0] + "" + ship.getCoords()[1, 1] + "_t");
                            toDrawMid.Content = mid;
                            Button toDrawMid2 = (Button)PlayerTargetTable.FindName(ship.getCoords()[2, 0] + "" + ship.getCoords()[2, 1] + "_t");
                            toDrawMid2.Content = mid2;
                            Button toDrawMid3 = (Button)PlayerTargetTable.FindName(ship.getCoords()[3, 0] + "" + ship.getCoords()[3, 1] + "_t");
                            toDrawMid3.Content = mid3;
                            Button toDrawEnd = (Button)PlayerTargetTable.FindName(ship.getCoords()[4, 0] + "" + ship.getCoords()[4, 1] + "_t");
                            toDrawEnd.Content = back;
                        }
                    }
                    else
                    {
                        if (ship.shipType.Equals("PatrolBoat"))
                        {
                            front = (Image)FindResource("ShipFront");
                            back  = (Image)FindResource("ShipBack");

                            Button toDrawStart = (Button)PlayerTargetTable.FindName(ship.getCoords()[0, 0] + ship.getCoords()[0, 1] + "_t");
                            toDrawStart.Content = front;
                            Button toDrawEnd = (Button)PlayerTargetTable.FindName(ship.getCoords()[1, 0] + ship.getCoords()[1, 1] + "_t");
                            toDrawEnd.Content = back;
                        }
                        else if (ship.shipType.Equals("Submarine") || ship.shipType.Equals("Destroyer"))
                        {
                            front = (Image)FindResource("ShipFront");
                            mid   = (Image)FindResource("ShipMid");
                            back  = (Image)FindResource("ShipBack");

                            Button toDrawStart = (Button)PlayerTargetTable.FindName(ship.getCoords()[0, 0] + "" + ship.getCoords()[0, 1] + "_t");
                            toDrawStart.Content = front;
                            Button toDrawMid = (Button)PlayerTargetTable.FindName(ship.getCoords()[1, 0] + "" + ship.getCoords()[1, 1] + "_t");
                            toDrawMid.Content = mid;
                            Button toDrawEnd = (Button)PlayerTargetTable.FindName(ship.getCoords()[2, 0] + "" + ship.getCoords()[2, 1] + "_t");
                            toDrawEnd.Content = back;
                        }
                        else if (ship.shipType.Equals("Battleship"))
                        {
                            front = (Image)FindResource("ShipFront");
                            mid   = (Image)FindResource("ShipMid");
                            mid2  = (Image)FindResource("ShipMid");
                            back  = (Image)FindResource("ShipBack");
                            Button toDrawStart = (Button)PlayerTargetTable.FindName(ship.getCoords()[0, 0] + "" + ship.getCoords()[0, 1] + "_t");
                            toDrawStart.Content = front;
                            Button toDrawMid = (Button)PlayerTargetTable.FindName(ship.getCoords()[1, 0] + "" + ship.getCoords()[1, 1] + "_t");
                            toDrawMid.Content = mid;
                            Button toDrawMid2 = (Button)PlayerTargetTable.FindName(ship.getCoords()[2, 0] + "" + ship.getCoords()[2, 1] + "_t");
                            toDrawMid2.Content = mid2;
                            Button toDrawEnd = (Button)PlayerTargetTable.FindName(ship.getCoords()[3, 0] + "" + ship.getCoords()[3, 1] + "_t");
                            toDrawEnd.Content = back;
                        }
                        else if (ship.shipType.Equals("Carrier"))
                        {
                            front = (Image)FindResource("ShipFront");
                            mid   = (Image)FindResource("ShipMid");
                            mid2  = (Image)FindResource("ShipMid");
                            mid3  = (Image)FindResource("ShipMid");
                            back  = (Image)FindResource("ShipBack");

                            Button toDrawStart = (Button)PlayerTargetTable.FindName(ship.getCoords()[0, 0] + "" + ship.getCoords()[0, 1] + "_t");
                            toDrawStart.Content = front;
                            Button toDrawMid = (Button)PlayerTargetTable.FindName(ship.getCoords()[1, 0] + "" + ship.getCoords()[1, 1] + "_t");
                            toDrawMid.Content = mid;
                            Button toDrawMid2 = (Button)PlayerTargetTable.FindName(ship.getCoords()[2, 0] + "" + ship.getCoords()[2, 1] + "_t");
                            toDrawMid2.Content = mid2;
                            Button toDrawMid3 = (Button)PlayerTargetTable.FindName(ship.getCoords()[3, 0] + "" + ship.getCoords()[3, 1] + "_t");
                            toDrawMid3.Content = mid3;
                            Button toDrawEnd = (Button)PlayerTargetTable.FindName(ship.getCoords()[4, 0] + "" + ship.getCoords()[4, 1] + "_t");
                            toDrawEnd.Content = back;
                        }
                    }
                }
            }
        }