Advertisement
Guest User

memeAssignment

a guest
Feb 21st, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Interfaces_CardConcepts;
  7.  
  8. namespace Interfaces_Delegate_Form
  9. {
  10. class GameController
  11. {
  12. // handles to model (entity) objects
  13. private Deck d; private Hand h;
  14.  
  15. public GameController(Deck d, Hand h) { this.d = d; this.h = h; }
  16.  
  17. // handles event that requests one more card be added to hand:
  18. public string handle(object sender, EventArgs e)
  19. {
  20. h.add(d.deal());
  21. return (h.ToString());
  22. }
  23. }
  24. }
  25.  
  26.  
  27.  
  28. using System;
  29. using System.Collections.Generic;
  30. using System.ComponentModel;
  31. using System.Data;
  32. using System.Drawing;
  33. using System.Linq;
  34. using System.Text;
  35. using System.Threading.Tasks;
  36. using System.Windows.Forms;
  37. using Interfaces_CardConcepts;
  38.  
  39. namespace Interfaces_Delegate_Form
  40. {
  41.  
  42. public partial class Form1 : Form
  43. {
  44. // handles to event handler and model:
  45. private EventHandler f; // method f has type Eventhandler
  46.  
  47.  
  48. public Form1(EventHandler f)
  49. {
  50. this.f = f;
  51. InitializeComponent();
  52. }
  53.  
  54. // handles button1 click: calls controller to execute algorithm
  55. // and then resets the view (label1)
  56. private void button1_Click(object sender, EventArgs e)
  57. {
  58. //f(sender, e); // call Eventhandler f to do its work
  59. label1.Text = f(sender, e);
  60.  
  61. }
  62. }
  63. }
  64.  
  65.  
  66. using System;
  67. using System.Collections.Generic;
  68. using System.Linq;
  69. using System.Threading.Tasks;
  70. using System.Windows.Forms;
  71. using Interfaces_CardConcepts;
  72.  
  73. namespace Interfaces_Delegate_Form
  74. {
  75. // the Delegate defines a data type for methods:
  76. public delegate string EventHandler(object sender, EventArgs e);
  77.  
  78. static class Program
  79. {
  80. /// <summary>
  81. /// Card game assembly:
  82. /// </summary>
  83. [STAThread]
  84. static void Main()
  85. {
  86. // allocate model (entity) objects and the controller:
  87. Hand h = new Hand();
  88. Deck d = new Deck();
  89. GameController c = new GameController(d,h);
  90.  
  91.  
  92.  
  93. Application.EnableVisualStyles();
  94. Application.SetCompatibleTextRenderingDefault(false);
  95.  
  96. // IMPORTANT: note first argument to new Form1
  97. // Activate Form and give it handles to the event handler and model:
  98. Application.Run(new Form1(c.handle));
  99. }
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement