I am creating a console zombie survival game that is suppose be random and be fairly complex, such as finding multiple weapons, and ammo types. However, I believe that I could save an object in array to use it again later, for correct information, but this way does not work.
I have tried looking of storing objects in arrays with no luck. I have tried to change the arrays from Item based to Object based with no luck.
class Firearm : Weapon
{
public Firemode firemode;
public int maxCapacity;
public int curCapacity;
public Type type;
public Caliber caliber;
public Firearm (string _name, float _damage, int _range, Firemode
_firemode, int _maxCapacity, int _curCapacity, Type _type, Caliber
_caliber)
{
name = _name;
damage = _damage;
range = _range;
firemode = _firemode;
maxCapacity = _maxCapacity;
curCapacity = _curCapacity;
type = _type;
caliber = _caliber;
}
public void FirearmStats()
{
Console.WriteLine("\n Name: {0}\n Damage: {1}\n Range: {2}\n
Firemode: {3}\n Max Capacity: {4}\n Current Capacity: {5}", name, damage,
range, firemode, maxCapacity, curCapacity);
}
}
static void Main(string[] args)
{
Random numberGenerator = new Random();
//Pistols
Firearm m9 = new Firearm("Beretta M9A1", 34.0F, 30,
Firemode.SemiAutomatic, 15, numberGenerator.Next(1, 16), Type.Pistol,
Caliber.nine);
....
Item[] inventory = new Item[14];
Item[] equipped = new Item[0];
.....
equipped[0] = m9;
Console.WriteLine("\nYou find a {0}", equipped[0].name);
//issue here with equipped[0]^^^
equipped[0].FirearmStats();
//and here ^^^^^
player.Command();
}
Severity Code Description Project File Line Suppression State Error CS1061 'Program.Item' does not contain a definition for 'FirearmStats' and no accessible extension method 'FirearmStats' accepting a first argument of type 'Program.Item' could be found (are you missing a using directive or an assembly reference?) ZombieConsoleGame E:\Visual Studio Projects\ZombieConsoleGame\ZombieConsoleGame\Program.cs 158 N/A