-
-
Save ScottLilly/b460c4adbe1abde3c7f4 to your computer and use it in GitHub Desktop.
Lesson 08.2 - Using class constructors with derived classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Engine | |
{ | |
public class HealingPotion : Item | |
{ | |
public int AmountToHeal { get; set; } | |
public HealingPotion(int id, string name, string namePlural, int amountToHeal) : base(id, name, namePlural) | |
{ | |
AmountToHeal = amountToHeal; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Engine | |
{ | |
public class Item | |
{ | |
public int ID { get; set; } | |
public string Name { get; set; } | |
public string NamePlural { get; set; } | |
public Item(int id, string name, string namePlural) | |
{ | |
ID = id; | |
Name = name; | |
NamePlural = namePlural; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Engine | |
{ | |
public class LivingCreature | |
{ | |
public int CurrentHitPoints { get; set; } | |
public int MaximumHitPoints { get; set; } | |
public LivingCreature(int currentHitPoints, int maximumHitPoints) | |
{ | |
CurrentHitPoints = currentHitPoints; | |
MaximumHitPoints = maximumHitPoints; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Engine | |
{ | |
public class Monster : LivingCreature | |
{ | |
public int ID { get; set; } | |
public string Name { get; set; } | |
public int MaximumDamage { get; set; } | |
public int RewardExperiencePoints { get; set; } | |
public int RewardGold { get; set; } | |
public Monster(int id, string name, int maximumDamage, int rewardExperiencePoints, int rewardGold, int currentHitPoints, int maximumHitPoints) | |
: base(currentHitPoints, maximumHitPoints) | |
{ | |
ID = id; | |
Name = name; | |
MaximumDamage = maximumDamage; | |
RewardExperiencePoints = rewardExperiencePoints; | |
RewardGold = rewardGold; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Engine | |
{ | |
public class Player : LivingCreature | |
{ | |
public int Gold { get; set; } | |
public int ExperiencePoints { get; set; } | |
public int Level { get; set; } | |
public Player(int currentHitPoints, int maximumHitPoints, int gold, int experiencePoints, int level) : base(currentHitPoints, maximumHitPoints) | |
{ | |
Gold = gold; | |
ExperiencePoints = experiencePoints; | |
Level = level; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Drawing; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows.Forms; | |
using Engine; | |
namespace SuperAdventure | |
{ | |
public partial class SuperAdventure : Form | |
{ | |
private Player _player; | |
public SuperAdventure() | |
{ | |
InitializeComponent(); | |
_player = new Player(10, 10, 20, 0, 1); | |
lblHitPoints.Text = _player.CurrentHitPoints.ToString(); | |
lblGold.Text = _player.Gold.ToString(); | |
lblExperience.Text = _player.ExperiencePoints.ToString(); | |
lblLevel.Text = _player.Level.ToString(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Engine | |
{ | |
public class Weapon : Item | |
{ | |
public int MinimumDamage { get; set; } | |
public int MaximumDamage { get; set; } | |
public Weapon(int id, string name, string namePlural, int minimumDamage, int maximumDamage) : base(id, name, namePlural) | |
{ | |
MinimumDamage = minimumDamage; | |
MaximumDamage = maximumDamage; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment