need to make the arrangement of words on the field 10x10, so that if the words intersect, then only with the same letters and so that a copy of the letter is not created at the intersection.
extends Spatial
var words
var way = ['leftToRight', 'rightToLeft', 'upToDown', 'downToUp']
func chooseWords(amount, theme):
var words = []
var file = File.new()
file.open(variables.dictionariesTres.get(theme), File.READ)
while !file.eof_reached():
words.append(file.get_line())
file.close()
var selected = []
for number in range(amount):
while true:
var select = words[randi()%len(words)]
if not(select in selected):
selected.append(select)
break
return selected
func chooseTheme():
return variables.dictionaries[randi()%len(variables.dictionaries)]
func setWordsOnField(words):
var way = 'leftToRight'
var wordsPositions = []
for word in words:
var position = [randi()%10, randi()%10]
while position in wordsPositions or position[0] + len(word) > 9:
position = [randi()%10, randi()%10]
if way == 'leftToRight':
wordsPositions.append(position)
for index in range(len(word)):
var letter = load(variables.alphabetObj[word[index].to_upper()]).instance()
letter.translate(Vector3((position[0] + index) * 3, 0, position[1] * 3))
add_child(letter)
func _ready():
randomize()
var theme = chooseTheme()
$theme.text = theme
words = chooseWords(3, theme)
setWordsOnField(words)
the problem is that words sometimes intersect to form a mixture of several letters.
I will be glad if, in addition to the direction from left to right, you do others, I also thought about the same directions only on the diagonal.
link to the project if needed: https://drive.google.com/file/d/1AH9ojG7YO9AWBuzBFCmbxX6mtIyYmysB/view?usp=sharing