-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextRPG.cs
More file actions
108 lines (98 loc) · 3.59 KB
/
textRPG.cs
File metadata and controls
108 lines (98 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
class Program
{
static void Main()
{
Console.Clear();
// Start of the program
Random random = new Random();
int heroHP = 100,
monsterHP = 100;
bool isHeroDefending = false,
isMonsterDefending = false;
while (heroHP > 0 && monsterHP > 0)
{
Console.WriteLine($"Hero's health: {heroHP}\tMonster's health: {monsterHP}");
Console.WriteLine("What do you want to do?\n1. Attack\t2. Defend\t3. Heal");
isHeroDefending = false;
bool validInput;
do
{
validInput = true;
string? input = Console.ReadLine();
// Hero's turn
if (int.TryParse(input, out int action))
{
if (action == 1) // Attack
{
int damage = random.Next(1, 10);
if (isMonsterDefending)
{
Console.WriteLine($"The monster defended your {damage} damage attack!");
damage /= 2;
}
monsterHP -= damage;
Console.WriteLine($"You hit the monster for {damage} damage!");
}
else if (action == 2) // Defend
{
isHeroDefending = true;
Console.WriteLine("You prepare to defend.");
}
else if (action == 3) // Heal
{
int heal = random.Next(1, 10);
heroHP += heal;
if (heroHP > 100)
heroHP = 100;
Console.WriteLine($"You healed for {heal} health!");
}
else
{
Console.WriteLine("Invalid action! Please choose 1, 2, or 3.");
validInput = false;
}
}
else
{
Console.WriteLine("Invalid input! Please enter a number.");
validInput = false;
}
} while (validInput == false);
// Monster's turn
int monsterAction = random.Next(1, 4);
isMonsterDefending = false;
if (monsterAction == 1) // Attack
{
int damage = random.Next(1, 10);
if (isHeroDefending)
{
Console.WriteLine($"You defended the monster's {damage} damage attack!");
damage /= 2;
}
heroHP -= damage;
Console.WriteLine($"The monster hit you for {damage} damage!");
}
else if (monsterAction == 2) // Defend
{
isMonsterDefending = true;
Console.WriteLine("The monster is preparing to defend.");
}
else if (monsterAction == 3) // Heal
{
int heal = random.Next(1, 10);
monsterHP += heal;
if (monsterHP > 100)
monsterHP = 100;
Console.WriteLine($"The monster healed for {heal} health!");
}
Console.WriteLine("\n");
}
// End of the battle
Console.WriteLine("Battle over!");
if (heroHP <= 0)
Console.WriteLine("The Monster won!");
else
Console.WriteLine("You won!");
}
}