@@ -137,8 +137,52 @@ void printNumbers() {
137137 printf (" |\n " );
138138}
139139
140+ static void printShipDistributionTable () {
141+ using namespace std ::string_view_literals;
142+
143+ std::cout
144+ << " The board will be populated with ships of the following sizes:\n\n " ;
145+
146+ const auto maxShipSize = ShipDistribution.size () + 1U ;
147+ const auto maxShipAmount =
148+ *std::max_element (ShipDistribution.begin (), ShipDistribution.end ());
149+
150+ constexpr std::string_view lengthLabel = " Ship length" sv;
151+ constexpr std::string_view amountLabel = " Number of ships" sv;
152+
153+ const auto maxShipSizeWidth =
154+ std::max (std::max (lengthLabel.size (), static_cast <std::size_t >(1U )),
155+ static_cast <std::size_t >(std::ceil (std::log10 (maxShipSize))));
156+ const auto maxShipAmountWidth = std::max (
157+ std::max (amountLabel.size (), static_cast <std::size_t >(1U )),
158+ static_cast <std::size_t >(std::ceil (std::log10 (maxShipAmount))));
159+
160+ std::cout << lengthLabel << " | " << amountLabel << ' \n ' ;
161+ for (std::size_t dashCounter = 0 ;
162+ dashCounter < lengthLabel.size () + amountLabel.size () + 3U ;
163+ dashCounter++)
164+ std::cout << ' -' ;
165+ std::cout << ' \n ' ;
166+
167+ std::for_each (ShipDistribution.begin (), ShipDistribution.end (),
168+ [&maxShipSizeWidth, &maxShipAmountWidth,
169+ shipSize = 0ULL ](const std::uint_least8_t amount) mutable {
170+ if (amount > 0 ) {
171+ std::cout << std::setw (maxShipSizeWidth) << shipSize++
172+ << " | " << std::setw (maxShipAmountWidth)
173+ << std::to_string (amount) << ' \n ' ;
174+ } else
175+ shipSize++;
176+ });
177+
178+ std::cout << std::endl;
179+ }
180+
140181/*
141- Used to print a short tutorial on game start
182+ Used to print a short tutorial on game start.
183+ This includes some gameplay instructions,
184+ the table of which symbols represent what
185+ and an overview of the ship amounts.
142186*/
143187void printTutorial () {
144188 clearScreen ();
@@ -158,6 +202,9 @@ void printTutorial() {
158202 for (size_t lines = 0 ; lines <= 70 ; lines++)
159203 std::cout << ' -' ;
160204 std::cout << ' \n ' ;
205+
206+ printShipDistributionTable ();
207+
161208 waitForReturn ();
162209}
163210/*
0 commit comments