CreateTileDirectory

From TRCCompSci - AQA Computer Science
Revision as of 14:11, 21 September 2017 by M0hk4l3 (talk | contribs) (Created page with "This may may be kind of bewildering to any who look at it with no previous knowledge of what this class does; a problem which isn't helped by the utter lack of documentation o...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This may may be kind of bewildering to any who look at it with no previous knowledge of what this class does; a problem which isn't helped by the utter lack of documentation or comments sorrounding it (do not grow up to become a programmer like this, ladies and gentlemen). But like any problem, with enough dedication one can decode what it's trying to do.

Recall in the "A-Level Comp Science_PM 2018 E8.PDF" file, it is stated that different words have different point values associated with them. This method tries to create a cross reference dictionary which can take a character value and convert it to the corresponding integer\point value which the character relates to. Once u understand this the method becomes quite the simple affair (although like many other things in this program, it's no less inefficient).

Firstly the method defines 3 seperate arrays of varying lengths. Each array stores a character index and the instance itself is used to determine the point value for the indexes. So for example, all the character indexes in the array "Value1" have a point value of 1. Those in the array "Value2" have a point value of 2 and in "Value3" have a point value of 3. At this point u may be wondering where the associations for characters with point values of 5 are, that comes later.

The method now iterates in range of 1 to 26 using index notation which begins at 0 and will end by 25. The next part requires some existing knowledge of the .NET platform or CLR, namely the return value of the method Array.IndexOf. This method loops through an array and returns the first found index of a given value; in the off case it can't find the index it returns a -1 value. Knowing this, the method then compares the current index within the for-loop (named Count) with consecutive array it defined before. Once it finds that an array contains the given index (and therefore returns a value > 1 or > && = 0 if u prefer) it adds the character value along with the desired point value. Note if the index is not contained within any of the 3 defined Arrays, the point value is assumed to be 5.