ProgaOra/20240415/WindowsFormsApp1/Form1.cs

164 lines
3.9 KiB
C#
Raw Permalink Normal View History

2024-04-15 09:20:18 +00:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
//Data.words.Add("alma");
//Data.words.Add("számítógép");
for (int i = 0; i < Data.word.Count(); i++)
{
label1.Text += "-";
}
WordToChars(Data.word);
Data.wordchar.Sort();
}
private void button1_Click(object sender, EventArgs e)
{
char guess = Convert.ToChar(textBox1.Text);
if (Isin(guess, Data.word))
{
if (CharNotInList(guess, Data.charfound))
{
2024-04-22 05:11:44 +00:00
Data.charfound.Insert(0, guess);
2024-04-15 09:20:18 +00:00
Data.charfound.Sort();
2024-04-17 10:10:58 +00:00
label1.Text = labelTextChange(label1.Text);
2024-04-15 09:20:18 +00:00
}
if (Samelist(Data.charfound, Data.wordchar))
{
MessageBox.Show("GRATULÁLOK!");
}
} else
{
Data.hiba++;
if (Data.hiba > 11)
{
MessageBox.Show("Sajnos vesztettél.");
Data.hiba = 0;
}
pictureBox1.Image = Image.FromFile($@"images\{Data.hiba}.png");
}
}
public static bool Isin(char x, string word)
{
foreach (char c in word)
{
if (c == x)
{
return true;
}
}
return false;
}
public static void WordToChars(string word)
{
foreach (char c in word)
{
if (CharNotInList(c, Data.wordchar))
{
Data.wordchar.Add(c);
}
}
}
public static bool CharNotInList(char c, List<char> charList)
{
foreach (char x in charList)
{
if (x == c)
{
return false;
}
}
return true;
}
public static bool Samelist(List<char> a, List<char> b)
{
if (a.Count != b.Count)
{
return false;
}
for (int i = 0; i < a.Count; i++)
{
if (a[i] != b[i])
{
return false;
}
}
return true;
}
2024-04-22 05:11:44 +00:00
public string labelTextChange(string current)
2024-04-15 09:20:18 +00:00
{
2024-04-22 05:11:44 +00:00
char[] temp = Data.word.ToCharArray();
char[] sol = current.ToCharArray();
while (Indexofchar(temp) != -1)
{
int a = Indexofchar(temp);
sol[a] = Data.charfound[0];
temp[a] = '_';
}
string asd = sol.ToString();
return asd;
}
public int Indexofchar(char[] arr)
{
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] == Data.wordchar[0])
{
return i;
}
}
return -1;
2024-04-15 09:20:18 +00:00
}
}
public static class Data
{
//public static List<string> words = new List<string>();
public static string word = "alma";
public static List<char> wordchar = new List<char>();
public static List<char> charfound = new List<char>();
public static int hiba = 0;
}
}