Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
少侠Smile丶
design patterns in games
提交
c09df35f
D
design patterns in games
项目概览
少侠Smile丶
/
design patterns in games
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
29
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
代码片段
项目成员
Pages
D
design patterns in games
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
29
Issue
29
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c09df35f
编写于
7月 04, 2021
作者:
少侠Smile丶
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add project && add dicorator and bridge
上级
d979a654
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
291 addition
and
1 deletion
+291
-1
Design Pattern/App.config
Design Pattern/App.config
+6
-0
Design Pattern/Client.cs
Design Pattern/Client.cs
+29
-0
Design Pattern/Design Patterns.csproj
Design Pattern/Design Patterns.csproj
+44
-0
Design Pattern/Structural/Bridge(桥接模式)/Bridge.cs
Design Pattern/Structural/Bridge(桥接模式)/Bridge.cs
+99
-0
Design Pattern/Structural/Decorator(装饰者)/Decorator.cs
Design Pattern/Structural/Decorator(装饰者)/Decorator.cs
+112
-0
README.md
README.md
+1
-1
未找到文件。
Design Pattern/App.config
0 → 100644
浏览文件 @
c09df35f
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
configuration
>
<
startup
>
<
supportedRuntime
version
=
"v4.0"
sku
=
".NETFramework,Version=v4.6.1"
/>
</
startup
>
</
configuration
>
\ No newline at end of file
Design Pattern/Client.cs
0 → 100644
浏览文件 @
c09df35f
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
Design_Pattern
{
class
Client
{
public
static
void
Main
()
{
// 装饰者
IExecute
exe
=
new
Decorator
();
exe
.
Execute
();
// 桥模式
exe
=
new
Bridge
();
exe
.
Execute
();
Console
.
ReadKey
();
}
}
public
interface
IExecute
{
void
Execute
();
}
}
Design Pattern/Design Patterns.csproj
0 → 100644
浏览文件 @
c09df35f
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"15.0"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<Import
Project=
"$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"
Condition=
"Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"
/>
<PropertyGroup>
<Configuration
Condition=
" '$(Configuration)' == '' "
>
Debug
</Configuration>
<Platform
Condition=
" '$(Platform)' == '' "
>
AnyCPU
</Platform>
<ProjectGuid>
{A0764AC7-5A51-4EC4-A3D8-EA452543D6D6}
</ProjectGuid>
<OutputType>
Exe
</OutputType>
<RootNamespace>
Design_Pattern
</RootNamespace>
<AssemblyName>
Design Pattern
</AssemblyName>
<TargetFrameworkVersion>
v4.6.1
</TargetFrameworkVersion>
<FileAlignment>
512
</FileAlignment>
<AutoGenerateBindingRedirects>
true
</AutoGenerateBindingRedirects>
<Deterministic>
true
</Deterministic>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "
>
<PlatformTarget>
AnyCPU
</PlatformTarget>
<DebugSymbols>
true
</DebugSymbols>
<DebugType>
full
</DebugType>
<Optimize>
false
</Optimize>
<OutputPath>
bin\Debug\
</OutputPath>
<DefineConstants>
DEBUG;TRACE
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "
>
<PlatformTarget>
AnyCPU
</PlatformTarget>
<DebugType>
pdbonly
</DebugType>
<Optimize>
true
</Optimize>
<OutputPath>
bin\Release\
</OutputPath>
<DefineConstants>
TRACE
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
<ItemGroup>
<None
Include=
"App.config"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"Client.cs"
/>
<Compile
Include=
"Structural\Bridge%28桥接模式%29\Bridge.cs"
/>
<Compile
Include=
"Structural\Decorator%28装饰者%29\Decorator.cs"
/>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
</Project>
\ No newline at end of file
Design Pattern/Structural/Bridge(桥接模式)/Bridge.cs
0 → 100644
浏览文件 @
c09df35f
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
Design_Pattern
{
public
class
Bridge
:
IExecute
{
void
IExecute
.
Execute
()
{
Console
.
WriteLine
(
"\n桥接模式执行......"
);
// 声明一个客户端的战斗会话类,会话链接类型为TCP
var
battle
=
new
ClientBattleSession
(
new
TCPSession
());
battle
.
OnConnect
();
battle
.
OnSend
();
battle
.
OnReceive
();
battle
.
OnClose
();
}
}
/* 定义实现者 */
/// <summary>
/// Implementor 会话接口
/// </summary>
public
interface
SessionImp
{
void
Send
();
void
Receive
();
}
public
class
UDPSession
:
SessionImp
{
public
void
Send
()
{
Console
.
WriteLine
(
"UDP Send"
);
}
public
void
Receive
()
{
Console
.
WriteLine
(
"UDP Receive"
);
}
}
public
class
TCPSession
:
SessionImp
{
public
void
Send
()
{
Console
.
WriteLine
(
"TCP Send"
);
}
public
void
Receive
()
{
Console
.
WriteLine
(
"TCP Receive"
);
}
}
/* 定义抽象类 */
public
abstract
class
BattleSession
{
protected
SessionImp
m_Imp
;
public
virtual
void
OnConnect
()
{
}
public
virtual
void
OnClose
()
{
}
public
virtual
void
OnSend
()
{
}
public
virtual
void
OnReceive
()
{
}
public
BattleSession
(
SessionImp
imp
)
{
m_Imp
=
imp
;
}
}
public
class
ClientBattleSession
:
BattleSession
{
public
override
void
OnConnect
()
{
base
.
OnConnect
();
Console
.
WriteLine
(
"Client onConnect"
);
}
public
override
void
OnClose
()
{
base
.
OnClose
();
Console
.
WriteLine
(
"Client onClose"
);
}
public
override
void
OnSend
()
{
base
.
OnSend
();
Console
.
WriteLine
(
"Client onSend"
);
m_Imp
.
Send
();
}
public
override
void
OnReceive
()
{
base
.
OnReceive
();
Console
.
WriteLine
(
"Client onReceive"
);
m_Imp
.
Receive
();
}
public
ClientBattleSession
(
SessionImp
imp
)
:
base
(
imp
)
{
}
}
//public class ServerBattleSession : BattleSession
//{
// //......
//}
}
Design Pattern/Structural/Decorator(装饰者)/Decorator.cs
0 → 100644
浏览文件 @
c09df35f
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
Design_Pattern
{
public
class
Decorator
:
IExecute
{
void
IExecute
.
Execute
()
{
Console
.
WriteLine
(
"装饰者模式执行......"
);
Person
person
=
new
Person
();
// 定义一个镶嵌了绿宝石的法杖
IDecorator
GreenStaff
=
new
GreenGemStone
(
new
Staff
());
person
.
SetWeapon
(
GreenStaff
);
person
.
UseWeapon
();
// 定义一个镶嵌了红宝石的法杖
IDecorator
RedStaff
=
new
RedGemStone
(
new
Staff
());
person
.
SetWeapon
(
RedStaff
);
person
.
UseWeapon
();
}
}
/// <summary>
/// 友情出演 人 类
/// </summary>
public
class
Person
{
IDecorator
m_Weapon
;
public
void
SetWeapon
(
IDecorator
weapon
)
{
m_Weapon
=
weapon
;
}
public
void
UseWeapon
()
{
m_Weapon
.
Attack
();
}
}
/// <summary>
/// 武器接口
/// </summary>
public
interface
IDecorator
{
void
Attack
();
}
/// <summary>
/// 法杖类(被装饰者)
/// </summary>
public
class
Staff
:
IDecorator
{
public
void
Attack
()
{
Console
.
WriteLine
(
"法杖进行攻击,普通伤害"
);
}
}
/*-------------------- 以下是装饰类 --------------------*/
/// <summary>
/// 宝石装饰抽象类
/// </summary>
public
abstract
class
GemStoneDecorator
:
IDecorator
{
IDecorator
m_Weapon
;
// 实现接口
public
virtual
void
Attack
()
{
m_Weapon
.
Attack
();
}
public
GemStoneDecorator
(
IDecorator
weapon
)
{
m_Weapon
=
weapon
;
}
}
/// <summary>
/// 红宝石类(具体装饰类),增加攻击效果:增加眩晕效果
/// </summary>
public
class
RedGemStone
:
GemStoneDecorator
{
public
override
void
Attack
()
{
base
.
Attack
();
Console
.
WriteLine
(
"镶嵌了红宝石的武器进行攻击,造成眩晕效果"
);
}
public
RedGemStone
(
IDecorator
weapon
)
:
base
(
weapon
)
{
}
}
/// <summary>
/// 绿宝石类(具体装饰类),增加攻击效果:增加降速效果
/// </summary>
public
class
GreenGemStone
:
GemStoneDecorator
{
public
override
void
Attack
()
{
base
.
Attack
();
Console
.
WriteLine
(
"镶嵌了绿宝石的武器进行攻击,造成降速效果"
);
}
public
GreenGemStone
(
IDecorator
weapon
)
:
base
(
weapon
)
{
}
}
}
README.md
浏览文件 @
c09df35f
# sample-data-repo
关于游戏开发中的设计模式
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录