示例#1
0
 public void CanInstantiateACharacterTest()
 {
     Dwarf dwarf = new Dwarf(RaceTypes.Dwarf);
     Assert.That(dwarf.RaceType == RaceTypes.Dwarf);
     Assert.That(dwarf.Constitution == 2);
     Assert.That(dwarf.Charisma == -2);
 }
示例#2
0
    private static Dwarf MoveDwarf(int playfieldWidth, Dwarf dwarf)
    {
        if (Console.KeyAvailable)
        {
            ConsoleKeyInfo pressedKey = Console.ReadKey(true);

            while (Console.KeyAvailable)
            {
                Console.ReadKey();
            }

            if (pressedKey.Key == ConsoleKey.LeftArrow)
            {
                if (dwarf.positionX - 1 >= 0)
                {
                    dwarf.positionX--;
                }
            }
            else if (pressedKey.Key == ConsoleKey.RightArrow)
            {
                if (dwarf.positionX + dwarf.symbols.Length - 1 < playfieldWidth)
                {
                    dwarf.positionX++;
                }
            }
        }

        return dwarf;
    }
示例#3
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            player1 = new Dwarf();
            boxxy = new Box();

            graphics.PreferredBackBufferHeight = 720;
            graphics.PreferredBackBufferWidth = 1280;
            graphics.IsFullScreen = false;
            graphics.ApplyChanges();
            base.Initialize();
        }
示例#4
0
    private void Start()
    {
        this.mapController = MapController.singleton;

        this.buildingPositions = new Dictionary <Tile, IBuilding>();

        //ResourceChange gold = new ResourceChange(ResourceType.Gold, 1000);
        //ResourceChange stone = new ResourceChange(ResourceType.Stone, 1000);
        //ResourceChange wood = new ResourceChange(ResourceType.Wood, 1000);
        //this.gameState = new BuildingGS(new List<ResourceChange>(3) { gold, stone, wood});
        this.displayAllResourceCount();

        // Set up worker units to be drawn
        Dwarf.staticInitalize(characterLayer, dwarfBase);
    }
示例#5
0
        public static void Main(string[] args)
        {
            Item espada  = new Item("Espada", 45, 0, null);
            Item baston  = new Item("Baston", 50, 10, null);
            Item garrote = new Item("Garrote", 35, 0, null);

            Item capa   = new Item("Capa de la invisibilidad", 0, 100, null);
            Item varita = new Item("Varita", 100, 45, null);

            Item excalibur = new Item("Excalibur", 80, 0, null);
            Item gwaihir   = new Item("Gwaihir", 70, 60, null);


            List <Item> artMagia   = new List <Item>();
            List <Item> itemsElfo  = new List <Item>();
            List <Item> itemsEnano = new List <Item>();

            artMagia.Add(baston);
            itemsElfo.Add(garrote);
            itemsEnano.Add(espada);

            artMagia.Add(capa);
            artMagia.Add(varita);

            itemsElfo.Add(excalibur);
            artMagia.Add(gwaihir);


            Wizard mago  = new Wizard("Mago", 60, artMagia);
            Dwarf  enano = new Dwarf("Enano", 40, itemsEnano);
            Elf    elfo  = new Elf("Elfo", 45, itemsElfo);

            Wizard Gandalf = new Wizard("Gandalf", 100, artMagia);

            Wizard hp = new Wizard("Harry Potter", 2, artMagia);
            Wizard lv = new Wizard("Lord Voldemort", 7, artMagia);


            ConsolePrinter print = new ConsolePrinter();

            print.AfterAttack(elfo.ElfAttack(mago.Items[0].Damage));
            print.AfterAttack(mago.WizardAttack(enano.Items[0].Damage));
            print.AfterAttack(enano.DwarfAttack(elfo.Items[0].Damage));
            print.AfterAttack(Gandalf.WizardAttack(elfo.Items[1].Damage));
            print.AfterAttack(hp.WizardAttack(lv.Items[2].Damage));

            print.AfterCure(elfo.ElfCure());
        }
 private void SearchRace()
 {
     if (isElfRadio.Checked)
     {
         elfHistories = elfLogic.GetAllElves();
         index        = 0;
         currentRace  = "elf";
         currentElf   = elfHistories.First();
         Display();
     }
     else if (isDwarfRadio.Checked)
     {
         dwarfHistories = dwarfLogic.GetAllDwarves();
         index          = 0;
         currentRace    = "dwarf";
         currentDwarf   = dwarfHistories.First();
         Display();
     }
     else if (isWizardRadio.Checked)
     {
         wizardHistories = wizardLogic.GetAllWizards();
         index           = 0;
         currentRace     = "wizard";
         currentWizard   = wizardHistories.First();
         Display();
     }
     else if (isHumanRadio.Checked)
     {
         humanHistories = humanLogic.GetAllHumans();
         index          = 0;
         currentRace    = "human";
         currentHuman   = humanHistories.First();
         Display();
     }
     else if (isHobbitRadio.Checked)
     {
         hobbitHistories = hobbitLogic.GetAllHobbits();
         index           = 0;
         currentRace     = "hobbit";
         currentHobbit   = hobbitHistories.First();
         Display();
     }
     else
     {
         MessageBox.Show("Please select one of the races!", "Error");
         return;
     }
 }
示例#7
0
        public void PuttingAttackItemInTest()
        {
            Dwarf gimli  = new Dwarf();
            Orc   dummy1 = new Orc();

            dummy1.ReceiveDamage(gimli.Attack());

            Orc        dummy2 = new Orc();
            BasicSword sword  = new BasicSword();

            gimli.AddItem(sword);

            dummy2.ReceiveDamage(gimli.Attack());

            Assert.AreEqual(dummy1.HealthActual - dummy2.HealthActual, sword.AttackPower);
        }
示例#8
0
        public void RemoveAnItemThatYouDoNotHaveTest()
        {
            Dwarf      gimli = new Dwarf();
            BasicSword sword = new BasicSword();

            try
            {
                gimli.RemoveItem(sword);
                Assert.Fail();
            }
            //Si hay una excepción al tratar de remover un item que no se tiene, se pasa el test.
            catch
            {
                Assert.Pass();
            }
        }
示例#9
0
        public void SetUp()
        {
            //Arrange
            sword  = new Sword("Espada rústica", 50, "Corte Fugaz");
            shield = new Shield("Escudo desgastado", 70, "Bloqueo");
            orc    = new Orc("Azog", 25, "Tanque");

            axe       = new Axe("Executioner", 50, "Corte decisivo");
            warhammer = new Warhammer("Mjölnir", 60, "Ultimatum");
            dwarf     = new Dwarf("Thorin", 70, "Luchador");

            magicStaff = new MagicStaff("Báculo ancestral", 50, "Poder mágico");
            spellBook  = new SpellBook("Occido Lumen", "Tiene hechizos poderosos");
            spell      = new Spell("You shall not pass", "Genera una barrera", 0, 70);
            wizard     = new Wizard("Gandalf", "Mago", spellBook);
        }
示例#10
0
        public void SetUp()
        {
            //Arrange
            sword        = new Sword("Espadon", 50, 0, "Corte Fugaz", false);
            goldenShield = new GoldenShield("Escudo Dorado", 0, 25, "Escudazo", false);
            orc          = new Orc("Azog", sword, goldenShield, "Tanque");

            axe       = new Axe("Hacha", 50, 5, "Corte Rapaz", false);
            warhammer = new Warhammer("Martillo de Guerra", 60, 10, "Martillazo", false);
            dwarf     = new Dwarf("Throrn", axe, warhammer, "Luchador");

            magicStaff = new MagicStaff("Báculo ancestral", "Hace hechizos", true);
            spellBook  = new SpellBook("Lumen", "Tiene hechizos", true);
            spell      = new Spell("You shall not pass", "Genera una barrera", true);
            wizard     = new Wizard("Gandalf", magicStaff, spellBook, "Mago");
        }
示例#11
0
        public void SetUp()
        {
            dwarf  = new Dwarf("Dwarf");
            dwarf1 = new Dwarf("Dwarf");
            Axe axe = new Axe();

            dwarf.Axe = axe;
            Shield shield = new Shield();
            Helmet helmet = new Helmet();

            dwarf.Shield  = shield;
            dwarf.Helmet  = helmet;
            dwarf1.Axe    = axe;
            dwarf1.Shield = shield;
            dwarf1.Helmet = helmet;
        }
示例#12
0
        public void T7_a_drunk_dwarf_character_make_less_damage()
        {
            var character = new Dwarf(50)
            {
                Name = "Gonar"
            };
            var characterClass = new Wizard(character);

            var baseDamage = character.Attack();
            var damages    = characterClass.Attack();

            character.Name.Should().Be("Gonar");
            characterClass.Should().BeOfType <Wizard>();

            damages.Quantity.Should().Be(baseDamage.Quantity + characterClass.Damages.Quantity);
            damages.Type.Should().Be(characterClass.Damages.Type);
        }
示例#13
0
    public bool moveDwarf(Dwarf d, Tile t)
    {
        // The dwarf is requesting to move into the provided tile
        // It's up to us to see if it's a valid tile to stand in
        // or if the dwarf has permission to stand there
        // The dwarf will draw itself and erase its old image

        // NOTE: This doesn't care where the dwarf is coming from
        // It's assumed the dwarf's current position is valid

        // TODO: We can add a lot of complexity to this method
        // TODO: For example, make only one dwarf allowed to stand in a position at a time
        //       For now, many dwarfs to occupying the same tile is valid

        // Check walkability of tile (The provided tile may be out of date or fake)
        return(allTiles[t.position.x, t.position.y].isWalkable);
    }
    static void Main(string[] args)
    {
        List <Dwarf> dwarves = new List <Dwarf>();
        var          hats    = new Dictionary <string, int>();

        string input;

        while ((input = Console.ReadLine()) != "Once upon a time")
        {
            string[] dwarfStats = input
                                  .Split(" <:>".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
                                  .ToArray();

            string dwarfName     = dwarfStats[0];
            string dwarfHatColor = dwarfStats[1];
            int    dwarfPhysics  = int.Parse(dwarfStats[2]);

            Dwarf dwarf     = new Dwarf(dwarfName, dwarfHatColor, dwarfPhysics);
            Dwarf sameDwarf = dwarves.FirstOrDefault(d => d.Name == dwarf.Name &&
                                                     d.HatColor == dwarf.HatColor);

            if (sameDwarf != null)
            {
                if (sameDwarf.Physics < dwarf.Physics)
                {
                    sameDwarf.Physics = dwarf.Physics;
                }
            }
            else
            {
                dwarves.Add(dwarf);

                if (hats.ContainsKey(dwarf.HatColor) == false)
                {
                    hats.Add(dwarf.HatColor, 1);
                }

                hats[dwarf.HatColor]++;
            }
        }

        foreach (Dwarf dwarf in dwarves.OrderByDescending(d => d.Physics).ThenByDescending(d => hats[d.HatColor]))
        {
            Console.WriteLine(dwarf);
        }
    }
示例#15
0
    public int ArrayPoolW()
    {
        for (int i = 0; i < N; i++)
        {
            _menArray[i] = new Man(0, 0, i, i);
        }
        for (int i = 0; i < N; i++)
        {
            _elvesArray[i] = new Elf(0, 0, i, i);
        }
        for (int i = 0; i < N; i++)
        {
            _dwarvesArray[i] = new Dwarf(0, 0, i);
        }

        return(_menArray.Length + _elvesArray.Length + _dwarvesArray.Length);
    }
示例#16
0
        public void TwoAttackItemsTest()
        {
            Dwarf gimli  = new Dwarf();
            Orc   dummy1 = new Orc();

            dummy1.ReceiveDamage(gimli.Attack());

            Orc          dummy2 = new Orc();
            BasicSword   sword  = new BasicSword();
            StygianBlade sword2 = new StygianBlade();

            gimli.AddItem(sword);
            gimli.AddItem(sword2);

            dummy2.ReceiveDamage(gimli.Attack());

            Assert.AreEqual(dummy1.HealthActual - dummy2.HealthActual, sword.AttackPower + sword2.AttackPower);
        }
示例#17
0
 private void Attack()
 {
     if (gameObjectChoosedToAttack != null && gameObjectChoosedToAttack.layer == 10)
     {
         es = gameObjectChoosedToAttack.GetComponentInChildren <EarthShaker>();
         es.SubHealth(damageBasic);
     }
     else if (gameObjectChoosedToAttack != null && gameObjectChoosedToAttack.layer == 11)
     {
         dwarf = gameObjectChoosedToAttack.GetComponentInChildren <Dwarf>();
         dwarf.SubHealth(damageBasic);
     }
     else if (gameObjectChoosedToAttack != null && gameObjectChoosedToAttack.layer == 12)
     {
         naga = gameObjectChoosedToAttack.GetComponentInChildren <NagaSiren>();
         naga.SubHealth(damageBasic);
     }
 }
        static void Main(string[] args)
        {
            Wizard gandalf = new Wizard("Gandalf");


            Dwarf gimli = new Dwarf("Gimli");

            Console.WriteLine($"Gimli has ❤️ {gimli.Health}");
            Console.WriteLine($"Gandalf attacks Gimli with ⚔️ {gandalf.AttackValue}");

            gimli.ReceiveAttack(gandalf.AttackValue);

            Console.WriteLine($"Gimli has ❤️ {gimli.Health}");

            gimli.Cure();

            Console.WriteLine($"Gimli has ❤️ {gimli.Health}");
        }
示例#19
0
        public override HandlerRequest Handle(HandlerRequest handlerRequest)
        {
            String cleanLine = handlerRequest.Line.Replace("\n", "");

            String[] typeSplit = cleanLine.Split('-');
            if (typeSplit[0] != "Dwarf")
            {
                return(nextHandler?.Handle(handlerRequest));
            }
            String[] values = typeSplit[1].Split(',');


            Dwarf dwarf = new Dwarf(values[0], Convert.ToInt32(values[1]), Convert.ToInt32(values[2]), Convert.ToInt32(values[3]));

            handlerRequest.ListOfCharacter.Add(dwarf);

            return(handlerRequest);
        }
        /// <summary>
        /// Delete:id
        /// </summary>
        public virtual HttpResponseMessage Delete(Guid id)
        {
            try
            {
                var obj = Dwarf <T> .Load(id);

                if (obj != null)
                {
                    obj.Delete();
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
            }

            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
示例#21
0
        public void T5_create_a_human_character_with_a_Name_and_Wizard_Class_and_Warrior_Class()
        {
            var dwarf = new Dwarf(0)
            {
                Name = "Gonar"
            };
            var warrior       = new Warrior(dwarf);
            var wizardWarrior = new Wizard(warrior);

            warrior.Should().BeOfType <Warrior>();
            wizardWarrior.Should().BeOfType <Wizard>();

            var attack = wizardWarrior.Attack();

            wizardWarrior.Name.Should().Be("Gonar");
            attack.Quantity.Should().Be(dwarf.NormalDamage + warrior.Damages.Quantity + wizardWarrior.Damages.Quantity);
            attack.Type.Should().Be(DamageTypes.Magical);
        }
示例#22
0
        public void NoItemForExchangeEncounterTest()
        {
            Dwarf      gimli   = new Dwarf();
            Elf        legolas = new Elf();
            BasicSword sword   = new BasicSword();

            try
            {
                ExchangeEncounter encounter = new ExchangeEncounter(gimli, legolas, sword.Name);
                encounter.PlayEncounter();
                Assert.Fail();
            }
            //Si hay una excepción al tratar de intercambiar un item que no se tiene, se pasa al bloque catch y por ende se cumple el test.
            catch
            {
                Assert.Pass();
            }
        }
示例#23
0
        public void DwarfCure_Healing_UpdatedLife()
        {
            Item        garrote   = new Item("Garrote", 26, 0, null);
            List <Item> armasElfo = new List <Item>();

            armasElfo.Add(garrote);
            Dwarf elfo = new Dwarf("Elfo de un ojo", 35, armasElfo);

            Item        paloMagico = new Item("Palo Magico", 33, 0, null);
            List <Item> armasMago  = new List <Item>();

            armasMago.Add(paloMagico);
            Wizard mago     = new Wizard("Mago Negro", 56, armasMago);
            string heal     = mago.WizardCure(20);
            string expected = "El Mago Mago Negro ha sido curado, su vida ahora es 76\n";

            Assert.AreEqual(expected, heal);
        }
示例#24
0
        public void PuttingDefenseItemInTest()
        {
            Dwarf  gimli = new Dwarf();
            Dragon dummy = new Dragon();

            gimli.ReceiveDamage(dummy.Attack());
            int checkPoint1 = gimli.HealthMax - gimli.HealthActual;

            gimli.Healing(1000);
            ChainMail armor = new ChainMail();

            gimli.AddItem(armor);

            gimli.ReceiveDamage(dummy.Attack());
            int checkPoint2 = gimli.HealthMax - gimli.HealthActual;

            Assert.AreEqual(checkPoint1 - checkPoint2, armor.DefensePower);
        }
示例#25
0
        // Probamos solo los metodos de la clase mago porque estrucutralmente son los mismos que los demas personajes, y hacen lo mismo.

        public void DwarfAttack_Damage_UpdatedLife()
        {
            Item        garrote   = new Item("Garrote", 26, 0, null);
            List <Item> armasElfo = new List <Item>();

            armasElfo.Add(garrote);
            Dwarf elfo = new Dwarf("Elfo de un ojo", 35, armasElfo);

            Item        paloMagico = new Item("Palo Magico", 33, 0, null);
            List <Item> armasMago  = new List <Item>();

            armasMago.Add(paloMagico);
            Wizard mago     = new Wizard("Mago Negro", 56, armasMago);
            string attack   = mago.WizardAttack(elfo.Items[0].Damage);
            string expected = "El Mago Mago Negro fue atacado, su vida ahora es 30\n";

            Assert.AreEqual(expected, attack);
        }
示例#26
0
        static void Main(string[] args)
        {
            Console.WriteLine("Let's play a Game in the Arena!");
            Console.WriteLine();

            Knight    knight    = new Knight();
            Assassian assassian = new Assassian();
            Monk      monk      = new Monk();
            Warrior   warrior   = new Warrior();
            Dwarf     dwarf     = new Dwarf();

            GameEngine game  = new GameEngine();
            Print      print = new Print();

            game.PlayArena(knight, dwarf, print);

            Console.ReadKey();
        }
        private void searchIDBtn_Click(object sender, EventArgs e)
        {
            PrevBtn.Visible = false;
            NextBtn.Visible = false;

            if (Int32.TryParse(idTxtBx.Text, out int result))
            {
                Person person = personLogic.GetPerson(result);
                if (person == null)
                {
                    MessageBox.Show("Person with ID was not found", "404: Not Found");
                }
                else
                {
                    currentRace = person.RaceType.ToLower();

                    if (person.RaceType == "elf")
                    {
                        currentElf = elfLogic.GetElf(result);
                    }
                    if (person.RaceType == "dwarf")
                    {
                        currentDwarf = dwarfLogic.GetDwarf(result);
                    }
                    if (person.RaceType == "human")
                    {
                        currentHuman = humanLogic.GetHuman(result);
                    }
                    if (person.RaceType == "wizard")
                    {
                        currentWizard = wizardLogic.GetWizard(result);
                    }
                    if (person.RaceType.ToLower() == "hobbit")
                    {
                        currentHobbit = hobbitLogic.GetHobbit(result);
                    }
                    Display();
                }
            }
            else
            {
                MessageBox.Show("ID must be a number!", "Error");
            }
        }
示例#28
0
        public void Setup()
        {
            dwarf = new Dwarf("Nacho");
            dwarf.AddItem("Helmet", 0, 20);
            dwarf.AddItem("Shield", 0, 10);

            wizard = new Wizard("Jero");
            SpellsBook book = new SpellsBook();

            book.AddSpell("Bola de fuego", 10, 0);
            book.AddSpell("Escudo de maná", 0, 20);
            wizard.SpellsBook = book;

            knight = new Knight("Rodri");
            knight.AddItem("Sword", 10, 0);

            knight2 = new Knight("Rodrialter");
            knight2.AddItem("Sword", 50, 0);
        }
示例#29
0
            public override void Populate()
            {
                var goblin = new Goblin();
                var human  = new Human();
                var animal = new Animal();
                var orc    = new Orc();
                var dwarf1 = new Dwarf();
                var dwarf2 = new Dwarf();

                Creatures = new Creature[]
                {
                    goblin, human, animal, orc, dwarf1, dwarf2
                };

                foreach (var creature in Creatures)
                {
                    creature.Speak();
                }
            }
示例#30
0
        static void Main(string[] args)
        {
            List <Dwarf> myDwarfs = new List <Dwarf>();

            while (true)
            {
                var inputLine = Console.ReadLine();
                if (inputLine == "Once upon a time")
                {
                    break;
                }
                var dwarfInfo = inputLine
                                .Split(new char[] { ' ', '<', ':', '>' },
                                       StringSplitOptions.RemoveEmptyEntries)
                                .ToList();
                var name    = dwarfInfo[0];
                var hat     = dwarfInfo[1];
                var physics = int.Parse(dwarfInfo[2]);

                if (myDwarfs.Any(x => x.name == name))
                {
                    Dwarf currDwarf = myDwarfs.First(x => x.name == name);
                    if (currDwarf.hatcolor == hat)
                    {
                        currDwarf.physics = Math.Max(physics, currDwarf.physics);
                    }
                    else
                    {
                        Dwarf newDwarf = new Dwarf(name, hat, physics);
                        myDwarfs.Add(newDwarf);
                    }
                }
                else
                {
                    Dwarf currDwarf = new Dwarf(name, hat, physics);
                    myDwarfs.Add(currDwarf);
                }
            }
            foreach (var dwarf in myDwarfs.OrderByDescending(x => x.physics))
            {
                Console.WriteLine($"({dwarf.hatcolor}) {dwarf.name} <-> {dwarf.physics}");
            }
        }
示例#31
0
        static void Main()
        {
            var allDwarfs = new Dictionary <string, List <Dwarf> >();
            var result    = new List <Dwarf>();

            var command = string.Empty;

            while ((command = Console.ReadLine()) != "Once upon a time")
            {
                var input  = command.Split(" <:> ").ToList();
                var name   = input[0];
                var color  = input[1];
                var physic = int.Parse(input[2]);

                if (!allDwarfs.ContainsKey(color))
                {
                    allDwarfs.Add(color, new List <Dwarf>());
                }

                if (allDwarfs[color].Any(x => x.Name == name))
                {
                    var reffDwarf = allDwarfs[color].FirstOrDefault(x => x.Name == name);
                    reffDwarf.Physic = Math.Max(physic, reffDwarf.Physic);
                }
                else
                {
                    var newDwarf = new Dwarf();
                    newDwarf.Name   = name;
                    newDwarf.Color  = color;
                    newDwarf.Physic = physic;
                    allDwarfs[color].Add(newDwarf);
                    result.Add(newDwarf);
                }
            }

            result = result.OrderByDescending(x => x.Physic)
                     .ThenByDescending(x => allDwarfs[x.Color].Count()).ToList();

            foreach (var dwarf in result)
            {
                Console.WriteLine($"({dwarf.Color}) {dwarf.Name} <-> {dwarf.Physic}");
            }
        }
示例#32
0
        public IActionResult AddDwarf([FromBody] Dwarf dwarf)
        {
            try
            {
                var result = DwarfManager.AddDwarf(dwarf);

                if (result == false)
                {
                    return(NotFound("Dwarf not added"));
                }

                return(Ok(result));
            }

            catch (Exception ex)
            {
                //Logger.Error(ex, "An exception occurred while retirving trivia questions");
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
示例#33
0
        public IActionResult UpdateDwarf([FromBody] Dwarf dwarf)
        {
            try
            {
                bool result = DwarfManager.UpdateDwarf(dwarf);

                if (result == false)
                {
                    return(NotFound("Requested trivia question does not exist"));
                }

                return(Ok(result));
            }

            catch (Exception ex)
            {
                //Logger.Error(ex, "An exception occurred while retirving trivia questions");
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
示例#34
0
        public static Hero MakeHero(string heroType)
        {
            Hero generatedHero = null;

            if (heroType == HeroFactory.Human)
            {
                generatedHero = new Human();
            }
            else if (heroType == HeroFactory.Elf)
            {
                generatedHero = new Elf();
            }
            else if (heroType == HeroFactory.Dwarf)
            {
                generatedHero = new Dwarf();
            }
            else
            {
                throw new InvalidHeroException("Entered hero is invalid!");
            }

            return generatedHero;
        }
示例#35
0
    static void Main()
    {
        // player playing field dimensions
        int playFieldWidth = 30;
        int playFieldHeight = 20;

        // dwarf creation
        Dwarf dwarf = new Dwarf();
        dwarf.colOne = (playFieldWidth / 2) - 1;
        dwarf.colTwo = (playFieldWidth / 2);
        dwarf.colThree = (playFieldWidth / 2) + 1;
        dwarf.row = playFieldHeight - 1;
        dwarf.color = ConsoleColor.Yellow;
        dwarf.signOne = '(';
        dwarf.signTwo = '0';
        dwarf.signThree = ')';

        // for random color generation
        ConsoleColor[] randomColor = new ConsoleColor[5];
        randomColor[0] = ConsoleColor.Green;
        randomColor[1] = ConsoleColor.Magenta;
        randomColor[2] = ConsoleColor.Cyan;
        randomColor[3] = ConsoleColor.Blue;
        randomColor[4] = ConsoleColor.White;

        // for random char generation
        char[] randomChar = new char[11];
        randomChar[0] = '^';
        randomChar[1] = '@';
        randomChar[2] = '*';
        randomChar[3] = '&';
        randomChar[4] = '+';
        randomChar[5] = '%';
        randomChar[6] = '$';
        randomChar[7] = '#';
        randomChar[8] = '!';
        randomChar[9] = '.';
        randomChar[10] = ';';

        // random numbers generator
        Random randomGenerator = new Random();

        // rocks
        List<GameObjects> rocks = new List<GameObjects>();

        // game field and cursor visibility
        Console.CursorVisible = false;
        Console.BufferHeight = Console.WindowHeight = 20;
        Console.BufferWidth = Console.WindowWidth = 60;
        int gameFieldBoundaries = playFieldWidth + 1;

        // game end conditions, speed and score
        int lives = 3;
        double sleepTime = 0.5;
        double speed = 150;
        int score = 0;

        // Game Rules
        PrintStringOnField(0, 0, "Welcome to the game Falling Rocks!", ConsoleColor.White);
        PrintStringOnField(0, 1, "You are a brave dwarf who is facing a rock-hurling troll!", ConsoleColor.White);
        PrintStringOnField(0, 2, "For each rock you avoid you gain 10 points.", ConsoleColor.White);
        PrintStringOnField(0, 3, "You lose 50 points and 1 life for each rock that hits you!", ConsoleColor.White);
        PrintStringOnField(0, 4, "The game speed increases over time.", ConsoleColor.White);
        PrintStringOnField(0, 5, "Good Luck!!!", ConsoleColor.White);
        PrintStringOnField(0, 6, "To start the game press \"y\", to exit press \"n\"", ConsoleColor.Green);
        Console.SetCursorPosition(0, 7);
        ConsoleKeyInfo yesOrNo = Console.ReadKey(true);
        if (yesOrNo.Key == ConsoleKey.Y)
        // game start
        {
            while (true)
            {
                // game speed
                speed += sleepTime;
                if (speed > 425)
                {
                    speed = 425;
                }

                // hit flag
                bool hit = false;

                // create rocks
                for (int i = 0; i < randomGenerator.Next(0, 5); i++)
                {
                    GameObjects newRock = new GameObjects();
                    newRock.color = randomColor[randomGenerator.Next(0, 4)];
                    newRock.col = randomGenerator.Next(0, playFieldWidth);
                    newRock.row = 0;
                    newRock.sign = randomChar[randomGenerator.Next(0, 10)];
                    rocks.Add(newRock);
                }
                // Move Dwarf
                while (Console.KeyAvailable)
                {
                    ConsoleKeyInfo pressedKey = Console.ReadKey(true);
                    while (Console.KeyAvailable)
                    {
                        Console.ReadKey(true);
                    }
                    if (pressedKey.Key == ConsoleKey.LeftArrow || pressedKey.Key == ConsoleKey.A)
                    {
                        if (dwarf.colOne - 1 > 0)
                        {
                            dwarf.colOne = dwarf.colOne - 1;
                            dwarf.colTwo = dwarf.colTwo - 1;
                            dwarf.colThree = dwarf.colThree - 1;
                        }
                    }
                    if (pressedKey.Key == ConsoleKey.RightArrow || pressedKey.Key == ConsoleKey.D)
                    {
                        if (dwarf.colThree + 1 < playFieldWidth)
                        {
                            dwarf.colOne = dwarf.colOne + 1;
                            dwarf.colTwo = dwarf.colTwo + 1;
                            dwarf.colThree = dwarf.colThree + 1;
                        }
                    }
                }

                // Move Rocks
                List<GameObjects> newList = new List<GameObjects>();
                for (int i = 0; i < rocks.Count; i++)
                {
                    GameObjects oldRock = rocks[i];
                    GameObjects newRock = new GameObjects();
                    newRock.col = oldRock.col;
                    newRock.row = oldRock.row + 1;
                    newRock.sign = oldRock.sign;
                    newRock.color = oldRock.color;
                    if (newRock.row == dwarf.row && (newRock.col == dwarf.colOne || newRock.col == dwarf.colTwo || newRock.col == dwarf.colThree)) // unit collision
                    {
                        hit = true;
                        lives -= 1;
                        if (lives <= 0)
                        {
                            PrintStringOnField(10, 9, "GAME OVER!", ConsoleColor.Red);
                            PrintStringOnField(6, 10, "Your score is: " + score, ConsoleColor.Red);
                            PrintStringOnField(5, 11, "Press [Enter] to exit", ConsoleColor.Red);
                            Console.ReadLine();
                            Environment.Exit(0);
                        }
                    }
                    if (newRock.row < playFieldHeight)
                    {
                        newList.Add(newRock);
                    }
                    else          // scoring system
                    {
                        score += 10;
                    }
                }
                rocks = newList;

                // Clear the console
                Console.Clear();

                // ReDraw playfield

                if (hit)
                {
                    rocks.Clear();
                    if (score <= 50)
                    {
                        score = 0;
                    }
                    else
                    {
                        score -= 50;
                    }

                    PrintOnField(dwarf.colOne, dwarf.row, 'X', ConsoleColor.Red);
                    PrintOnField(dwarf.colTwo, dwarf.row, 'X', ConsoleColor.Red);
                    PrintOnField(dwarf.colThree, dwarf.row, 'X', ConsoleColor.Red);
                }
                else
                {
                    PrintDwarfOnField(dwarf.colOne, dwarf.colTwo, dwarf.colThree, dwarf.row,
                        dwarf.signOne, dwarf.signTwo, dwarf.signThree, dwarf.color); // drawing the dwarf
                }

                foreach (GameObjects rock in rocks)
                {
                    PrintOnField(rock.col, rock.row, rock.sign, rock.color);
                }

                for (int i = 0; i < playFieldHeight; i++)  // playfield boundaries
                {
                    PrintOnField(playFieldWidth, i, '|', ConsoleColor.Gray);
                }

                // Print Score
                PrintStringOnField(40, 9, "Lives: " + lives, ConsoleColor.White);
                PrintStringOnField(40, 10, "Speed: " + speed, ConsoleColor.White);
                PrintStringOnField(40, 11, "Score: " + score, ConsoleColor.White);

                // Slow down the console
                Thread.Sleep(500 - (int)speed);
            }
        }
        if (yesOrNo.Key == ConsoleKey.N)
            return;
        else
        {
            Main();
        }
    }
示例#36
0
    static void Main()
    {
        Console.CursorVisible = false;
        Console.WindowHeight = 30;
        Console.WindowWidth = 60;
        Console.BufferHeight = Console.WindowHeight;
        Console.BufferWidth = Console.WindowWidth;

        Random randomGenerator = new Random(DateTime.Now.Millisecond);

        double sleepTime = 101;
        double allScore = 0;
        bool gameOver = false;

        List<Rocks> allRocks = new List<Rocks>();
        List<Rocks> Remove = new List<Rocks>();
        Dwarf dwarf = new Dwarf(Console.WindowWidth / 2, Console.WindowHeight - 1);

        while(true)
        {
         char rockSymbol=' ';
         int randomSymbol = randomGenerator.Next(0,12);
            switch(randomSymbol)
                {
                    case 0: rockSymbol = '^'; break;
                    case 1: rockSymbol = '@'; break;
                    case 2: rockSymbol = '*'; break;
                    case 3: rockSymbol = '&'; break;
                    case 4: rockSymbol = '+'; break;
                    case 5: rockSymbol = '%'; break;
                    case 6: rockSymbol = '$'; break;
                    case 7: rockSymbol = '#'; break;
                    case 8: rockSymbol = '!'; break;
                    case 9: rockSymbol = '.'; break;
                    case 10: rockSymbol = ';'; break;
                    case 11: rockSymbol = '-'; break;
                    default: Console.Write("Error!"); break;
                }

                ConsoleColor[] colors =
                {
                     ConsoleColor.Yellow,
                     ConsoleColor.DarkGreen,
                     ConsoleColor.DarkCyan,
                     ConsoleColor.Green,
                     ConsoleColor.DarkBlue,
                     ConsoleColor.Magenta,
                     ConsoleColor.White,
                     ConsoleColor.DarkRed,
                     ConsoleColor.DarkGray
                };

            int iColor = randomGenerator.Next(0, 9);
            int xRock = randomGenerator.Next(0, 59);
            allRocks.Add(new Rocks(xRock, 0, rockSymbol, colors[iColor]));

             foreach (Rocks rock in allRocks)
             {
                 Console.SetCursorPosition(rock.x, rock.y);
                 Console.Write(' ');
                 if (rock.y < Console.WindowHeight - 1)
                 {

                     rock.y++;
                     if (rock.y == Console.WindowHeight - 1 && (rock.x == dwarf.x || rock.x == dwarf.x - 1 || rock.x == dwarf.x + 1) && !gameOver)
                     {
                         gameOver = true;
                     }
                     rock.WriteRock();
                 }
                 else
                 {
                     Remove.Add(rock);
                 }

             }

             foreach (Rocks rock in Remove)
             {
                 allRocks.Remove(rock);
             }

            while (Console.KeyAvailable)
            {
                ConsoleKeyInfo key = Console.ReadKey(true);
                if (key.Key == ConsoleKey.LeftArrow && dwarf.x > 1)
                {
                    dwarf.DelDwarf();
                    dwarf.x -= 1;
                    dwarf.WriteDwarf();
                    foreach (Rocks rock in allRocks)
                    {
                        if (rock.y == Console.WindowHeight - 1 && (rock.x == dwarf.x || rock.x == dwarf.x - 1 || rock.x == dwarf.x + 1))
                        {
                            gameOver = true;
                            rock.WriteRock();
                            break;
                        }
                    }

                    if (gameOver)break;

                }
                else if (key.Key == ConsoleKey.RightArrow && dwarf.x < Console.WindowWidth - 3)
                {
                    dwarf.DelDwarf();
                    dwarf.x += 1;
                    dwarf.WriteDwarf();
                    foreach (Rocks rock in allRocks)
                    {
                        if (rock.y == Console.WindowHeight - 1 && (rock.x == dwarf.x || rock.x == dwarf.x - 1 || rock.x == dwarf.x + 1))
                        {
                            gameOver = true;
                            rock.WriteRock();
                        }
                    }

                    if (gameOver)break;
                }
            }

            if (!gameOver)
            {
                allScore += DateTime.Now.Second;
            }
            else
            {
                Console.Title = "YOUR SCORE = " + allScore.ToString();
                break;
            }

            Thread.Sleep((int)sleepTime);
            sleepTime -= 0.02;

        }
        Console.BufferHeight += 1;
        Console.WindowWidth += 1;
        Console.SetCursorPosition(0, Console.WindowHeight);
        Console.WriteLine("YOUR SCORE = " + allScore.ToString() + " TRY AGAIN ");
    }
示例#37
0
    static void Main(string[] args)
    {
        int playFieldWidth = 20;
        int livesCount = 5;
        int score = 0;

        Console.BufferHeight = Console.WindowHeight = 20;
        Console.BufferWidth = Console.WindowWidth = 40;
        Dwarf userDwarf = new Dwarf();
        userDwarf.x = 10;
        userDwarf.y = Console.WindowHeight - 1;
        userDwarf.c = "(0)";
        userDwarf.color = ConsoleColor.Green;

        Random randomGen = new Random();
        List<Dwarf> objList = new List<Dwarf>();

        while (true)
        {
            bool hit = false;
            int variations = randomGen.Next(0, 100);
            if (variations <= 10)
            {
                Dwarf objectOne = new Dwarf();
                objectOne.color = ConsoleColor.Cyan;
                objectOne.x = randomGen.Next(0, playFieldWidth);
                objectOne.y = 0;
                objectOne.c = "^";
                objList.Add(objectOne);
            }else if (variations>10 && variations<=20)
            {
                Dwarf objectOne = new Dwarf();
                objectOne.color = ConsoleColor.Magenta;
                objectOne.x = randomGen.Next(0, playFieldWidth);
                objectOne.y = 0;
                objectOne.c = "@";
                objList.Add(objectOne);
            }
            else if (variations>20 && variations<=30)
            {
                Dwarf objectOne = new Dwarf();
                objectOne.color = ConsoleColor.Yellow;
                objectOne.x = randomGen.Next(0, playFieldWidth);
                objectOne.y = 0;
                objectOne.c = "*";
                objList.Add(objectOne);
            }
            else if (variations > 30 && variations <= 40)
            {
                Dwarf objectOne = new Dwarf();
                objectOne.color = ConsoleColor.DarkYellow;
                objectOne.x = randomGen.Next(0, playFieldWidth);
                objectOne.y = 0;
                objectOne.c = "&";
                objList.Add(objectOne);
            }
            else if (variations > 40 && variations <= 50)
            {
                Dwarf objectOne = new Dwarf();
                objectOne.color = ConsoleColor.Gray;
                objectOne.x = randomGen.Next(0, playFieldWidth);
                objectOne.y = 0;
                objectOne.c = "+";
                objList.Add(objectOne);

            }
            else if (variations > 50 && variations <= 60)
            {
                Dwarf objectOne = new Dwarf();
                objectOne.color = ConsoleColor.Magenta;
                objectOne.x = randomGen.Next(0, playFieldWidth);
                objectOne.y = 0;
                objectOne.c = "%";
                objList.Add(objectOne);

            }
            else if (variations > 60 && variations <= 70)
            {
                Dwarf objectOne = new Dwarf();
                objectOne.color = ConsoleColor.Yellow;
                objectOne.x = randomGen.Next(0, playFieldWidth);
                objectOne.y = 0;
                objectOne.c = "$";
                objList.Add(objectOne);
            }
            else if (variations > 70 && variations <= 80)
            {
                Dwarf objectOne = new Dwarf();
                objectOne.color = ConsoleColor.White;
                objectOne.x = randomGen.Next(0, playFieldWidth);
                objectOne.y = 0;
                objectOne.c = "#";
                objList.Add(objectOne);

            }
            else if (variations > 80 && variations <= 85)
            {
                Dwarf objectOne = new Dwarf();
                objectOne.color = ConsoleColor.Blue;
                objectOne.x = randomGen.Next(0, playFieldWidth);
                objectOne.y = 0;
                objectOne.c = "!";
                objList.Add(objectOne);

            }
            else if (variations > 85 && variations <= 90)
            {
                Dwarf objectOne = new Dwarf();
                objectOne.color = ConsoleColor.DarkMagenta;
                objectOne.x = randomGen.Next(0, playFieldWidth);
                objectOne.y = 0;
                objectOne.c = ".";
                objList.Add(objectOne);

            }
            else
            {
                Dwarf objectOne = new Dwarf();
                objectOne.color = ConsoleColor.DarkRed;
                objectOne.x = randomGen.Next(0, playFieldWidth);
                objectOne.y = 0;
                objectOne.c = ",";
                objList.Add(objectOne);
            }

            if (Console.KeyAvailable)
            {
                while (Console.KeyAvailable)
                {
                    Console.ReadKey(true);
                }
                ConsoleKeyInfo pressedKey = Console.ReadKey(true);
                if (pressedKey.Key == ConsoleKey.LeftArrow)
                {
                    if ((userDwarf.x - 1) >= 0)
                    {
                        userDwarf.x = userDwarf.x - 1;
                    }
                }
                else if (pressedKey.Key == ConsoleKey.RightArrow)
                {
                    if ((userDwarf.x + 1) < playFieldWidth)
                    {
                        userDwarf.x = userDwarf.x + 1;
                    }
                }

            }
            List<Dwarf> newList = new List<Dwarf>();

            for (int i = 0; i < objList.Count; i++)
            {
                Dwarf oldDwarf = objList[i];
                Dwarf objectOne = new Dwarf();
                objectOne.x = oldDwarf.x;
                objectOne.y = oldDwarf.y + 1;
                objectOne.c = oldDwarf.c;
                objectOne.color = oldDwarf.color;

                if (objectOne.y == userDwarf.y && (objectOne.x == userDwarf.x || objectOne.x == (userDwarf.x + 1) || objectOne.x == (userDwarf.x + 2)))
                {
                    livesCount--;
                    score-=100;
                    hit = true;
                    if (livesCount <= 0)
                    {
                        PrintStatOnPosition(2, 10, "GAME OVER!", ConsoleColor.Red);
                        PrintStatOnPosition(2, 11, "Press ENTER to exit", ConsoleColor.Red);
                        Console.ReadLine();
                        Environment.Exit(0);
                    }
                }
                if (objectOne.y < Console.WindowHeight)
                {
                    newList.Add(objectOne);
                    score++;
                }

            }

            objList = newList;

            Console.Clear();
            PrintOnPosition(userDwarf.x, userDwarf.y, userDwarf.c, userDwarf.color);
            foreach (var dwarf in objList)
            {
                if (hit)
                {
                    Console.Clear();
                    PrintOnPosition(userDwarf.x, userDwarf.y, "#", ConsoleColor.Red);
                }
                else
                {
                    PrintOnPosition(dwarf.x, dwarf.y, dwarf.c, dwarf.color);
                }
            }

            PrintStatOnPosition(25, 10, "Lives:" + livesCount, ConsoleColor.White);
            PrintStatOnPosition(25, 9, "Score:" + score, ConsoleColor.Yellow);

            Thread.Sleep(150);
        }
    }
示例#38
0
 public void FamilyGrowth()
 {
     Dwarf dwarf = new Dwarf(true, _dwarves.Count + 1);
     _dwarves.Add(dwarf);
     CalculatePlayerScore();
 }
    static void Main(string[] args)
    {
        int playfieldWidth = 21;
        int lifeCount = 3;
        int scoreCounter = 0;
        int score = 0;
        Console.BufferHeight = Console.WindowHeight = 20;
        Console.BufferWidth = Console.WindowWidth = 33;
        Dwarf dwarf = new Dwarf();
        dwarf.x = 10;
        dwarf.y = Console.WindowHeight - 1;
        dwarf.str = "(0)";
        dwarf.color = ConsoleColor.White;
        Random ramNums = new Random();
        List<Rock> rocks = new List<Rock>();

        while (true)
        {
            scoreCounter++;

            //create new rock
            ConsoleColor[] cslcolor = new ConsoleColor[10] { ConsoleColor.Blue, ConsoleColor.Green, ConsoleColor.Yellow, ConsoleColor.Red, ConsoleColor.Magenta, ConsoleColor.Red, ConsoleColor.DarkYellow, ConsoleColor.DarkCyan, ConsoleColor.DarkBlue, ConsoleColor.Cyan };
            char[] rockType=new char[11]{'^','@','*','&','+','%','$','#','!','.',';'};
            Rock newRock = new Rock();
            newRock.color = cslcolor[ramNums.Next(0, 10)];
            newRock.x = ramNums.Next(0, 21);
            newRock.y = 0;
            newRock.c = rockType[ramNums.Next(0, 11)];
            rocks.Add(newRock);
            //clear board
            Console.Clear();
            //dwarf moving
            if (Console.KeyAvailable)
            {
                ConsoleKeyInfo pressedKey = Console.ReadKey(true);
                while (Console.KeyAvailable)
                {
                    Console.ReadKey();
                }
                if (pressedKey.Key == ConsoleKey.LeftArrow)
                {
                    if (dwarf.x - 1 >= 0)
                    {
                        dwarf.x = dwarf.x - 1;
                    }

                }
                if (pressedKey.Key == ConsoleKey.RightArrow)
                {
                    if (dwarf.x + 3 <= playfieldWidth)
                    {
                        dwarf.x = dwarf.x + 1;
                    }

                }

            }
            //rocks falling and collision
            List<Rock> newList = new List<Rock>();
            for (int i = 0; i < rocks.Count; i++)
            {
                Rock oldRock = rocks[i];
                Rock currentRock = new Rock();
                currentRock.x = oldRock.x;
                currentRock.y = oldRock.y + 1; ;
                currentRock.c = oldRock.c;
                currentRock.color = oldRock.color;
                if (currentRock.y == dwarf.y && ((currentRock.x == dwarf.x) || (currentRock.x == dwarf.x + 1) || (currentRock.x == dwarf.x + 2)))
                {
                    lifeCount--;
                    score = score - 5;
                    if (score < 0) score = 0;
                    if (lifeCount <= 0)
                    {
                        PrintString(21, 8, "Game Over");
                        Console.ReadLine();
                        return;
                    }
                }
                if (currentRock.y < Console.WindowHeight)
                {
                    newList.Add(currentRock);
                }
            }
            rocks = newList;

            //draw board
            PrintString(dwarf.x, dwarf.y, dwarf.str, dwarf.color);
            foreach (Rock rock in rocks)
            {
                PrintSymbol(rock.x, rock.y, rock.c, rock.color);
            }

            //statistics
            PrintString(22, 5, "Lives: " + lifeCount, ConsoleColor.White);
            if (scoreCounter % 10 == 0) score++;
            PrintString(22, 7, "Score: " + score, ConsoleColor.White);

            //delay
            Thread.Sleep(500);
        }
    }
示例#40
0
 public FallingRocksEngine(Dwarf dwarf, IGameBoard gameBoard)
 {
     this.dwarf = dwarf;
     this.gameBoard = gameBoard;
     this.rocks = new List<Rock>();
 }
示例#41
0
 static void ConstructUser()
 {
     player = new Dwarf();
     player.Col = playfieldWidth / 2;
     player.Row = Console.WindowHeight - 1;
     player.SymbolString = "(0)";
     player.Color = ConsoleColor.White;
     player.Lives = maxLives;
 }
示例#42
0
    public static void Main()
    {
        using (SoundPlayer TextMusic = new SoundPlayer(@"../../Music/Tension-music-loop-114-bpm.wav"))
        {
            TextMusic.PlayLooping();
        }

        int playfieldHignt = Hight;
        int playgrowndWidth = Width;
        Console.BufferHeight = Console.WindowHeight = Hight;
        Console.BufferWidth = Console.WindowWidth = Width;
        Console.BackgroundColor = ConsoleColor.Yellow;

        Dwarf gogo = new Dwarf();
        gogo.X = (Console.WindowWidth / 2) - 2;
        gogo.Y = Console.WindowHeight - 1;
        gogo.Color = ConsoleColor.DarkMagenta;
        gogo.Face = "(0)";

        Random randomGerator = new Random();

        List<Rock> rocks = new List<Rock>();

        int level = 1;
        int health = 100;
        int points = 0;
        int bonusHealth = 10;
        int speedUp = 0;

        while (true)
        {
            {
                Rock newRock = new Rock();
                ConsoleColor currentRockColor =
                    (ConsoleColor)randomGerator.Next(Enum.GetNames(typeof(ConsoleColor)).Length);

                while (true)
                {
                    if (currentRockColor != Console.BackgroundColor)
                    {
                        newRock.Color = currentRockColor;
                        break;
                    }
                    else
                    {
                        currentRockColor = (ConsoleColor)randomGerator.Next(Enum.GetNames(typeof(ConsoleColor)).Length);
                    }
                }

                newRock.Y = SkyHight;
                newRock.X = randomGerator.Next(0, playgrowndWidth);
                newRock.Symbol = RockType[randomGerator.Next(RockType.Length)];
                rocks.Add(newRock);
            }

            /// Move dwarf(key pressed)
            if (Console.KeyAvailable)
            {
                ConsoleKeyInfo pressedKey = Console.ReadKey(true);

                /// Clear buffer if key is pressed more than one before redrawing
                while (Console.KeyAvailable)
                {
                    Console.ReadKey(true);
                }

                if (pressedKey.Key == ConsoleKey.LeftArrow)
                {
                    if (gogo.X - 1 > 0)
                    {
                        gogo.X = gogo.X - 1;
                    }
                }
                else if (pressedKey.Key == ConsoleKey.RightArrow)
                {
                    if (gogo.X + 1 < playgrowndWidth - gogo.Face.Length)
                    {
                        gogo.X = gogo.X + 1;
                    }
                }
            }

            /// Move FallingRocks
            for (int i = 0; i < rocks.Count; i++)
            {
                Rock oldRock = rocks[i];
                if (rocks[i].Y < playfieldHignt - 1)
                {
                    Rock newRock = new Rock();
                    newRock.X = oldRock.X;
                    newRock.Y = oldRock.Y + 1;
                    newRock.Symbol = oldRock.Symbol;
                    newRock.Color = oldRock.Color;
                    rocks.Remove(oldRock);
                    rocks.Add(newRock);
                }
                else
                {
                    rocks.Remove(oldRock);
                }
            }

            /// Check for colision with rock
            foreach (var rock in rocks)
            {
                if (rock.Y == playfieldHignt - 1)
                {
                    for (int i = 0; i < gogo.Face.Length; i++)
                    {
                        if (gogo.X + i == rock.X)
                        {
                            if (rock.Symbol == '@' && health <= MaxHealth - bonusHealth)
                            {
                                Console.Beep(1000, 150);

                                health += bonusHealth;
                            }
                            else
                            {
                                Console.Beep(2200, 100);
                                health -= 5;
                            }
                        }
                        else
                        {
                            points += 2;
                        }

                        if (points == LevelUpPoints * level)
                        {
                            level++;
                            speedUp += Acceleration;

                            if (health <= MaxHealth - 100)
                            {
                                health += 100;
                            }
                            else
                            {
                                health = MaxHealth;
                            }
                        }
                    }
                }
            }

            /// Clear Console
            Console.Clear();

            /// check if game is end
            if (health > 0 && points < MaxPoints)
            {
                /// REDrow info - Result
                string title = "FOLLING ROCKS";
                string currentLevel = string.Format("LEVEL {0}", level);
                string currentHealth = string.Format("HEALTH {0}%", health);
                string currentPoints = string.Format("POINTS {0}", points);

                PrintStringOnPosition((Width - title.Length) / 2, 1, title, ConsoleColor.DarkMagenta);
                PrintStringOnPosition((Width - currentLevel.Length) / 2, 3, currentLevel, ConsoleColor.DarkMagenta);
                PrintStringOnPosition(5, 5, currentHealth);
                PrintStringOnPosition(Width - currentPoints.Length - 6, 5, currentPoints);
                PrintStringOnPosition(0, SkyHight, new string('`', Width), ConsoleColor.Blue);

                /// ReDraw dwarf and rocks
                PrintStringOnPosition(gogo.X, gogo.Y, gogo.Face, gogo.Color);

                foreach (var rock in rocks)
                {
                    PrintOnPosition(rock.X, rock.Y, rock.Symbol, rock.Color);
                }

                /// Slow down  program
                Thread.Sleep(150 + speedUp);
            }
            else
            {
                /// Game is over
                Console.BackgroundColor = ConsoleColor.Green;
                Console.Clear();
                ConsoleColor color = ConsoleColor.DarkGreen;
                string gameOver = "END GAME";
                string youLosе = "You Lose";
                string youWon = "You Won";
                string newGame = "Pres ENTER for New Game";
                string endGame = "Press DEL for Exit";

                PrintStringOnPosition((Width - gameOver.Length) / 2, SkyHight - 5, gameOver, color);

                if (health == 0)
                {
                    PrintStringOnPosition((Width - youLosе.Length) / 2, SkyHight - 4, youLosе, color);
                }
                else
                {
                    PrintStringOnPosition((Width - youWon.Length) / 2, SkyHight - 4, youWon, color);
                }

                PrintStringOnPosition((Width - newGame.Length) / 2, SkyHight - 2, newGame, color);
                PrintStringOnPosition((Width - endGame.Length) / 2, SkyHight - 1, endGame, color);

                string key = Console.ReadKey().Key.ToString();

                if (key.ToUpper() == "ENTER")
                {
                    Console.Clear();
                    Console.BackgroundColor = ConsoleColor.Yellow;
                    health = 100;
                    points = 0;
                    speedUp = 0;
                    level = 1;
                    continue;
                }
                else if (key.ToUpper() == "DELETE")
                {
                    Environment.Exit(0);
                    Environment.Exit(0);
                }
            }
        }
    }
示例#43
0
    static void Main()
    {
        SetBufferSize();

        int playfieldWidth = 2 * Console.WindowWidth / 3;

        // creating the dwarf
        Dwarf dwarf = new Dwarf();
        dwarf.positionX = playfieldWidth / 2;
        dwarf.positionY = Console.WindowHeight - 1;
        dwarf.color = ConsoleColor.Yellow;
        dwarf.symbols = "(0)";

        Random rand = new Random();

        List<Rock> rocks = new List<Rock>();
        bool isHitted = false;

        int livesCount = 2;
        int counterWhenToCreateRock = 0;
        int userScore = 0;
        double acceleration = 0.0;

        int intervalForCreatingRocks = 0;

        while (true)
        {
            dwarf = MoveDwarf(playfieldWidth, dwarf);  // moving dwarf when left or right arrow is pressed

            // depending on the userScore, increase acceleration
            //acceleration = increaseAcceleration(userScore);

            intervalForCreatingRocks = decreaseIntervalForCreatingRocks(userScore); // in some conditions decrease the interval for creating rocks

            // in every intervalForCreatingRocks time we will create one rock and add it to the list of rocks
            if (counterWhenToCreateRock % intervalForCreatingRocks == 0)
            {
                counterWhenToCreateRock = 0;
                Rock createdRock = CreateRock(playfieldWidth, rand);
                rocks.Add(createdRock);
            }

            List<Rock> movedRocks = MoveRocks(rocks); // move rocks one position down

            for (int i = 0; i < movedRocks.Count; i++) // loop for every rock in movedRocks
            {
                Rock currentRock = new Rock();
                currentRock = movedRocks[i];

                // check if some rock hit the dwarf
                if (currentRock.y == dwarf.positionY && (dwarf.positionX <= currentRock.x + currentRock.symbols.Length - 1) && (dwarf.positionX + dwarf.symbols.Length - 1 >= currentRock.x))
                {
                    //if the dwarf is hit, and there is any lives left, decrease lives with 1 and set isHitted to true
                    if (livesCount - 1 >= 0)
                    {
                        livesCount--;
                        isHitted = true;
                    }
                }

                //check is there is no more lives, and if there isn't print some information ot the console
                if (livesCount <= 0)
                {
                    Console.Clear();
                    Draw(Console.WindowWidth / 2 - 5, Console.WindowHeight / 2 + 2, ConsoleColor.DarkRed, "GAME OVER");
                    Draw(Console.WindowWidth / 2 - 6, Console.WindowHeight / 2 - 2, ConsoleColor.DarkRed, "Your score: " + userScore);
                    Draw(Console.WindowWidth / 2 - 10, Console.WindowHeight / 2 - 4, ConsoleColor.DarkRed, "Press any key to exit");

                    Console.ReadLine();
                    return;
                }

                //check if rock is on the board of the console, and if it is increase userScore with the lenght of the rock
                if (currentRock.y == Console.WindowHeight - 1 && !isHitted)
                {
                    userScore += currentRock.symbols.Length;
                }


            }

            rocks = movedRocks;

            // clear the console from previous output and after that print the moved rocks, the dwarf and some information on the right
            Console.Clear();

            //check if the dwarf is hit
            if (isHitted)
            {
                //if dwarf was hitted clear rocks so that we begin our game from the beggining and draw (X) with DarkRed to see that we were hitted
                rocks.Clear();
                Draw(dwarf.positionX, dwarf.positionY, ConsoleColor.DarkRed, "(X)");

            }
            else
            {
                //if it was not hitted than draw the dwarf
                Draw(dwarf.positionX, dwarf.positionY, dwarf.color, dwarf.symbols);
            }

            // draw every rock from the current list of rocks
            foreach (Rock rock in rocks)
            {
                Draw(rock.x, rock.y, rock.color, rock.symbols);
            }

            //print some information about the game
            Draw(playfieldWidth + 2, Console.WindowHeight / 2 - 6, ConsoleColor.Red, "Lives left: " + livesCount);
            Draw(playfieldWidth + 2, Console.WindowHeight / 2 - 2, ConsoleColor.Red, "Score: " + userScore);
            Draw(playfieldWidth + 2, Console.WindowHeight / 2 + 2, ConsoleColor.Red, "Time for rock falling: " + intervalForCreatingRocks);


            //if you want to play the game with acceleration, not with constant speed of falling

            /*
            if ((int) userScore * acceleration < 350)
            {
                Thread.Sleep(500 - (int) (userScore * acceleration));
            }
            else
            {
                Thread.Sleep(150);
            }
             */

            Thread.Sleep(150);

            counterWhenToCreateRock++;
            isHitted = false;
        }
    }
    static void Main(string[] args)
    {
        // Console settings
        Console.CursorVisible = false;
        Console.BufferHeight = Console.WindowHeight = 20;
        Console.BufferWidth = Console.WindowWidth = 30;
        Console.BackgroundColor = ConsoleColor.Gray;
        Console.Clear();

        //Playfield restriction
        int playFieldWidth = Console.WindowWidth - 8;

        int sleep = 150;

        Random randomGenerator = new Random();

        // Rock types
        char[] rocksArr = new char[] {
            '^', '@', '&', '+',
            '%', '$', '#', '!',
            '.', ';', '-'
        };

        // Player beginning position, color and symbols
        Dwarf userDwarf = new Dwarf();
        userDwarf.x = (Console.WindowWidth - 8) / 2;
        userDwarf.y = Console.WindowHeight - 1;
        userDwarf.color = ConsoleColor.DarkBlue;
        userDwarf.symbolArr = new char[] {
            '(', '0', ')'
        };

        int livesCount = 5;
        int score = 0;

        // Add every new rock to a List
        List<Rock> rocks = new List<Rock>();

        // A warning message :)
        Console.ForegroundColor = ConsoleColor.DarkBlue;
        Console.Write("Are you ready to get...\n ");
        Thread.Sleep(sleep + 1500);
        Console.ForegroundColor = ConsoleColor.Red;
        Thread.Sleep(sleep + 50);
        Console.Write("CRUSHED??\n");
        Console.ForegroundColor = ConsoleColor.DarkBlue;
        Console.Write("Press any key to continue...");
        Console.ReadKey();

        while (true)
        {
            // Set game speed
            Thread.Sleep(sleep + 50);

            // Rocks colors
            ConsoleColor color1 = ConsoleColor.DarkGreen;
            ConsoleColor color2 = ConsoleColor.DarkCyan;
            ConsoleColor color3 = ConsoleColor.DarkYellow;
            ConsoleColor color4 = ConsoleColor.Red;
            ConsoleColor color5 = ConsoleColor.Black;

            // Generate random rock position, color, symbol and the count of the symbol
            ConsoleColor[] rockColors = new ConsoleColor[5]{
                color1, color2, color3, color4, color5
            };

            int rockNum = randomGenerator.Next(1, 4);
            char rockSymbol = rocksArr[randomGenerator.Next(0, rocksArr.Length)];
            Rock newRock = new Rock();
            newRock.color = rockColors[randomGenerator.Next(0, 5)];
            newRock.x1 = randomGenerator.Next(0, playFieldWidth - 2);
            newRock.y = 0;
            newRock.symbolArr = new char[rockNum];

            // If the rock has more than 1 symbol, assign every next symbol with a X coordinate
            if (rockNum == 2)
            {
                newRock.x2 = newRock.x1 + 1;
            }
            else if (rockNum == 3)
            {
                newRock.x2 = newRock.x1 + 1;
                newRock.x3 = newRock.x2 + 1;
            }
            if (newRock.x2 == 0)
            {
                newRock.x2 = -1;
            }
            if (newRock.x3 == 0)
            {
                newRock.x3 = -1;
            }

            // Add the symbols to an array and add the compleated rock object to the List<rocks>
            for (int i = 0; i < newRock.symbolArr.Length; i++)
            {
                newRock.symbolArr[i] = rockSymbol;
            }
            rocks.Add(newRock);

            // Check if a key is pressed and move player
            while (Console.KeyAvailable)
            {
                ConsoleKeyInfo pressedKey = Console.ReadKey(true);
                if (pressedKey.Key == ConsoleKey.LeftArrow)
                {
                    if (userDwarf.x - 1 > 0)
                    {
                        userDwarf.x--;
                    }
                }
                else if (pressedKey.Key == ConsoleKey.RightArrow)
                {
                    if (userDwarf.x < playFieldWidth - 2)
                    {
                        userDwarf.x++;
                    }
                }
            }

            // Clear everything
            Console.Clear();

            // Print the new player position
            PrintObject(userDwarf.x - 1, userDwarf.y, userDwarf.symbolArr, userDwarf.color);

            // A new list of rocks to help with the rock positions
            List<Rock> newListRocks = new List<Rock>();

            // Copy each rock to a new temporary rock and add it to the new list if its position is valid
            for (int i = 0; i < rocks.Count; i++)
            {
                Rock oldRock = rocks[i];
                Rock newRockMod = new Rock();
                newRockMod.x1 = oldRock.x1;
                newRockMod.x2 = oldRock.x2;
                newRockMod.x3 = oldRock.x3;
                newRockMod.y = oldRock.y + 1;
                newRockMod.color = oldRock.color;
                newRockMod.symbolArr = new char[oldRock.symbolArr.Length];
                Array.Copy(oldRock.symbolArr, newRockMod.symbolArr, oldRock.symbolArr.Length);

                // Check if the rock is hitting the player and if so, take one life
                if (newRockMod.y == userDwarf.y &&
                    ((newRockMod.x1 == userDwarf.x - 1 || newRockMod.x1 == userDwarf.x || newRockMod.x1 == userDwarf.x + 1) ||
                    (newRockMod.x2 == userDwarf.x - 1 || newRockMod.x2 == userDwarf.x || newRockMod.x2 == userDwarf.x + 1) ||
                    (newRockMod.x3 == userDwarf.x - 1 || newRockMod.x3 == userDwarf.x || newRockMod.x3 == userDwarf.x + 1)))
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.SetCursorPosition(userDwarf.x - 1, Console.WindowHeight - 1);
                    Console.Write('X');
                    Console.SetCursorPosition(userDwarf.x, Console.WindowHeight - 1);
                    Console.Write('X');
                    Console.SetCursorPosition(userDwarf.x + 1, Console.WindowHeight - 1);
                    Console.Write('X');
                    livesCount--;
                }

                // Check if the rock's Y is bigger than the window height and if so, remove it and add score
                if (newRockMod.y < Console.WindowHeight)
                {
                    newListRocks.Add(newRockMod);
                }
                else
                {
                    score += 100;
                }
            }

            // Check the lives count
            if (livesCount == 0)
            {
                Console.Clear();
                Console.SetCursorPosition(Console.WindowWidth / 2 - 8, Console.WindowHeight / 2 - 1);
                Console.Write("Game Over!");
                Console.SetCursorPosition(Console.WindowWidth / 2 - 8, Console.WindowHeight / 2);
                Console.Write("Your score is {0}", score);
                while (true) ;
            }

            // Copy the new rocks to the array
            rocks = newListRocks;

            // Print the rocks
            foreach (Rock rock in rocks)
            {
                PrintObject(rock.x1, rock.y, rock.symbolArr, rock.color);
            }

            // Print the info
            Console.ForegroundColor = ConsoleColor.Black;
            for (int i = 0; i < Console.WindowHeight; i++)
            {
                Console.SetCursorPosition(Console.WindowWidth - 8, i);
                Console.Write("|");
            }
            Console.SetCursorPosition(Console.WindowWidth - 7, 5);
            Console.Write("Lives:");
            Console.SetCursorPosition(Console.WindowWidth - 7, 6);
            Console.Write(livesCount);
            Console.SetCursorPosition(Console.WindowWidth - 7, 2);
            Console.Write("Score:");
            Console.SetCursorPosition(Console.WindowWidth - 7, 3);
            Console.Write(score);
        }
    }
示例#45
0
    static void Main()
    {
        //char[] rocksArray = { '!', '@', '#', '$', '%', '&', '^', '+', '-' };
        string dwarfSymbol = "(0)";
        double speed = 100.0;
        int playfieldWidth = 16;
        int livesCount = 5;
        Console.BufferHeight = Console.WindowHeight = 20;
        Console.BufferWidth = Console.WindowWidth = 50;

        Dwarf dwarf = new Dwarf();
        {
            dwarf.x = 8;
            dwarf.y = Console.WindowHeight - 1;
            dwarf.s = dwarfSymbol;
            dwarf.color = ConsoleColor.Yellow;
        }
        Random randomGenerator = new Random();
        //int randomStone = randomGenerator.Next(rocksArray.Length);
        List<Objects> objects = new List<Objects>();

        while (true)
        {
            speed = speed + 5;
            if (speed > 400)
            {
                speed = 400;
            }
            bool isHit = false;
            {
                // adding bonus objects
                int chance = randomGenerator.Next(0, 100);
                if (chance < 10)
                {
                    Objects bonus = new Objects();
                    bonus.color = ConsoleColor.Blue;
                    bonus.c = '@';
                    bonus.x = randomGenerator.Next(0, playfieldWidth);
                    bonus.y = 0;
                    objects.Add(bonus);
                }
                else if (chance < 20)
                {
                    Objects bonus = new Objects();
                    bonus.color = ConsoleColor.DarkMagenta;
                    bonus.c = '%';
                    bonus.x = randomGenerator.Next(0, playfieldWidth);
                    bonus.y = 0;
                    objects.Add(bonus);
                }
                else
                {
                    Objects newRock = new Objects();
                    newRock.color = ConsoleColor.Green;
                    newRock.x = randomGenerator.Next(0, playfieldWidth);
                    newRock.y = 0;
                    int num = randomGenerator.Next(0, 10);
                    //newRock.c = '#';
                    //char[] rocksArray = { '!', '@', '#', '$', '%', '&', '^', '+', '-' }; //no use of this
                    newRock.c = (char)('#' + num);
                    //char[] chars = "$#*?^&".ToCharArray();
                    //Random randomChar = new Random();
                    //int num = randomChar.Next(chars.Length);
                    //Console.WriteLine(chars[num]);
                    objects.Add(newRock);
                }

            }

            // move the dwarf (key pressed)
            while (Console.KeyAvailable)
            {
                ConsoleKeyInfo pressedKey = Console.ReadKey(true);
                if (pressedKey.Key == ConsoleKey.LeftArrow)
                {
                    if (dwarf.x - 1 >= 0)
                    {
                        dwarf.x = dwarf.x - 1;
                    }
                }
                else if (pressedKey.Key == ConsoleKey.RightArrow)
                {
                    if (dwarf.x + 1 < playfieldWidth)
                    {
                        dwarf.x = dwarf.x + 1;
                    }
                }
            }

            //creating new list of rocks
            List<Objects> newListOfRocks = new List<Objects>();

            // move rocks
            for (int i = 0; i < objects.Count; i++)
            {
                Objects oldRock = objects[i];
                Objects newObject = new Objects();
                newObject.x = oldRock.x;
                newObject.y = oldRock.y + 1;
                newObject.c = oldRock.c;
                //newObject.c = rocksArray[randomStone];
                newObject.color = oldRock.color;

                // check if rocks are hitting the dwarf
                //if (newObject.c == '%' && newObject.y == dwarf.y && newObject.x == dwarf.x)
                if (newObject.c == '%' && newObject.y == dwarf.y && newObject.x >= dwarf.x && newObject.x <= dwarf.x + 2)
                {
                    speed -= 100;
                    if (speed < 150)
                    {
                        speed = 150;
                    }
                }
                if (newObject.c == '@' && newObject.y == dwarf.y && newObject.x >= dwarf.x && newObject.x <= dwarf.x + 2)
                {
                    livesCount++;
                }
                if (newObject.color == ConsoleColor.Green)
                {
                    if (newObject.y == dwarf.y && newObject.x >= dwarf.x && newObject.x <= dwarf.x + 2)
                    {
                        if (newObject.c == '!' || newObject.c == '&' || newObject.c == '#' || newObject.c == '$' ||
                            newObject.c == '^' || newObject.c == '+' || newObject.c == '-' || newObject.c == '(' ||
                            newObject.c == ')' || newObject.c == '\'' || newObject.c == ',' || newObject.c == '*' ||
                            newObject.c == '%' || newObject.c == '@')
                        {
                            livesCount--;
                            isHit = true;
                            speed = 100;
                            if (livesCount <= 0)
                            {
                                PrintStringOnPosition(playfieldWidth + 3, 10, "!!!GAME OVER!!!", ConsoleColor.Red);
                                PrintStringOnPosition(playfieldWidth + 3, 12, "Press [ENTER] to exit...", ConsoleColor.Gray);
                                Console.ReadLine();
                                Environment.Exit(0);
                            }
                        }
                    }
                }
                if (newObject.y < Console.WindowHeight)
                {
                    newListOfRocks.Add(newObject);
                }
            }
            objects = newListOfRocks;

            // clear the console
            Console.Clear();

            // redraw playfield
            if (isHit)
            {
                Console.Beep();
                objects.Clear();
                PrintRockOnPosition(dwarf.x, dwarf.y, 'X', ConsoleColor.Red);
            }
            else
            {
                PrintDwarfOnPosition(dwarf.x, dwarf.y, dwarf.s, dwarf.color);
            }
            foreach (Objects rock in objects)
            {
                PrintRockOnPosition(rock.x, rock.y, rock.c, rock.color);
            }

            // draw info
            PrintStringOnPosition(playfieldWidth + 3, 4, "Lives: " + livesCount, ConsoleColor.White);
            PrintStringOnPosition(playfieldWidth + 3, 5, "Speed: " + speed, ConsoleColor.White);
            PrintStringOnPosition(playfieldWidth + 3, 6, "% decreases the speed", ConsoleColor.DarkMagenta);
            PrintStringOnPosition(playfieldWidth + 3, 7, "@ gives you a new life", ConsoleColor.Blue);
            PrintStringOnPosition(playfieldWidth + 3, 8, "Beware of green objects!", ConsoleColor.Green);

            // slow down program
            int maxSpeed = (int)(600 - speed);
            Thread.Sleep(maxSpeed);

            //exiting the program? how?
        }
    }
示例#46
0
    static void Main()
    {
        int playfieldWidth = 25;
        int livesCount = 5;
        int scoresCount = 0;
        Console.BufferHeight = Console.WindowHeight = 30;
        Console.BufferWidth = Console.WindowWidth = 55;
        Dwarf dwarf = new Dwarf();
        dwarf.myX = 12;
        dwarf.myY = Console.WindowHeight - 1;
        dwarf.str = "(0)";
        Random randomGenerator = new Random();
        List<Rock> rocks = new List<Rock>();

        while (true)
        {
            {
                char[] symbol = { '^', '@', '*', '&', '+', '%', '$', '#', '!', '.', ';', '-' };
                Random randomChar = new Random();
                int c = randomChar.Next(0, 12);
                char symbolPrint = symbol[c];

                string[] colorNames = ConsoleColor.GetNames(typeof(ConsoleColor));
                Random randomColor = new Random();
                string randomColorName = colorNames[randomColor.Next(colorNames.Length)];
                Rock newRock = new Rock();
                newRock.color = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), randomColorName);
                if (newRock.color == ConsoleColor.Black) newRock.color = ConsoleColor.White;
                newRock.x = randomGenerator.Next(0, playfieldWidth);
                newRock.y = 0;
                newRock.c = symbolPrint;
                rocks.Add(newRock);
            }

            // Move rocks
            List<Rock> newList = new List<Rock>();
            for (int i = 0; i < rocks.Count; i++)
            {
                Rock oldRock = rocks[i];
                Rock newRock = new Rock();
                newRock.x = oldRock.x;
                newRock.y = oldRock.y + 1;
                newRock.c = oldRock.c;
                newRock.color = oldRock.color;
                if (newRock.x == dwarf.myX && newRock.y == dwarf.myY || newRock.x == dwarf.myX + 1
                    && newRock.y == dwarf.myY || newRock.x == dwarf.myX + 2 && newRock.y == dwarf.myY)
                {
                    livesCount--;
                    Console.Beep();
                    if (livesCount <= 0)
                    {
                        PrintStringPosition(8, 7, "GAME OVER!!!", ConsoleColor.Red);
                        Console.ReadLine();
                        return;
                    }
                }
                if (newRock.y < Console.WindowHeight)
                {
                    newList.Add(newRock);
                    scoresCount++;
                }

            }
            rocks = newList;
            // Move the dwarf
            if (Console.KeyAvailable)
            {
                ConsoleKeyInfo pressedKey = Console.ReadKey(true);
                while (Console.KeyAvailable) Console.ReadKey(true);
                if (pressedKey.Key == ConsoleKey.LeftArrow)
                {
                    if (dwarf.myX - 1 >= 0)
                    {
                        dwarf.myX--;
                    }
                }
                else if (pressedKey.Key == ConsoleKey.RightArrow)
                {
                    if (dwarf.myX + 1 < playfieldWidth)
                    {
                        dwarf.myX++;
                    }
                }
            }
            Console.Clear();
            // Redraw playfield
            PrintDwarf(dwarf.myX, dwarf.myY, dwarf.str, dwarf.dcolor = ConsoleColor.Blue);
            foreach (Rock rock in rocks)
            {
                PrintPosition(rock.x, rock.y, rock.c, rock.color);
            }
            // Draw info
            for (int borderY = 0; borderY <= Console.WindowHeight - 1; borderY++)
            {
                PrintStringPosition(27, borderY, "||", ConsoleColor.White);
            }
            PrintStringPosition(30, 4, "Falling Bricks", ConsoleColor.Yellow);
            PrintStringPosition(30, 7, "Lives Left: " + livesCount, ConsoleColor.White);
            PrintStringPosition(30, 8, "Scores: " + scoresCount, ConsoleColor.White);
            PrintStringPosition(30, 11, "Controls:", ConsoleColor.DarkMagenta);
            PrintStringPosition(30, 12, "Use the left", ConsoleColor.Green);
            PrintStringPosition(30, 13, "and right arrow", ConsoleColor.Green);
            PrintStringPosition(30, 14, "to move the dwarf (0)", ConsoleColor.Green);
            //Slow down the program
            Thread.Sleep(150);
        }
    }
示例#47
0
 static void Main()
 {
     int field = 50;
     Console.BufferHeight = Console.WindowHeight = 5;
     Console.BufferWidth = Console.WindowWidth = 61;
     Dwarf userDwarf = new Dwarf();
     int livesCount = 5;
     userDwarf.x = 30;
     userDwarf.y = Console.WindowHeight - 1;
     userDwarf.str = "(0)";
     userDwarf.color = ConsoleColor.Yellow;
     Random randomGenerator = new Random();
     List<Object> objects = new List<Object>();
     while (true)
     {
         bool hitted = false;
         //^  @  *  &  +  %  $  # !  . ; -
         for (int index = 0; index < 3; index++)
         {
             int chance = randomGenerator.Next(0, 2);
             if (chance == 0)
             {
                 Rock newObject = new Rock();
                 newObject.color = ConsoleColor.DarkRed;
                 newObject.c = '^';
                 newObject.x = randomGenerator.Next(0, field);
                 newObject.y = 0;
                 objects.Add(newObject);
             }
             else if (chance == 1)
             {
                 Rock newObject = new Rock();
                 newObject.color = ConsoleColor.Cyan;
                 newObject.c = '@';
                 newObject.x = randomGenerator.Next(0, field);
                 newObject.y = 0;
                 objects.Add(newObject);
             }
             else
             {
                 Rock newCar = new Rock();
                 newCar.color = ConsoleColor.Green;
                 newCar.x = randomGenerator.Next(0, field);
                 newCar.y = 0;
                 newCar.c = '*';
                 objects.Add(newCar);
             }
         }
         while (Console.KeyAvailable)
         {
             ConsoleKeyInfo pressedKey = Console.ReadKey(true);
             //while (Console.KeyAvailable) Console.ReadKey(true);
             if (pressedKey.Key == ConsoleKey.LeftArrow)
             {
                 if (userDwarf.x - 1 >= 0)
                 {
                     userDwarf.x = userDwarf.x - 1;
                 }
             }
             else if (pressedKey.Key == ConsoleKey.RightArrow)
             {
                 if (userDwarf.x + 3 < field)
                 {
                     userDwarf.x = userDwarf.x + 1;
                 }
             }
         }
         List<Object> newList = new List<Object>();
         for (int i = 0; i < objects.Count; i++)
         {
             Rock oldRock = (Rock)objects[i];
             Rock newObject = new Rock();
             newObject.x = oldRock.x;
             newObject.y = oldRock.y + 1;
             newObject.c = oldRock.c;
             newObject.color = oldRock.color;
             if ((newObject.c == '@' || newObject.c == '^') && newObject.y == userDwarf.y && (newObject.x == userDwarf.x || newObject.x == userDwarf.x+1||newObject.x == userDwarf.x+2))
             {
                 livesCount--;
                 hitted = true;
             }
             if (livesCount <= 0)
             {
                 PrintString(12, 20, "GAME OVER!!!", ConsoleColor.Red);
                 PrintString(8, 12, "Press [enter] to exit", ConsoleColor.Red);
                 Console.ReadLine();
                 Environment.Exit(0);
             }
             if (newObject.y < Console.WindowHeight)
             {
                 newList.Add(newObject);
             }
         }
         objects = newList;
         Console.Clear();
         hitted = false;
         foreach (Rock rock in objects)
         {
             PrintFallingRocs(rock.x, rock.y, rock.c, rock.color);
         }
         PrintString(50, 4, "Lives: " + livesCount, ConsoleColor.White);
         PrintString(userDwarf.x, userDwarf.y, userDwarf.str, userDwarf.color);
         Thread.Sleep(200);
     }
 }
示例#48
0
    static void Main()
    {
        //Basic game information
        double speed = 300.0;
        int playFieldWidth = 20;
        int livesCount = 5;
        Console.BufferHeight = Console.WindowHeight = 20;
        Console.BufferWidth = Console.WindowWidth = 40;

        //Drawing the Dwarf
        Dwarf user = new Dwarf();
        user.x = 5;
        user.y = Console.WindowHeight - 1;
        user.c = 'O';
        user.color = ConsoleColor.Yellow;

        //Drawing rocks
        Random randomGenerator = new Random();
        List<Rock> rocks = new List<Rock>();
        while (true)
        {
            //increasing difficulty over time
            if (speed < 400)
            {
                speed++;
            }
            {
                Rock newRock = new Rock();
                newRock.color = ConsoleColor.Green;
                newRock.x = randomGenerator.Next(0, playFieldWidth);
                newRock.y = 0;
                newRock.c = '@';
                rocks.Add(newRock);
            }

            //Controls
            if (Console.KeyAvailable)
            {
                ConsoleKeyInfo pressedKey = Console.ReadKey(true);
                while (Console.KeyAvailable)
                {
                    Console.ReadKey(true);
                }
                if (pressedKey.Key == ConsoleKey.LeftArrow)
                {
                    if (user.x - 1 >= 0)
                    {
                        user.x = user.x - 1;
                    }
                }

                else if (pressedKey.Key == ConsoleKey.RightArrow)
                {
                    if (user.x + 1 < playFieldWidth)
                    {
                        user.x = user.x + 1;
                    }
                }

            }

            //Moving rocks
            List<Rock> newList = new List<Rock>();
            for (int i = 0; i < rocks.Count; i++)
            {
                Rock oldRock = rocks[i];
                Rock newRock = new Rock();
                newRock.x = oldRock.x;
                newRock.y = oldRock.y + 1;
                newRock.c = oldRock.c;
                newRock.color = oldRock.color;

                //Collision
                if (newRock.y == user.y && newRock.x == user.x)
                {
                    livesCount--;
                    PrintStringOnPosition(user.x, user.y, "X", ConsoleColor.Red);
                    if (livesCount <= 0)
                    {
                        PrintStringOnPosition(23, 10, "GAME OVER!!!", ConsoleColor.Red);
                        Console.ReadLine();
                        Environment.Exit(0);
                    }
                }
                if (newRock.y < Console.WindowHeight)
                {
                    newList.Add(newRock);
                }
                
            }
            rocks = newList;
            Console.Clear();
            PrintOnPosition(user.x, user.y, user.c, user.color);
            foreach (Rock rock in rocks)
            {
                PrintOnPosition(rock.x, rock.y, rock.c, rock.color);
            }

            //Info
            PrintStringOnPosition(23, 4, "Lives: " + livesCount, ConsoleColor.White);
            PrintStringOnPosition(23, 5, "Rock speed: " + speed, ConsoleColor.White);

            //Game speed
            Thread.Sleep((int)(600-speed));
        }
    }