using Godot;
using Godot.Collections;
using System;
using System.Collections.Generic;

public partial class remplissage : Node2D
{
	[Export] Array<Texture2D> _textures;
    

    List<string> questions = new List<string>
{
    "Why should I give you a candy ?",
    "Is SAO a good anime ?",
    "Is the earth flat ?",
    "What’s the answer to 1+1 ?",
    "What’s the answer to life ?",
    "I don’t like your cosplay",
    "Man or bear ?",
    "Is it Spooky Month already ?",
    "Do people always smile when they see a dead body ?",
    "Why did the girl fall off the swing ?",
    "▯▉▓◢▍▯▓▓▌▯▓▯▍▯▌▯▯▕◢",
    "What do you taste like ?",
    "With the lights out, is it less dangerous ?",
    "Are you my lover ?",
    "I want your teeth.",
    "There’s so many monsters tonight ! It’s creepy !",
    "Tell me your best villain line !",
    "Is it Christmas ?",
    "Where is my grandma ?",
    "Be honest with me… Am I ugly ?",
    "The sky is so pretty !",
    "Did you have a good day ? Mine was the worst ever.",
    "Can you show me your house ?",
    "Do you believe in ghosts ?",
    "I like going to the cemetery a lot. We can go there together !",
    "Do you know Bob ? I saw him last night going somewhere with a knife.",
    "That guy Bob, I saw him running near the park last night.",
    "I was at the park last night and I heard someone screaming !",
    "My friend Bob asked me two days ago if he could borrow my shovel, but he didn't give it back to me !",
    "I saw a new flower bed in the park this morning. But it was very ugly and there was a flower that looked like a hand.",
    "I discovered this morning that someone stole my car ! There was just a shovel left on the floor !",
    "I heard that the little Georgie is dead. It’s sad to die at this age. No one is safe nowadays.",
    "You know, sometimes I feel like I shouldn’t be here",
    "This book is not good ! I should have known when I saw the creepy face on the cover. Do you want it ?",
    "A weird guy with a mask stalks me everyday ! Can you help me ?",
    "Do you think the sun is black ?",
    "I ate my family. Would you like to taste them ?",
    "I don’t have a good memory. What day is it ?"
};

    List<Node2D> _nodes;
	private int RandSeed = 69;


    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
	{
		int i = 0;
		_nodes = new List<Node2D>();
		foreach (Node2D node in this.GetChildren())
		{
			_nodes.Add(node);
		}
        
		shuffle(_nodes, RandSeed);

		foreach (Node2D node in _nodes)
		{
			if (i < _textures.Count) node.Set("image_mob", _textures[i]);
			i++;
		}
	}

	

	private void shuffle(List<Node2D> nodes, int seed)
	{
		Random rnd = new Random(seed);
		int n = nodes.Count;

		while(n > 1)
		{
			n--;
			int k = rnd.Next(n + 1);
			
			Node2D value = nodes[k];
			nodes[k] = nodes[n];
			nodes[n] = value;
		}
	}
}
