Advertisement
sergezhu

Untitled

Apr 30th, 2023
622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.49 KB | None | 0 0
  1. namespace ConsoleApp1;
  2.  
  3. using System.Text;
  4.  
  5. public class Task19
  6. {
  7.     public void Run()
  8.     {
  9.         Console.InputEncoding = Encoding.Unicode;
  10.         Console.OutputEncoding = Encoding.Unicode;
  11.        
  12.         int bossAttackPower = 66;
  13.         int bossMaxHealth = 600;
  14.         int playerMaxHealth = 400;
  15.  
  16.         string shadowSpiritSummonSpellName = "Shadow Spirit Summon";
  17.         int shadowSpiritSummonSpellPower = 50;
  18.  
  19.         string fireDogsSummonSpellName = "Fire Dogs Summon";
  20.         int fireDogsSummonSpellPower = 90;
  21.  
  22.         string dimensionalRiftJumpSpellName = "Dimensional Rift Jump";
  23.         int dimensionalRiftJumpSpellPower = 250;
  24.         int dimensionalRiftJumpSpellHealthBound = 50;
  25.  
  26.         string reflectShieldSpellName = "Reflect Shield";
  27.         int reflectShieldSpellPower = 25;
  28.         int reflectShieldSpellDuration = 3;
  29.         int reflectShieldSpellRemainedTurns = 0;
  30.  
  31.         int bossHealth = bossMaxHealth;
  32.         int playerHealth = playerMaxHealth;
  33.         string previousSpellName = string.Empty;
  34.        
  35.         bool canExit = false;
  36.  
  37.         while ( canExit == false )
  38.         {
  39.             bool canUseShadowSpiritSummonSpell = true;
  40.             bool canUseFireDogsSummonSpell = string.Equals( previousSpellName, shadowSpiritSummonSpellName );
  41.             bool canUseDimensionalRiftJumpSpell = playerHealth <= dimensionalRiftJumpSpellHealthBound;
  42.             bool canUseReflectShieldSpell = reflectShieldSpellRemainedTurns == 0;
  43.  
  44.             string spellsList = "Select spell (type name for use): \n";
  45.            
  46.             if( canUseShadowSpiritSummonSpell )
  47.                 spellsList = $"{spellsList}#  {shadowSpiritSummonSpellName} \n";
  48.            
  49.             if( canUseFireDogsSummonSpell )
  50.                 spellsList = $"{spellsList}#  {fireDogsSummonSpellName} \n";
  51.            
  52.             if( canUseDimensionalRiftJumpSpell )
  53.                 spellsList = $"{spellsList}#  {dimensionalRiftJumpSpellName} \n";
  54.            
  55.             if( canUseReflectShieldSpell )
  56.                 spellsList = $"{spellsList}#  {reflectShieldSpellName} \n";
  57.            
  58.             Console.WriteLine(spellsList);
  59.  
  60.             string selectedSpellName = string.Empty;
  61.             bool isSelectedSpellProperly = false;
  62.  
  63.             while ( isSelectedSpellProperly == false )
  64.             {
  65.                 selectedSpellName = Console.ReadLine();
  66.  
  67.                 isSelectedSpellProperly = string.Equals( selectedSpellName, shadowSpiritSummonSpellName ) && canUseShadowSpiritSummonSpell;
  68.                 isSelectedSpellProperly |= string.Equals( selectedSpellName, fireDogsSummonSpellName ) && canUseFireDogsSummonSpell;
  69.                 isSelectedSpellProperly |= string.Equals( selectedSpellName, dimensionalRiftJumpSpellName ) && canUseDimensionalRiftJumpSpell;
  70.                 isSelectedSpellProperly |= string.Equals( selectedSpellName, reflectShieldSpellName ) && canUseReflectShieldSpell;
  71.                
  72.                 if(isSelectedSpellProperly == false)
  73.                     Console.WriteLine("Entered invalid spell, try again:");
  74.             }
  75.  
  76.            
  77.             if ( string.Equals( selectedSpellName, shadowSpiritSummonSpellName ) )
  78.             {
  79.                 bossHealth -= shadowSpiritSummonSpellPower;
  80.                 Console.WriteLine( $"Player deal damage {shadowSpiritSummonSpellPower}, boss health is {bossHealth} now" );
  81.             }
  82.  
  83.             if ( string.Equals( selectedSpellName, fireDogsSummonSpellName ) )
  84.             {
  85.                 bossHealth -= fireDogsSummonSpellPower;
  86.                 Console.WriteLine( $"Player deal damage {fireDogsSummonSpellPower}, boss health is {bossHealth} now" );
  87.  
  88.             }
  89.  
  90.             if ( string.Equals( selectedSpellName, dimensionalRiftJumpSpellName ) )
  91.             {
  92.                 playerHealth += dimensionalRiftJumpSpellPower;
  93.                 Console.WriteLine( $"Player restore {dimensionalRiftJumpSpellPower} hitpoints, player health is {playerHealth} now" );
  94.             }
  95.  
  96.             if ( string.Equals( selectedSpellName, reflectShieldSpellName ) )
  97.             {
  98.                 reflectShieldSpellRemainedTurns = reflectShieldSpellDuration;
  99.                 Console.WriteLine( $"Reflect shield has been activated on {reflectShieldSpellDuration} turns" );
  100.             }
  101.  
  102.             bool isBossDead = bossHealth <= 0;
  103.             previousSpellName = selectedSpellName;
  104.  
  105.             if ( isBossDead == false )
  106.             {
  107.                 playerHealth -= bossAttackPower;
  108.                 Console.WriteLine( $"Boss deal damage {bossAttackPower}, player health is {playerHealth} now" );
  109.  
  110.                 if ( reflectShieldSpellRemainedTurns > 0 )
  111.                 {
  112.                     bossHealth -= reflectShieldSpellPower;
  113.                     reflectShieldSpellRemainedTurns--;
  114.                     Console.WriteLine( $"Reflect shield deal damage {reflectShieldSpellPower}, " +
  115.                                        $"remained {reflectShieldSpellRemainedTurns} turns, boss health is {bossHealth} now" );
  116.                 }
  117.             }
  118.             else
  119.             {
  120.                 Console.WriteLine("Boss is dead. Player win.");
  121.             }
  122.  
  123.             bool isPlayerDead = playerHealth <= 0;
  124.  
  125.             if ( isPlayerDead )
  126.             {
  127.                 Console.WriteLine( "Player is dead. Player lose." );
  128.             }
  129.            
  130.             Console.WriteLine();
  131.  
  132.             canExit = isPlayerDead || isBossDead;
  133.         }
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement