I am creating a rock paper scissors game in Pascal for my computer science class at university.
I have the code where I type 0, 1, or 2 to represent rock, paper, or scissors and that is fully random.
I was wondering if there was a way to make the letters r,p,s random to stand for rock, paper, or scissors instead of using the numbers.
I have tried to randomize this game with r,p and s. Does the random "command" only work for numbers, and if so, is their a command to randomize letters?).
Thank you for taking the time to read this! If you have any questions please feel free to ask me, thanks!
ps. I don't know if you know what I am talking about but I tried to post the code for over half an hour at 5 am and it still isn't formatted correctly and wont let me post it, sorry I'm new to this.
You can define an enum and then get the highest value in the enum with HIGH(). Then convert to integer using ORD, and add one, to get the number of elements in the enum. Call random, and cast back to enum type.
Free Pascal allows to write enum values to the console as demonstrated, this might not work with e.g. Delphi.
Maybe it can be generalized to a generics function, but I'm not that familiar with those.