コード例 #1
0
        public Pieza GetPieza(char key)
        {
            Pieza piezas = null;

            if (_piezas.ContainsKey(key))
            {
                piezas = _piezas[key];
            }
            else
            {
                switch (key)
                {
                case 'P': piezas = new Peon(key); break;

                case 'R': piezas = new Rey(key); break;

                case 'r': piezas = new Reina(key); break;

                case 'C': piezas = new Caballo(key); break;

                case 'A': piezas = new Alfil(key); break;

                case 'T': piezas = new Torre(key); break;

                case 'D': piezas = new Dama(key); break;
                }
                _piezas.Add(key, piezas);
            }
            return(piezas);
        }
コード例 #2
0
        public async Task <ActionResult> Delete(string id, Peon peon)
        {
            try
            {
                var token = _session.GetString("Token");
                if (Seguridad.validarUsuarioAdministrativo(token))
                {
                    if (ModelState.IsValid)
                    {
                        await ControladoraUsuarios.getInstance(_settings).EliminarPeon(id);

                        return(RedirectToAction("Index"));
                    }
                    return(View(peon));
                }
                else
                {
                    return(RedirectToAction("Login", "Account"));
                }
            }
            catch (MensajeException msg)
            {
                TempData["Error"] = msg.Message;
                return(RedirectToAction("Index"));
            }
            catch (Exception)
            {
                TempData["Error"] = "Ha ocurrido un error inesperado, intente de nuevo mas tarde";
                return(RedirectToAction("Index"));
            }
        }
コード例 #3
0
ファイル: tablero.cs プロジェクト: sideral/aledrez
    public void ActualizarTablero(Movimiento mov)
    {
        int[] piezasPosibles;
        for (int i = 0; i < 2; i++)
        {
            piezasPosibles = this[mov.Origen].Movs[i].ToArray();

            for (int j = 0; j < piezasPosibles.Length; j++)
            {
                this[piezasPosibles[j]].Tipo.GenerarMovOrigen(piezasPosibles[j], mov, this);
            }
            piezasPosibles = this[mov.Destino].Movs[i].ToArray();

            for (int j = 0; j < piezasPosibles.Length; j++)
            {
                this[piezasPosibles[j]].Tipo.GenerarMovDestino(piezasPosibles[j], mov, this);
            }

            if (this[mov.Destino].Tipo.Color != i)
            {
                piezasPosibles = this[mov.Destino].Protectores[i].ToArray();
                for (int j = 0; j < piezasPosibles.Length; j++)
                {
                    this[piezasPosibles[j]].Tipo.GenerarMovProtectores(piezasPosibles[j], mov, this);
                }
            }
        }

        piezasPosibles = this[mov.Origen].Bloqueados.ToArray();
        for (int j = 0; j < piezasPosibles.Length; j++)
        {
            Peon peon = this[piezasPosibles[j]].Tipo as Peon;
            peon.Desbloquear(piezasPosibles[j], mov.Origen, this);
        }
    }
コード例 #4
0
ファイル: PeonsViewModel.cs プロジェクト: devsuperman/G3
        async Task DetailsPeon(Peon peon)
        {
            if (peon is null)
            {
                return;
            }

            var route = $"{nameof(DetailsPeonPage)}?id={peon.Id}";
            await Shell.Current.GoToAsync(route);
        }
コード例 #5
0
    private void DestroyPiece()
    {
        if (board[(int)dest.x, (int)dest.y] != null)
        {
            Destroy(board[(int)dest.x, (int)dest.y].gameObject);
            return;
        }

        if (enPassant)
        {
            Peon peon = board[(int)orig.x, (int)orig.y].GetComponent <Peon>();
            Destroy(board[(int)dest.x, (int)dest.y - peon.direction].gameObject);
            return;
        }
    }
コード例 #6
0
ファイル: Pieza.cs プロジェクト: HendrysTobar/Xirgu
    /// <summary>
    /// Factory Method
    /// </summary>
    /// <param name="tipo">es el tipo de pieza, peon o reina del enum Jugadores</param>
    /// <returns>retorna un objeto de las subclases peon o reina dependiendo del tipo</returns>

    public static Pieza HacerPieza(TiposPiezas t)
    {
        Pieza rta;

        if (t == TiposPiezas.peon)
        {
            rta      = new Peon();
            rta.tipo = t;
            return(rta);
        }
        if (t == TiposPiezas.Reina)
        {
            rta      = new Reina();
            rta.tipo = t;
            return(rta);
        }
        return(null);
    }
コード例 #7
0
    //Init the level based on a level text file
    public void init(string mapPath, string entitiesPath = null)
    {
        _mountainTex = GameEnvironment.getAssetManager().GetSprite("Sprites/Tiles/Mountain1");
        _waterTex    = GameEnvironment.getAssetManager().GetSprite("Sprites/Tiles/water");
        _dirtTex     = GameEnvironment.getAssetManager().GetSprite("Sprites/Tiles/dirt");
        _mapWidth    = data.tSize();
        _mapHeight   = data.tSize();
        GameEnvironment.getCamera().SetMaxBounds(data.tSize() * data.tSize(), data.tSize() * data.tSize());
        _mapData      = new byte[_mapWidth, _mapHeight];
        _entitiesData = new char[_mapWidth, _mapHeight];
        loadMap(mapPath);
        if (entitiesPath != null)
        {
            loadEntities(entitiesPath);
        }
        else
        {
            for (int i = 0; i < 20; i++)
            {
                if (i < 10)
                {
                    Footman e = new Footman(this, new Vector2(GameEnvironment.getRandom().Next(10) * data.tSize(), GameEnvironment.getRandom().Next(10) * data.tSize()));
                    entities.Add(e);
                }
                if (i >= 10)
                {
                    Grunt e = new Grunt(this, new Vector2((GameEnvironment.getRandom().Next(10) + 10) * data.tSize(), (GameEnvironment.getRandom().Next(10) + 10) * data.tSize()));
                    entities.Add(e);
                }
                //Unit e = new Unit();
                //e.init(new Vector2(GameEnvironment.getRandom().Next(18) * data.tSize(), GameEnvironment.getRandom().Next(18) * data.tSize()), "birb");
                //entities.Add(e);
            }
            Player = new Player(this);
            Farm orcFarm = new Farm(this, new Vector2(16 * data.tSize(), 17 * data.tSize()), BuildingAndUnit.faction.Orc);
            entities.Add(orcFarm);
            Farm humanFarm = new Farm(this, new Vector2(5 * data.tSize(), 8 * data.tSize()), BuildingAndUnit.faction.Human);
            entities.Add(humanFarm);
            Tree Tree1 = new Tree(this, new Vector2(9 * data.tSize(), 1 * data.tSize()));
            entities.Add(Tree1);
            Tree Tree2 = new Tree(this, new Vector2(2 * data.tSize(), 5 * data.tSize()));
            entities.Add(Tree2);
            Mine Mine = new Mine(this, new Vector2(1 * data.tSize(), 1 * data.tSize()));
            entities.Add(Mine);
            Townhall Townhall = new Townhall(this, new Vector2(7 * data.tSize(), 3 * data.tSize()), BuildingAndUnit.faction.Human);
            entities.Add(Townhall);
            Townhall orcTownhall = new Townhall(this, new Vector2(20 * data.tSize(), 22 * data.tSize()), BuildingAndUnit.faction.Orc);
            entities.Add(orcTownhall);
            Barracks humanBarracks = new Barracks(this, new Vector2(12 * data.tSize(), 6 * data.tSize()), BuildingAndUnit.faction.Human);
            entities.Add(humanBarracks);
            Barracks orcBarracks = new Barracks(this, new Vector2(18 * data.tSize(), 18 * data.tSize()), BuildingAndUnit.faction.Orc);
            entities.Add(orcBarracks);
            Peasant Worker = new Peasant(this, new Vector2(10 * data.tSize(), 7 * data.tSize()));
            entities.Add(Worker);
            Peon Worker1 = new Peon(this, new Vector2(15 * data.tSize(), 15 * data.tSize()));
            entities.Add(Worker1);

            TreasureChest Chest1 = new TreasureChest(this, new Vector2(5 * data.tSize(), 2 * data.tSize()));
            entities.Add(Chest1);



            Archer archer = new Archer(this, new Vector2(5 * data.tSize(), 10 * data.tSize()));
            entities.Add(archer);
            // Projectile projectile = new Projectile(this, Mine, Tree2);
            // Projectiles.Add(projectile);
        }
    }
コード例 #8
0
    private void loadEntities(string entitiesPath)
    {
        System.IO.StreamReader file = new System.IO.StreamReader(entitiesPath);
        if (file != null)
        {
            for (int i = 0; i < _mapHeight; i++)
            {
                string a = file.ReadLine();
                int    x = 0;
                foreach (char c in a)
                {
                    _entitiesData[x, i] = c;
                    x++;
                    if (x == 64)
                    {
                        break;
                    }
                }
            }
            file.Close();
        }

        Player = new Player(this);

        for (int i = 0; i < _mapWidth; i++)
        {
            for (int j = 0; j < _mapHeight; j++)
            {
                switch (_entitiesData[i, j])
                {
                case 't':     // tree
                    Tree tree = new Tree(this, new Vector2(i * data.tSize(), j * data.tSize()));
                    entities.Add(tree);
                    break;

                case 'm':     //mine
                    Mine mine = new Mine(this, new Vector2(i * data.tSize(), j * data.tSize()));
                    entities.Add(mine);
                    break;

                case 's':     //human stronghold/townhall
                    Townhall hTownhall = new Townhall(this, new Vector2(i * data.tSize(), j * data.tSize()), BuildingAndUnit.faction.Human);
                    entities.Add(hTownhall);
                    break;

                case 'S':     //orc stronghold/townhall
                    Townhall oTownhall = new Townhall(this, new Vector2(i * data.tSize(), j * data.tSize()), BuildingAndUnit.faction.Orc);
                    entities.Add(oTownhall);
                    break;

                case 'f':     //human farm
                    Farm hFarm = new Farm(this, new Vector2(i * data.tSize(), j * data.tSize()), BuildingAndUnit.faction.Human);
                    entities.Add(hFarm);
                    break;

                case 'F':     // orc farm
                    Farm oFarm = new Farm(this, new Vector2(i * data.tSize(), j * data.tSize()), BuildingAndUnit.faction.Orc);
                    entities.Add(oFarm);
                    break;

                case 'b':     //human barracks
                    Barracks hBarracks = new Barracks(this, new Vector2(i * data.tSize(), j * data.tSize()), BuildingAndUnit.faction.Human);
                    entities.Add(hBarracks);
                    break;

                case 'B':     //orc barracks
                    Barracks oBarracks = new Barracks(this, new Vector2(i * data.tSize(), j * data.tSize()), BuildingAndUnit.faction.Orc);
                    entities.Add(oBarracks);
                    break;

                default:
                    break;
                }
            }
        }
        for (int i = 0; i < _mapWidth; i++)
        {
            for (int j = 0; j < _mapHeight; j++)
            {
                switch (_entitiesData[i, j])
                {
                case 'g':     //footman
                    Footman footman = new Footman(this, new Vector2(i * data.tSize(), j * data.tSize()));
                    entities.Add(footman);
                    break;

                case 'G':     //grunt
                    Grunt grunt = new Grunt(this, new Vector2(i * data.tSize(), j * data.tSize()));
                    entities.Add(grunt);
                    break;

                case 'p':     //peasant
                    Peasant peasant = new Peasant(this, new Vector2(i * data.tSize(), j * data.tSize()));
                    entities.Add(peasant);
                    break;

                case 'P':     //peon
                    Peon peon = new Peon(this, new Vector2(i * data.tSize(), j * data.tSize()));
                    entities.Add(peon);
                    break;

                case 'a':     //archer
                    Archer archer = new Archer(this, new Vector2(i * data.tSize(), j * data.tSize()));
                    entities.Add(archer);
                    break;

                case 'A':     //spearman
                    Spearman spearman = new Spearman(this, new Vector2(i * data.tSize(), j * data.tSize()));
                    entities.Add(spearman);
                    break;

                default:
                    break;
                }
            }
        }
    }