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

Untitled

By: a guest on Jul 31st, 2012  |  syntax: C#  |  size: 3.21 KB  |  hits: 21  |  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 bootcamp
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.  
  19.         /*
  20.         1 = Pushups
  21.         2 = Jumping Jacks
  22.         3 = Situps
  23.         4 = Squats
  24.         5 = Burpees
  25.         */
  26.  
  27.         Random random = new Random();
  28.  
  29.         int GetAmount(int type)
  30.         {
  31.             int raw_mod = random.Next(10, 15);
  32.             int mod = raw_mod / 10;
  33.  
  34.             if (type == 1) // Pushups
  35.             {
  36.                 return random.Next(5, 16) * mod;
  37.             }
  38.             else if (type == 2) // Jumping jacks
  39.             {
  40.                 return random.Next(15, 26) * mod;
  41.             }
  42.             else if (type == 3) // Situps
  43.             {
  44.                 return random.Next(10, 21) * mod;
  45.             }
  46.             else if (type == 4) // Squats
  47.             {
  48.                 return random.Next(15, 21) * mod;
  49.             }
  50.             else if (type == 5) // Burpees
  51.             {
  52.                 return random.Next(10, 26) * mod;
  53.             }
  54.  
  55.             return 15 * mod;
  56.         }
  57.  
  58.         string GetName(int type)
  59.         {
  60.             if (type == 1) // Pushups
  61.             {
  62.                 return "push-ups";
  63.             }
  64.             else if (type == 2) // Jumping jacks
  65.             {
  66.                 return "jumping jacks";
  67.             }
  68.             else if (type == 3) // Situps
  69.             {
  70.                 return "sit-ups";
  71.             }
  72.             else if (type == 4) // Squats
  73.             {
  74.                 return "squats";
  75.             }
  76.             else if (type == 5) // Burpees
  77.             {
  78.                 return "burpees";
  79.             }
  80.  
  81.             return "ERROR";
  82.         }
  83.  
  84.         private void level_Scroll(object sender, EventArgs e)
  85.         {
  86.             int lvl = level.Value;
  87.  
  88.             if (lvl == 1)
  89.             {
  90.                 levellabel.Text = "Level: Private";
  91.             }
  92.             else if (lvl == 2)
  93.             {
  94.                 levellabel.Text = "Level: Colonel";
  95.             }
  96.             else if (lvl == 3)
  97.             {
  98.                 levellabel.Text = "Level: General";
  99.             }
  100.         }
  101.  
  102.         private void Form1_Load(object sender, EventArgs e)
  103.         {
  104.             // Do nothing
  105.         }
  106.  
  107.         private void roll_Click(object sender, EventArgs e)
  108.         {
  109.             tasks.Items.Clear();
  110.            
  111.             int tasks_amount = random.Next(4, 7);
  112.  
  113.             for (int i = 0; i < tasks_amount + 1; i++)
  114.             {
  115.                 if (i != tasks_amount)
  116.                 {
  117.                     int type = random.Next(1, 6);
  118.                     int amount = GetAmount(type) * level.Value;
  119.  
  120.                     string display = "Do " + Convert.ToString(amount) + " " + GetName(type) + ".";
  121.  
  122.                     tasks.Items.Add(display);
  123.                 }
  124.                 else
  125.                 {
  126.                     tasks.Items.Add("Go home, soldier.");
  127.                 }
  128.             }
  129.         }
  130.     }
  131. }