Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Interfaces_CardConcepts;
- namespace Interfaces_Delegate_Form
- {
- class GameController
- {
- // handles to model (entity) objects
- private Deck d; private Hand h;
- public GameController(Deck d, Hand h) { this.d = d; this.h = h; }
- // handles event that requests one more card be added to hand:
- public string handle(object sender, EventArgs e)
- {
- h.add(d.deal());
- return (h.ToString());
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using Interfaces_CardConcepts;
- namespace Interfaces_Delegate_Form
- {
- public partial class Form1 : Form
- {
- // handles to event handler and model:
- private EventHandler f; // method f has type Eventhandler
- public Form1(EventHandler f)
- {
- this.f = f;
- InitializeComponent();
- }
- // handles button1 click: calls controller to execute algorithm
- // and then resets the view (label1)
- private void button1_Click(object sender, EventArgs e)
- {
- //f(sender, e); // call Eventhandler f to do its work
- label1.Text = f(sender, e);
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using Interfaces_CardConcepts;
- namespace Interfaces_Delegate_Form
- {
- // the Delegate defines a data type for methods:
- public delegate string EventHandler(object sender, EventArgs e);
- static class Program
- {
- /// <summary>
- /// Card game assembly:
- /// </summary>
- [STAThread]
- static void Main()
- {
- // allocate model (entity) objects and the controller:
- Hand h = new Hand();
- Deck d = new Deck();
- GameController c = new GameController(d,h);
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- // IMPORTANT: note first argument to new Form1
- // Activate Form and give it handles to the event handler and model:
- Application.Run(new Form1(c.handle));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement