Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Created by SharpDevelop.
- * User: Admin
- * Date: 8.2.2022 г.
- * Time: 8:11
- *
- * To change this template use Tools | Options | Coding | Edit Standard Headers.
- */
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Windows.Forms;
- using System.IO;
- using System.Linq;
- namespace besene_12a
- {
- /// <summary>
- /// Description of MainForm.
- /// </summary>
- public partial class MainForm : Form
- {
- string[] words;
- string pcWord = "";
- List<string> activeWord = new List<string>();
- List<string> wrongLetters = new List<string>();
- string[] pictures = {"hang1.png", "hang2.png",
- "hang3.png", "hang4.png","hang5.png","hang6.png",
- "hang7.png","hang8.png","hang9.png", "hang10.png"};
- int index = 0;
- public MainForm()
- {
- //
- // The InitializeComponent() call is required for Windows Forms designer support.
- //
- InitializeComponent();
- //
- // TODO: Add constructor code after the InitializeComponent() call.
- //
- }
- void MainFormLoad(object sender, EventArgs e)
- {
- words = File.ReadAllLines("words.txt");
- }
- void ButtonNewGameClick(object sender, EventArgs e)
- {
- labelLetter.Visible = true;
- textBoxLetter.Visible = true;
- buttonCheck.Visible = true;
- labelResult.Visible = false;
- labelWord.ForeColor = Color.Black;
- wrongLetters.Clear();
- activeWord.Clear();
- index = 0;
- Random r = new Random();
- int wordIndex = r.Next(0, words.Length);
- pcWord = words[wordIndex];
- for (int i = 0; i < pcWord.Length; i++)
- {
- activeWord.Add("_");
- }
- labelWord.Text = string.Join(" ", activeWord);
- }
- void ButtonCheckClick(object sender, EventArgs e)
- {
- string userLetter = textBoxLetter.Text.ToLower();
- if (userLetter.Length != 1)
- {
- MessageBox.Show("Въведи буква");
- return;
- }
- if (char.Parse(userLetter) < 'а'
- || char.Parse(userLetter) > 'я')
- {
- MessageBox.Show("Въведи буква между 'а' и 'я'");
- return;
- }
- textBoxLetter.Text = "";
- bool isWrong = true;
- for (int i = 0; i < pcWord.Length; i++)
- {
- if (char.Parse(userLetter) == pcWord[i])
- {
- isWrong = false;
- activeWord[i] = userLetter;
- }
- }
- labelWord.Text = string.Join(" ", activeWord);
- if (!activeWord.Any(x => x == "_"))
- {
- labelLetter.Visible = false;
- textBoxLetter.Visible = false;
- buttonCheck.Visible = false;
- labelWord.ForeColor = Color.Green;
- labelWord.Text = string.Join(" ", activeWord);
- labelResult.Visible = true;
- labelResult.ForeColor = Color.Green;
- labelResult.Text = "ПЕЧЕЛИШ !!!";
- }
- if (isWrong)
- {
- if (!wrongLetters.Contains(userLetter))
- {
- wrongLetters.Add(userLetter);
- labelWrongLetters.Text = string.Join(", ", wrongLetters);
- pictureBox1.Image = Image.FromFile(pictures[index]);
- index++;
- if (index >= pictures.Length)
- {
- labelLetter.Visible = false;
- textBoxLetter.Visible = false;
- buttonCheck.Visible = false;
- labelWord.ForeColor = Color.Red;
- var word = pcWord.ToCharArray();
- labelWord.Text = string.Join(" ", word);
- labelResult.Visible = true;
- labelResult.ForeColor = Color.Red;
- labelResult.Text = "ГУБИШ !!!";
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement