What I have done is set up an abstract class named Quest, I have then established 3 other classes: CollectQuest, LocateQuest and QuestionQuest, all of which inherit generic quest properties from the Quest abstract class.
I am trying to establish a variable which will identify the current state of the quest and initially I went with the option of defining 3 bools:
private bool questAvailable; // True = New Quest Available | False = Quest Not Available.
private bool questPickedUp; // True = Quest Obtained | False = Quest Not Obtained.
private bool questIsComplete; //True = Quest Finished | False = Quest In Progress.
After careful thought I thought that it would be better to establish an enum that will identify the state of a given quest:
private enum questState
{
Available,
NotAvailable,
InProgress,
Finished,
Completed,
NA
}
My abstract Quest class:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Abstract class contains attributes of a generic quest.
/// questAvailable: True = New Quest Available | False = Quest Not Available.
/// questPickedUp: True = Quest Obtained | False = Quest Not Obtained.
/// questIsComplete: True = Quest Finished | False = Quest In Progress.
/// https://msdn.microsoft.com/en-us/library/yd3z1377.aspx
/// https://unity3d.com/learn/tutorials/topics/scripting/enumerations
/// </summary>
public abstract class Quest //: MonoBehaviour
{
private string questName; // The First Job.
private string questDescription; // Collect 3 Planks of Wood.
private string questOrigin; // Town Mayor.
private string questReward; // Initiation Badge.
private int questScore; // Number of stars earned, 1 - 3.
private bool questAvailable; // True or False, indicating if quest can be intitated.
private bool questPickedUp; // True or False, indicating if quest has been picked up.
private bool questIsComplete; // True or False, indicating if quest is completed.
// Quest states.
private enum questState
{
Available,
NotAvailable,
InProgress,
Finished,
Completed,
NA
}
public Quest(string name, string desc, string origin, string reward, int score, bool available, bool pickedUp, bool isComplete, enum state)
{
// Calling the set accessor of the "X" property.
QuestName = name;
QuestDescription = desc;
QuestOrigin = origin;
QuestReward = reward;
QuestScore = score;
QuestAvailable = available;
QuestPickedUp = pickedUp;
QuestIsComplete = isComplete;
}
public string QuestName
{
get
{
return questName;
}
set
{
questName = value;
}
}
public string QuestDescription
{
get
{
return questDescription;
}
set
{
questDescription = value;
}
}
public string QuestOrigin
{
get
{
return questOrigin;
}
set
{
questOrigin = value;
}
}
public string QuestReward
{
get
{
return questReward;
}
set
{
questReward = value;
}
}
public int QuestScore
{
get
{
return questScore;
}
set
{
questScore = value;
}
}
public bool QuestAvailable
{
get
{
return questAvailable;
}
set
{
questAvailable = value;
}
}
public bool QuestPickedUp
{
get
{
return questPickedUp;
}
set
{
questPickedUp = value;
}
}
public bool QuestIsComplete
{
get
{
return questIsComplete;
}
set
{
questIsComplete = value;
}
}
/**public enum QuestState { Available, NotAvailable, InProgress, Finished, Completed, NA }
{
get
{
return quests;
}
set
{
QuestState = value;
}
}**/
}
My issue is on line 37.
An Example of one quest class inheriting from the Quest abstract class:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CollectQuest : Quest
{
private int currentCollectionAmount; // Should start at 0.
private int targetCollectionAmount;
private GameObject itemToCollect;
public CollectQuest(int currentCollectionAmount, int targetCollectionAmount, GameObject itemToCollect, string name, string desc, string origin, string reward, int score, bool available, bool pickedUp, bool isComplete)
: base(name, desc, origin, reward, score, available, pickedUp, isComplete)
{
this.currentCollectionAmount = currentCollectionAmount;
this.targetCollectionAmount = targetCollectionAmount;
this.itemToCollect = itemToCollect;
}
public override string ToString()
{
return "The quest " + QuestName + " that was obtained from " + QuestOrigin + " requires you to collect " + targetCollectionAmount + " " + itemToCollect.name + "." + System.Environment.NewLine
+ "You were awarded with " + QuestReward + " and achieved a total of " + string.Format("{0:}", QuestScore) + " stars.";
}
}
This leaves me with two questions, (I am new to abstract classes and inheritance):
- Is it even possible have an enum as a property of an abstract class which can then be inherited in another class?
- Am I going about this problem in the right way, should I just use a combination of bools to determine the state of a quest?
Any help is appreciated! Thank you very much! ![]()