Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 2. Napravite jednostavnu igru vješala. Pojmovi se učitavaju u listu iz datoteke, i u
- svakoj partiji se odabire nasumični pojam iz liste. Omogućiti svu
- funkcionalnost koju biste očekivali od takve igre. Nije nužno crtati vješala,
- dovoljno je na labeli ispisati koliko je pokušaja za odabir slova preostalo.*/
- 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 LV6_2
- {
- public partial class form_vjesala : Form
- {
- public form_vjesala()
- {
- InitializeComponent();
- }
- int pogodak = 0;
- int pokusaji = 10;
- string rijec;
- static Random random = new Random();
- List<Label> labels = new List<Label>();
- List<string> rijeci = new List<string>();
- string path = "C:\\Users\\Ana\\Documents\\Visual Studio 2017\\Projects\\LV6\\LV6 Zad2\\rijeci.txt";
- private void Form1_Load(object sender, EventArgs e)
- {
- using (System.IO.StreamReader reader = new System.IO.StreamReader(@path))
- {
- string line;
- while ((line = reader.ReadLine()) != null)
- {
- rijeci.Add(line);
- }
- }
- int r = random.Next(rijeci.Count);
- rijec = (string)rijeci[r];
- private void button_pokusaj_Click(object sender, EventArgs e)
- {
- if (textBox_pokusaj.Text.Length == 0 || textBox_pokusaj.Text.Length > 1)
- {
- textBox_pokusaj.Text = "";
- MessageBox.Show("Greška!");
- }
- else
- {
- if (rijec.Contains(textBox_pokusaj.Text))
- {
- for (int i = 0; i < rijec.Length; i++)
- {
- if (rijec.IndexOf(textBox_pokusaj.Text) == rijec.IndexOf(rijec[i]))
- {
- if (labels[i].Text == "_")
- {
- labels[i].Text = textBox_pokusaj.Text;
- pogodak++;
- }
- else
- {
- MessageBox.Show("Slovo već postoji!");
- break;
- }
- }
- }
- textBox_pokusaj.Text = "";
- if (pogodak == rijec.Length)
- {
- MessageBox.Show("Pobjeda!");
- Application.Exit();
- }
- }
- else
- {
- if (pokusaji == 1)
- {
- textBox_pokusaj.Text = "";
- pokusaji--;
- label_pokusaji.Text = "Preostalo pokusaja: " + pokusaji;
- MessageBox.Show("Izgubio/la si.");
- Application.Exit();
- }
- else
- {
- textBox_pokusaj.Text = "";
- pokusaji--;
- label_pokusaji.Text = "Preostali pokusaji: " + pokusaji;
- }
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment