Code Red > .NET
A Game in 25 lines.
(1/1)
kdub_nz:
Was challenged to write a RPG in less than 25 lines.
--- Code - C#: ---Console.WriteLine(" -------------------"); GameLoop(); Console.WriteLine(" -------------------"); Console.ReadKey();} private static void GameLoop(){ Random random = new Random(); int monsterHealth = 16, heroHealth = 16, fate = 0; while (( heroHealth > 0 ) && ( monsterHealth > 0 )) { fate = random.Next(1, 11); monsterHealth -= fate; Console.WriteLine($"Monster was damaged and lost {fate} health " + $"and now has {monsterHealth} health."); if (monsterHealth <= 0) { Console.WriteLine("Monster suffers a horrible death !! "); continue; } fate = random.Next(1, 11); heroHealth -= fate; Console.WriteLine($"Hero was wounded and lost {fate} health " + $"and now has {heroHealth} health."); if (heroHealth <= 0) { Console.WriteLine("Hero achieves a heroic martyrdom !! "); } }}
--- Quote --- -------------------
Monster was damaged and lost 1 health and now has 15 health.
Hero was wounded and lost 6 health and now has 10 health.
Monster was damaged and lost 2 health and now has 13 health.
Hero was wounded and lost 3 health and now has 7 health.
Monster was damaged and lost 7 health and now has 6 health.
Hero was wounded and lost 10 health and now has -3 health.
Hero achieves a heroic martyrdom !!
-------------------
--- End quote ---
24 lines in the game loop was a win.
. . . but definitely not Legend of Zelda
It's Alive!:
but line 31 :whistling:
Waiting for the latest Zelda, due out next month , I've played them all!
kdub_nz:
--- Quote from: Beavis on April 07, 2023, 11:11:34 PM ---but line 31 :whistling:
Waiting for the latest Zelda, due out next month , I've played them all!
--- End quote ---
My personal style allows for a single line unnested statement in a conditional when there is a single result action.
. . . . that's my story , and it just happened to reduce the code mass by 2 lines. Lucky, hey? :angel:
This satisfies my rules too :
--- Code - C#: ---if (heroHealth <= 0) { Console.WriteLine("Hero achieves a heroic martyrdom !! "); }
Navigation
[0] Message Index
Go to full version