Pavle_nis

test-SLAGALICA

Nov 29th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 13.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. using System.Data.OleDb;
  12. using ADODB;
  13. using Microsoft.VisualBasic;
  14.  
  15. namespace Slagalica
  16. {
  17.     public partial class Slagalica : Form
  18.     {
  19.         public Slagalica()
  20.         {
  21.             InitializeComponent();
  22.         }
  23.         ADODB.Connection Conn = new ADODB.Connection();
  24.         long i = 0;
  25.         string[] slova = new string[12];
  26.         string rec = null;
  27.         long proteklo = 0;
  28.         string korisceno = null;
  29.         long lastLen = 0;
  30.         Random rand = new Random();
  31.         private void Slagalica_Load(object sender, EventArgs e)
  32.         {
  33.             OleDbConnection connection = new OleDbConnection();
  34.             connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Pavle\Documents\Visual Studio 2015\Projects\Slagalica\Slagalica\Slagalica.accdb;
  35. Persist Security Info=False;";
  36.             connection.Open();
  37.             connection.Close();
  38.         }
  39.  
  40.         private void button1_Click(object sender, EventArgs e)
  41.         {
  42.             Label[] label = new Label[] { label1, label2, label3, label4, label5, label6, label7, label8, label9, label10, label11, label12 };
  43.             for (int i = 0; i < 12; i++)
  44.                 slova[i] = Convert.ToString(label[i]);
  45.  
  46.             if (!button1.Enabled)
  47.                 return;
  48.             if (button1.Text == "Start")
  49.             {
  50.                 i = 0;
  51.                 timer1.Enabled = true;
  52.                 button1.Text = "Stop";
  53.                 button1.Enabled = true;
  54.             }
  55.             else
  56.             {
  57.                 label[i].Text = slova[i];
  58.                 i = i + 1;
  59.                 if (i == 12)
  60.                 {
  61.                     textBox1.Enabled = true;
  62.                     button1.Enabled = false;
  63.                     button1.Text = "Start";
  64.                     timer1.Enabled = false;
  65.                     Vreme.Enabled = true;
  66.                     textBox1.Focus();
  67.                 }
  68.             }
  69.         }
  70.         private void timer1_Tick(object sender, EventArgs e)
  71.         {
  72.             Label[] label = new Label[] { label1, label2, label3, label4, label5, label6, label7, label8, label9, label10, label11, label12 };
  73.             // for (int i = 0; i < 12; i++)
  74.             // slova[i] = Convert.ToString(label[i]);
  75.  
  76.            
  77.             long ascii = 0;
  78.  
  79.             ascii = rand.Next(65, 90);
  80.             while (!(ascii != Convert.ToInt32("W") & ascii != Convert.ToInt32("X") & ascii != Convert.ToInt32("Q")))
  81.             {
  82.                 ascii = rand.Next(65, 90);
  83.             }
  84.  
  85.             //label[i].Text = Strings.Chr(ascii);
  86.             label[i].Text = Convert.ToString(ascii);
  87.             //DoEvents();
  88.             Application.DoEvents();
  89.         }
  90.  
  91.         private void Vreme_Tick(object sender, EventArgs e)
  92.         {
  93.             proteklo = proteklo + 1;
  94.             double pbUnit;
  95.             int pbWIDTH, pbHEIGHT, pbComplete;
  96.  
  97.             Bitmap bmp;
  98.             Graphics g;
  99.             pbWIDTH = pictureBox1.Width;
  100.             pbHEIGHT = pictureBox1.Height;
  101.             pbUnit = pbWIDTH / 100.0;
  102.             pbComplete = 0;
  103.             bmp = new Bitmap(pbWIDTH, pbHEIGHT);
  104.             Vreme.Interval = 50;    //in millisecond
  105.             Vreme.Tick += new EventHandler(this.Vreme_Tick);
  106.             Vreme.Start();
  107.  
  108.             g = Graphics.FromImage(bmp);
  109.             g.Clear(Color.LightSkyBlue);
  110.             g.FillRectangle(Brushes.CornflowerBlue, new Rectangle(0, 0, (int)(pbComplete * pbUnit), pbHEIGHT));
  111.             g.DrawString(pbComplete + "%", new Font("Arial", pbHEIGHT / 2), Brushes.Black, new PointF(pbWIDTH / 2 - pbHEIGHT, pbHEIGHT / 10));
  112.             pictureBox1.Image = bmp;
  113.             pbComplete++;
  114.             if (pbComplete > 100)
  115.             {
  116.                 g.Dispose();
  117.                 Vreme.Stop();
  118.             }
  119.  
  120.             if (proteklo == 60)
  121.             {
  122.                 textBox2.Text = rec;
  123.                 MessageBox.Show("Vreme je isteklo", "Slagalica", MessageBoxButtons.OK, MessageBoxIcon.Information);
  124.                 proteklo = 0;
  125.                 Vreme.Enabled = false;
  126.                 textBox2.Enabled = false;
  127.             }
  128.         }
  129.  
  130.         private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
  131.         {
  132.             long n = 0;
  133.             bool ima = false;
  134.             string r = null;
  135.             Recordset rs = new Recordset();
  136.  
  137.             textBox1.Text = textBox1.Text.ToUpper();
  138.             if (e.KeyChar > 96 && e.KeyChar < 123)
  139.                 e.KeyChar = Convert.ToChar(e.KeyChar - 32);
  140.             if (e.KeyChar < 65 || e.KeyChar > 90)
  141.  
  142.                 if (e.KeyChar == (char)Keys.Back || e.KeyChar == (char)Keys.Delete)
  143.                     return;
  144.             if (e.KeyChar == (char)Keys.Return)
  145.             {
  146.                 Vreme.Enabled = false;
  147.                 r = textBox1.Text;
  148.  
  149.                 if (r.Length < 2)
  150.                 {
  151.                     MessageBox.Show("Takva rec ne postoji!", "Slagalica", MessageBoxButtons.OK, MessageBoxIcon.Information);
  152.                     label14.Text = "0";
  153.                     goto proc_exit;
  154.                 }
  155.                 //rs = Conn.Execute("SELECT DISTINCT Reci FROM " + Convert.ToString(r.Length));
  156.                 ima = false;
  157.                 while (!rs.EOF)
  158.                 {
  159.                     if ((rs.Fields[0].Value) == r)
  160.                     {
  161.                         ima = true;
  162.                         //nasli smo rec
  163.                         break; // TODO: might not be correct. Was : Exit Do
  164.                     }
  165.                     rs.MoveNext();
  166.                 }
  167.                 if (ima)
  168.                 {
  169.                     //poeni: svako slovo nosi 10 poena - proteklo vreme (0-60)
  170.                     // label14 = 10 * r.Length - Math.Round(((picProgres.Width / picVreme.ScaleWidth) * 60));
  171.                     MessageBox.Show("Prihavatamo vasu rec!", "Slagalica", MessageBoxButtons.OK, MessageBoxIcon.Information);
  172.                 }
  173.                 else
  174.                 {
  175.                     label14.Text = "0";
  176.                     MessageBox.Show("Takva rec ne postoji!", "Slagalica", MessageBoxButtons.OK, MessageBoxIcon.Information);
  177.                 }
  178.                 //picProgres.Width = 0;
  179.  
  180.                 proc_exit:
  181.                 textBox2.Text = rec.ToUpper();
  182.                 e.KeyChar = (char)0;
  183.             }
  184.             else
  185.             {
  186.                 long k = 0;
  187.                 k = 0;
  188.                 tryAgain:
  189.                 ima = false;
  190.                 for (n = k; k < 11; k++)
  191.                 {
  192.                     if (e.KeyChar == Convert.ToInt32(slova))
  193.                     {
  194.                         ima = true;
  195.                     }
  196.                     if (Strings.InStr(1, korisceno, ":" + n + ":") > 0)
  197.                     {
  198.                         k = n + 1;
  199.                         goto tryAgain;
  200.                     }
  201.                     else
  202.                         korisceno = korisceno + n + ":";
  203.                 }
  204.                 if (!ima)
  205.                 {
  206.                     e.KeyChar= (char)0;
  207.                 }
  208.             }
  209.         }
  210.  
  211.         /*private void textBox1_KeyPress(int KeyAscii)
  212.         {
  213.             long n = 0;
  214.             bool ima = false;
  215.             string r = null;
  216.             Recordset rs = new Recordset();
  217.  
  218.             textBox1.Text = textBox1.Text.ToUpper();
  219.             if (KeyAscii > 96 && KeyAscii < 123)
  220.                 KeyAscii = KeyAscii - 32;
  221.             if (KeyAscii < 65 || KeyAscii > 90)
  222.  
  223.                 if (KeyAscii == (char)Keys.Back || KeyAscii == (char)Keys.Delete)
  224.                     return;
  225.             if (KeyAscii == (char)Keys.Return)
  226.             {
  227.                 Vreme.Enabled = false;
  228.                 r = textBox1.Text;
  229.  
  230.                 if (r.Length < 2)
  231.                 {
  232.                     MessageBox.Show("Takva rec ne postoji!", "Slagalica", MessageBoxButtons.OK, MessageBoxIcon.Information);
  233.                     label14.Text = "0";
  234.                     goto proc_exit;
  235.                 }
  236.                 //rs = Conn.Execute("SELECT DISTINCT Reci FROM " + Convert.ToString(r.Length));
  237.                 ima = false;
  238.                 while (!rs.EOF)
  239.                 {
  240.                     if ((rs.Fields[0].Value) == r)
  241.                     {
  242.                         ima = true;
  243.                         //nasli smo rec
  244.                         break; // TODO: might not be correct. Was : Exit Do
  245.                     }
  246.                     rs.MoveNext();
  247.                 }
  248.                 if (ima)
  249.                 {
  250.                     //poeni: svako slovo nosi 10 poena - proteklo vreme (0-60)
  251.                     // label14 = 10 * r.Length - Math.Round(((picProgres.Width / picVreme.ScaleWidth) * 60));
  252.                     MessageBox.Show("Prihavatamo vasu rec!", "Slagalica", MessageBoxButtons.OK, MessageBoxIcon.Information);
  253.                 }
  254.                 else
  255.                 {
  256.                     label14.Text = "0";
  257.                     MessageBox.Show("Takva rec ne postoji!", "Slagalica", MessageBoxButtons.OK, MessageBoxIcon.Information);
  258.                 }
  259.                 //picProgres.Width = 0;
  260.  
  261.                 proc_exit:
  262.                 textBox2.Text = rec.ToUpper();
  263.                 KeyAscii = 0;
  264.             }
  265.             else
  266.             {
  267.                 long k = 0;
  268.                 k = 0;
  269.                 tryAgain:
  270.                 ima = false;
  271.                 for (n = k; k < 11; k++)
  272.                 {
  273.                     if (KeyAscii == Convert.ToInt32(slova))
  274.                     {
  275.                         ima = true;
  276.                     }
  277.                     if (Strings.InStr(1, korisceno, ":" + n + ":") > 0)
  278.                     {
  279.                         k = n + 1;
  280.                         goto tryAgain;
  281.                     }
  282.                     else
  283.                         korisceno = korisceno + n + ":";
  284.                 }
  285.                 if (!ima)
  286.                 {
  287.                     KeyAscii = 0;
  288.                 }
  289.             }
  290.         }
  291.         private void textBox1_Change()
  292.         {
  293.             int n = 0;
  294.             //long n = 0;
  295.             long k = 0;
  296.             long l = 0;
  297.             string tmp = null;
  298.  
  299.             if (textBox1.Text.Length < lastLen)
  300.             {
  301.                 korisceno = ":";
  302.  
  303.                 for (n = 1; n < textBox1.Text.Length; n++)
  304.                 {
  305.                     tmp = Strings.Mid(textBox1.Text, n, 1);
  306.                     l = 0;
  307.                 }
  308.                 findNext:
  309.                 for (k = l; l < 11; l++)
  310.                 {
  311.                     if (tmp == slova[k])
  312.                     {
  313.                         if (Strings.InStr(1, korisceno, ":" + k + ":") > 0)
  314.                         {
  315.                             l = k + 1;
  316.                             goto findNext;
  317.                         }
  318.                         else
  319.                         {
  320.                             korisceno = korisceno + k + ":";
  321.                         }
  322.                     }
  323.                 }
  324.             }
  325.             else
  326.             {
  327.                 lastLen = textBox1.Text.Length;
  328.             }
  329.         }*/
  330.         private void textBox1_Change()
  331.         {
  332.             int n = 0;
  333.             //long n = 0;
  334.             long k = 0;
  335.             long l = 0;
  336.             string tmp = null;
  337.  
  338.             if (textBox1.Text.Length < lastLen)
  339.             {
  340.                 korisceno = ":";
  341.  
  342.                 for (n = 1; n < textBox1.Text.Length; n++)
  343.                 {
  344.                     tmp = Strings.Mid(textBox1.Text, n, 1);
  345.                     l = 0;
  346.                 }
  347.                 findNext:
  348.                 for (k = l; l < 11; l++)
  349.                 {
  350.                     if (tmp == slova[k])
  351.                     {
  352.                         if (Strings.InStr(1, korisceno, ":" + k + ":") > 0)
  353.                         {
  354.                             l = k + 1;
  355.                             goto findNext;
  356.                         }
  357.                         else
  358.                         {
  359.                             korisceno = korisceno + k + ":";
  360.                         }
  361.                     }
  362.                 }
  363.             }
  364.             else
  365.             {
  366.                 lastLen = textBox1.Text.Length;
  367.             }
  368.         }
  369.         /*public long getRandom(long min, long max)
  370.         {
  371.             return Convert.ToInt64(Conversion.Int((max - min + 1) *Rnd + min));
  372.         }*/
  373.         public long getRandom(int min, int max)
  374.         {
  375.             return Convert.ToInt64(Conversion.Int(rand.Next(max - min + 1) + min));
  376.         }
  377.         void shuffleArray(string[] inArray)
  378.         {
  379.             long n = 0;
  380.             long k = 0;
  381.             string  tmp;
  382.  
  383.             for (n = Information.LBound(inArray); n <= Information.UBound(inArray); n++)
  384.             {
  385.                 k = getRandom(Information.LBound(inArray), Information.UBound(inArray));
  386.                 tmp = inArray[n];
  387.                 //prvo pamtimo n clan array-a
  388.                 inArray[n] = inArray[k];
  389.                 //potom ga zamenjujemom sa k clanom array-a
  390.                 inArray[k] = tmp;
  391.                 //i zamenjujemo k clan sa n clanom (k se bira random)
  392.             }
  393.         }
  394.     }
  395. }
Advertisement
Add Comment
Please, Sign In to add comment