Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.VisualBasic;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data;
- using System.Diagnostics;
- internal class Form1 : System.Windows.Forms.Form
- {
- ADODB.Connection Conn = new ADODB.Connection();
- int i;
- string[] slova = new string[12];
- string rec;
- int proteklo;
- string korisceno;
- int lastLen;
- private void Form1_KeyUp(System.Object eventSender, System.Windows.Forms.KeyEventArgs eventArgs)
- {
- short KeyCode = eventArgs.KeyCode;
- short Shift = eventArgs.KeyData / 0x10000;
- if (KeyCode == 32 & Shift == 0)
- lblStartStop_Click(lblStartStop, new System.EventArgs());
- }
- private void Form1_Load(System.Object eventSender, System.EventArgs eventArgs)
- {
- Conn.Open(("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + My.Application.Info.DirectoryPath + "\\" + "slagalica.mdb" + ";Persist Security Info=False"));
- VBMath.Randomize();
- this.Show();
- System.Windows.Forms.Application.DoEvents();
- lblNova_Click(lblNova, new System.EventArgs());
- }
- private void lblIzlaz_Click(System.Object eventSender, System.EventArgs eventArgs)
- {
- this.Close();
- }
- private void lblNova_Click(System.Object eventSender, System.EventArgs eventArgs)
- {
- ADODB.Recordset rs = new ADODB.Recordset();
- int n = 0;
- int duzina = 0;
- string tmp = null;
- int ascii = 0;
- lblStartStop.Text = "Start";
- Timor.Enabled = false;
- lblStartStop.Enabled = false;
- txtInput.Text = "";
- txtNajduza.Text = "";
- txtInput.Enabled = false;
- duzina = getRandom(ref 8, ref 12);
- rs.Open("SELECT DISTINCT Reci FROM " + Convert.ToString(duzina), Conn, ADODB.CursorTypeEnum.adOpenKeyset);
- rs.Move(getRandom(ref 0, ref rs.RecordCount - 1));
- rec = rs.Fields(0).Value;
- tmp = Strings.UCase(rec);
- while (!(Strings.Len(tmp) == 12)) {
- ascii = getRandom(ref 65, ref 90);
- while (!(ascii != Strings.Asc("W") & ascii != Strings.Asc("X") & ascii != Strings.Asc("Q"))) {
- ascii = getRandom(ref 65, ref 90);
- }
- tmp = tmp + Strings.Chr(ascii);
- }
- for (n = 0; n <= 11; n++) {
- lblSlovo(n).Text = "";
- slova(n) = Strings.Mid(tmp, n + 1, 1);
- }
- shuffleArray(ref slova);
- picProgres.Width = 0;
- proteklo = 0;
- lblPoeni.Text = "0";
- korisceno = ":";
- lblStartStop.Enabled = true;
- }
- private void lblStartStop_Click(System.Object eventSender, System.EventArgs eventArgs)
- {
- if (!lblStartStop.Enabled)
- return;
- if (lblStartStop.Text == "Start") {
- i = 0;
- Timor.Enabled = true;
- lblStartStop.Text = "Stop";
- lblStartStop.Enabled = true;
- } else {
- lblSlovo(i).Text = slova(i);
- i = i + 1;
- if (i == 12) {
- txtInput.Enabled = true;
- lblStartStop.Enabled = false;
- lblStartStop.Text = "Start";
- Timor.Enabled = false;
- Vreme.Enabled = true;
- txtInput.Focus();
- }
- }
- }
- private void Timor_Tick(System.Object eventSender, System.EventArgs eventArgs)
- {
- int ascii = 0;
- ascii = getRandom(ref 65, ref 90);
- while (!(ascii != Strings.Asc("W") & ascii != Strings.Asc("X") & ascii != Strings.Asc("Q"))) {
- ascii = getRandom(ref 65, ref 90);
- }
- lblSlovo(i).Text = Strings.Chr(ascii);
- System.Windows.Forms.Application.DoEvents();
- }
- private void Vreme_Tick(System.Object eventSender, System.EventArgs eventArgs)
- {
- object picVreme = null;
- proteklo = proteklo + 1;
- picProgres.Width = VB6.TwipsToPixelsX((proteklo / 60) * picVreme.ScaleWidth);
- if (proteklo == 60) {
- txtNajduza.Text = rec;
- setInfo(ref "Vreme je isteklo.");
- proteklo = 0;
- Vreme.Enabled = false;
- txtInput.Enabled = false;
- }
- System.Windows.Forms.Application.DoEvents();
- }
- private void txtInput_KeyPress(System.Object eventSender, System.Windows.Forms.KeyPressEventArgs eventArgs)
- {
- short KeyAscii = Strings.Asc(eventArgs.KeyChar);
- object picVreme = null;
- int n = 0;
- bool ima = false;
- string r = null;
- ADODB.Recordset rs = new ADODB.Recordset();
- if (KeyAscii > 96 & KeyAscii < 123)
- KeyAscii = KeyAscii - 32;
- int k = 0;
- short counter = 0;
- if (KeyAscii < 65 | KeyAscii > 90) {
- if (KeyAscii == System.Windows.Forms.Keys.Back | KeyAscii == System.Windows.Forms.Keys.Delete)
- goto EventExitSub;
- if (KeyAscii == System.Windows.Forms.Keys.Return) {
- Vreme.Enabled = false;
- r = txtInput.Text;
- if (Strings.Len(r) < 2) {
- setInfo(ref "Takva rec ne postoji.");
- lblPoeni.Text = "0";
- goto proc_exit;
- }
- rs = Conn.Execute("SELECT DISTINCT Reci FROM " + Convert.ToString(Strings.Len(r)));
- ima = false;
- while (!rs.EOF) {
- if (Strings.UCase(rs.Fields(0).Value) == r) {
- ima = true;
- break;
- }
- rs.MoveNext();
- }
- if (ima) {
- lblPoeni.Text = Convert.ToString(10 * Strings.Len(r) - System.Math.Round((VB6.PixelsToTwipsX(picProgres.Width) / picVreme.ScaleWidth) * 60));
- setInfo(ref "Prihvatamo vasu rec.");
- } else {
- lblPoeni.Text = "0";
- setInfo(ref "Takva rec ne postoji.");
- }
- picProgres.Width = 0;
- proc_exit:
- txtNajduza.Text = Strings.UCase(rec);
- }
- KeyAscii = 0;
- } else {
- k = 0;
- tryAgain:
- ima = false;
- counter = k;
- for (n = counter; n <= 11; n++) {
- if (KeyAscii == Strings.Asc(slova(n))) {
- ima = true;
- if (Strings.InStr(1, korisceno, ":" + n + ":") > 0) {
- k = n + 1;
- goto tryAgain;
- } else {
- korisceno = korisceno + n + ":";
- }
- break;
- }
- }
- if (!ima)
- KeyAscii = 0;
- }
- EventExitSub:
- eventArgs.KeyChar = Strings.Chr(KeyAscii);
- if (KeyAscii == 0) {
- eventArgs.Handled = true;
- }
- }
- private void txtInput_TextChanged(System.Object eventSender, System.EventArgs eventArgs)
- {
- int n = 0;
- int k = 0;
- int l = 0;
- string tmp = null;
- short counter = 0;
- if (Strings.Len(txtInput.Text) < lastLen) {
- korisceno = ":";
- for (n = 1; n <= Strings.Len(txtInput.Text); n++) {
- tmp = Strings.Mid(txtInput.Text, n, 1);
- l = 0;
- findNext:
- counter = l;
- for (k = counter; k <= 11; k++) {
- if (tmp == slova(k)) {
- if (Strings.InStr(1, korisceno, ":" + k + ":") > 0) {
- l = k + 1;
- goto findNext;
- } else {
- korisceno = korisceno + k + ":";
- break;
- }
- }
- }
- }
- } else {
- lastLen = Strings.Len(txtInput.Text);
- }
- }
- private void infoTimer_Timer()
- {
- infoTimer.Enabled = false;
- lblInfo.Text = "";
- }
- public void setInfo(ref string inf)
- {
- lblInfo.Text = inf;
- infoTimer.Enabled = true;
- }
- public int getRandom(ref int min, ref int max)
- {
- return Convert.ToInt32(Conversion.Int((max - min + 1) * VBMath.Rnd() + min));
- }
- public void shuffleArray(ref string[] inArray)
- {
- int n = 0;
- int k = 0;
- string tmp = null;
- for (n = Information.LBound(inArray); n <= Information.UBound(inArray); n++) {
- k = getRandom(ref Information.LBound(inArray), ref Information.UBound(inArray));
- tmp = inArray(n);
- inArray(n) = inArray(k);
- inArray(k) = tmp;
- }
- }
- public Form1()
- {
- Load += Form1_Load;
- KeyUp += Form1_KeyUp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment