public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Pipelines,PlanetId,Staff")] Shipyard shipyard)
        {
            if (id != shipyard.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(shipyard);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ShipyardExists(shipyard.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PlanetId"] = new SelectList(_context.Planets, "Id", "Name", shipyard.PlanetId);
            return(View(shipyard));
        }
        public async Task <IActionResult> PutShipyard(int id, Shipyard shipyard)
        {
            if (id != shipyard.Id)
            {
                return(BadRequest());
            }

            _context.Entry(shipyard).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ShipyardExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
    public bool TryDeployShip(Ship ship, Shipyard shipyard)
    {
        if (shipyard.HostedShip != ship)
        {
            Debug.LogError("Trying to deploy from wrong shipyard");
            return(false);
        }

        if (ship.ConstructionRemaining > 0)
        {
            Debug.LogError("Trying to deploy incomplete ship");
            return(false);
        }

        // if we get here, all good
        shipyard.ClearHostedCard();
        _game.Player.Ships.Add(ship);
        _actions.Add(new DeployAction(ship, shipyard));

        GameViewController.DeployShip(ship, true);

        GameViewController.AddGameLogMessage(string.Format("<b>You</b> deploy {0}", ship.CardName));

        return(true);
    }
        public async Task <ActionResult <Shipyard> > PostShipyard(Shipyard shipyard)
        {
            _context.Shipyards.Add(shipyard);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetShipyard", new { id = shipyard.Id }, shipyard));
        }
    public bool TryPlayShipyard(Shipyard shipyard)
    {
        // card must be in the players hand
        if (!_game.Player.Hand.Contains(shipyard))
        {
            return(false);
        }

        // need enough money
        if (shipyard.BaseCost > _game.Player.Credits)
        {
            return(false);
        }

        // playing costs a click
        if (_game.Player.Clicks < 1)
        {
            return(false);
        }

        // if we get here, go ahead and play it
        _actions.Add(new ShipyardAction(shipyard));
        _game.Player.Shipyards.Add(shipyard);
        _game.Player.ChangeCredits(-shipyard.BaseCost);
        ChangeClicks(-1);

        GameViewController.MoveToConstructionArea(shipyard, true);
        GameViewController.AddGameLogMessage(string.Format("<b>You</b> play {0}", shipyard.CardName));

        return(true);
    }
Пример #6
0
    public void Setup()
    {
        //Deck = _deck.Clone();
        Deck.Shuffle();

        // set starting credits
        Credits = Deck.Faction.StartingCredits;

        // set starting clicks
        Clicks = Deck.Faction.ClicksPerTurn;

        // create starting shipyards
        Shipyards = new List <Shipyard>();
        for (int i = 0; i < Deck.Faction.Shipyards.Count; i++)
        {
            Shipyard shipyard = Deck.Faction.Shipyards[i];
            Shipyards.Add(shipyard);
        }

        // initialize lists
        Ships             = new List <Ship>();
        Missiles          = new List <Missile>();
        OngoingOperations = new List <Operation>();
        Hand    = new List <PlayableCard>();
        Discard = new List <PlayableCard>();
    }
Пример #7
0
        public ActionResult DeleteConfirmed(int id)
        {
            Shipyard shipyard = db.Shipyards.Find(id);

            db.Shipyards.Remove(shipyard);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #8
0
 internal ShipyardEvent InvokeEvent(ShipyardEvent arg)
 {
     if (_api.ValidateEvent(arg))
     {
         Shipyard?.Invoke(_api, arg);
     }
     return(arg);
 }
Пример #9
0
 public ActionResult Edit([Bind(Include = "ShipyardID,ShipyardName,Location")] Shipyard shipyard)
 {
     if (ModelState.IsValid)
     {
         db.Entry(shipyard).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(shipyard));
 }
Пример #10
0
    public void AddShipyard(Shipyard shipyard, bool belongsToPlayer)
    {
        // instantiate
        Transform shipyardTransform = InstantiateCardPrefab(shipyard, belongsToPlayer);

        // position
        Transform constructionArea = (belongsToPlayer ? PlayerConstructionAreaGUI : OpponentConstructionAreaGUI);

        shipyardTransform.SetParent(constructionArea);
    }
Пример #11
0
 public ActionResult Edit([Bind(Include = "ShipyardID,ShipYardName,CurrentNumberOfShipsDocked,ShipYardDockNumber,TotalNumberOfContainers")] Shipyard shipyard)
 {
     if (ModelState.IsValid)
     {
         db.Entry(shipyard).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(shipyard));
 }
    private void ProcessAdvanceConstructionAction(Player player, Player opponent, Game game, string shipId, string shipyardId)
    {
        Shipyard shipyard = FindCardIn(shipyardId, player.Shipyards);
        Ship     ship     = shipyard.HostedShip;

        // TODO - check that the shipId matches hosted card

        ServerLog(string.Format("Advancing construction of {0}({1}) on {2}({3}) for {4}", ship.CardName, ship.CardId, shipyard.CardName, shipyard.CardId, player.Name), game);
        ship.AdvanceConstruction(1);
        ChangeClicks(player, -1);
    }
Пример #13
0
        public ActionResult Create([Bind(Include = "ShipyardID,ShipyardName,Location")] Shipyard shipyard)
        {
            if (ModelState.IsValid)
            {
                db.Shipyards.Add(shipyard);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(shipyard));
        }
Пример #14
0
        public ShipyardTests()
        {
            _battleship = Mock.Of <IShip>();
            _destroyer  = Mock.Of <IShip>();

            _shipyard = new Shipyard(new Dictionary <ShipType, Func <IShip> >
            {
                { ShipType.Battleship, () => _battleship },
                { ShipType.Destroyer, () => _destroyer },
            });
        }
Пример #15
0
 public Ogame()
 {
     Resources  = new Resources();
     Facilities = new Facilities();
     Research   = new Research();
     Shipyard   = new Shipyard();
     Defense    = new Defense();
     Fleet      = new Fleet();
     Galaxy     = new Galaxy();
     webDriver  = new Driver().D;
 }
Пример #16
0
    private void TryDeploy(GameClientController gameClient, Ship ship, Shipyard shipyard)
    {
        Debug.Log(string.Format("Trying to deploy {0}({1}) from {2}({3})", ship.CardName, ship.CardId, shipyard.CardName, shipyard.CardId));
        if (gameClient.TryDeployShip(ship, shipyard))
        {
            Debug.Log("Deploy successful");

            // remove this construction panel
            Destroy(transform.parent.gameObject);
        }
    }
Пример #17
0
        public ActionResult Create([Bind(Include = "ShipyardID,ShipYardName,CurrentNumberOfShipsDocked,ShipYardDockNumber,TotalNumberOfContainers")] Shipyard shipyard)
        {
            if (ModelState.IsValid)
            {
                db.Shipyards.Add(shipyard);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(shipyard));
        }
    private void TryDeploy(GameClientController gameClient, Ship ship, Shipyard shipyard)
    {
        Debug.Log(string.Format("Trying to deploy {0}({1}) from {2}({3})", ship.CardName, ship.CardId, shipyard.CardName, shipyard.CardId));
        if (gameClient.TryDeployShip(ship, shipyard))
        {
            Debug.Log("Deploy successful");

            // remove this construction panel
            Destroy(transform.parent.gameObject);
        }
    }
        public async Task <IActionResult> Create([Bind("Id,Name,Pipelines,PlanetId,Staff")] Shipyard shipyard)
        {
            if (ModelState.IsValid)
            {
                _context.Add(shipyard);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PlanetId"] = new SelectList(_context.Planets, "Id", "Name", shipyard.PlanetId);
            return(View(shipyard));
        }
    private void ProcessOpponentDeployShipAction(string shipId, string shipyardId)
    {
        // move the ship to the deployed area
        Shipyard shipyard = _game.Opponent.Shipyards.Find(x => x.CardId == shipyardId);
        Ship     ship     = shipyard.HostedShip;

        _game.Opponent.Ships.Add(ship);
        shipyard.ClearHostedCard();

        GameViewController.DeployShip(ship, false);

        GameViewController.AddGameLogMessage(string.Format("<b>{0}</b> deploys {1}", _game.Opponent.Name, ship.CardName));
    }
Пример #21
0
        public void PopulateShipList(Shipyard shipyard, string location, List <Ship> ships, bool minorOnly, int turn)
        {
            _shipyard = shipyard;
            _ships    = ships;
            List <string> optionList = new List <string>();

            optionList.Add("None");
            optionList.AddRange(ships.Select(s => s.ToString()));
            ShipDropdown.AddOptions(optionList);
            LocationText.text = location;
            _isMinorOnly      = minorOnly;
            _turn             = turn;
        }
    private void ProcessOpponentAdvanceConstructionAction(string shipId, string shipyardId)
    {
        Shipyard shipyard = _game.Opponent.Shipyards.Find(x => x.CardId == shipyardId);
        Ship     ship     = shipyard.HostedShip;

        ship.AdvanceConstruction(1);
        _game.Opponent.ChangeClicks(-1);

        // update gui panel
        GameViewController.UpdateConstructionRemaining(ship);

        GameViewController.AddGameLogMessage(string.Format("<b>{0}</b> advances construction of {1}", _game.Opponent.Name, ship.CardName));
    }
    public bool TryHost(Ship ship, Shipyard shipyard)
    {
        // ship card must be in the players hand
        if (!_game.Player.Hand.Contains(ship))
        {
            return(false);
        }

        // can only host one card
        if (shipyard.HostedShip != null)
        {
            return(false);
        }

        // can only host ships up to a certain size
        if (ship.Size > shipyard.MaxSize)
        {
            return(false);
        }

        // need enough money
        if (ship.BaseCost > _game.Player.Credits)
        {
            return(false);
        }

        // hosting costs a click
        if (_game.Player.Clicks < 1)
        {
            return(false);
        }

        // TODO - we could gather the reasons for failure here and do something e.g display a popup?

        // if we get here is all good, host away
        _actions.Add(new HostShipAction(ship, shipyard));
        ChangeClicks(-1);
        _game.Player.ChangeCredits(-ship.BaseCost);
        shipyard.HostCard(ship);
        ship.StartConstruction();
        _game.Player.Hand.Remove(ship);

        GameViewController.HostShip(ship, shipyard, true);

        UpdatePlayerStateGUI();
        EnableDisableControls();

        GameViewController.AddGameLogMessage(string.Format("<b>You</b> host {0} on {1}", ship.CardName, shipyard.CardName));

        return(true);
    }
Пример #24
0
        // GET: Shipyards/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Shipyard shipyard = db.Shipyards.Find(id);

            if (shipyard == null)
            {
                return(HttpNotFound());
            }
            return(View(shipyard));
        }
Пример #25
0
        /// <summary>
        /// Initializes setup phase
        /// </summary>
        /// <param name="sender">The Button</param>
        /// <param name="e">The Event</param>
        private void setup(object sender, EventArgs e)
        {
            // Close start menu
            grid.Children.Clear();

            // Initialize setup phase
            shipyard = new Shipyard();

            // Add shipyard
            grid.Children.Add(shipyard);

            // Once buttonSubmit is clicked
            shipyard.play += new EventHandler(start);
        }
    private void ProcessShipyardAction(Player player, Player opponent, Game game, string shipyardId)
    {
        Shipyard shipyard = (Shipyard)FindCardIn(shipyardId, player.Hand);

        // TODO - error if not found

        // TODO - error if not enough credits

        player.Hand.Remove(shipyard);
        player.Shipyards.Add(shipyard);
        player.ChangeClicks(-1);
        player.ChangeCredits(-shipyard.BaseCost);

        ServerLog(string.Format("Playing shipyard {0}({1}) for {2}", shipyard.CardName, shipyard.CardId, player.Name));
    }
    private void ProcessOpponentShipyardAction(string shipyardId, CardCodename cardCodename)
    {
        // card needs to be instantiated
        Shipyard shipyard = (Shipyard)CardFactory.CreateCard(cardCodename, shipyardId);

        GameViewController.AddShipyard(shipyard, false);

        // spend the resources
        _game.Opponent.ChangeClicks(-1);
        _game.Opponent.ChangeCredits(-shipyard.BaseCost);
        _game.Opponent.Hand.RemoveAt(0);
        _game.Opponent.Shipyards.Add(shipyard);

        // log
        GameViewController.AddGameLogMessage(string.Format("<b>{0}</b> plays {1}", _game.Opponent.Name, shipyard.CardName));
    }
    public bool TryAdvanceConstruction(Ship ship, Shipyard shipyard)
    {
        // cant advance if already complete
        if (ship.ConstructionRemaining < 1)
        {
            return(false);
        }

        // if we get here, go ahead and perform the advancement
        ship.AdvanceConstruction(1);
        _actions.Add(new AdvanceConstructionAction(ship, shipyard));
        ChangeClicks(-1);

        GameViewController.AddGameLogMessage(string.Format("<b>You</b> advance construction of {0}", ship.CardName));
        return(true);
    }
    private void ProcessDeployShipAction(Player player, Player opponent, Game game, string shipId, string shipyardId)
    {
        Shipyard shipyard = FindCardIn(shipyardId, player.Shipyards);

        // TODO - error if shipyard not found

        Ship ship = shipyard.HostedShip;

        // TODO - error if this is not the correct ship

        // TODO - error if not complete

        ServerLog(string.Format("Deploying {0}({1}) from {2}({3}) for {4}", ship.CardName, ship.CardId, shipyard.CardName, shipyard.CardId, player.Name), game);
        shipyard.ClearHostedCard();
        player.Ships.Add(ship);
    }
Пример #30
0
    public void OnDrop(PointerEventData eventData)
    {
        DragHandler d = eventData.pointerDrag.GetComponent <DragHandler>();

        if (d != null)
        {
            CardLink cl = eventData.pointerDrag.GetComponent <CardLink>();
            if (cl != null)
            {
                if (GameClientController == null)
                {
                    GameClientController = FindObjectOfType <GameClientController>();
                }

                Card card = cl.Card;
                Debug.Log(card.CardName + " was dropped on " + gameObject.name);

                if (card.CardType == CardType.SHIP && DropZoneType == DropZoneType.PLAYER_SHIPYARD)
                {
                    // try to host the ship on the shipyard
                    Shipyard shipyard = (Shipyard)GetComponent <CardLink>().Card;

                    if (GameClientController.TryHost((Ship)card, shipyard))
                    {
                        d.returnToParent = false;
                    }
                }

                if (card.CardType == CardType.SHIPYARD && DropZoneType == DropZoneType.PLAYER_CONSTRUCTION_AREA)
                {
                    if (GameClientController.TryPlayShipyard((Shipyard)card))
                    {
                        d.returnToParent = false;
                    }
                }

                if (card.CardType == CardType.OPERATION)
                {
                    if (GameClientController.TryPlayOperation((Operation)card))
                    {
                        d.returnToParent = false;
                    }
                }
            }
        }
    }
Пример #31
0
    public void AdvanceConstruction()
    {
        GameClientController gameClient = FindObjectOfType <GameClientController>();
        Transform            shipGO     = transform.parent.parent; // grandparent should be the card game object - better way to do this? search up 1 level at a time?
        Transform            shipyardGO = shipGO.parent;
        Ship     ship     = (Ship)shipGO.GetComponent <CardLink>().Card;
        Shipyard shipyard = (Shipyard)shipyardGO.GetComponent <CardLink>().Card;

        if (_constructionComplete)
        {
            TryDeploy(gameClient, ship, shipyard);
        }
        else
        {
            TryAdvance(gameClient, ship, shipyard);
        }
    }
Пример #32
0
    public Faction(string dataStr)
    {
        string[] data = dataStr.Split('|');

        FactionName      = data[0];
        StartingHandSize = int.Parse(data[1]);
        StartingCredits  = int.Parse(data[2]);
        ClicksPerTurn    = int.Parse(data[3]);
        Homeworld        = (Homeworld)CardFactory.CreateCard((CardCodename)Enum.Parse(typeof(CardCodename), data[4]), data[5]);
        Shipyards        = new List <Shipyard>();
        int numShipyards = int.Parse(data[6]);

        for (int i = 0; i < numShipyards; i++)
        {
            Shipyard shipyard = (Shipyard)CardFactory.CreateCard((CardCodename)Enum.Parse(typeof(CardCodename), data[7 + (i * 2)]), data[8 + (i * 2)]);
            Shipyards.Add(shipyard);
        }
    }
    private void TryAdvance(GameClientController gameClient, Ship ship, Shipyard shipyard)
    {
        Debug.Log(string.Format("Trying to advance construction of {0}({1}) on {2}({3})", ship.CardName, ship.CardId, shipyard.CardName, shipyard.CardId));
        if (gameClient.TryAdvanceConstruction(ship, shipyard))
        {
            Debug.Log("Advance successful, trying to update GUI");
            // successfully advanced - decrement the amount
            Text constructionRemaining = (Text)transform.parent.FindChild("ConstructionRemaining").GetComponent(typeof(Text));
            constructionRemaining.text = ship.ConstructionRemaining.ToString();

            if (ship.ConstructionRemaining == 0)
            {
                _constructionComplete = true;

                // change button text
                Text button = (Text)transform.FindChild("AdvanceConstructionButtonText").GetComponent(typeof(Text));
                button.text = "Deploy";
            }
        }
    }
 public ShipyardAction(Shipyard shipyard)
     : base(ActionType.SHIPYARD)
 {
     Shipyard = shipyard;
 }
Пример #35
0
 public DeployAction(Ship ship, Shipyard shipyard)
     : base(ActionType.DEPLOY_SHIP)
 {
     Ship = ship;
     Shipyard = shipyard;
 }
    public void HostShip(Ship ship, Shipyard shipyard, bool belongsToPlayer)
    {
        Transform shipTransform;
        if (belongsToPlayer)
        {
            // will already be in hand, just find it
            shipTransform = _transformById[ship.CardId];
        }
        else
        {
            // will not exist yet, need to instantiate
            shipTransform = InstantiateCardPrefab(ship, false);
        }
        Transform shipyardTransform = FindCardTransformById(shipyard.CardId);

        // add "construction remaining" overlay
        var constructionPanelPrefab = Instantiate(ConstructionPanelPrefab);
        constructionPanelPrefab.name = "ConstructionPanel";
        var constructionRemaining = (Text)constructionPanelPrefab.Find("ConstructionRemaining").GetComponent(typeof(Text));
        constructionRemaining.text = ship.ConstructionRemaining.ToString();

        if (belongsToPlayer == false)
        {
            // deactivate the "advance" button
            Button button = constructionPanelPrefab.Find("AdvanceConstructionButton").GetComponent<Button>();
            button.transform.localScale = new Vector3();
            button.interactable = false;
        }

        constructionPanelPrefab.SetParent(shipTransform);
        constructionPanelPrefab.localPosition = new Vector3(0, 0, 0);

        // position the ship on the shipyard
        shipTransform.SetParent(shipyardTransform);
        shipTransform.localPosition = new Vector3(15, 15, 0);
    }
    public void AddShipyard(Shipyard shipyard, bool belongsToPlayer)
    {
        // instantiate
        Transform shipyardTransform = InstantiateCardPrefab(shipyard, belongsToPlayer);

        // position
        Transform constructionArea = (belongsToPlayer ? PlayerConstructionAreaGUI : OpponentConstructionAreaGUI);
        shipyardTransform.SetParent(constructionArea);
    }
 public HostShipAction(Ship ship, Shipyard shipyard)
     : base(ActionType.HOST_SHIP)
 {
     Ship = ship;
     Shipyard = shipyard;
 }
 public AdvanceConstructionAction(Ship ship, Shipyard shipyard)
     : base(ActionType.ADVANCE_CONSTRUCTION)
 {
     Ship = ship;
     Shipyard = shipyard;
 }