抽象工厂模式(abstract)创建型模式 c#简单例子
适用于玩家用户数play1、play2....有变化,而行为move、jum无变化时
玩家playone的行为:向左移动和向上跳跃
玩家playtwo的行为:向右移动和向下跳跃
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace adapterpattern
{
public partial class abstractForm : Form
{
public abstractForm()
{
InitializeComponent();
}
private void btnDisplay_Click(object sender, EventArgs e)
{
playFactory pf1 = new playone();//隐藏行为move和jump.
playWorld p1 = new playWorld(pf1);//行为向左移动和向上跳跃
this.listBox1.Items.Add(p1.createPlay());
playWorld p2 = new playWorld(new playtwo());//行为向右移动和向下跳跃
this.listBox1.Items.Add(p2.createPlay());
}
}
public class playWorl