Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: None  |  size: 4.20 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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.Windows.Forms;
  9.  
  10. namespace WindowsFormsApplication1
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public int minutes;
  15.         public int seconds;
  16.  
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.  
  21.         }
  22.  
  23.         List<string> verbs = new List<string>();
  24.         List<string> ponies = new List<string>();
  25.         List<string> nouns = new List<string>();
  26.  
  27.         private void Form1_Load_1(object sender, EventArgs e)
  28.         {
  29.             string[] buffer;
  30.             string[] buffer2;
  31.  
  32.             buffer = System.IO.File.ReadAllLines(".\\Verbs.csv");
  33.             foreach (string line in buffer)
  34.             {
  35.                 buffer2 = line.Split(',');
  36.                 foreach (string item in buffer2)
  37.                 {
  38.                     verbs.Add(item);
  39.                 }
  40.             }
  41.  
  42.             buffer = System.IO.File.ReadAllLines(".\\Ponies.csv");
  43.             foreach (string line in buffer)
  44.             {
  45.                 buffer2 = line.Split(',');
  46.                 foreach (string item in buffer2)
  47.                 {
  48.                     ponies.Add(item);
  49.                 }
  50.             }
  51.  
  52.             buffer = System.IO.File.ReadAllLines(".\\Nouns.csv");
  53.             foreach (string line in buffer)
  54.             {
  55.                 buffer2 = line.Split(',');
  56.                 foreach (string item in buffer2)
  57.                 {
  58.                     nouns.Add(item);
  59.                 }
  60.             }
  61.         }
  62.  
  63.         private void poniesButton_Click(object sender, EventArgs e)
  64.         {
  65.  
  66.             if (verbs.Count < 1 || ponies.Count < 1 || nouns.Count < 1)
  67.             {
  68.                 boxponiesText.Text = "Error loading dictionary files...";
  69.                 return;
  70.             }
  71.             Random rnd = new Random();
  72.             string verb = verbs[rnd.Next(verbs.Count - 1)];
  73.             string pony = ponies[rnd.Next(ponies.Count - 1)];
  74.             string noun = nouns[rnd.Next(nouns.Count - 1)];
  75.             string sentence = pony + " " + verb + " " + noun;
  76.             boxponiesText.Text = sentence;
  77.  
  78.             if (minTxt.Text != "")
  79.             {
  80.                 timer1.Enabled = true;
  81.                 try
  82.                 {
  83.                     minutes = System.Convert.ToInt32(minTxt.Text);
  84.                     seconds = System.Convert.ToInt32("00");
  85.                 }
  86.                 catch (Exception ex)
  87.                 {
  88.                     MessageBox.Show(ex.Message);
  89.                 }
  90.             }
  91.             else
  92.             {
  93.                 MessageBox.Show("I need some time!");
  94.             }
  95.         }
  96.        
  97.         private void timer1_Tick_1(object sender, EventArgs e)
  98.         {
  99. {
  100.             // Verify if the time didn't pass.
  101.             if (minutes == 0)
  102.             {
  103.  
  104.                 // If the time is over, clear all settings and fields.
  105.                 // Also, show the message, notifying that the time is over.
  106.                 lblMin.Text = "00";
  107.  
  108.  
  109.                 if (seconds == 0)
  110.                 {
  111.                     System.Threading.Thread.Sleep(500);
  112.                     timer1.Enabled = false;
  113.                     System.Media.SystemSounds.Asterisk.Play();
  114.                     MessageBox.Show(" Hey everypony times up, Show your art.");
  115.                 }
  116.             }
  117.             else
  118.             {
  119.                 // Else continue counting.
  120.                 if (seconds < 1)
  121.                 {
  122.                     seconds = 59;
  123.                     if (minutes == 0)
  124.                     {
  125.                         minutes = 59;
  126.  
  127.  
  128.                     }
  129.                     else
  130.                     {
  131.                         minutes -= 1;
  132.                     }
  133.                 }
  134.                 else
  135.                     seconds -= 1;
  136.                 // Display the current values of hours, minutes and seconds in
  137.                 // the corresponding fields.
  138.                 lblMin.Text = minutes.ToString();
  139.                 lblSec.Text = seconds.ToString();
  140.             }
  141.         }
  142.         }
  143.  
  144.         }
  145.         }