I'm trying to learn swift by creating different short games or apps. while trying to test my new gain knowledge on a game, I realized that I need to create a func that I didnt know how to create. I've looked around and none of the answers I've found really helped me understand what I have to do.
I'll summarize my game:
Its a single view app. I've got five func.
I want to randomly pick a function to be executed.
After the function is executed the user will press a button that runs the random pick function again to randomly pick a func, but this time only out of the four other func that are left, and so on. At the same time once the five functions have been executed I want to restart the pick a random func all over again. so the game goes on and on for ever.
I'm not sure how to place the func In an array to make it work.
For example I've been using the following script in the game.
Func one generates a Label that shows a random string.
I've used the following script to create a random word generator for a label with out repeats and once it runs through all the words in the array it restarts again randomly. (It works perfectly)
struct randword {
var wordstring : String! }
var stentenceword = [randword]
var stentecenumber = Int
func wordsinsentence (){
sentenceword = [randoword(wordstring:"House"), randoword(wordstring:"Truck"), randoword(wordstring:"Ladder")]
}
func pickword(){
if sentenceword.count > 0 {
sentencenumber = random () % sentenceword.count
wordlabel.text = sentecneword[sentencenumber].wordstring
sentenceword.removeAtIndex(sentencenumber)
); if sentenceword.count <= 0{
wordsinsentence() }
Func two generates a random Image using the same script as before, just slightly modified for images.
Func three is a timer game with another script... and so on..etc etc.
Now I want all five func to randomly be picked and removed then once there aren't anymore left to restart, as on the example script I placed above.
I've tried using the same script and modifying it to replace the string! array with a function array, but with no positive result.
Can anyone help me with a solution or showing me another option of how I should do it?
Aucun commentaire:
Enregistrer un commentaire