Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Gurra98 |
Hi! i’m trying to learn coding just for fun and I came up with an simple idea for a wordgame. it’s gridbased using a 10x8 grid with letterpieces that can be swapped around to match words, pretty similar to how you match 3 pieces in candycrush. so i’m using this tutorial series on youtube https://www.youtube.com/watch?v=YhykrMFHOV4&list=PL4vbr3u7UKWqwQlvwvgNcgDL1p_3hcNn2. I’m using almost the same code as in the videos but change it a bit so it suits my specific needs better. however i’ve been stuck on a problem when it comes to finding the words, so i have questions. this is my function for finding words `func find_words_length_of_3():
for i in width:
for j in height:
if all_pieces[i][j] != null:
if i> 0 && i < width -1:
if all_pieces[i-1][j] !=null && all_pieces[i+1][j] !=null:
if all_pieces[i-1][j].letter == word[0][0] && all_pieces[i][j].letter == word[0][1] && all_pieces[i+1][j].letter == word[0][2]:
all_pieces[i-1][j].matched = true
all_pieces[i-1][j].dim()
all_pieces[i][j].matched = true
all_pieces[i][j].dim()
all_pieces[i+1][j].matched = true
all_pieces[i+1][j].dim()
“word” is an array of words I made.
the problem I’m having is that with this solution, is that I need to repeat the func for every single word, changing the word[0][…] to word[1][…] and so on. So my first question is if it is possible to make the func check next word in the array by itself without me needing to repeat the code for every word? I tried a solution by my own that looked like thisif all_pieces[i-1][j].letter !=word[0][0]: word += 1 if all_pieces[i][j].letter !=word[0][1]: word +=1 if all_pieces[i+1][j] !=word[0][2]: word +=1
but it just crashes the game.
My second question is, How do I import a wordlist/dictionary in to the project? And how do i sort it so 3 letters words comes first then 4 letters and so on? I think the most optimal would be if I could divide the words into different arrays according to how many letters they have.
As you might notice I’m really new to coding and most likely have done several major mistakes. I hope i can get an nice answer anyways;-).