Pavle_nis

Translated To C# Slagalica(Microsoft)

Dec 7th, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.05 KB | None | 0 0
  1. using Microsoft.VisualBasic;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Diagnostics;
  7.  
  8. internal class Form1 : System.Windows.Forms.Form
  9. {
  10.     ADODB.Connection Conn = new ADODB.Connection();
  11.     int i;
  12.     string[] slova = new string[12];
  13.     string rec;
  14.     int proteklo;
  15.     string korisceno;
  16.     int lastLen;
  17.  
  18.     private void Form1_KeyUp(System.Object eventSender, System.Windows.Forms.KeyEventArgs eventArgs)
  19.     {
  20.         short KeyCode = eventArgs.KeyCode;
  21.         short Shift = eventArgs.KeyData / 0x10000;
  22.         if (KeyCode == 32 & Shift == 0)
  23.             lblStartStop_Click(lblStartStop, new System.EventArgs());
  24.     }
  25.  
  26.     private void Form1_Load(System.Object eventSender, System.EventArgs eventArgs)
  27.     {
  28.         Conn.Open(("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + My.Application.Info.DirectoryPath + "\\" + "slagalica.mdb" + ";Persist Security Info=False"));
  29.         VBMath.Randomize();
  30.         this.Show();
  31.         System.Windows.Forms.Application.DoEvents();
  32.         lblNova_Click(lblNova, new System.EventArgs());
  33.     }
  34.  
  35.     private void lblIzlaz_Click(System.Object eventSender, System.EventArgs eventArgs)
  36.     {
  37.         this.Close();
  38.     }
  39.  
  40.     private void lblNova_Click(System.Object eventSender, System.EventArgs eventArgs)
  41.     {
  42.         ADODB.Recordset rs = new ADODB.Recordset();
  43.         int n = 0;
  44.         int duzina = 0;
  45.         string tmp = null;
  46.         int ascii = 0;
  47.  
  48.         lblStartStop.Text = "Start";
  49.         Timor.Enabled = false;
  50.         lblStartStop.Enabled = false;
  51.  
  52.         txtInput.Text = "";
  53.         txtNajduza.Text = "";
  54.         txtInput.Enabled = false;
  55.  
  56.         duzina = getRandom(ref 8, ref 12);
  57.         rs.Open("SELECT DISTINCT Reci FROM " + Convert.ToString(duzina), Conn, ADODB.CursorTypeEnum.adOpenKeyset);
  58.         rs.Move(getRandom(ref 0, ref rs.RecordCount - 1));
  59.         rec = rs.Fields(0).Value;
  60.         tmp = Strings.UCase(rec);
  61.  
  62.         while (!(Strings.Len(tmp) == 12)) {
  63.             ascii = getRandom(ref 65, ref 90);
  64.             while (!(ascii != Strings.Asc("W") & ascii != Strings.Asc("X") & ascii != Strings.Asc("Q"))) {
  65.                 ascii = getRandom(ref 65, ref 90);
  66.             }
  67.             tmp = tmp + Strings.Chr(ascii);
  68.         }
  69.  
  70.         for (n = 0; n <= 11; n++) {
  71.             lblSlovo(n).Text = "";
  72.             slova(n) = Strings.Mid(tmp, n + 1, 1);
  73.         }
  74.  
  75.         shuffleArray(ref slova);
  76.  
  77.         picProgres.Width = 0;
  78.         proteklo = 0;
  79.         lblPoeni.Text = "0";
  80.         korisceno = ":";
  81.  
  82.         lblStartStop.Enabled = true;
  83.  
  84.     }
  85.  
  86.     private void lblStartStop_Click(System.Object eventSender, System.EventArgs eventArgs)
  87.     {
  88.         if (!lblStartStop.Enabled)
  89.             return;
  90.         if (lblStartStop.Text == "Start") {
  91.             i = 0;
  92.             Timor.Enabled = true;
  93.             lblStartStop.Text = "Stop";
  94.             lblStartStop.Enabled = true;
  95.         } else {
  96.             lblSlovo(i).Text = slova(i);
  97.             i = i + 1;
  98.             if (i == 12) {
  99.                 txtInput.Enabled = true;
  100.                 lblStartStop.Enabled = false;
  101.                 lblStartStop.Text = "Start";
  102.                 Timor.Enabled = false;
  103.                 Vreme.Enabled = true;
  104.                 txtInput.Focus();
  105.             }
  106.         }
  107.     }
  108.  
  109.     private void Timor_Tick(System.Object eventSender, System.EventArgs eventArgs)
  110.     {
  111.         int ascii = 0;
  112.  
  113.         ascii = getRandom(ref 65, ref 90);
  114.         while (!(ascii != Strings.Asc("W") & ascii != Strings.Asc("X") & ascii != Strings.Asc("Q"))) {
  115.             ascii = getRandom(ref 65, ref 90);
  116.         }
  117.  
  118.         lblSlovo(i).Text = Strings.Chr(ascii);
  119.         System.Windows.Forms.Application.DoEvents();
  120.     }
  121.  
  122.     private void Vreme_Tick(System.Object eventSender, System.EventArgs eventArgs)
  123.     {
  124.         object picVreme = null;
  125.         proteklo = proteklo + 1;
  126.         picProgres.Width = VB6.TwipsToPixelsX((proteklo / 60) * picVreme.ScaleWidth);
  127.         if (proteklo == 60) {
  128.             txtNajduza.Text = rec;
  129.             setInfo(ref "Vreme je isteklo.");
  130.             proteklo = 0;
  131.             Vreme.Enabled = false;
  132.             txtInput.Enabled = false;
  133.         }
  134.         System.Windows.Forms.Application.DoEvents();
  135.     }
  136.  
  137.     private void txtInput_KeyPress(System.Object eventSender, System.Windows.Forms.KeyPressEventArgs eventArgs)
  138.     {
  139.         short KeyAscii = Strings.Asc(eventArgs.KeyChar);
  140.         object picVreme = null;
  141.         int n = 0;
  142.         bool ima = false;
  143.         string r = null;
  144.         ADODB.Recordset rs = new ADODB.Recordset();
  145.  
  146.         if (KeyAscii > 96 & KeyAscii < 123)
  147.             KeyAscii = KeyAscii - 32;
  148.         int k = 0;
  149.         short counter = 0;
  150.         if (KeyAscii < 65 | KeyAscii > 90) {
  151.             if (KeyAscii == System.Windows.Forms.Keys.Back | KeyAscii == System.Windows.Forms.Keys.Delete)
  152.                 goto EventExitSub;
  153.             if (KeyAscii == System.Windows.Forms.Keys.Return) {
  154.                 Vreme.Enabled = false;
  155.                 r = txtInput.Text;
  156.  
  157.                 if (Strings.Len(r) < 2) {
  158.                     setInfo(ref "Takva rec ne postoji.");
  159.                     lblPoeni.Text = "0";
  160.                     goto proc_exit;
  161.                 }
  162.  
  163.                 rs = Conn.Execute("SELECT DISTINCT Reci FROM " + Convert.ToString(Strings.Len(r)));
  164.  
  165.                 ima = false;
  166.                 while (!rs.EOF) {
  167.                     if (Strings.UCase(rs.Fields(0).Value) == r) {
  168.                         ima = true;
  169.                         break;
  170.                     }
  171.                     rs.MoveNext();
  172.                 }
  173.  
  174.                 if (ima) {
  175.                     lblPoeni.Text = Convert.ToString(10 * Strings.Len(r) - System.Math.Round((VB6.PixelsToTwipsX(picProgres.Width) / picVreme.ScaleWidth) * 60));
  176.                     setInfo(ref "Prihvatamo vasu rec.");
  177.                 } else {
  178.                     lblPoeni.Text = "0";
  179.                     setInfo(ref "Takva rec ne postoji.");
  180.                 }
  181.  
  182.                 picProgres.Width = 0;
  183.                 proc_exit:
  184.  
  185.                 txtNajduza.Text = Strings.UCase(rec);
  186.             }
  187.             KeyAscii = 0;
  188.         } else {
  189.             k = 0;
  190.             tryAgain:
  191.             ima = false;
  192.             counter = k;
  193.             for (n = counter; n <= 11; n++) {
  194.                 if (KeyAscii == Strings.Asc(slova(n))) {
  195.                     ima = true;
  196.                     if (Strings.InStr(1, korisceno, ":" + n + ":") > 0) {
  197.                         k = n + 1;
  198.                         goto tryAgain;
  199.                     } else {
  200.                         korisceno = korisceno + n + ":";
  201.                     }
  202.                     break;
  203.                 }
  204.             }
  205.             if (!ima)
  206.                 KeyAscii = 0;
  207.         }
  208.         EventExitSub:
  209.         eventArgs.KeyChar = Strings.Chr(KeyAscii);
  210.         if (KeyAscii == 0) {
  211.             eventArgs.Handled = true;
  212.         }
  213.     }
  214.  
  215.     private void txtInput_TextChanged(System.Object eventSender, System.EventArgs eventArgs)
  216.     {
  217.         int n = 0;
  218.         int k = 0;
  219.         int l = 0;
  220.         string tmp = null;
  221.  
  222.         short counter = 0;
  223.         if (Strings.Len(txtInput.Text) < lastLen) {
  224.             korisceno = ":";
  225.             for (n = 1; n <= Strings.Len(txtInput.Text); n++) {
  226.                 tmp = Strings.Mid(txtInput.Text, n, 1);
  227.                 l = 0;
  228.                 findNext:
  229.                 counter = l;
  230.                 for (k = counter; k <= 11; k++) {
  231.                     if (tmp == slova(k)) {
  232.                         if (Strings.InStr(1, korisceno, ":" + k + ":") > 0) {
  233.                             l = k + 1;
  234.                             goto findNext;
  235.                         } else {
  236.                             korisceno = korisceno + k + ":";
  237.                             break;
  238.                         }
  239.                     }
  240.                 }
  241.             }
  242.         } else {
  243.             lastLen = Strings.Len(txtInput.Text);
  244.         }
  245.  
  246.     }
  247.  
  248.     private void infoTimer_Timer()
  249.     {
  250.         infoTimer.Enabled = false;
  251.         lblInfo.Text = "";
  252.     }
  253.  
  254.     public void setInfo(ref string inf)
  255.     {
  256.         lblInfo.Text = inf;
  257.         infoTimer.Enabled = true;
  258.     }
  259.  
  260.     public int getRandom(ref int min, ref int max)
  261.     {
  262.         return Convert.ToInt32(Conversion.Int((max - min + 1) * VBMath.Rnd() + min));
  263.     }
  264.  
  265.     public void shuffleArray(ref string[] inArray)
  266.     {
  267.         int n = 0;
  268.         int k = 0;
  269.         string tmp = null;
  270.  
  271.         for (n = Information.LBound(inArray); n <= Information.UBound(inArray); n++) {
  272.             k = getRandom(ref Information.LBound(inArray), ref Information.UBound(inArray));
  273.             tmp = inArray(n);
  274.             inArray(n) = inArray(k);
  275.             inArray(k) = tmp;
  276.         }
  277.     }
  278.     public Form1()
  279.     {
  280.         Load += Form1_Load;
  281.         KeyUp += Form1_KeyUp;
  282.     }
  283. }
Advertisement
Add Comment
Please, Sign In to add comment