zoukankan      html  css  js  c++  java
  • DOTA版设计模式——外观模式

    外观模式,不知道你是否会碰到这样的场景,公司要开会了,由你负责布置会场,你需要做的工作有:
    1.把窗帘拉下来。
    2.摆好椅子。
    3.降下投影幕布。
    4.打开投影仪。
    5...............
    太烦了,有时你甚至少做了一样,别怕,如果有了外观模式就可以高枕无忧了。简单的说,外观模式就是把1~5条甚至更多的操作抽象为一个操作,那就是------------开会
    在本例中,外观模式就是把游戏初始化的操作合并为一个操作,Game类中的GameStart。
    此模式比较好理解,具体请see完整代码哟。
    测试代码:
                DotaPatternLibrary.Facade.Game game = new DotaPatternLibrary.Facade.Game();
                game.GameStart();
    完整代码:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    using DotaCommon;

    namespace DotaPatternLibrary.Facade
    {
        
    public class Game
        {
            
    public void GameStart()
            {
                HeroFactory heroFactory 
    = new HeroFactory();
                heroFactory.CreateModel();
                heroFactory.SetSkill();
                heroFactory.Maps();
                BotWildNPC botWildNPC 
    = new BotWildNPC();
                botWildNPC.CreateModel();
                botWildNPC.Maps();
                Music music 
    = new Music();
                music.SelectMusic();
                music.Play();
                Terrain terrain 
    = new Terrain();
                terrain.RandomTerrain();
                terrain.Maps();
            }
        }

        
    internal class HeroFactory
        {
            
    public void CreateModel()
            {
                LandpyForm.Form.OutputResult(
    "CreateHeroModel");
            }

            
    public void SetSkill()
            {
                LandpyForm.Form.OutputResult(
    "SetHeroSkill");
            }

            
    public void Maps()
            {
                LandpyForm.Form.OutputResult(
    "MapsHero");
            }
        }

        
    internal class BotWildNPC
        {
            
    public void CreateModel()
            {
                LandpyForm.Form.OutputResult(
    "CreateBotWildNPCModel");
            }

            
    public void Maps()
            {
                LandpyForm.Form.OutputResult(
    "MapsBotWildNPC");
            }
        }

        
    internal class Music
        {
            
    public void SelectMusic()
            {
                LandpyForm.Form.OutputResult(
    "SelectMusic");
            }

            
    public void Play()
            {
                LandpyForm.Form.OutputResult(
    "MusicPlay");
            }
        }

        
    internal class Terrain
        {
            
    public void RandomTerrain()
            {
                LandpyForm.Form.OutputResult(
    "RandomTerrain");
            }

            
    public void Maps()
            {
                LandpyForm.Form.OutputResult(
    "MapsTerrain");
            }
        }
    }
    敬告

    作者:pangxiaoliang
    出处:http://www.cnblogs.com/pangxiaoliang
    本文版权归pangxiaoliang和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,谢谢合作。
  • 相关阅读:
    小白的linux笔记3:对外联通——开通ssh和ftp和smb共享
    小白的linux笔记2:关于进程的基本操作
    小白的linux笔记1:CentOS 8 安装与设置
    Python+Flask+MysqL的web技术建站过程
    管理信息系统 第三部分 作业
    数据迁移
    模型分离(选做)
    密码保护
    实现搜索功能
    完成个人中心—导航标签
  • 原文地址:https://www.cnblogs.com/pangxiaoliang/p/1531152.html
Copyright © 2011-2022 走看看