-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6076 from AndresGraneroSala/main
Reto #47 c#
- Loading branch information
Showing
1 changed file
with
89 additions
and
0 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
Retos/Reto #47 - LA PALABRA DE 100 PUNTOS [Fácil]/c#/AndresGraneroSala.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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>().text = $"Points: {points} - Word: {word}"; | ||
|
||
if (points==100) | ||
{ | ||
textPoints.GetComponent<Text>().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 (letterPos32bit<numA32bit|| letterPos32bit>numA32bit+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(); | ||
} | ||
} |