I have seen the Writings on the wall...
- Retro Rocket ASCII Art
- Nested for-loop art
- Print the Retro Rocket
- Maybe a golfed C# answer from me
But I took this relatively serious and created a VerticalRocket
class that I would like reviewed, kind of like a little "am I getting better at writing code" project/review experience (granted this was done while waiting for code to compile and queries to run).
What can I learn from this experience?
class VerticalRocket
{
private int _FuselageSections = 2;
public int FuselageSections
{
get
{
return _FuselageSections;
}
set
{
if (value <= 100 && value > 0)
{
_FuselageSections = value;
}
}
}
public List<string> rocketPartsList = new List<string>();
private string Divider = "+=*=*=*=*=*=*+";
private List<string> upDesigns = new List<string>
{
@"|../\..../\..|"
, @"|./\/\../\/\.|"
, @"|/\/\/\/\/\/\|"
};
private List<string> downDesigns = new List<string>
{
@"|\/\/\/\/\/\/|"
, @"|.\/\/..\/\/.|"
, @"|..\/....\/..|"
};
private List<string> NoseParts = new List<string>
{
@" /\"
, @" /**\"
, @" //**\\"
, @" ///**\\\"
, @" ////**\\\\"
, @" /////**\\\\\"
};
private List<string> BoosterParts = new List<string>
{
@" //**\\"
, @" ///**\\\"
, @" ////**\\\\"
, @" /////**\\\\\"
};
/// <summary>
/// Creates a Generic Rocket with 2 Fuselage Sections.
/// </summary>
public VerticalRocket()
{
rocket(FuselageSections);
}
/// <summary>
/// creates a rocket with specified number of Fuselage sections
/// </summary>
/// <param name="sections">Number of Fuselage Sections Desired</param>
public VerticalRocket(int sections)
{
FuselageSections = sections;
rocket(FuselageSections);
}
public List<string> Fuselage(bool diamondShape)
{
List<string> fuselage = new List<string>();
if (diamondShape)
{
foreach (string line in upDesigns)
{
fuselage.Add(line);
}
foreach (string line in downDesigns)
{
fuselage.Add(line);
}
}
else
{
foreach (string line in downDesigns)
{
fuselage.Add(line);
}
foreach (string line in upDesigns)
{
fuselage.Add(line);
}
}
return fuselage;
}
public List<string> Nose()
{
List<string> nose = new List<string>();
foreach (string line in NoseParts)
{
nose.Add(line);
}
return nose;
}
public List<string> Booster()
{
List<string> booster = new List<string>();
foreach (string line in BoosterParts)
{
booster.Add(line);
}
return booster;
}
public void rocket(int sections)
{
bool wantDiamond = sections % 2 == 0 ? true : false; //this will keep the X at the bottom
rocketPartsList.AddRange(Nose());
rocketPartsList.Add(Divider);
for (int i = 0; i < sections; i++)
{
rocketPartsList.AddRange(Fuselage(wantDiamond));
wantDiamond = !wantDiamond;
rocketPartsList.Add(Divider);
}
rocketPartsList.AddRange(Booster());
}
public override string ToString()
{
string output = "";
foreach (string line in rocketPartsList)
{
output += line + Environment.NewLine;
}
return output;
}
}
Note
Up-To-Date code can be found on my Github Repo