Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Created by SharpDevelop.
- * User: Admin
- * Date: 21.1.2022 г.
- * Time: 9:15
- *
- * 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;
- namespace besenica
- {
- /// <summary>
- /// Description of MainForm.
- /// </summary>
- public partial class MainForm : Form
- {
- public string[] words;
- public 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 pictureIndex = 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)
- {
- activeWord.Clear();
- wrongLetters.Clear();
- labelWrongLetters.Text = "";
- pictureBox1.Image = null;
- pictureIndex = 0;
- textBoxLetter.Enabled = true;
- buttonCheck.Enabled = true;
- Random r = new Random();
- int index = r.Next(0, words.Length);
- pcWord = words[index];
- for (int i = 0; i < pcWord.Length; i++)
- {
- activeWord.Add(" _ ");
- }
- labelWord.Text = string.Join("", activeWord);
- }
- void ButtonCheckClick(object sender, EventArgs e)
- {
- string letter = textBoxLetter.Text.ToLower();
- if (letter.Length != 1)
- {
- MessageBox.Show("Въведи буква");
- textBoxLetter.Text = "";
- return;
- }
- if (char.Parse(letter) < 'а'|| char.Parse(letter) > 'я')
- {
- MessageBox.Show("Буквата трябва да е между А и Я");
- textBoxLetter.Text = "";
- return;
- }
- textBoxLetter.Text = "";
- bool isPresent = false;
- for (int i = 0; i < pcWord.Length; i++)
- {
- if (char.Parse(letter) == pcWord[i])
- {
- activeWord[i] = " " + letter + " ";
- isPresent = true;
- }
- }
- labelWord.Text = string.Join("", activeWord);
- if (!isPresent)
- {
- if (!wrongLetters.Contains(letter))
- {
- wrongLetters.Add(letter);
- labelWrongLetters.Text = string.Join(", ", wrongLetters);
- pictureBox1.Image = Image.FromFile(pictures[pictureIndex]);
- pictureIndex++;
- if (pictureIndex >= 10)
- {
- textBoxLetter.Enabled = false;
- buttonCheck.Enabled = false;
- MessageBox.Show("Губите");
- return;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement