From 4057c69e3a4c4e59189195250dd64e6264256e4d Mon Sep 17 00:00:00 2001 From: AndresGS Date: Wed, 13 Dec 2023 10:57:08 +0100 Subject: [PATCH] Reto #47 c# --- .../c#/AndresGraneroSala.cs" | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 "Retos/Reto #47 - LA PALABRA DE 100 PUNTOS [F\303\241cil]/c#/AndresGraneroSala.cs" diff --git "a/Retos/Reto #47 - LA PALABRA DE 100 PUNTOS [F\303\241cil]/c#/AndresGraneroSala.cs" "b/Retos/Reto #47 - LA PALABRA DE 100 PUNTOS [F\303\241cil]/c#/AndresGraneroSala.cs" new file mode 100644 index 0000000000..c8d65957f0 --- /dev/null +++ "b/Retos/Reto #47 - LA PALABRA DE 100 PUNTOS [F\303\241cil]/c#/AndresGraneroSala.cs" @@ -0,0 +1,89 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; +using System.Text; +using System; +using System.Globalization; +using System.Text; + +/* + *Este script está hecho para unity el proyecto completo está en https://github.com/AndresGraneroSala/retos-semanales-mouredev + */ + + +public class ManagerInput : MonoBehaviour +{ + [SerializeField] private InputField input; + private const int numA32bit= 97; + private const int numÑAlphabet= 15; + private const int totalLettersInAlphabet=27; + + [SerializeField] private GameObject prefab; + [SerializeField] private Transform content; + + private void Start() + { + GoBackEdit(); + } + + public void SubmitWord() + { + if (string.IsNullOrEmpty( input.text)) {return;} + if (string.IsNullOrWhiteSpace( input.text)) {return;} + + string word = input.text; + + if(input.text==""){return;} + + char[] letters = word.Replace(" ","").ToCharArray(); + + int points = 0; + + foreach (var letter in letters) + { + points += GetPointsLetter(letter); + } + + GameObject textPoints = Instantiate(prefab,content); + textPoints.GetComponent().text = $"Points: {points} - Word: {word}"; + + if (points==100) + { + textPoints.GetComponent().color= Color.yellow; + } + + + input.text = ""; + + } + + int GetPointsLetter(char letter) + { + if (char.ToLower(letter) == 'ñ'){return numÑAlphabet;} + + + int points = 0; + + char letterClear = letter.ToString().Normalize(NormalizationForm.FormD).ToLower()[0]; + print(letter); + + int letterPos32bit = Convert.ToInt32(char.ToLower(letterClear)); + + if (letterPos32bitnumA32bit+26) + {/*no letter*/ return 0;} + + + bool isUpperÑ = letterPos32bit >= numA32bit + numÑAlphabet - 1; + + points += letterPos32bit - (numA32bit - 1); + points += isUpperÑ ? 1 : 0; + return points; + } + + public void GoBackEdit() + { + input.ActivateInputField(); + } +}