Saturday, November 9, 2013

Machine Player




One might well be tempted to use random numbers, in the context of a game,to help define the moves of the machine Player. Random is a call to the Randomnumber engine, while random is a call for a run-time number. By putting 4 in the parameters'parentheses, one is specifying a random integer between between 0 and 4, hence one of 5.

What happens next is dependent on drawing number 3.

I have used an enumeration to identify the tiles in the code. Once the button is clicked, one is free to search for a match between the tile number and the random number. If/where there is one, asubsequent colour change occurs.

Enumerations are particualr: it is the index within the enum - an int - which is of interest.




 

No comments: