-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
99 lines (82 loc) · 2.94 KB
/
Program.cs
File metadata and controls
99 lines (82 loc) · 2.94 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
// // creates 3 heroes
// Console.WriteLine("\nInitial Hero Info");
// // uses default constructor, the hero gets default values that was set in Hero()
// Hero hero1 = new Hero();
// // uses parameterized constructor
// Hero hero2 = new Hero("Star", "Mage", 85, 25);
// // pass invalid health and attack power on purpose to show validation working
// // the property setters print messages and cut off at 0 and 1
// Hero hero3 = new Hero("Legolas", "Archer", 110, -5);
// // current state of each hero
// hero1.DisplayHeroInfo();
// hero2.DisplayHeroInfo();
// hero3.DisplayHeroInfo();
// // test taking damage with different amounts
// Console.WriteLine("\nDamage Tests");
// hero1.TakeDamage(15); // 100 -> 85
// hero2.TakeDamage(40); // 85 -> 45
// hero3.TakeDamage(60); // this is already cut off at 0 so it stays 0
// hero3.TakeDamage(5); // still stays 0
// // show attack messages (uses AttackPower)
// Console.WriteLine("\nAttack Tests");
// hero1.PerformAttack("Goblin");
// hero2.PerformAttack("Orc");
// hero3.PerformAttack("War Elephant");
// // try invalid values manually to text validation
// Console.WriteLine("\nValidation Tests");
// hero1.Health = 999; // invalid, sets to 0
// hero1.AttackPower = 0; // invalid, sets to 1
// hero1.DisplayHeroInfo(); // confirm it
// // keeps console window open
// Console.WriteLine("\nPress any key to exit...");
// Console.ReadKey();
// Assignment Hero Builder: Specialization below
// Hero mis abstract now, so cannot do new Hero()
// instead I create specialized heroes instead
Warrior w1 = new Warrior(
name: "Leonidas",
heroType: "Warrior",
health: 95,
attackPower: 22,
weaponType: "Spear"
);
Mage m1 = new Mage(
name: "Gandalf",
heroType: "Mage",
health: 80,
attackPower: 27,
spellType: "Lightning"
);
// show individual details (overriden methods include class specific info)
Console.WriteLine("\nIndividual Hero Info");
w1.DisplayHeroInfo();
m1.DisplayHeroInfo();
// unique specials (Bastract method implemenetd per type)
Console.WriteLine("\nSpecial Abilities");
w1.PerformSpecialAbility();
m1.PerformSpecialAbility();
// inherited and overriden behavior
Console.WriteLine("\nAttack and Damage Tests");
w1.PerformAttack("War Elephant");
m1.PerformAttack("Orc Chief");
w1.TakeDamage(30);
m1.TakeDamage(50);
// polymorphism here
// treats warrior and mage as their base type (hero) in one collection
List<Hero> party = new List<Hero> { w1, m1 };
Console.WriteLine("\nParty Roster (Polymorphic Loop)");
foreach (Hero h in party)
{
// overriden methods called
// based on actual runtime type so warrior or mage
h.DisplayHeroInfo();
h.PerformSpecialAbility();
}
// tests
Console.WriteLine("\nValidation Check (reusing base rules)");
w1.Health = 150; // invalid, prints message and cuts off at 0
m1.AttackPower = 0; // invalid, prints message and cuts off at 1
w1.DisplayHeroInfo();
m1.DisplayHeroInfo();
Console.WriteLine("\nPress any key to exit...");
Console.ReadKey();