2022-11-27 18:58:30 +01:00
|
|
|
using Godot;
|
|
|
|
|
using System;
|
|
|
|
|
|
2022-12-31 05:51:34 +01:00
|
|
|
namespace lettergodot
|
2022-11-27 18:58:30 +01:00
|
|
|
{
|
2022-12-31 05:51:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
public class Letterbox : Node2D
|
2022-11-27 18:58:30 +01:00
|
|
|
{
|
2022-12-31 05:51:34 +01:00
|
|
|
// Called when the node enters the scene tree for the first time.
|
|
|
|
|
public override void _Ready()
|
2022-11-27 18:58:30 +01:00
|
|
|
{
|
2022-12-31 05:51:34 +01:00
|
|
|
// assign random letters to all the child nodes of type Letter
|
|
|
|
|
foreach (var letter in GetChildren())
|
2022-11-27 18:58:30 +01:00
|
|
|
{
|
2022-12-31 05:51:34 +01:00
|
|
|
if (letter is Letter)
|
|
|
|
|
{
|
|
|
|
|
((Letter)letter).Value = RandomLetterAsAString();
|
|
|
|
|
}
|
2022-11-27 18:58:30 +01:00
|
|
|
}
|
2022-12-31 05:51:34 +01:00
|
|
|
|
2022-11-27 18:58:30 +01:00
|
|
|
}
|
|
|
|
|
|
2022-12-31 05:51:34 +01:00
|
|
|
// method that returns a string with a random capital letter inside
|
|
|
|
|
private string RandomLetterAsAString()
|
|
|
|
|
{
|
|
|
|
|
var random = new Random();
|
|
|
|
|
var randomLetter = (char)random.Next('A', 'Z' + 1);
|
|
|
|
|
return randomLetter.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|