The king hears the prophecy that his daughter will give birth to a son that will one day kill him.
Because the king feared the son that would one day kill him, he locked his daughter up so she could not have a baby.
Even though Princess Danae was locked up in a castle with no doors and only a slit of a opening, she got impregnated and gave birth to her son.
Since the Princess got mysteriously impregnated, the king was fearing that she was under protection of the gods, so, he put the princess and the baby on a boat set them adrift.
They arrived at an island where they were welcomed by King Polydectes, who was eventually fell in love with princess Danae. This is where Perseus grew and blossomed into the best fighter, climber etc on the island. But he had a knack of adventure and I’d not like the peacefulness of the island.
The only way that the king could marry the princess is for him to get rid of Perseus. So, he said that he was getting married wanted gifts from everybody. Perseus said that he would get the head of medusa for him. This was outrageous and he knew that Perseus would fail, die, and he would get to marry the princess. But Perseus knew he would get the head of Medusa. So he went on a quest.