Skip to content

Instantly share code, notes, and snippets.

@ScottLilly
Created April 19, 2014 15:58
Show Gist options
  • Save ScottLilly/b460c4adbe1abde3c7f4 to your computer and use it in GitHub Desktop.
Save ScottLilly/b460c4adbe1abde3c7f4 to your computer and use it in GitHub Desktop.
Lesson 08.2 - Using class constructors with derived classes
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;
}
}
}
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;
}
}
}
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;
}
}
}
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;
}
}
}
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;
}
}
}
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();
}
}
}
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