コード例 #1
0
        private void SpinnerRank_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
        {
            List <Ship> shipsRank;

            switch (e.Position)
            {
            case 0:
                shipsRank        = shipsAll;
                shipAdapter      = new ShipAdapter(this, shipsRank);
                listView.Adapter = shipAdapter;
                break;

            case 1:
                shipsRank        = shipsAll.Where(x => x.Rank == "III").ToList();
                shipAdapter      = new ShipAdapter(this, shipsRank);
                listView.Adapter = shipAdapter;
                break;

            case 2:
                shipsRank        = shipsAll.Where(x => x.Rank == "IV").ToList();
                shipAdapter      = new ShipAdapter(this, shipsRank);
                listView.Adapter = shipAdapter;
                break;

            case 3:
                shipsRank        = shipsAll.Where(x => x.Rank == "V").ToList();
                shipAdapter      = new ShipAdapter(this, shipsRank);
                listView.Adapter = shipAdapter;
                break;
            }
        }
コード例 #2
0
        /// <summary>
        /// Search Dialog Initialization
        /// </summary>
        private void SearchDialogInitialization()
        {
            dialog   = new Dialog(this);
            inflater = LayoutInflater.From(this);
            view     = inflater.Inflate(Resource.Layout._searchDialog, null);

            spinnerNation = view.FindViewById <Spinner>(Resource.Id.spinnerNation);
            spinnerRank   = view.FindViewById <Spinner>(Resource.Id.spinnerRank);

            listView   = view.FindViewById <ListView>(Resource.Id.listView);
            searchView = view.FindViewById <SearchView>(Resource.Id.searchView);
            searchView.SetQueryHint("HMS..");

            shipAdapter      = new ShipAdapter(this, arrayOfShips.ShipsListApi);
            listView.Adapter = shipAdapter;
            SpinnerInitialization();
        }
コード例 #3
0
        private void _InfoSpinnerRank_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
        {
            selectedRank = ranks[e.Position].Id;

            if (selectedNation == 100 && selectedRank == 100)
            {
                ships       = ShipCollection.GetShip();
                AdapterShip = new ShipAdapter(this, ships);
                _InfoSpinnerShip.Adapter = AdapterShip;
            }
            else
            if (selectedNation == 100)
            {
                List <Ship> shipsAll = ShipCollection.GetShip();
                var         shipvar  = from s in shipsAll
                                       where s.RankId == selectedRank
                                       select s;
                ships       = shipvar.ToList <Ship>();
                AdapterShip = new ShipAdapter(this, ships);
                _InfoSpinnerShip.Adapter = AdapterShip;
            }
            else
            if (selectedRank == 100)
            {
                List <Ship> shipsAll = ShipCollection.GetShip();
                var         shipvar  = from s in shipsAll
                                       where s.NationId == selectedNation
                                       select s;
                ships       = shipvar.ToList <Ship>();
                AdapterShip = new ShipAdapter(this, ships);
                _InfoSpinnerShip.Adapter = AdapterShip;
            }
            else
            {
                ships       = ShipSelector(selectedNation, selectedRank);
                AdapterShip = new ShipAdapter(this, ships);
                _InfoSpinnerShip.Adapter = AdapterShip;
            }
        }
コード例 #4
0
        private void SpinnerNation_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
        {
            shipsAll = arrayOfShips.ShipsListApi;
            spinnerRank.SetSelection(0);
            switch (e.Position)
            {
            case 0:
                shipAdapter      = new ShipAdapter(this, arrayOfShips.ShipsListApi);
                listView.Adapter = shipAdapter;
                break;

            case 1:
                shipsAll         = shipsAll.Where(x => x.Nation == "USA").ToList();
                shipAdapter      = new ShipAdapter(this, shipsAll);
                listView.Adapter = shipAdapter;
                break;

            case 2:
                shipsAll         = shipsAll.Where(x => x.Nation == "Germany").ToList();
                shipAdapter      = new ShipAdapter(this, shipsAll);
                listView.Adapter = shipAdapter;
                break;

            case 3:
                shipsAll         = shipsAll.Where(x => x.Nation == "USSR").ToList();
                shipAdapter      = new ShipAdapter(this, shipsAll);
                listView.Adapter = shipAdapter;
                break;

            case 4:
                shipsAll         = shipsAll.Where(x => x.Nation == "Britain").ToList();
                shipAdapter      = new ShipAdapter(this, shipsAll);
                listView.Adapter = shipAdapter;
                break;

            case 5:
                shipsAll         = shipsAll.Where(x => x.Nation == "Japan").ToList();
                shipAdapter      = new ShipAdapter(this, shipsAll);
                listView.Adapter = shipAdapter;
                break;

            case 6:
                shipsAll         = shipsAll.Where(x => x.Nation == "China").ToList();
                shipAdapter      = new ShipAdapter(this, shipsAll);
                listView.Adapter = shipAdapter;
                break;

            case 7:
                shipsAll         = shipsAll.Where(x => x.Nation == "Italy").ToList();
                shipAdapter      = new ShipAdapter(this, shipsAll);
                listView.Adapter = shipAdapter;
                break;

            case 8:
                shipsAll         = shipsAll.Where(x => x.Nation == "France").ToList();
                shipAdapter      = new ShipAdapter(this, shipsAll);
                listView.Adapter = shipAdapter;
                break;

            case 9:
                shipsAll         = shipsAll.Where(x => x.Nation == "Sweden").ToList();
                shipAdapter      = new ShipAdapter(this, shipsAll);
                listView.Adapter = shipAdapter;
                break;
            }
        }
コード例 #5
0
        protected sealed override void BattleShipObjects(int battleId, string playerBoard)
        //protected override void BattleShipObjects(int battleId, string playerBoard)
        {
            var    db              = ApplicationDbContext.GetInstance();
            Battle battle          = db.Battles.Find(battleId);
            var    currentUserName = getCurrentUserName();

            var currentPlayer = db.Users.FirstOrDefault(x => x.UserName == currentUserName);

            var copy  = playerBoard;
            var ships = "acegikmq";

            //Code for Command design patter

            List <ICommand> commands = new List <ICommand>();

            ICommand extraLargeShip = new GetExtraLargeShipLocation();
            ICommand largeShip      = new GetLargeShipLocation();
            ICommand normalShip     = new GetNormalShipLocation();
            ICommand smallShip      = new GetSmallShipLocation();
            ICommand extraSmallShip = new GetExtraSmallShipLocation();

            commands.Add(extraLargeShip);
            commands.Add(largeShip);
            commands.Add(normalShip);
            commands.Add(smallShip);
            commands.Add(extraSmallShip);

            //Code for Visitor design patter

            IVisitor shipVisitor  = new ShipVisitor();
            IVisitor planeVisitor = new PlaneVisitor();
            IVisitor otherVisitor = new OtherVisitor();

            IVisitable getExtraLargeShip = new GetExtraLargeShipLocation();
            IVisitable getLargeShip      = new GetLargeShipLocation();
            IVisitable getNormalShip     = new GetNormalShipLocation();
            IVisitable getSmallShip      = new GetSmallShipLocation();
            IVisitable getExtraSmallShip = new GetExtraSmallShipLocation();

            for (int i = 0; i < copy.Length; i++)
            {
                if (ships.Contains(copy[i]) && ships.Length > 0)
                {
                    var x    = i % 10;
                    var y    = i / 10;
                    int endx = 0;
                    int endy = 0;

                    bool isHorizontal = i < copy.Length - 1 && copy[i + 1] == copy[i] ? true : false;
                    switch (copy[i])
                    {
                    case 'a':
                        //This line is used for command design patter
                        List <int> extraLargeShipLocation = commands[0].Execute(isHorizontal, i);
                        //This line is used for visitor design patter
                        List <int> getExtraLargeShipLocation = getExtraLargeShip.accept(shipVisitor, isHorizontal, i);
                        //endx = extraLargeShipLocation[0];
                        //endy = extraLargeShipLocation[1];
                        endx = getExtraLargeShipLocation[0];
                        endy = getExtraLargeShipLocation[1];
                        //System.Diagnostics.Debug.WriteLine("Command: Location of extra large ship was found");
                        break;

                    case 'm':
                        //This line is used for command design patter
                        List <int> largeShipLocation = commands[1].Execute(isHorizontal, i);
                        //This line is used for visitor design patter
                        List <int> getLargeShipLocation = getLargeShip.accept(planeVisitor, isHorizontal, i);
                        //endx = largeShipLocation[0];
                        //endy = largeShipLocation[1];
                        endx = getLargeShipLocation[0];
                        endy = getLargeShipLocation[1];
                        //System.Diagnostics.Debug.WriteLine("Command: Location of large ship was found");
                        break;

                    case 'q':
                        //This line is used for command design patter
                        List <int> normalShipLocation = commands[2].Execute(isHorizontal, i);
                        //This line is used for visitor design patter
                        List <int> getNormalShipLocation = getNormalShip.accept(otherVisitor, isHorizontal, i);
                        //endx = normalShipLocation[0];
                        //endy = normalShipLocation[1];
                        endx = getNormalShipLocation[0];
                        endy = getNormalShipLocation[1];
                        //System.Diagnostics.Debug.WriteLine("Command: Location of normal ship was found");
                        break;

                    case 'i':
                        //This line is used for command design patter
                        List <int> smallShipLocation = commands[3].Execute(isHorizontal, i);
                        //This line is used for visitor design patter
                        List <int> getSmallShipLocation = getSmallShip.accept(shipVisitor, isHorizontal, i);
                        //endx = smallShipLocation[0];
                        //endy = smallShipLocation[1];
                        endx = getSmallShipLocation[0];
                        endy = getSmallShipLocation[1];
                        //System.Diagnostics.Debug.WriteLine("Command: Location of small ship was found");
                        break;

                    case 'e':
                        //This line is used for command design patter
                        List <int> extraSmallShipLocation = commands[4].Execute(isHorizontal, i);
                        //This line is used for visitor design patter
                        List <int> getExtraSmallShipLocation = getExtraSmallShip.accept(otherVisitor, isHorizontal, i);
                        //endx = extraSmallShipLocation[0];
                        //endy = extraSmallShipLocation[1];
                        endx = getExtraSmallShipLocation[0];
                        endy = getExtraSmallShipLocation[1];
                        //System.Diagnostics.Debug.WriteLine("Command: Location of extra small ship was found");
                        break;

                    case 'c':
                        endx = isHorizontal ? x + 4 : x;
                        endy = isHorizontal ? y : y + 4;
                        break;

                    case 'k':
                        endx = isHorizontal ? x + 1 : x;
                        endy = isHorizontal ? y : y + 1;
                        break;

                    case 'g':
                        endx = isHorizontal ? x + 1 : x;
                        endy = isHorizontal ? y : y + 1;
                        break;
                    }
                    ships = ships.Remove(ships.IndexOf(copy[i]), 1);
                    //Facade facade = new Facade(currentPlayer, battle, x, endx, y, endy, isHorizontal);
                    IAdapter shipAdapter = new ShipAdapter(currentPlayer, battle, x, endx, y, endy, isHorizontal);
                    //Ship ship = facade.GetShip();
                    Ship ship = (Ship)shipAdapter.GetObject(0);
                    db.Ships.Add(ship);
                }
            }
            System.Diagnostics.Debug.WriteLine("TemplateShips : Template. Required operation- BattleShipObjects");
        }