Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialFredrik Rönnehag
2,342 PointsCreating the tower[] object
Error message: Error CS7036 There is no argument given that corresponds to the required formal parameter 'path' of 'Tower.Tower(MapLocation, Path)'
Game.cs
// Lines causing the error
Tower[] towers = {
new Tower(new MapLocation(1,3,map)),
new Tower(new MapLocation(3,3,map)),
new Tower(new MapLocation(5,3,map))
};
Tower.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TowerDefenseGame
{
class Tower
{
private readonly MapLocation _mapLocation;
private const int _turretRange = 1;
private const int _turretPower = 1;
public Tower(MapLocation location, Path path)
{
for (int i = 0; i < path.Length; i++)
{
MapLocation pathToCheck = path.GetLocationAt(i);
if(location.X == pathToCheck.X && location.Y == pathToCheck.Y)
{
throw new OutOfBoundsException("Towers can't be placed on a path");
}
}
_mapLocation = location;
}
public void FireOnInvaders(Invader[] invaders)
{
foreach(var invader in invaders)
{
if (invader.IsActive && _mapLocation.InRangeOf(invader.Location, _turretRange))
{
invader.DecreaseHealth(_turretPower);
break;
}
}
}
}
}
1 Answer
Fredrik Rönnehag
2,342 PointsFound the error!
public Tower(MapLocation location)
{
l_location = location;
}
Needed to create a second constructor.