Exemple #1
0
    public static List <Upgrade> UpgradeGenerator(PlayerShips shipName, bool hitpoint = true, int count = 10)
    {
        List <Upgrade> upgrades = new List <Upgrade>();
        PlayerShip     ship     = GameData.PlayerShipObjects[shipName].GetComponent <PlayerShip>();

        for (int i = 0; i < count; i++)
        {
            double   ii = i + 1 * 1.334;
            Upgrades upgradeType;
            int      bonus;
            int      costMetal;
            int      requiredLevel;
            if (hitpoint)
            {
                upgradeType   = Upgrades.Hitpoints;
                bonus         = (int)(ii * ship.Level * 75.22);
                costMetal     = (int)(ii * ship.Level * 5.18);
                requiredLevel = ship.Level + (i / 4);
            }
            else
            {
                upgradeType   = Upgrades.Speed;
                bonus         = (int)ii;
                costMetal     = (int)(ii * 13.71);
                requiredLevel = ship.Level + (i / 8);
            }
            int costScrap = costMetal * GameData.MetalPrice;

            upgrades.Add(new Upgrade(upgradeType, bonus, costScrap, costMetal, requiredLevel));
        }
        return(upgrades);
    }
Exemple #2
0
 public void HandleShooting(int[] coordinates)
 {
     Board.HandleShotOnSquare(coordinates);
     if (Board.CheckIfShip(coordinates))
     {
         PlayerShips.HitShip(coordinates);
         UpdateZonesAfterDefeatingShip(coordinates);
     }
 }
        public Savegame(string fileLoc)
        {
            this._playerShips = new ObservableCollection <Ship>();
            this._shipyards   = new ObservableCollection <Shipyard>();
            this._stations    = new ObservableCollection <Station>();

            Path = fileLoc;
            Data = XElement.Load(_path, LoadOptions.PreserveWhitespace);

            IEnumerable <XElement> ships = from ship in _data.Descendants().Elements("component")
                                           where (string)ship.Attribute("owner") == "player" && (string)ship.Attribute("state") != "wreck" && ((string)ship.Attribute("class") == "ship_xl" | (string)ship.Attribute("class") == "ship_l" | (string)ship.Attribute("class") == "ship_s" | (string)ship.Attribute("class") == "ship_xs")
                                           orderby(string) ship.Attribute("name")
                                           select ship;

            foreach (XElement ship in ships)
            {
                PlayerShips.Add(new Ship(ship));
            }

            IEnumerable <XElement> shipyards = this._data.Descendants().Elements("component").Where(delegate(XElement shipyard)
            {
                bool result = false;
                if (shipyard.Attribute("macro") != null && shipyard.Attribute("macro").Value.ToString().EndsWith("yard_macro"))
                {
                    result = true;
                }
                return(result);
            }
                                                                                                    );

            foreach (XElement shipyard in shipyards)
            {
                Shipyards.Add(new Shipyard(shipyard));
            }


            IEnumerable <XElement> stations = this._data.Descendants().Elements("component").Where(delegate(XElement ele)
            {
                bool result = false;
                if (ele.Attribute("owner") != null && ele.Attribute("class") != null && (ele.Attribute("owner").Value.ToString() == "player") && ele.Attribute("class").Value.Contains("station"))
                {
                    result = true;
                }

                return(result);
            });

            foreach (XElement station in stations)
            {
                Stations.Add(new Station(station));
            }
        }
Exemple #4
0
        public void UpdateZonesAfterDefeatingShip(int[] coordinates)
        {
            Ship ship = PlayerShips.GetShipAtCoordinates(coordinates);

            if (!ship.IsAlive)
            {
                foreach (int[] zoneCoordinates in ship.SafeZoneCoordinates)
                {
                    Board.board[zoneCoordinates[0]][zoneCoordinates[1]].IsHit = true;
                    if (!(alreadySelected.Any(x => x[0] == zoneCoordinates[0] && x[1] == zoneCoordinates[1])))
                    {
                        alreadySelected.Add(zoneCoordinates);
                    }
                }
            }
        }
Exemple #5
0
    public static List <Upgrade>[] ShipUpgrades(PlayerShips shipName)
    {
        List <Upgrade>[] upgrades = new List <Upgrade> [2];

        List <Upgrade> hitpoints = null;
        List <Upgrade> speed     = null;

        switch (shipName)
        {
        case PlayerShips.Avalon:
            hitpoints = new List <Upgrade>();
            speed     = new List <Upgrade>();

            hitpoints = UpgradeGenerator(shipName);
            speed     = UpgradeGenerator(shipName, false, 10);

            break;

        case PlayerShips.Templar:
            hitpoints = new List <Upgrade>();
            speed     = new List <Upgrade>();

            hitpoints = UpgradeGenerator(shipName);
            speed     = UpgradeGenerator(shipName, false, 0);

            break;

        case PlayerShips.Invictus:
            hitpoints = new List <Upgrade>();
            speed     = new List <Upgrade>();

            hitpoints = UpgradeGenerator(shipName);
            speed     = UpgradeGenerator(shipName, false, 20);

            break;
        }

        upgrades[0] = hitpoints;
        upgrades[1] = speed;

        return(upgrades);
    }
Exemple #6
0
 public virtual void Refresh(HangarShip ship)
 {
     ShipName.text = ship.Ship.name;
     shipType      = ship.Type;
     if (ship.Bought == true)
     {
         if (ship.Used)
         {
             StatusMessage("Used");
         }
         else
         {
             StatusMessage("Bought");
         }
     }
     else
     {
         StatusMessage("Required level " + ship.Ship.Level);
     }
 }
Exemple #7
0
    public void ChangeShip(PlayerShips shipName, bool start = false)
    {
        if (!Ships[shipName].Bought)
        {
            Debug.Log(shipName + " nie jest kupiony");
            return;
        }

        if (Ship != null)
        {
            foreach (HangarShip hangar in Ships.Values.Where(o => o.Used))
            {
                hangar.Used = false;
            }
        }

        foreach (Transform t in transform.Find("Ship"))
        {
            Destroy(t.gameObject);
        }

        Ships[shipName].Used = true;

        GameObject ship = Instantiate(Ships[shipName].Model, transform.Find("Ship"));

        Ship     = ship.GetComponent <PlayerShip>();
        ShipName = shipName;

        if (!start)
        {
            foreach (Item item in Items.Where(o => o.Equipped))
            {
                item.Equipped = false;
            }

            Gui.windows[Windows.Hangar].Script.Refresh();
        }
    }
Exemple #8
0
    public void BuyShip(PlayerShips shipName, bool scrap)
    {
        if (!Ships[shipName].Bought)
        {
            bool buy = false;
            if (scrap)
            {
                if (Scrap >= Ships[shipName].Ship.CostScrap)
                {
                    Scrap -= Ships[shipName].Ship.CostScrap;
                    buy    = true;
                }
                else
                {
                    Debug.LogError("Brak scrapu");
                }
            }
            else
            {
                if (Metal >= Ships[shipName].Ship.CostMetal)
                {
                    Scrap -= Ships[shipName].Ship.CostMetal;
                    buy    = true;
                }
                else
                {
                    Debug.LogError("Brak metalu");
                }
            }

            if (buy)
            {
                Ships[shipName].Bought = true;
                Gui.windows[Windows.Hangar].Script.Refresh();
            }
        }
    }
Exemple #9
0
    public bool Used;                                              //SAVE



    public HangarShip(GameObject model, PlayerShips type)
    {
        Model = model;
        Ship  = model.GetComponent <PlayerShip>();
        Type  = type;
    }
Exemple #10
0
 public void AutomaticShipPopulation()
 {
     PlayerShips.AutomaticShipListPopulation(IsRebellion, Board);
 }
Exemple #11
0
 public void PopulatePlayerShipList()
 {
     PlayerShips.PopulatePlayerShipsList(IsRebellion, Board);
 }
Exemple #12
0
        private void HandleShipRequest(object sender, ShipMessage msg)
        {
            ShipPeer    peer    = sender as ShipPeer;
            ShipRequest request = msg as ShipRequest;

            JoinShipResponce responce = new JoinShipResponce();

            PlayerShip shipToLink = null;

            if (peer.LinkedShip != null)
            {
                shipToLink = peer.LinkedShip;
            }
            else
            {
                if (request.Join)
                {
                    shipToLink = PlayerShips.Find((x) => x.LinkedShip.GUID == request.RequestedShipID);
                    if (shipToLink == null || shipToLink.Locked && shipToLink.Password != request.Password)
                    {
                        responce.Error   = true;
                        responce.Message = "NoShipToJoin";
                        peer.Send(responce);
                        return; // nope!
                    }
                    else
                    {
                        if (!shipToLink.ControlingPeers.Contains(peer))
                        {
                            shipToLink.ControlingPeers.Add(peer);
                        }

                        peer.LinkedShip = shipToLink;
                    }
                }
            }

            if (shipToLink == null)
            {
                var template = TemplateDatabase.GetTemplate(request.RequestedShipID);
                int shipID   = ActiveScenario.SpawnPlayableShip(peer.Connection.RemoteUniqueIdentifier.ToString(), template == null ? string.Empty : template.Name, request.Name);

                var ship = ZoneManager.GetFirstMatch(new PlayableShipFinder(shipID)) as Ship;

                shipToLink            = new PlayerShip();
                shipToLink.LinkedShip = ship;
                shipToLink.ControlingPeers.Add(peer);
                shipToLink.Locked   = request.Password != string.Empty;
                shipToLink.Password = request.Password;

                peer.LinkedShip = shipToLink;
                PlayerShips.Add(shipToLink);
            }

            // send back the responce with the ship they are on
            responce.Error   = false;
            responce.Message = shipToLink.LinkedShip.Name;
            responce.ShipID  = shipToLink.LinkedShip.GUID;
            peer.Send(responce);

            // send an info and status update
        }
Exemple #13
0
        public void ProccessArrangement()
        {
            int type = 0;


            bool isTruePunct = false;

            Console.WriteLine("Вы должны расставить корабли. В запасе:");
            Console.WriteLine($"1. Катер (однапалубный) - {boat}");
            Console.WriteLine($"2. Эсминцы (двухпалубный) - {destroyers}");
            Console.WriteLine($"3. Крейсеры (трёхпалубный) - {cruisers}");
            Console.WriteLine($"4. Линкор (четырёхпалубный) - {battleship}\n");
            while (!isTruePunct)
            {
                Console.Write($"Введите номер корабля: ");
                var isDigit = int.TryParse(Console.ReadLine(), out int punct);
                if (isDigit && (punct > 0 || punct < 5))
                {
                    switch (punct)
                    {
                    case 1:
                        type = 1;
                        if (boat == 0)
                        {
                            Console.WriteLine("Кораблей такого типа нет в запасе");
                        }
                        else
                        {
                            isTruePunct = true;
                        }
                        break;

                    case 2:
                        type = 2;
                        if (destroyers == 0)
                        {
                            Console.WriteLine("Кораблей такого типа нет в запасе");
                        }
                        else
                        {
                            isTruePunct = true;
                        }
                        break;

                    case 3:
                        type = 3;
                        if (cruisers == 0)
                        {
                            Console.WriteLine("Кораблей такого типа нет в запасе");
                        }
                        else
                        {
                            isTruePunct = true;
                        }
                        break;

                    case 4:
                        type = 4;
                        if (battleship == 0)
                        {
                            Console.WriteLine("Кораблей такого типа нет в запасе");
                        }
                        else
                        {
                            isTruePunct = true;
                        }
                        break;

                    default:
                        Console.WriteLine("Введите число от 1 до 4");
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("Введите число от 1 до 4");
                }
            }
            string alph       = "";
            bool   isTrueAlph = false;

            while (!isTrueAlph)
            {
                Console.Write("Введите букву: ");
                alph = Console.ReadLine();
                if (alph != "A" && alph == "B" && alph != "C" && alph != "D" && alph != "E" && alph != "F" && alph != "G" && alph != "H" && alph != "I" && alph != "J")
                {
                    Console.WriteLine("Вы должны ввести букву от A-J");
                }
                else
                {
                    isTrueAlph = true;
                }
            }
            string number       = string.Empty;
            bool   isTrueNumber = false;

            while (!isTrueNumber)
            {
                Console.Write("Введите число: ");
                number = Console.ReadLine();
                if (number != "1" && number != "2" && number != "3" && number != "4" && number != "5" && number != "6" && number != "7" && number != "8" && number != "9" && number != "10")
                {
                    Console.WriteLine("Вы должны ввести число от 1-10");
                }
                else
                {
                    isTrueNumber = true;
                }
            }
            int alphDigit = 0;

            if (alph == "A")
            {
                alphDigit = 1;
            }
            else if (alph == "B")
            {
                alphDigit = 2;
            }
            else if (alph == "C")
            {
                alphDigit = 3;
            }
            else if (alph == "D")
            {
                alphDigit = 4;
            }
            else if (alph == "E")
            {
                alphDigit = 5;
            }
            else if (alph == "F")
            {
                alphDigit = 6;
            }
            else if (alph == "G")
            {
                alphDigit = 7;
            }
            else if (alph == "H")
            {
                alphDigit = 8;
            }
            else if (alph == "I")
            {
                alphDigit = 9;
            }
            else if (alph == "J")
            {
                alphDigit = 10;
            }
            if (type == 1)
            {
                PositionShip boatPos = new PositionShip
                {
                    Alph   = alphDigit,
                    Number = Int32.Parse(number)
                };
                Console.WriteLine("Корабль поставлен!");
                Console.Clear();
                PlayerShips.Add(boatPos);
            }
            else
            {
                Console.WriteLine("1. Вверх");
                Console.WriteLine("2. Вниз");
                Console.WriteLine("3. Вправо");
                Console.WriteLine("4. Влево");
                string direction       = "";
                bool   isTrueDirection = false;
                while (!isTrueDirection)
                {
                    Console.Write("Выберите направление для корабля: ");
                    direction = Console.ReadLine();
                    if (direction != "1" && direction != "2" && direction != "3" && direction != "4")
                    {
                        Console.WriteLine("Вы должны ввести число от 1-4");
                    }
                    else
                    {
                        if (direction == "1")
                        {
                            if (Int32.Parse(number) - type < 0)
                            {
                                Console.WriteLine("Корабль невозможно поставить");
                            }
                            else
                            {
                                isTrueDirection = true;
                            }
                        }
                        else if (direction == "2")
                        {
                            if (Int32.Parse(number) + type > 10)
                            {
                                Console.WriteLine("Корабль невозможно поставить");
                            }
                            else
                            {
                                isTrueDirection = true;
                            }
                        }
                        else if (direction == "3")
                        {
                            if (Char.Parse(number) + type > 74)
                            {
                                Console.WriteLine("Корабль невозможно поставить");
                            }
                            else
                            {
                                isTrueDirection = true;
                            }
                        }
                        else if (direction == "4")
                        {
                            if (Char.Parse(number) - type < 65)
                            {
                                Console.WriteLine("Корабль невозможно поставить");
                            }
                            else
                            {
                                isTrueDirection = true;
                            }
                        }
                        else
                        {
                            isTrueNumber = true;
                        }
                    }
                }

                for (int i = 0; i < type; i++)
                {
                    PositionShip position = new PositionShip();
                    if (direction == "1")
                    {
                        position = new PositionShip
                        {
                            Alph   = alphDigit,
                            Number = Int32.Parse(number) - i
                        };
                    }
                    else if (direction == "2")
                    {
                        position = new PositionShip
                        {
                            Alph   = alphDigit,
                            Number = Int32.Parse(number) + i
                        };
                    }
                    else if (direction == "3")
                    {
                        position = new PositionShip
                        {
                            Alph   = alphDigit + i,
                            Number = Int32.Parse(number)
                        };
                    }
                    else if (direction == "4")
                    {
                        position = new PositionShip
                        {
                            Alph   = alphDigit - i,
                            Number = Int32.Parse(number)
                        };
                    }

                    PlayerShips.Add(position);
                }

                Console.WriteLine("Корабль поставлен!");
                Console.Clear();
            }
            if (type == 1)
            {
                boat--;
            }
            else if (type == 2)
            {
                destroyers--;
            }
            else if (type == 3)
            {
                cruisers--;
            }
            else if (type == 4)
            {
                battleship--;
            }
            Start();
        }