Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- using System.Data.OleDb;
- using ADODB;
- using Microsoft.VisualBasic;
- namespace Slagalica
- {
- public partial class Slagalica : Form
- {
- public Slagalica()
- {
- InitializeComponent();
- }
- ADODB.Connection Conn = new ADODB.Connection();
- long i = 0;
- string[] slova = new string[12];
- string rec = null;
- long proteklo = 0;
- string korisceno = null;
- long lastLen = 0;
- Random rand = new Random();
- private void Slagalica_Load(object sender, EventArgs e)
- {
- OleDbConnection connection = new OleDbConnection();
- connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Pavle\Documents\Visual Studio 2015\Projects\Slagalica\Slagalica\Slagalica.accdb;
- Persist Security Info=False;";
- connection.Open();
- connection.Close();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- Label[] label = new Label[] { label1, label2, label3, label4, label5, label6, label7, label8, label9, label10, label11, label12 };
- for (int i = 0; i < 12; i++)
- slova[i] = Convert.ToString(label[i]);
- if (!button1.Enabled)
- return;
- if (button1.Text == "Start")
- {
- i = 0;
- timer1.Enabled = true;
- button1.Text = "Stop";
- button1.Enabled = true;
- }
- else
- {
- label[i].Text = slova[i];
- i = i + 1;
- if (i == 12)
- {
- textBox1.Enabled = true;
- button1.Enabled = false;
- button1.Text = "Start";
- timer1.Enabled = false;
- Vreme.Enabled = true;
- textBox1.Focus();
- }
- }
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- Label[] label = new Label[] { label1, label2, label3, label4, label5, label6, label7, label8, label9, label10, label11, label12 };
- // for (int i = 0; i < 12; i++)
- // slova[i] = Convert.ToString(label[i]);
- long ascii = 0;
- ascii = rand.Next(65, 90);
- while (!(ascii != Convert.ToInt32("W") & ascii != Convert.ToInt32("X") & ascii != Convert.ToInt32("Q")))
- {
- ascii = rand.Next(65, 90);
- }
- //label[i].Text = Strings.Chr(ascii);
- label[i].Text = Convert.ToString(ascii);
- //DoEvents();
- Application.DoEvents();
- }
- private void Vreme_Tick(object sender, EventArgs e)
- {
- proteklo = proteklo + 1;
- double pbUnit;
- int pbWIDTH, pbHEIGHT, pbComplete;
- Bitmap bmp;
- Graphics g;
- pbWIDTH = pictureBox1.Width;
- pbHEIGHT = pictureBox1.Height;
- pbUnit = pbWIDTH / 100.0;
- pbComplete = 0;
- bmp = new Bitmap(pbWIDTH, pbHEIGHT);
- Vreme.Interval = 50; //in millisecond
- Vreme.Tick += new EventHandler(this.Vreme_Tick);
- Vreme.Start();
- g = Graphics.FromImage(bmp);
- g.Clear(Color.LightSkyBlue);
- g.FillRectangle(Brushes.CornflowerBlue, new Rectangle(0, 0, (int)(pbComplete * pbUnit), pbHEIGHT));
- g.DrawString(pbComplete + "%", new Font("Arial", pbHEIGHT / 2), Brushes.Black, new PointF(pbWIDTH / 2 - pbHEIGHT, pbHEIGHT / 10));
- pictureBox1.Image = bmp;
- pbComplete++;
- if (pbComplete > 100)
- {
- g.Dispose();
- Vreme.Stop();
- }
- if (proteklo == 60)
- {
- textBox2.Text = rec;
- MessageBox.Show("Vreme je isteklo", "Slagalica", MessageBoxButtons.OK, MessageBoxIcon.Information);
- proteklo = 0;
- Vreme.Enabled = false;
- textBox2.Enabled = false;
- }
- }
- private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
- {
- long n = 0;
- bool ima = false;
- string r = null;
- Recordset rs = new Recordset();
- textBox1.Text = textBox1.Text.ToUpper();
- if (e.KeyChar > 96 && e.KeyChar < 123)
- e.KeyChar = Convert.ToChar(e.KeyChar - 32);
- if (e.KeyChar < 65 || e.KeyChar > 90)
- if (e.KeyChar == (char)Keys.Back || e.KeyChar == (char)Keys.Delete)
- return;
- if (e.KeyChar == (char)Keys.Return)
- {
- Vreme.Enabled = false;
- r = textBox1.Text;
- if (r.Length < 2)
- {
- MessageBox.Show("Takva rec ne postoji!", "Slagalica", MessageBoxButtons.OK, MessageBoxIcon.Information);
- label14.Text = "0";
- goto proc_exit;
- }
- //rs = Conn.Execute("SELECT DISTINCT Reci FROM " + Convert.ToString(r.Length));
- ima = false;
- while (!rs.EOF)
- {
- if ((rs.Fields[0].Value) == r)
- {
- ima = true;
- //nasli smo rec
- break; // TODO: might not be correct. Was : Exit Do
- }
- rs.MoveNext();
- }
- if (ima)
- {
- //poeni: svako slovo nosi 10 poena - proteklo vreme (0-60)
- // label14 = 10 * r.Length - Math.Round(((picProgres.Width / picVreme.ScaleWidth) * 60));
- MessageBox.Show("Prihavatamo vasu rec!", "Slagalica", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else
- {
- label14.Text = "0";
- MessageBox.Show("Takva rec ne postoji!", "Slagalica", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- //picProgres.Width = 0;
- proc_exit:
- textBox2.Text = rec.ToUpper();
- e.KeyChar = (char)0;
- }
- else
- {
- long k = 0;
- k = 0;
- tryAgain:
- ima = false;
- for (n = k; k < 11; k++)
- {
- if (e.KeyChar == Convert.ToInt32(slova))
- {
- ima = true;
- }
- if (Strings.InStr(1, korisceno, ":" + n + ":") > 0)
- {
- k = n + 1;
- goto tryAgain;
- }
- else
- korisceno = korisceno + n + ":";
- }
- if (!ima)
- {
- e.KeyChar= (char)0;
- }
- }
- }
- /*private void textBox1_KeyPress(int KeyAscii)
- {
- long n = 0;
- bool ima = false;
- string r = null;
- Recordset rs = new Recordset();
- textBox1.Text = textBox1.Text.ToUpper();
- if (KeyAscii > 96 && KeyAscii < 123)
- KeyAscii = KeyAscii - 32;
- if (KeyAscii < 65 || KeyAscii > 90)
- if (KeyAscii == (char)Keys.Back || KeyAscii == (char)Keys.Delete)
- return;
- if (KeyAscii == (char)Keys.Return)
- {
- Vreme.Enabled = false;
- r = textBox1.Text;
- if (r.Length < 2)
- {
- MessageBox.Show("Takva rec ne postoji!", "Slagalica", MessageBoxButtons.OK, MessageBoxIcon.Information);
- label14.Text = "0";
- goto proc_exit;
- }
- //rs = Conn.Execute("SELECT DISTINCT Reci FROM " + Convert.ToString(r.Length));
- ima = false;
- while (!rs.EOF)
- {
- if ((rs.Fields[0].Value) == r)
- {
- ima = true;
- //nasli smo rec
- break; // TODO: might not be correct. Was : Exit Do
- }
- rs.MoveNext();
- }
- if (ima)
- {
- //poeni: svako slovo nosi 10 poena - proteklo vreme (0-60)
- // label14 = 10 * r.Length - Math.Round(((picProgres.Width / picVreme.ScaleWidth) * 60));
- MessageBox.Show("Prihavatamo vasu rec!", "Slagalica", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else
- {
- label14.Text = "0";
- MessageBox.Show("Takva rec ne postoji!", "Slagalica", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- //picProgres.Width = 0;
- proc_exit:
- textBox2.Text = rec.ToUpper();
- KeyAscii = 0;
- }
- else
- {
- long k = 0;
- k = 0;
- tryAgain:
- ima = false;
- for (n = k; k < 11; k++)
- {
- if (KeyAscii == Convert.ToInt32(slova))
- {
- ima = true;
- }
- if (Strings.InStr(1, korisceno, ":" + n + ":") > 0)
- {
- k = n + 1;
- goto tryAgain;
- }
- else
- korisceno = korisceno + n + ":";
- }
- if (!ima)
- {
- KeyAscii = 0;
- }
- }
- }
- private void textBox1_Change()
- {
- int n = 0;
- //long n = 0;
- long k = 0;
- long l = 0;
- string tmp = null;
- if (textBox1.Text.Length < lastLen)
- {
- korisceno = ":";
- for (n = 1; n < textBox1.Text.Length; n++)
- {
- tmp = Strings.Mid(textBox1.Text, n, 1);
- l = 0;
- }
- findNext:
- for (k = l; l < 11; l++)
- {
- if (tmp == slova[k])
- {
- if (Strings.InStr(1, korisceno, ":" + k + ":") > 0)
- {
- l = k + 1;
- goto findNext;
- }
- else
- {
- korisceno = korisceno + k + ":";
- }
- }
- }
- }
- else
- {
- lastLen = textBox1.Text.Length;
- }
- }*/
- private void textBox1_Change()
- {
- int n = 0;
- //long n = 0;
- long k = 0;
- long l = 0;
- string tmp = null;
- if (textBox1.Text.Length < lastLen)
- {
- korisceno = ":";
- for (n = 1; n < textBox1.Text.Length; n++)
- {
- tmp = Strings.Mid(textBox1.Text, n, 1);
- l = 0;
- }
- findNext:
- for (k = l; l < 11; l++)
- {
- if (tmp == slova[k])
- {
- if (Strings.InStr(1, korisceno, ":" + k + ":") > 0)
- {
- l = k + 1;
- goto findNext;
- }
- else
- {
- korisceno = korisceno + k + ":";
- }
- }
- }
- }
- else
- {
- lastLen = textBox1.Text.Length;
- }
- }
- /*public long getRandom(long min, long max)
- {
- return Convert.ToInt64(Conversion.Int((max - min + 1) *Rnd + min));
- }*/
- public long getRandom(int min, int max)
- {
- return Convert.ToInt64(Conversion.Int(rand.Next(max - min + 1) + min));
- }
- void shuffleArray(string[] inArray)
- {
- long n = 0;
- long k = 0;
- string tmp;
- for (n = Information.LBound(inArray); n <= Information.UBound(inArray); n++)
- {
- k = getRandom(Information.LBound(inArray), Information.UBound(inArray));
- tmp = inArray[n];
- //prvo pamtimo n clan array-a
- inArray[n] = inArray[k];
- //potom ga zamenjujemom sa k clanom array-a
- inArray[k] = tmp;
- //i zamenjujemo k clan sa n clanom (k se bira random)
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment