using System;
namespace Console game
{
public class LookCommand : Command
{
public LookCommand(string[] idents):base(idents)
{
}
public override string Execute(Player p, string[] text)
{
/// <summary>
/// Trial 1
/// </summary>
/// <returns>The container.</returns>
/// <param name="p">P.</param>
/// <param name="ContainerId">Container identifier.</param>
if (text.Length == 3 || text.Length == 5)
{
if (text[0] == "look")
{
if (text[1] == "at")
{
if (text.Length == 5)
{
if (text[3] == "in")
{
IHaveInventery container = FetchContainer(p, text[4]);
if (container != null)
{
if (container.locate(text[2]) != null)
{
return LookAtIn(text[2], container);
}
else
{
return "I can't find<<" + text[2] + ">> in <<" + text[4] + ">>";
}
}
}
else
{
return "what do you want to look in ?";
}
}
if(text.Length == 3)
{
IHaveInventery container = p as IHaveInventery;
return LookAtIn(text[2], container);
}
else
{
return "I can't find<<" + text[2] + ">>";
}
}
else
{
return "What do you want to look at ?";
}
}
else
{
return "Error in look input";
}
}
else
{
return "I don't know how to look at that !";
}
}
private IHaveInventery FetchContainer(Player p, string ContainerId)
{
return p.Locate(ContainerId) as IHaveInventery;
}
private string LookAtIn(string thingId, IHaveInventery Container)
{
return Container.locate(thingId).FullDescription;
}
}
}
I am beginner of programming there must be syntax or logic error occurred. They would not past the Unittest. Error
Aucun commentaire:
Enregistrer un commentaire