Guest User

Untitled

a guest
Oct 18th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 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.Windows.Forms;
  9.  
  10. namespace Hw_09_AileenChung2
  11. {
  12. public partial class Form1 : Form
  13. {
  14. static DateTime _randomDate;
  15. DateTime _guess;
  16. DateTime _previousGuess;
  17.  
  18.  
  19. public Form1()
  20. {
  21. InitializeComponent();
  22.  
  23. }
  24.  
  25. public static void RandomDateGenerator()
  26. {
  27.  
  28. DateTime oneYearAgo = DateTime.Today.AddYears(-1);
  29. TimeSpan span = DateTime.Today - oneYearAgo;
  30.  
  31. int numDays = span.Days;
  32.  
  33. Random random = new Random();
  34. int randomInt = random.Next(numDays);
  35. _randomDate = oneYearAgo.AddDays(randomInt);
  36.  
  37. }
  38.  
  39.  
  40. //this is what happens once someone confirms their guess
  41. private void btnGuess_Click(object sender, EventArgs e)
  42. {
  43. int tries = 0;
  44. tries++;
  45.  
  46. if (dateGuess.Value == _randomDate)
  47. {
  48. lblStatus.Text = "You got it!";
  49. }
  50.  
  51. else
  52. {
  53. lblStatus.Text = "Incorrect.";
  54. }
  55. }
  56. // this it he DateTimePicker that the guesser uses to guess the random date.
  57. //i want to only have them allowed to guess from today's date to a year ago from todays date.
  58. private void dateGuess_ValueChanged(object sender, EventArgs e)
  59. {
  60. //min date
  61. dateGuess.MinDate = DateTime.Today;
  62.  
  63. //max date
  64. dateGuess.MaxDate = DateTime.Today.AddYears(-1);
  65. }
  66.  
  67.  
  68. }
  69. }
Add Comment
Please, Sign In to add comment