patterncsharpMinor
Up, up and away in a Retro Rocket
Viewed 0 times
andretroawayrocket
Problem
I have seen the Writings on the wall...
But I took this relatively serious and created a
What can I learn from this experience?
```
class VerticalRocket
{
private int _FuselageSections = 2;
public int FuselageSections
{
get
{
return _FuselageSections;
}
set
{
if (value 0)
{
_FuselageSections = value;
}
}
}
public List rocketPartsList = new List();
private string Divider = "+======+";
private List upDesigns = new List
{
@"|../\..../\..|"
, @"|./\/\../\/\.|"
, @"|/\/\/\/\/\/\|"
};
private List downDesigns = new List
{
@"|\/\/\/\/\/\/|"
, @"|.\/\/..\/\/.|"
, @"|..\/....\/..|"
};
private List NoseParts = new List
{
@" /\"
, @" /**\"
, @" //**\\"
, @" ///**\\\"
, @" ////**\\\\"
, @" /////**\\\\\"
};
private List BoosterParts = new List
{
@" //**\\"
, @" ///**\\\"
, @" ////**\\\\"
, @" /////**\\\\\"
};
///
/// Creates a Generic Rocket with 2 Fuselage Sections.
///
public VerticalRocket()
{
rocket(FuselageSections);
}
///
/// creates a rocket with specified number of Fuselage sections
///
/// Number of Fuselage Sections Desired
public VerticalRocket(int sections)
{
FuselageSections = sections;
rocket(FuselageSections);
}
public List Fuselage(bool diamondShape)
{
List fuselage = new List();
if (diamo
- 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 0)
{
_FuselageSections = value;
}
}
}
public List rocketPartsList = new List();
private string Divider = "+======+";
private List upDesigns = new List
{
@"|../\..../\..|"
, @"|./\/\../\/\.|"
, @"|/\/\/\/\/\/\|"
};
private List downDesigns = new List
{
@"|\/\/\/\/\/\/|"
, @"|.\/\/..\/\/.|"
, @"|..\/....\/..|"
};
private List NoseParts = new List
{
@" /\"
, @" /**\"
, @" //**\\"
, @" ///**\\\"
, @" ////**\\\\"
, @" /////**\\\\\"
};
private List BoosterParts = new List
{
@" //**\\"
, @" ///**\\\"
, @" ////**\\\\"
, @" /////**\\\\\"
};
///
/// Creates a Generic Rocket with 2 Fuselage Sections.
///
public VerticalRocket()
{
rocket(FuselageSections);
}
///
/// creates a rocket with specified number of Fuselage sections
///
/// Number of Fuselage Sections Desired
public VerticalRocket(int sections)
{
FuselageSections = sections;
rocket(FuselageSections);
}
public List Fuselage(bool diamondShape)
{
List fuselage = new List();
if (diamo
Solution
- I don't like that the
FuselageSectionssilently discards out of
bounds values, throwing an exception would be better.
-
Maybe there are shorter ways, but
Fuselage can use AddRange aswell:
if (diamondShape)
{
fuselage.AddRange(upDesigns);
fuselage.AddRange(downDesigns);
}
else
{
fuselage.AddRange(downDesigns);
fuselage.AddRange(upDesigns);
}-
wantDiamond can just bebool wantDiamond = sections % 2 == 0;and that (
foo ? true : false or the reverse) is something I'llalways fix if I see it somewhere.
-
ToString can just bereturn String.Join(Environment.NewLine, rocketPartsList);instead.
-
Nose, Booster can all just create a copy with the Listconstructor, i.e.
return new List(BoosterParts);and so on.
Otherwise looks fine; if it was actually part of a larger program I'd
move the parts itself into classes and have them output (
ToString)themselves instead.
Code Snippets
if (diamondShape)
{
fuselage.AddRange(upDesigns);
fuselage.AddRange(downDesigns);
}
else
{
fuselage.AddRange(downDesigns);
fuselage.AddRange(upDesigns);
}bool wantDiamond = sections % 2 == 0;return String.Join(Environment.NewLine, rocketPartsList);return new List<string>(BoosterParts);Context
StackExchange Code Review Q#67470, answer score: 7
Revisions (0)
No revisions yet.