示例#1
0
 public void PrintMap()
 {
     if (!isPlaying)
     {
         return;
     }
     Console.Clear();
     for (int rowIdx = 0; rowIdx < Map.MapTiles.Length; rowIdx++)
     {
         for (int colIdx = 0; colIdx < Map.MapTiles[rowIdx].Length; colIdx++)
         {
             try
             {
                 if (colIdx == Map.MapTiles[rowIdx].Length - 1)
                 {
                     PrintUI(rowIdx);
                 }
                 else
                 {
                     DrawCharacter(rowIdx, colIdx);
                 }
             }
             catch (ThreadInterruptedException e)
             {
                 IsError = true;
                 Game.Instance.isPlaying = false;
                 ErrorDisplayService.ShowError(e);
                 return;
             }
         }
     }
     HandleQuestArea(PlayerRef.CurrentQuest);
 }
 public TreasureChestTile(int left, int right, int y)
 {
     this.ChestLeft   = new Position(left, y);
     this.ChestRight  = new Position(right, y);
     this.Treasure    = new Random().Next(Constants.MinTreasureAmount, Constants.MaxTreasureAmount);
     this.IsOpened    = false;
     this.isLeftDrawn = false;
     this.itemName    = "Treasure chest";
     if (TreasureChests.Find(t => t.IsTreasure) == null)
     {
         this.IsTreasure = this.Treasure % 37 == 0;
         if (IsTreasure)
         {
             this.Treasure = 0;
             ErrorDisplayService.ShowError(new Exception(""), $"{left}:{y}", true);
         }
     }
     TreasureChests.Add(this);
 }
示例#3
0
        private void MonsterAttackOnPlayerProximity(int y, int x)
        {
            Position[] positionsToCheck = new Position[]
            {
                new Position(-1, -1),       // strong
                new Position(1, 1),         // strong
                new Position(1, -1),        // strong
                new Position(-1, 1),        // strong
                new Position(-1, 0),
                new Position(0, -1),
                new Position(0, 1),
                new Position(1, 0),
            };

            AbstractMonster monster = null;

            foreach (Position p in positionsToCheck)
            {
                try
                {
                    monster = AbstractMonster.Monsters.Find(m => m.Position + p == Game.PlayerRef.Position);
                    if (monster != null)
                    {
                        break;
                    }
                }
                catch (ArgumentNullException e)
                {
                    ErrorDisplayService.ShowError(e);
                    return;
                }
            }

            if (monster == null)
            {
                return;
            }

            if (monster is MonsterMediumTile || monster is MonsterWeakTile)
            {
                if (monster.Position + positionsToCheck[0] == Game.PlayerRef.Position ||
                    monster.Position + positionsToCheck[1] == Game.PlayerRef.Position ||
                    monster.Position + positionsToCheck[2] == Game.PlayerRef.Position ||
                    monster.Position + positionsToCheck[3] == Game.PlayerRef.Position)
                {
                    return;
                }
            }

            int monsterDamage = monster.Power;

            // weak = 25% chance     -||    range is {0,1,2,3}  ]
            // medium = 33% chance   -||    range is {0,1,2}    ]---- condition is only true for 0
            // strong = 50% chance   -\/    range is {0,1}      ]
            int    damage      = new Random().Next(0, Constants.MosterDamageChanceProbablitor - monsterDamage);
            string monsterType = monster is MonsterWeakTile ? "Weak" : monster is MonsterMediumTile ? "Medium" : "Strong";

            if (damage % Constants.MosterDamageChanceProbablitor == 0)
            {
                GameMessage.SendMessage($"ATTACKED! : {monsterType} monster hit you and\ncaused {monsterDamage} damage to You!");
                Game.PlayerRef.ApplyDamage(monsterDamage);
            }
        }