Dota design mode-Bridging

Source: Internet
Author: User
Tags dota
The bridge mode is relatively simple, mainly using a combination.
UML diagram:

In this article, I have created some scenarios, which are not often used in Dota.
Dota has five teammates. If I say that, if your teammates eat too much watermelon and want to take a nap, but now is the key. He is a group controller, you can't sacrifice a pair of underpants for victory. We can only share units. Now you can control yourself or the heroes of your teammates. You can click a hero to control it. Here you can use bridging.
As mentioned above, bridging is a combination. First, heroes are indispensable unless they have been sent back to spring water and are not reborn:
Public   Interface Ihero
{
Void Action ();
}

///   <Summary>
/// Soul guard
///   </Summary>
Public   Class Terrorblade: ihero
{
Public Terrorblade ()
{
}

# RegionIhero Member

Public VoidAction ()
{
Landpyform. Form. outputresult ("Terrorblade action");
}

# Endregion
}

///   <Summary>
/// Druid
///   </Summary>
Public   Class Syllabear: ihero
{
Public Syllabear ()
{
}

# RegionIhero Member

Public VoidAction ()
{
Landpyform. Form. outputresult ("Syllabear action");
}

# Endregion
}
What's worse? Of course it's our players. is a game called a game without any players?
Public   Class Gamer
{
Private Ihero _ hero;
Public Ihero hero
{
Set {_ Hero = Value ;}
}

Public   Void Action ()
{
_ Hero. Action ();
}
}
The gamer class contains the ihero interface, which is dependent on Inversion. No matter what new hero Code You don't need to change it. The decoupling is absolutely decoupled. Headfirst says, "use multiple combinations and use less inheritance.
The test code is as follows:
Dotapatternlibrary. Bridge. gamer = new dotapatternlibrary. Bridge. gamer ();
Dotapatternlibrary. Bridge. ihero hero = new dotapatternlibrary. Bridge. syllabear ();
Gamer. Hero = hero;
Gamer. Action ();
Hero = new dotapatternlibrary. Bridge. terrorblade ();
Gamer. Hero = hero;
Gamer. Action ();
You can switch between controllable heroes at any time.
Complete code: Using System;
Using System. Collections. Generic;
Using System. LINQ;
Using System. text;

UsingDotacommon;

NamespaceDotapatternlibrary. Bridge
{

Public InterfaceIhero
{
VoidAction ();
}

///   <Summary>
/// Soul guard
///   </Summary>
Public   Class Terrorblade: ihero
{
Public Terrorblade ()
{
}

# RegionIhero Member

Public VoidAction ()
{
Landpyform. Form. outputresult ("Terrorblade action");
}

# Endregion
}

///   <Summary>
/// Druid
///   </Summary>
Public   Class Syllabear: ihero
{
Public Syllabear ()
{
}

# RegionIhero Member

Public VoidAction ()
{
Landpyform. Form. outputresult ("Syllabear action");
}

# endregion
}

Public class gamer
{< br> private ihero _ hero;
Public ihero hero
{< br> set {_ hero = value ;}< BR >}

Public void action ()
{< br> _ hero. action ();
}< BR >}< br>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.