├── .gitattributes ├── .gitignore ├── DesignPatternsGame.AbstractFactory ├── BlueGoo.cs ├── BlueGooFactory.cs ├── BrownGoo.cs ├── BrownGooFactory.cs ├── DesignPatternsGame.AbstractFactory.csproj ├── GreenGoo.cs ├── GreenGooFactory.cs ├── IEnemyFactory.cs ├── Properties │ └── AssemblyInfo.cs ├── README.md ├── RedGoo.cs ├── RedGooFactory.cs └── Spawner.cs ├── DesignPatternsGame.Adapter ├── DesignPatternsGame.Adapter.csproj ├── Foulu.cs ├── Properties │ └── AssemblyInfo.cs ├── README.md ├── Zero.cs └── ZeroAdapter.cs ├── DesignPatternsGame.Bridge ├── BridgeCharacter.cs ├── DesignPatternsGame.Bridge.csproj ├── Foulu.cs ├── IMoveStrategy.cs ├── Properties │ └── AssemblyInfo.cs ├── README.md ├── RunStrategy.cs └── WalkStrategy.cs ├── DesignPatternsGame.Builder ├── DesignPatternsGame.Builder.csproj ├── GameCharacter.cs ├── MainCharacterBuilder.cs └── Properties │ └── AssemblyInfo.cs ├── DesignPatternsGame.ChainOfResponsibility ├── ChargerChain.cs ├── DesignPatternsGame.ChainOfResponsibility.csproj ├── Megaman.cs ├── NormalCharger.cs ├── Properties │ └── AssemblyInfo.cs ├── README.md └── UltraCharger.cs ├── DesignPatternsGame.Command ├── CreateGodCommand.cs ├── CreateRobotCommand.cs ├── DesignPatternsGame.Command.csproj ├── ICommand.cs └── Properties │ └── AssemblyInfo.cs ├── DesignPatternsGame.Common ├── Animation.cs ├── BaseGame.cs ├── DesignPatternsGame.Common.csproj ├── GameSprite.cs ├── Properties │ └── AssemblyInfo.cs └── README.md ├── DesignPatternsGame.Composite ├── CompositeGameSprite.cs ├── DesignPatternsGame.Composite.csproj ├── ICompositeMove.cs └── Properties │ └── AssemblyInfo.cs ├── DesignPatternsGame.Decorator ├── DesignPatternsGame.Decorator.csproj ├── GameSpriteDecorator.cs ├── GameSpriteFastDecorator.cs ├── GameSpriteSlowDecorator.cs └── Properties │ └── AssemblyInfo.cs ├── DesignPatternsGame.Facade ├── DesignPatternsGame.Facade.csproj ├── FouluFacade.cs └── Properties │ └── AssemblyInfo.cs ├── DesignPatternsGame.Factory ├── DesignPatternsGame.Factory.csproj ├── Foulu.cs ├── GameSpriteFactory.cs ├── Properties │ └── AssemblyInfo.cs └── Zero.cs ├── DesignPatternsGame.Mediator ├── DesignPatternsGame.Mediator.csproj ├── Foulu.cs ├── GameSpriteMediator.cs └── Properties │ └── AssemblyInfo.cs ├── DesignPatternsGame.Memento ├── DesignPatternsGame.Memento.csproj ├── Foulu.cs ├── FouluRecorder.cs ├── Memento.cs └── Properties │ └── AssemblyInfo.cs ├── DesignPatternsGame.Observer ├── DesignPatternsGame.Observer.csproj ├── Follower.cs ├── Foulu.cs ├── IGodEmperor.cs ├── IGodEmperorObserver.cs ├── Properties │ └── AssemblyInfo.cs └── README.md ├── DesignPatternsGame.Prototype ├── DesignPatternsGame.Prototype.csproj ├── Foulu.cs └── Properties │ └── AssemblyInfo.cs ├── DesignPatternsGame.Proxy ├── DesignPatternsGame.Proxy.csproj ├── Foulu.cs ├── FouluProxy.cs └── Properties │ └── AssemblyInfo.cs ├── DesignPatternsGame.Singleton ├── DesignPatternsGame.Singleton.csproj ├── Foulu.cs └── Properties │ └── AssemblyInfo.cs ├── DesignPatternsGame.State ├── DesignPatternsGame.State.csproj ├── Foulu.cs ├── IMoveState.cs ├── Properties │ └── AssemblyInfo.cs ├── RunningState.cs └── WalkingState.cs ├── DesignPatternsGame.Strategy ├── DesignPatternsGame.Strategy.csproj ├── IMoveStrategy.cs ├── MovableCharacter.cs ├── Properties │ └── AssemblyInfo.cs ├── README.md ├── RunStrategy.cs └── WalkStrategy.cs ├── DesignPatternsGame.Visitor ├── Boost.cs ├── DesignPatternsGame.Visitor.csproj ├── Foulu.cs ├── IAccept.cs ├── IVisitor.cs └── Properties │ └── AssemblyInfo.cs ├── DesignPatternsGame.sln ├── DesignPatternsGame ├── DesignPatternsGame │ ├── AbstractFactoryGame.cs │ ├── AdapterGame.cs │ ├── BridgeGame.cs │ ├── BuilderGame.cs │ ├── ChainOfResponsibilityGame.cs │ ├── CommandGame.cs │ ├── CompositeGame.cs │ ├── DecoratorGame.cs │ ├── DesignPatternsGame.csproj │ ├── FacadeGame.cs │ ├── FactoryGame.cs │ ├── FlyweightGame.cs │ ├── Game.ico │ ├── GameMenu.cs │ ├── GameThumbnail.png │ ├── MediatorGame.cs │ ├── MementoGame.cs │ ├── ObserverGame.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── PrototypeGame.cs │ ├── ProxyGame.cs │ ├── SingletonGame.cs │ ├── StateGame.cs │ ├── StrategyGame.cs │ └── VisitorGame.cs └── DesignPatternsGameContent │ ├── DesignPatternsGameContent.contentproj │ ├── Foulu.png │ ├── Megaman.png │ ├── MorphGoo.png │ ├── Ryu.png │ └── Zero.png └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # Build results 10 | 11 | [Dd]ebug/ 12 | [Rr]elease/ 13 | x64/ 14 | build/ 15 | [Bb]in/ 16 | [Oo]bj/ 17 | 18 | # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets 19 | !packages/*/build/ 20 | 21 | # MSTest test Results 22 | [Tt]est[Rr]esult*/ 23 | [Bb]uild[Ll]og.* 24 | 25 | *_i.c 26 | *_p.c 27 | *.ilk 28 | *.meta 29 | *.obj 30 | *.pch 31 | *.pdb 32 | *.pgc 33 | *.pgd 34 | *.rsp 35 | *.sbr 36 | *.tlb 37 | *.tli 38 | *.tlh 39 | *.tmp 40 | *.tmp_proj 41 | *.log 42 | *.vspscc 43 | *.vssscc 44 | .builds 45 | *.pidb 46 | *.log 47 | *.scc 48 | 49 | # Visual C++ cache files 50 | ipch/ 51 | *.aps 52 | *.ncb 53 | *.opensdf 54 | *.sdf 55 | *.cachefile 56 | 57 | # Visual Studio profiler 58 | *.psess 59 | *.vsp 60 | *.vspx 61 | 62 | # Guidance Automation Toolkit 63 | *.gpState 64 | 65 | # ReSharper is a .NET coding add-in 66 | _ReSharper*/ 67 | *.[Rr]e[Ss]harper 68 | 69 | # TeamCity is a build add-in 70 | _TeamCity* 71 | 72 | # DotCover is a Code Coverage Tool 73 | *.dotCover 74 | 75 | # NCrunch 76 | *.ncrunch* 77 | .*crunch*.local.xml 78 | 79 | # Installshield output folder 80 | [Ee]xpress/ 81 | 82 | # DocProject is a documentation generator add-in 83 | DocProject/buildhelp/ 84 | DocProject/Help/*.HxT 85 | DocProject/Help/*.HxC 86 | DocProject/Help/*.hhc 87 | DocProject/Help/*.hhk 88 | DocProject/Help/*.hhp 89 | DocProject/Help/Html2 90 | DocProject/Help/html 91 | 92 | # Click-Once directory 93 | publish/ 94 | 95 | # Publish Web Output 96 | *.Publish.xml 97 | 98 | # NuGet Packages Directory 99 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 100 | #packages/ 101 | 102 | # Windows Azure Build Output 103 | csx 104 | *.build.csdef 105 | 106 | # Windows Store app package directory 107 | AppPackages/ 108 | 109 | # Others 110 | sql/ 111 | *.Cache 112 | ClientBin/ 113 | [Ss]tyle[Cc]op.* 114 | ~$* 115 | *~ 116 | *.dbmdl 117 | *.[Pp]ublish.xml 118 | *.pfx 119 | *.publishsettings 120 | 121 | # RIA/Silverlight projects 122 | Generated_Code/ 123 | 124 | # Backup & report files from converting an old project file to a newer 125 | # Visual Studio version. Backup files are not needed, because we have git ;-) 126 | _UpgradeReport_Files/ 127 | Backup*/ 128 | UpgradeLog*.XML 129 | UpgradeLog*.htm 130 | 131 | # SQL Server files 132 | App_Data/*.mdf 133 | App_Data/*.ldf 134 | 135 | 136 | #LightSwitch generated files 137 | GeneratedArtifacts/ 138 | _Pvt_Extensions/ 139 | ModelManifest.xml 140 | 141 | # ========================= 142 | # Windows detritus 143 | # ========================= 144 | 145 | # Windows image file caches 146 | Thumbs.db 147 | ehthumbs.db 148 | 149 | # Folder config file 150 | Desktop.ini 151 | 152 | # Recycle Bin used on file shares 153 | $RECYCLE.BIN/ 154 | 155 | # Mac desktop service store files 156 | .DS_Store 157 | -------------------------------------------------------------------------------- /DesignPatternsGame.AbstractFactory/BlueGoo.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Common; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Graphics; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | 9 | namespace DesignPatternsGame.AbstractFactory 10 | { 11 | public class BlueGoo : GameSprite 12 | { 13 | public BlueGoo(Texture2D spriteTexture, Vector2 spritePosition) 14 | : base(spriteTexture, spritePosition) 15 | { 16 | Animation = new Animation(100, 48, 48, 27, 0, 48 * 1); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /DesignPatternsGame.AbstractFactory/BlueGooFactory.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | using Microsoft.Xna.Framework.Content; 3 | using Microsoft.Xna.Framework.Graphics; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | 9 | namespace DesignPatternsGame.AbstractFactory 10 | { 11 | public class BlueGooFactory : IEnemyFactory 12 | { 13 | public Common.GameSprite Create(ContentManager content, Vector2 spritePosition) 14 | { 15 | return new BlueGoo(content.Load("MorphGoo"), spritePosition); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /DesignPatternsGame.AbstractFactory/BrownGoo.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Common; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Graphics; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | 9 | namespace DesignPatternsGame.AbstractFactory 10 | { 11 | public class BrownGoo : GameSprite 12 | { 13 | public BrownGoo(Texture2D spriteTexture, Vector2 spritePosition) 14 | : base(spriteTexture, spritePosition) 15 | { 16 | Animation = new Animation(100, 48, 48, 27, 0, 48 * 3); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /DesignPatternsGame.AbstractFactory/BrownGooFactory.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | using Microsoft.Xna.Framework.Content; 3 | using Microsoft.Xna.Framework.Graphics; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | 9 | namespace DesignPatternsGame.AbstractFactory 10 | { 11 | public class BrownGooFactory : IEnemyFactory 12 | { 13 | public Common.GameSprite Create(ContentManager content, Vector2 spritePosition) 14 | { 15 | return new BrownGoo(content.Load("MorphGoo"), spritePosition); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /DesignPatternsGame.AbstractFactory/GreenGoo.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Common; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Graphics; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | 9 | namespace DesignPatternsGame.AbstractFactory 10 | { 11 | public class GreenGoo : GameSprite 12 | { 13 | public GreenGoo(Texture2D spriteTexture, Vector2 spritePosition) 14 | : base(spriteTexture, spritePosition) 15 | { 16 | Animation = new Animation(100, 48, 48, 27, 0, 48 * 2); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /DesignPatternsGame.AbstractFactory/GreenGooFactory.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Common; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Content; 4 | using Microsoft.Xna.Framework.Graphics; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | 10 | namespace DesignPatternsGame.AbstractFactory 11 | { 12 | public class GreenGooFactory : IEnemyFactory 13 | { 14 | public Common.GameSprite Create(ContentManager content, Vector2 spritePosition) 15 | { 16 | return new GreenGoo(content.Load("MorphGoo"), spritePosition); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /DesignPatternsGame.AbstractFactory/IEnemyFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | using DesignPatternsGame.Common; 12 | 13 | namespace DesignPatternsGame.AbstractFactory 14 | { 15 | public interface IEnemyFactory 16 | { 17 | GameSprite Create(ContentManager content, Vector2 spritePosition); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /DesignPatternsGame.AbstractFactory/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DesignPatternsGame.AbstractFactory")] 9 | [assembly: AssemblyProduct("DesignPatternsGame.AbstractFactory")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyCopyright("Copyright © 2014")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. Only Windows 19 | // assemblies support COM. 20 | [assembly: ComVisible(false)] 21 | 22 | // On Windows, the following GUID is for the ID of the typelib if this 23 | // project is exposed to COM. On other platforms, it unique identifies the 24 | // title storage container when deploying this assembly to the device. 25 | [assembly: Guid("3679f042-4923-486e-91a7-f9dc67301834")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | [assembly: AssemblyVersion("1.0.0.0")] -------------------------------------------------------------------------------- /DesignPatternsGame.AbstractFactory/README.md: -------------------------------------------------------------------------------- 1 | Abstract Factory Pattern 2 | ======================== 3 | 4 | Using an abstract Factory it is possible to create the desired object type without making the instantiated class aware of it. 5 | 6 | In this example I can create different types of Goos by changing the factory. 7 | http://youtu.be/p0SwjtbzjdM 8 | 9 | 10 | Another example is in Starcraft where the player choses one race and have their base and units spawn accordingly: https://www.youtube.com/watch?v=N8_wwa90tzM -------------------------------------------------------------------------------- /DesignPatternsGame.AbstractFactory/RedGoo.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Common; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Graphics; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | 9 | namespace DesignPatternsGame.AbstractFactory 10 | { 11 | public class RedGoo : GameSprite 12 | { 13 | public RedGoo(Texture2D spriteTexture, Vector2 spritePosition) 14 | : base(spriteTexture, spritePosition) 15 | { 16 | Animation = new Animation(100, 48, 48, 27); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /DesignPatternsGame.AbstractFactory/RedGooFactory.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | using Microsoft.Xna.Framework.Content; 3 | using Microsoft.Xna.Framework.Graphics; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | 9 | namespace DesignPatternsGame.AbstractFactory 10 | { 11 | public class RedGooFactory : IEnemyFactory 12 | { 13 | public Common.GameSprite Create(ContentManager content, Vector2 spritePosition) 14 | { 15 | return new RedGoo(content.Load("MorphGoo"), spritePosition); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /DesignPatternsGame.AbstractFactory/Spawner.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | using Microsoft.Xna.Framework.Content; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace DesignPatternsGame.AbstractFactory 9 | { 10 | public class Spawner 11 | { 12 | public IEnemyFactory EnemyFactory { get; set; } 13 | 14 | private ContentManager content; 15 | 16 | private Vector2 nextPoint = Vector2.Zero; 17 | 18 | private int totalSpawned = 0; 19 | 20 | public Spawner(ContentManager content) 21 | { 22 | this.content = content; 23 | 24 | EnemyFactory = new GreenGooFactory(); 25 | } 26 | 27 | public Common.GameSprite Spawn() 28 | { 29 | var mod = totalSpawned % 15; 30 | nextPoint += totalSpawned == 0 ? Vector2.Zero : new Vector2(50, mod == 0 ? 50 : 0); 31 | 32 | if (mod == 0 && totalSpawned != 0) 33 | nextPoint = new Vector2(0, nextPoint.Y + 10); 34 | 35 | ++totalSpawned; 36 | 37 | return EnemyFactory.Create(this.content, this.nextPoint); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /DesignPatternsGame.Adapter/DesignPatternsGame.Adapter.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | {2886D458-58A7-4A77-A524-D7487B1E1F62} 5 | {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 6 | Debug 7 | x86 8 | Library 9 | Properties 10 | DesignPatternsGame.Adapter 11 | DesignPatternsGame.Adapter 12 | v4.0 13 | Client 14 | v4.0 15 | Windows 16 | Reach 17 | 401e2967-49fe-4ed9-baa2-794b947c77cf 18 | Library 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\x86\Debug 25 | DEBUG;TRACE;WINDOWS 26 | prompt 27 | 4 28 | true 29 | false 30 | x86 31 | false 32 | 33 | 34 | pdbonly 35 | true 36 | bin\x86\Release 37 | TRACE;WINDOWS 38 | prompt 39 | 4 40 | true 41 | false 42 | x86 43 | true 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 4.0 55 | 56 | 57 | 4.0 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | {af729afb-a869-4656-8453-03ffd407775d} 70 | DesignPatternsGame.Common 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 86 | -------------------------------------------------------------------------------- /DesignPatternsGame.Adapter/Foulu.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | using DesignPatternsGame.Common; 12 | 13 | namespace DesignPatternsGame.Adapter 14 | { 15 | public class Foulu : GameSprite 16 | { 17 | public Foulu(Texture2D spriteTexture, Vector2 spritePosition) 18 | : base(spriteTexture, spritePosition) 19 | { 20 | } 21 | 22 | public override void Move(GamePadState Controller1) 23 | { 24 | SpritePosition += 2 * new Vector2(Controller1.ThumbSticks.Left.X, 0); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /DesignPatternsGame.Adapter/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DesignPatternsGame.Adapter")] 9 | [assembly: AssemblyProduct("DesignPatternsGame.Adapter")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyCopyright("Copyright © 2014")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. Only Windows 19 | // assemblies support COM. 20 | [assembly: ComVisible(false)] 21 | 22 | // On Windows, the following GUID is for the ID of the typelib if this 23 | // project is exposed to COM. On other platforms, it unique identifies the 24 | // title storage container when deploying this assembly to the device. 25 | [assembly: Guid("19a79bc8-0c42-4225-9838-4b59d52be2c0")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | [assembly: AssemblyVersion("1.0.0.0")] -------------------------------------------------------------------------------- /DesignPatternsGame.Adapter/README.md: -------------------------------------------------------------------------------- 1 | Adapter Pattern 2 | =============== 3 | 4 | Using this pattern we can easily integrate third party code into our code by using the adapter wrapper. 5 | 6 | Another example is in Starcraft Mario could be an unit: https://www.youtube.com/watch?v=hvpXKZhNINc -------------------------------------------------------------------------------- /DesignPatternsGame.Adapter/Zero.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DesignPatternsGame.Adapter 7 | { 8 | public sealed class Zero 9 | { 10 | public void MoveDashing() 11 | { 12 | // 3rd party code - unmodifiable 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /DesignPatternsGame.Adapter/ZeroAdapter.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Common; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Graphics; 4 | using Microsoft.Xna.Framework.Input; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | 10 | namespace DesignPatternsGame.Adapter 11 | { 12 | public class ZeroAdapter : GameSprite 13 | { 14 | private Zero zero; 15 | 16 | public ZeroAdapter(Zero zero, Texture2D spriteTexture, Vector2 spritePosition) 17 | : base(spriteTexture, spritePosition) 18 | { 19 | this.zero = zero; 20 | } 21 | 22 | public override void Move(GamePadState Controller1) 23 | { 24 | zero.MoveDashing(); 25 | 26 | // adapt values to match your game 27 | SpritePosition += 2 * new Vector2(Controller1.ThumbSticks.Left.X, 0); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /DesignPatternsGame.Bridge/BridgeCharacter.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Common; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Graphics; 4 | using Microsoft.Xna.Framework.Input; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | 10 | namespace DesignPatternsGame.Bridge 11 | { 12 | public abstract class BridgeCharacter : GameSprite 13 | { 14 | public BridgeCharacter(Texture2D spriteTexture, Vector2 spritePosition) 15 | : base(spriteTexture, spritePosition) 16 | { 17 | } 18 | 19 | public override abstract void Move(GamePadState Controller1); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /DesignPatternsGame.Bridge/Foulu.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | using DesignPatternsGame.Common; 12 | 13 | namespace DesignPatternsGame.Bridge 14 | { 15 | public class Foulu : BridgeCharacter 16 | { 17 | public IMoveStrategy MoveStrategy { get; set; } 18 | 19 | public Foulu(Texture2D spriteTexture, Vector2 spritePosition) 20 | : base(spriteTexture, spritePosition) 21 | { 22 | MoveStrategy = new WalkStrategy(); 23 | } 24 | 25 | public override void Move(GamePadState Controller1) 26 | { 27 | SpritePosition = MoveStrategy.Move(SpritePosition, Controller1); 28 | } 29 | 30 | public override void Draw(GameTime gameTime, SpriteBatch spriteBatch) 31 | { 32 | MoveStrategy.Draw(gameTime, spriteBatch, SpriteTexture, SpritePosition); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /DesignPatternsGame.Bridge/IMoveStrategy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | 12 | namespace DesignPatternsGame.Bridge 13 | { 14 | public interface IMoveStrategy 15 | { 16 | Vector2 Move(Vector2 spritePosition, GamePadState controllerState); 17 | 18 | void Draw(GameTime gameTime, SpriteBatch spriteBatch, Texture2D texture, Vector2 position); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /DesignPatternsGame.Bridge/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DesignPatternsGame.Bridge")] 9 | [assembly: AssemblyProduct("DesignPatternsGame.Bridge")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyCopyright("Copyright © 2014")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. Only Windows 19 | // assemblies support COM. 20 | [assembly: ComVisible(false)] 21 | 22 | // On Windows, the following GUID is for the ID of the typelib if this 23 | // project is exposed to COM. On other platforms, it unique identifies the 24 | // title storage container when deploying this assembly to the device. 25 | [assembly: Guid("d6e32445-b8b7-4653-bf5f-805dd39e7563")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | [assembly: AssemblyVersion("1.0.0.0")] -------------------------------------------------------------------------------- /DesignPatternsGame.Bridge/README.md: -------------------------------------------------------------------------------- 1 | Bridge Pattern 2 | ============== 3 | 4 | Can control the behavior of methods accordingly to the bridge implementation. And can vary the behavior by the concrete class implementation. -------------------------------------------------------------------------------- /DesignPatternsGame.Bridge/RunStrategy.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Common; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Graphics; 4 | using Microsoft.Xna.Framework.Input; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | 10 | namespace DesignPatternsGame.Bridge 11 | { 12 | public class RunStrategy : IMoveStrategy 13 | { 14 | private Animation animation; 15 | 16 | public RunStrategy() 17 | { 18 | this.animation = new Animation(100, 48, 48, 5, 0, 48 * 4); 19 | } 20 | 21 | public Vector2 Move(Vector2 spritePosition, GamePadState controllerState) 22 | { 23 | return spritePosition + 7 * new Vector2(controllerState.ThumbSticks.Left.X, -controllerState.ThumbSticks.Left.Y); 24 | } 25 | 26 | public void Draw(GameTime gameTime, SpriteBatch spriteBatch, Texture2D texture, Vector2 position) 27 | { 28 | this.animation.Draw(gameTime, spriteBatch, texture, position); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /DesignPatternsGame.Bridge/WalkStrategy.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Common; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Graphics; 4 | using Microsoft.Xna.Framework.Input; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | 10 | namespace DesignPatternsGame.Bridge 11 | { 12 | public class WalkStrategy : IMoveStrategy 13 | { 14 | private Animation animation; 15 | 16 | public WalkStrategy() 17 | { 18 | this.animation = new Animation(100, 48, 48, 5, offsetY: 48); 19 | } 20 | 21 | public Vector2 Move(Vector2 spritePosition, GamePadState controllerState) 22 | { 23 | return spritePosition + 2 * new Vector2(controllerState.ThumbSticks.Left.X, -controllerState.ThumbSticks.Left.Y); 24 | } 25 | 26 | public void Draw(GameTime gameTime, SpriteBatch spriteBatch, Texture2D texture, Vector2 position) 27 | { 28 | this.animation.Draw(gameTime, spriteBatch, texture, position); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /DesignPatternsGame.Builder/DesignPatternsGame.Builder.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | {ED593CE0-2971-45BB-A932-655ECDCE8129} 5 | {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 6 | Debug 7 | x86 8 | Library 9 | Properties 10 | DesignPatternsGame.Builder 11 | DesignPatternsGame.Builder 12 | v4.0 13 | Client 14 | v4.0 15 | Windows 16 | Reach 17 | 9f07826f-ab52-4224-ab1f-d8f189817b1b 18 | Library 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\x86\Debug 25 | DEBUG;TRACE;WINDOWS 26 | prompt 27 | 4 28 | true 29 | false 30 | x86 31 | false 32 | 33 | 34 | pdbonly 35 | true 36 | bin\x86\Release 37 | TRACE;WINDOWS 38 | prompt 39 | 4 40 | true 41 | false 42 | x86 43 | true 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 4.0 55 | 56 | 57 | 4.0 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | {af729afb-a869-4656-8453-03ffd407775d} 69 | DesignPatternsGame.Common 70 | 71 | 72 | 73 | 74 | 82 | -------------------------------------------------------------------------------- /DesignPatternsGame.Builder/GameCharacter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | using DesignPatternsGame.Common; 12 | 13 | namespace DesignPatternsGame.Builder 14 | { 15 | public class GameCharacter : GameSprite 16 | { 17 | public GameCharacter(Texture2D spriteTexture, Vector2 spritePosition) 18 | : base(spriteTexture, spritePosition) 19 | { 20 | } 21 | 22 | public override void Move(GamePadState Controller1) 23 | { 24 | SpritePosition += 2 * new Vector2(Controller1.ThumbSticks.Left.X, 0); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /DesignPatternsGame.Builder/MainCharacterBuilder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | using DesignPatternsGame.Common; 12 | 13 | namespace DesignPatternsGame.Builder 14 | { 15 | public class MainCharacterBuilder 16 | { 17 | private ContentManager content; 18 | 19 | public GameCharacter Result { get; private set; } 20 | 21 | public MainCharacterBuilder(ContentManager content) 22 | { 23 | this.content = content; 24 | } 25 | 26 | public void BuildGod() 27 | { 28 | Result = new GameCharacter(content.Load("Foulu"), new Vector2(40, 100)); 29 | Result.Animation = new Animation(250, 48, 48, 5, offsetY: 48); 30 | } 31 | 32 | public void BuildRobot() 33 | { 34 | Result = new GameCharacter(content.Load("Zero"), new Vector2(40, 100)); 35 | Result.Animation = new Animation(250, 48, 48, 9); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /DesignPatternsGame.Builder/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DesignPatternsGame.Builder")] 9 | [assembly: AssemblyProduct("DesignPatternsGame.Builder")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyCopyright("Copyright © 2014")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. Only Windows 19 | // assemblies support COM. 20 | [assembly: ComVisible(false)] 21 | 22 | // On Windows, the following GUID is for the ID of the typelib if this 23 | // project is exposed to COM. On other platforms, it unique identifies the 24 | // title storage container when deploying this assembly to the device. 25 | [assembly: Guid("01294eb2-5db2-4f73-ba74-d06348320ab3")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | [assembly: AssemblyVersion("1.0.0.0")] -------------------------------------------------------------------------------- /DesignPatternsGame.ChainOfResponsibility/ChargerChain.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Common; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Graphics; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | 9 | namespace DesignPatternsGame.ChainOfResponsibility 10 | { 11 | public abstract class ChargerChain 12 | { 13 | public ChargerChain Next { get; set; } 14 | 15 | public virtual void Charge(SpriteBatch spriteBatch, GameTime gameTime, double elapsed) 16 | { 17 | if (Next != null) 18 | Next.Charge(spriteBatch, gameTime, elapsed); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /DesignPatternsGame.ChainOfResponsibility/Megaman.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | using DesignPatternsGame.Common; 12 | 13 | namespace DesignPatternsGame.ChainOfResponsibility 14 | { 15 | public class Megaman : GameSprite 16 | { 17 | public Megaman(Texture2D spriteTexture, Vector2 spritePosition) 18 | : base(spriteTexture, spritePosition) 19 | { 20 | //Animation = new Animation(250, 48, 72, 9); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /DesignPatternsGame.ChainOfResponsibility/NormalCharger.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Common; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Graphics; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | 9 | namespace DesignPatternsGame.ChainOfResponsibility 10 | { 11 | public class NormalCharger : ChargerChain 12 | { 13 | private GameSprite character; 14 | private readonly Animation animation = new Animation(250, 48, 72, 7, 48 * 2, 0); 15 | 16 | public NormalCharger(GameSprite character) 17 | { 18 | this.character = character; 19 | } 20 | 21 | public override void Charge(SpriteBatch spriteBatch, GameTime gameTime, double elapsed) 22 | { 23 | if (elapsed < 7500) 24 | { 25 | this.animation.Draw(gameTime, spriteBatch, this.character.SpriteTexture, this.character.SpritePosition); 26 | } 27 | else 28 | { 29 | base.Charge(spriteBatch, gameTime, elapsed); 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /DesignPatternsGame.ChainOfResponsibility/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DesignPatternsGame.ChainOfResponsibility")] 9 | [assembly: AssemblyProduct("DesignPatternsGame.ChainOfResponsibility")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyCopyright("Copyright © 2014")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. Only Windows 19 | // assemblies support COM. 20 | [assembly: ComVisible(false)] 21 | 22 | // On Windows, the following GUID is for the ID of the typelib if this 23 | // project is exposed to COM. On other platforms, it unique identifies the 24 | // title storage container when deploying this assembly to the device. 25 | [assembly: Guid("1190841b-04d8-48a6-ac31-1329605619fd")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | [assembly: AssemblyVersion("1.0.0.0")] -------------------------------------------------------------------------------- /DesignPatternsGame.ChainOfResponsibility/README.md: -------------------------------------------------------------------------------- 1 | ChainOfResponsibility Pattern 2 | ============================= 3 | 4 | One class has a responsability and when it has done all it could it tries to reach the next class in the chain to continue the work and so on... 5 | 6 | In this example one class is responsible for rendering Megaman charging the level 1 power and when the responsability of this class ends it reaches the next resposable class in the chain and start working rendering the level 2 power. 7 | 8 | Another example is in Starcraft where units can heal others using the chain: https://www.youtube.com/watch?v=EtR2dVXdVGo 9 | 10 | For a basic example there is also a dude in a bank: https://www.youtube.com/watch?v=O28YpB4fo18 -------------------------------------------------------------------------------- /DesignPatternsGame.ChainOfResponsibility/UltraCharger.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Common; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Graphics; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | 9 | namespace DesignPatternsGame.ChainOfResponsibility 10 | { 11 | public class UltraCharger : ChargerChain 12 | { 13 | private GameSprite character; 14 | 15 | private readonly Animation animation = new Animation(250, 48, 72, 9, 0, 72); 16 | 17 | public UltraCharger(GameSprite character) 18 | { 19 | this.character = character; 20 | } 21 | 22 | public override void Charge(SpriteBatch spriteBatch, GameTime gameTime, double elapsed) 23 | { 24 | if (elapsed < 15000) 25 | { 26 | this.animation.Draw(gameTime, spriteBatch, this.character.SpriteTexture, this.character.SpritePosition); 27 | } 28 | else 29 | { 30 | base.Charge(spriteBatch, gameTime, elapsed); 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /DesignPatternsGame.Command/CreateGodCommand.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Common; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Content; 4 | using Microsoft.Xna.Framework.Graphics; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | 10 | namespace DesignPatternsGame.Command 11 | { 12 | public class CreateGodCommand : ICommand 13 | { 14 | public Common.GameSprite Execute(ContentManager content) 15 | { 16 | var fouLu = new Common.GameSprite(content.Load("Foulu"), Vector2.Zero); 17 | 18 | fouLu.Animation = new Animation(250, 48, 48, 5, offsetY: 48); 19 | 20 | return fouLu; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /DesignPatternsGame.Command/CreateRobotCommand.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Common; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Content; 4 | using Microsoft.Xna.Framework.Graphics; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | 10 | namespace DesignPatternsGame.Command 11 | { 12 | public class CreateRobotCommand : ICommand 13 | { 14 | public Common.GameSprite Execute(ContentManager content) 15 | { 16 | var zero = new Common.GameSprite(content.Load("Zero"), Vector2.Zero); 17 | 18 | zero.Animation = new Animation(250, 48, 48, 9); 19 | 20 | return zero; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /DesignPatternsGame.Command/DesignPatternsGame.Command.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | {72F07994-9355-4E06-932C-553650CED99D} 5 | {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 6 | Debug 7 | x86 8 | Library 9 | Properties 10 | DesignPatternsGame.Command 11 | DesignPatternsGame.Command 12 | v4.0 13 | Client 14 | v4.0 15 | Windows 16 | Reach 17 | 3f59f060-f091-4170-adaf-0cbe0d911318 18 | Library 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\x86\Debug 25 | DEBUG;TRACE;WINDOWS 26 | prompt 27 | 4 28 | true 29 | false 30 | x86 31 | false 32 | 33 | 34 | pdbonly 35 | true 36 | bin\x86\Release 37 | TRACE;WINDOWS 38 | prompt 39 | 4 40 | true 41 | false 42 | x86 43 | true 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 4.0 55 | 56 | 57 | 4.0 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | {af729afb-a869-4656-8453-03ffd407775d} 70 | DesignPatternsGame.Common 71 | 72 | 73 | 74 | 75 | 83 | -------------------------------------------------------------------------------- /DesignPatternsGame.Command/ICommand.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Common; 2 | using Microsoft.Xna.Framework.Content; 3 | using Microsoft.Xna.Framework.Input; 4 | using System; 5 | 6 | namespace DesignPatternsGame.Command 7 | { 8 | public interface ICommand 9 | { 10 | GameSprite Execute(ContentManager content); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DesignPatternsGame.Command/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DesignPatternsGame.Command")] 9 | [assembly: AssemblyProduct("DesignPatternsGame.Command")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyCopyright("Copyright © 2015")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. Only Windows 19 | // assemblies support COM. 20 | [assembly: ComVisible(false)] 21 | 22 | // On Windows, the following GUID is for the ID of the typelib if this 23 | // project is exposed to COM. On other platforms, it unique identifies the 24 | // title storage container when deploying this assembly to the device. 25 | [assembly: Guid("ef29514e-9055-4906-b569-b049a8f92cb3")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | [assembly: AssemblyVersion("1.0.0.0")] -------------------------------------------------------------------------------- /DesignPatternsGame.Common/Animation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | 12 | namespace DesignPatternsGame.Common 13 | { 14 | public class Animation 15 | { 16 | private double elapsed = 0; 17 | 18 | public int Frame { get; set; } 19 | 20 | public int Delay { get; set; } 21 | 22 | public int SpriteWidth { get; set; } 23 | 24 | public int SpriteHeight { get; set; } 25 | 26 | public int TotalFrames { get; set; } 27 | 28 | public int OffsetX { get; set; } 29 | 30 | public int OffsetY { get; set; } 31 | 32 | public Animation(int delay, int spriteWidth, int spriteHeight, int totalFrames, int offsetX = 0, int offsetY = 0) 33 | { 34 | Delay = delay; 35 | SpriteWidth = spriteWidth; 36 | SpriteHeight = spriteHeight; 37 | TotalFrames = totalFrames; 38 | OffsetX = offsetX; 39 | OffsetY = offsetY; 40 | } 41 | 42 | public void Draw(GameTime gameTime, SpriteBatch spriteBatch, Texture2D texture, Vector2 position) 43 | { 44 | spriteBatch.Draw(texture, position, new Rectangle(OffsetX + SpriteWidth * Frame, OffsetY, SpriteWidth, SpriteHeight), Color.White); 45 | 46 | elapsed += gameTime.ElapsedGameTime.TotalMilliseconds; 47 | 48 | if (elapsed > Delay) 49 | { 50 | elapsed = 0; 51 | ++Frame; 52 | 53 | if (Frame > TotalFrames) 54 | Frame = 0; 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /DesignPatternsGame.Common/BaseGame.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | using DesignPatternsGame.Common; 12 | 13 | namespace DesignPatternsGame.Common 14 | { 15 | public abstract class BaseGame : Microsoft.Xna.Framework.Game 16 | { 17 | public Color BackgroundColor { get; set; } 18 | public GraphicsDeviceManager Graphics { get; set; } 19 | public SpriteBatch SpriteBatch { get; set; } 20 | 21 | public GamePadState Controller1 22 | { 23 | get 24 | { 25 | return GamePad.GetState(PlayerIndex.One); 26 | } 27 | } 28 | 29 | public delegate void OnCustomDrawing(GameTime gameTime); 30 | public event OnCustomDrawing CustomDrawing; 31 | 32 | public BaseGame() 33 | { 34 | Graphics = new GraphicsDeviceManager(this); 35 | Content.RootDirectory = "Content"; 36 | BackgroundColor = Color.Black; 37 | } 38 | 39 | protected override void LoadContent() 40 | { 41 | SpriteBatch = new SpriteBatch(GraphicsDevice); 42 | 43 | base.LoadContent(); 44 | } 45 | 46 | protected override void Update(GameTime gameTime) 47 | { 48 | if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) 49 | this.Exit(); 50 | 51 | #if WINDOWS 52 | if (Keyboard.GetState().IsKeyDown(Keys.Escape)) 53 | this.Exit(); 54 | #endif 55 | 56 | base.Update(gameTime); 57 | } 58 | 59 | protected override void Draw(GameTime gameTime) 60 | { 61 | GraphicsDevice.Clear(BackgroundColor); 62 | 63 | SpriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend); 64 | 65 | if (CustomDrawing != null) 66 | CustomDrawing(gameTime); 67 | 68 | SpriteBatch.End(); 69 | 70 | base.Draw(gameTime); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /DesignPatternsGame.Common/DesignPatternsGame.Common.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | {AF729AFB-A869-4656-8453-03FFD407775D} 5 | {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 6 | Debug 7 | x86 8 | Library 9 | Properties 10 | DesignPatternsGame.Common 11 | DesignPatternsGame.Common 12 | v4.0 13 | Client 14 | v4.0 15 | Windows 16 | Reach 17 | 0bbca58e-1d8b-4cb2-b60c-562fef64ee27 18 | Library 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\x86\Debug 25 | DEBUG;TRACE;WINDOWS 26 | prompt 27 | 4 28 | true 29 | false 30 | x86 31 | false 32 | 33 | 34 | pdbonly 35 | true 36 | bin\x86\Release 37 | TRACE;WINDOWS 38 | prompt 39 | 4 40 | true 41 | false 42 | x86 43 | true 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 4.0 55 | 56 | 57 | 4.0 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 80 | -------------------------------------------------------------------------------- /DesignPatternsGame.Common/GameSprite.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | using Microsoft.Xna.Framework.Graphics; 3 | using Microsoft.Xna.Framework.Input; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | 9 | namespace DesignPatternsGame.Common 10 | { 11 | public class GameSprite 12 | { 13 | public Vector2 SpritePosition { get; set; } 14 | 15 | public virtual Animation Animation { get; set; } 16 | 17 | public Texture2D SpriteTexture { get; set; } 18 | 19 | public virtual uint SpeedRatio { get; set; } 20 | 21 | public GameSprite(Texture2D spriteTexture, Vector2 spritePosition) 22 | { 23 | SpriteTexture = spriteTexture; 24 | SpritePosition = spritePosition; 25 | SpeedRatio = 1; 26 | } 27 | 28 | public virtual void Move(GamePadState gamePadState) 29 | { 30 | SpritePosition += SpeedRatio * new Vector2(gamePadState.ThumbSticks.Left.X, 0); 31 | } 32 | 33 | public virtual void Draw(GameTime gameTime, SpriteBatch spriteBatch) 34 | { 35 | Animation.Draw(gameTime, spriteBatch, SpriteTexture, SpritePosition); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /DesignPatternsGame.Common/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DesignPatternsGame.Common")] 9 | [assembly: AssemblyProduct("DesignPatternsGame.Common")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyCopyright("Copyright © 2014")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. Only Windows 19 | // assemblies support COM. 20 | [assembly: ComVisible(false)] 21 | 22 | // On Windows, the following GUID is for the ID of the typelib if this 23 | // project is exposed to COM. On other platforms, it unique identifies the 24 | // title storage container when deploying this assembly to the device. 25 | [assembly: Guid("01bae5e6-bf74-4b41-9556-6c7764597c58")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | [assembly: AssemblyVersion("1.0.0.0")] -------------------------------------------------------------------------------- /DesignPatternsGame.Common/README.md: -------------------------------------------------------------------------------- 1 | Commom 2 | ====== 3 | 4 | Helper classes to implement game elements. -------------------------------------------------------------------------------- /DesignPatternsGame.Composite/CompositeGameSprite.cs: -------------------------------------------------------------------------------- 1 | namespace DesignPatternsGame.Composite 2 | { 3 | using DesignPatternsGame.Common; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Graphics; 6 | using Microsoft.Xna.Framework.Input; 7 | using System.Collections.Generic; 8 | 9 | public class CompositeGameSprite : ICompositeMove 10 | { 11 | private List composition = new List(); 12 | 13 | public void Add(GameSprite sprite) 14 | { 15 | this.composition.Add(sprite); 16 | } 17 | 18 | public void Move(GamePadState gamePadState) 19 | { 20 | foreach (var item in this.composition) 21 | { 22 | item.Move(gamePadState); 23 | } 24 | } 25 | 26 | public void Draw(GameTime gameTime, SpriteBatch spriteBatch) 27 | { 28 | foreach (var item in this.composition) 29 | { 30 | item.Draw(gameTime, spriteBatch); 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /DesignPatternsGame.Composite/DesignPatternsGame.Composite.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | {FD189AE9-AE45-4E22-A8AD-A63E467A9B4A} 5 | {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 6 | Debug 7 | x86 8 | Library 9 | Properties 10 | DesignPatternsGame.Composite 11 | DesignPatternsGame.Composite 12 | v4.0 13 | Client 14 | v4.0 15 | Windows 16 | Reach 17 | edfc2e89-90c1-4743-b49e-85a65395d25e 18 | Library 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\x86\Debug 25 | DEBUG;TRACE;WINDOWS 26 | prompt 27 | 4 28 | true 29 | false 30 | x86 31 | false 32 | 33 | 34 | pdbonly 35 | true 36 | bin\x86\Release 37 | TRACE;WINDOWS 38 | prompt 39 | 4 40 | true 41 | false 42 | x86 43 | true 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 4.0 55 | 56 | 57 | 4.0 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | {af729afb-a869-4656-8453-03ffd407775d} 69 | DesignPatternsGame.Common 70 | 71 | 72 | 73 | 74 | 82 | -------------------------------------------------------------------------------- /DesignPatternsGame.Composite/ICompositeMove.cs: -------------------------------------------------------------------------------- 1 | namespace DesignPatternsGame.Composite 2 | { 3 | using Microsoft.Xna.Framework; 4 | using Microsoft.Xna.Framework.Graphics; 5 | using Microsoft.Xna.Framework.Input; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Text; 10 | 11 | public interface ICompositeMove 12 | { 13 | void Move(GamePadState gamePadState); 14 | 15 | void Draw(GameTime gameTime, SpriteBatch spriteBatch); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /DesignPatternsGame.Composite/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DesignPatternsGame.Composite")] 9 | [assembly: AssemblyProduct("DesignPatternsGame.Composite")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyCopyright("Copyright © 2015")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. Only Windows 19 | // assemblies support COM. 20 | [assembly: ComVisible(false)] 21 | 22 | // On Windows, the following GUID is for the ID of the typelib if this 23 | // project is exposed to COM. On other platforms, it unique identifies the 24 | // title storage container when deploying this assembly to the device. 25 | [assembly: Guid("d1fce37f-d2eb-4ae4-ab65-cc81ef8b3e6c")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | [assembly: AssemblyVersion("1.0.0.0")] -------------------------------------------------------------------------------- /DesignPatternsGame.Decorator/DesignPatternsGame.Decorator.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | {967D36BD-4777-41DD-A439-76A1EA644DEA} 5 | {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 6 | Debug 7 | x86 8 | Library 9 | Properties 10 | DesignPatternsGame.Decorator 11 | DesignPatternsGame.Decorator 12 | v4.0 13 | Client 14 | v4.0 15 | Windows 16 | Reach 17 | cf11965a-ac33-4862-881a-d6c628d1e062 18 | Library 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\x86\Debug 25 | DEBUG;TRACE;WINDOWS 26 | prompt 27 | 4 28 | true 29 | false 30 | x86 31 | false 32 | 33 | 34 | pdbonly 35 | true 36 | bin\x86\Release 37 | TRACE;WINDOWS 38 | prompt 39 | 4 40 | true 41 | false 42 | x86 43 | true 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 4.0 55 | 56 | 57 | 4.0 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | {af729afb-a869-4656-8453-03ffd407775d} 70 | DesignPatternsGame.Common 71 | 72 | 73 | 74 | 75 | 83 | -------------------------------------------------------------------------------- /DesignPatternsGame.Decorator/GameSpriteDecorator.cs: -------------------------------------------------------------------------------- 1 | namespace DesignPatternsGame.Decorator 2 | { 3 | using DesignPatternsGame.Common; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | using System; 12 | using System.Collections.Generic; 13 | using System.Linq; 14 | 15 | public class GameSpriteDecorator : GameSprite 16 | { 17 | public GameSpriteDecorator(GameSprite gameSprite) 18 | : base(gameSprite.SpriteTexture, gameSprite.SpritePosition) 19 | { 20 | Animation = gameSprite.Animation; 21 | SpeedRatio = gameSprite.SpeedRatio; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /DesignPatternsGame.Decorator/GameSpriteFastDecorator.cs: -------------------------------------------------------------------------------- 1 | namespace DesignPatternsGame.Decorator 2 | { 3 | using DesignPatternsGame.Common; 4 | using Microsoft.Xna.Framework; 5 | 6 | public class GameSpriteFastDecorator : GameSpriteDecorator 7 | { 8 | public GameSpriteFastDecorator(GameSprite gameSprite) 9 | : base(gameSprite) 10 | { 11 | 12 | } 13 | public override uint SpeedRatio 14 | { 15 | get 16 | { 17 | return base.SpeedRatio + 1; 18 | } 19 | set 20 | { 21 | base.SpeedRatio = value; 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /DesignPatternsGame.Decorator/GameSpriteSlowDecorator.cs: -------------------------------------------------------------------------------- 1 | namespace DesignPatternsGame.Decorator 2 | { 3 | using DesignPatternsGame.Common; 4 | using Microsoft.Xna.Framework; 5 | 6 | public class GameSpriteSlowDecorator : GameSpriteDecorator 7 | { 8 | public GameSpriteSlowDecorator(GameSprite gameSprite) 9 | : base(gameSprite) 10 | { 11 | 12 | } 13 | 14 | public override uint SpeedRatio 15 | { 16 | get 17 | { 18 | return base.SpeedRatio - 1; 19 | } 20 | set 21 | { 22 | base.SpeedRatio = value; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /DesignPatternsGame.Decorator/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DesignPatternsGame.Decorator")] 9 | [assembly: AssemblyProduct("DesignPatternsGame.Decorator")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyCopyright("Copyright © 2015")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. Only Windows 19 | // assemblies support COM. 20 | [assembly: ComVisible(false)] 21 | 22 | // On Windows, the following GUID is for the ID of the typelib if this 23 | // project is exposed to COM. On other platforms, it unique identifies the 24 | // title storage container when deploying this assembly to the device. 25 | [assembly: Guid("45667355-72ae-442f-9f06-65c94db12aca")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | [assembly: AssemblyVersion("1.0.0.0")] -------------------------------------------------------------------------------- /DesignPatternsGame.Facade/DesignPatternsGame.Facade.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | {277D3CDE-EBDA-486A-AA48-5BA9D6E3E5A1} 5 | {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 6 | Debug 7 | x86 8 | Library 9 | Properties 10 | DesignPatternsGame.Facade 11 | DesignPatternsGame.Facade 12 | v4.0 13 | Client 14 | v4.0 15 | Windows 16 | Reach 17 | cea3a3fd-5801-4779-b6ee-30edd833e9e4 18 | Library 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\x86\Debug 25 | DEBUG;TRACE;WINDOWS 26 | prompt 27 | 4 28 | true 29 | false 30 | x86 31 | false 32 | 33 | 34 | pdbonly 35 | true 36 | bin\x86\Release 37 | TRACE;WINDOWS 38 | prompt 39 | 4 40 | true 41 | false 42 | x86 43 | true 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 4.0 55 | 56 | 57 | 4.0 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | {af729afb-a869-4656-8453-03ffd407775d} 68 | DesignPatternsGame.Common 69 | 70 | 71 | 72 | 73 | 81 | -------------------------------------------------------------------------------- /DesignPatternsGame.Facade/FouluFacade.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | using DesignPatternsGame.Common; 12 | 13 | namespace DesignPatternsGame.Facade 14 | { 15 | public class FouluFacade 16 | { 17 | private ContentManager content; 18 | private string textureName; 19 | private Vector2 position; 20 | 21 | public FouluFacade(ContentManager content, string textureName, Vector2 position) 22 | { 23 | this.content = content; 24 | this.textureName = textureName; 25 | this.position = position; 26 | } 27 | 28 | public GameSprite AssemblyCharacter() 29 | { 30 | return new GameSprite(this.content.Load(this.textureName), this.position) 31 | { 32 | Animation = new Animation(300, 48, 48, 5, offsetY: 48) 33 | }; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /DesignPatternsGame.Facade/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DesignPatternsGame.Facade")] 9 | [assembly: AssemblyProduct("DesignPatternsGame.Facade")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyCopyright("Copyright © 2015")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. Only Windows 19 | // assemblies support COM. 20 | [assembly: ComVisible(false)] 21 | 22 | // On Windows, the following GUID is for the ID of the typelib if this 23 | // project is exposed to COM. On other platforms, it unique identifies the 24 | // title storage container when deploying this assembly to the device. 25 | [assembly: Guid("eb695139-8e1b-4cf7-a7fb-f9f025900ce3")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | [assembly: AssemblyVersion("1.0.0.0")] -------------------------------------------------------------------------------- /DesignPatternsGame.Factory/DesignPatternsGame.Factory.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | {1A0B7A10-EEA9-44C3-B2DA-F6AF2F17628A} 5 | {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 6 | Debug 7 | x86 8 | Library 9 | Properties 10 | DesignPatternsGame.Factory 11 | DesignPatternsGame.Factory 12 | v4.0 13 | Client 14 | v4.0 15 | Windows 16 | Reach 17 | d7ffa418-1693-43c8-bbcc-7702bf89df4c 18 | Library 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\x86\Debug 25 | DEBUG;TRACE;WINDOWS 26 | prompt 27 | 4 28 | true 29 | false 30 | x86 31 | false 32 | 33 | 34 | pdbonly 35 | true 36 | bin\x86\Release 37 | TRACE;WINDOWS 38 | prompt 39 | 4 40 | true 41 | false 42 | x86 43 | true 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 4.0 55 | 56 | 57 | 4.0 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | {af729afb-a869-4656-8453-03ffd407775d} 70 | DesignPatternsGame.Common 71 | 72 | 73 | 74 | 75 | 83 | -------------------------------------------------------------------------------- /DesignPatternsGame.Factory/Foulu.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Common; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Content; 4 | using Microsoft.Xna.Framework.Graphics; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | 10 | namespace DesignPatternsGame.Factory 11 | { 12 | public class Foulu : GameSprite 13 | { 14 | public Foulu(ContentManager content) 15 | : base(content.Load("Foulu"), Vector2.Zero) 16 | { 17 | Animation = new Animation(300, 48, 48, 5, offsetY: 48); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /DesignPatternsGame.Factory/GameSpriteFactory.cs: -------------------------------------------------------------------------------- 1 | namespace DesignPatternsGame.Factory 2 | { 3 | using DesignPatternsGame.Common; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | using System; 12 | using System.Collections.Concurrent; 13 | using System.Collections.Generic; 14 | using System.Linq; 15 | 16 | public class GameSpriteFactory 17 | { 18 | private ContentManager content; 19 | 20 | private readonly ConcurrentDictionary cache = new ConcurrentDictionary(); 21 | 22 | public GameSpriteFactory(ContentManager content) 23 | { 24 | this.content = content; 25 | } 26 | 27 | public GameSprite Create() where T : GameSprite 28 | { 29 | return this.cache.GetOrAdd(typeof(T), (v) => Activator.CreateInstance(typeof(T), new[] { content }) as T); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /DesignPatternsGame.Factory/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DesignPatternsGame.Factory")] 9 | [assembly: AssemblyProduct("DesignPatternsGame.Factory")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyCopyright("Copyright © 2015")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. Only Windows 19 | // assemblies support COM. 20 | [assembly: ComVisible(false)] 21 | 22 | // On Windows, the following GUID is for the ID of the typelib if this 23 | // project is exposed to COM. On other platforms, it unique identifies the 24 | // title storage container when deploying this assembly to the device. 25 | [assembly: Guid("26346a22-2dc3-4cd3-a3c3-4f0dcdeded70")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | [assembly: AssemblyVersion("1.0.0.0")] -------------------------------------------------------------------------------- /DesignPatternsGame.Factory/Zero.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Common; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Content; 4 | using Microsoft.Xna.Framework.Graphics; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | 10 | namespace DesignPatternsGame.Factory 11 | { 12 | public class Zero : GameSprite 13 | { 14 | public Zero(ContentManager content) 15 | : base(content.Load("Zero"), Vector2.Zero) 16 | { 17 | Animation = new Animation(250, 48, 48, 9); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /DesignPatternsGame.Mediator/DesignPatternsGame.Mediator.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | {54337AAD-38C6-4B6B-9705-39A635E46AEE} 5 | {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 6 | Debug 7 | x86 8 | Library 9 | Properties 10 | DesignPatternsGame.Mediator 11 | DesignPatternsGame.Mediator 12 | v4.0 13 | Client 14 | v4.0 15 | Windows 16 | Reach 17 | 52cd3243-c8a2-443f-bba8-5cdd7c0ca9a5 18 | Library 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\x86\Debug 25 | DEBUG;TRACE;WINDOWS 26 | prompt 27 | 4 28 | true 29 | false 30 | x86 31 | false 32 | 33 | 34 | pdbonly 35 | true 36 | bin\x86\Release 37 | TRACE;WINDOWS 38 | prompt 39 | 4 40 | true 41 | false 42 | x86 43 | true 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 4.0 55 | 56 | 57 | 4.0 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | {af729afb-a869-4656-8453-03ffd407775d} 69 | DesignPatternsGame.Common 70 | 71 | 72 | 73 | 74 | 82 | -------------------------------------------------------------------------------- /DesignPatternsGame.Mediator/Foulu.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Common; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Content; 4 | using Microsoft.Xna.Framework.Graphics; 5 | using Microsoft.Xna.Framework.Input; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Text; 10 | 11 | namespace DesignPatternsGame.Mediator 12 | { 13 | public class Foulu : GameSprite 14 | { 15 | private GameSpriteMediator mediator; 16 | 17 | public Foulu(ContentManager content, GameSpriteMediator mediator) 18 | : base(content.Load("Foulu"), Vector2.Zero) 19 | { 20 | this.mediator = mediator; 21 | this.mediator.OnMoving += mediator_OnMoving; 22 | Animation = new Animation(300, 48, 48, 5, offsetY: 48); 23 | } 24 | 25 | private void mediator_OnMoving(GamePadState gamePadState) 26 | { 27 | this.Move(gamePadState); 28 | } 29 | 30 | public void CallFollowers(GamePadState gamePadState) 31 | { 32 | mediator.NotifyMoving(gamePadState); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /DesignPatternsGame.Mediator/GameSpriteMediator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | using DesignPatternsGame.Common; 12 | 13 | namespace DesignPatternsGame.Mediator 14 | { 15 | public class GameSpriteMediator 16 | { 17 | public delegate void MovingEvent(GamePadState gamePadState); 18 | public event MovingEvent OnMoving; 19 | 20 | public void NotifyMoving(GamePadState gamePadState) 21 | { 22 | if (OnMoving != null) 23 | OnMoving(gamePadState); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /DesignPatternsGame.Mediator/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DesignPatternsGame.Mediator")] 9 | [assembly: AssemblyProduct("DesignPatternsGame.Mediator")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyCopyright("Copyright © 2015")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. Only Windows 19 | // assemblies support COM. 20 | [assembly: ComVisible(false)] 21 | 22 | // On Windows, the following GUID is for the ID of the typelib if this 23 | // project is exposed to COM. On other platforms, it unique identifies the 24 | // title storage container when deploying this assembly to the device. 25 | [assembly: Guid("46bb5c22-3bee-4541-93cf-c54f09118383")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | [assembly: AssemblyVersion("1.0.0.0")] -------------------------------------------------------------------------------- /DesignPatternsGame.Memento/DesignPatternsGame.Memento.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | {91C19CC6-58F7-46B4-A808-1E21553D5DA8} 5 | {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 6 | Debug 7 | x86 8 | Library 9 | Properties 10 | DesignPatternsGame.Memento 11 | DesignPatternsGame.Memento 12 | v4.0 13 | Client 14 | v4.0 15 | Windows 16 | Reach 17 | 4727d3fc-d91a-4349-b540-872d2239e359 18 | Library 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\x86\Debug 25 | DEBUG;TRACE;WINDOWS 26 | prompt 27 | 4 28 | true 29 | false 30 | x86 31 | false 32 | 33 | 34 | pdbonly 35 | true 36 | bin\x86\Release 37 | TRACE;WINDOWS 38 | prompt 39 | 4 40 | true 41 | false 42 | x86 43 | true 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 4.0 55 | 56 | 57 | 4.0 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | {af729afb-a869-4656-8453-03ffd407775d} 70 | DesignPatternsGame.Common 71 | 72 | 73 | 74 | 75 | 83 | -------------------------------------------------------------------------------- /DesignPatternsGame.Memento/Foulu.cs: -------------------------------------------------------------------------------- 1 | namespace DesignPatternsGame.Memento 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using Microsoft.Xna.Framework; 7 | using Microsoft.Xna.Framework.Audio; 8 | using Microsoft.Xna.Framework.Content; 9 | using Microsoft.Xna.Framework.GamerServices; 10 | using Microsoft.Xna.Framework.Graphics; 11 | using Microsoft.Xna.Framework.Input; 12 | using Microsoft.Xna.Framework.Media; 13 | using DesignPatternsGame.Common; 14 | 15 | public class Foulu : GameSprite 16 | { 17 | public Foulu(ContentManager content) 18 | : base(content.Load("Foulu"), Vector2.Zero) 19 | { 20 | Animation = new Animation(300, 48, 48, 5, offsetY: 48); 21 | } 22 | 23 | public Memento Memento 24 | { 25 | get 26 | { 27 | return new Memento { Position = SpritePosition }; 28 | } 29 | set 30 | { 31 | SpritePosition = value.Position; 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /DesignPatternsGame.Memento/FouluRecorder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DesignPatternsGame.Memento 7 | { 8 | public class FouluRecorder 9 | { 10 | private Foulu foulu; 11 | private List mementos; 12 | private int currentIndex = -1; 13 | 14 | public FouluRecorder(Foulu foulu) 15 | { 16 | this.foulu = foulu; 17 | this.mementos = new List(); 18 | } 19 | 20 | public void Record() 21 | { 22 | this.mementos.Add(this.foulu.Memento); 23 | ++currentIndex; 24 | } 25 | 26 | public void Reset() 27 | { 28 | this.mementos.Clear(); 29 | this.currentIndex = -1; 30 | } 31 | 32 | public void Rewind() 33 | { 34 | if (this.currentIndex > 0) 35 | { 36 | this.foulu.Memento = this.mementos.ElementAt(--currentIndex); 37 | } 38 | } 39 | 40 | public void Foward() 41 | { 42 | if (this.currentIndex < this.mementos.Count - 1) 43 | { 44 | this.foulu.Memento = this.mementos.ElementAt(++currentIndex); 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /DesignPatternsGame.Memento/Memento.cs: -------------------------------------------------------------------------------- 1 | namespace DesignPatternsGame.Memento 2 | { 3 | using Microsoft.Xna.Framework; 4 | using System; 5 | 6 | public class Memento 7 | { 8 | public Vector2 Position { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /DesignPatternsGame.Memento/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DesignPatternsGame.Memento")] 9 | [assembly: AssemblyProduct("DesignPatternsGame.Memento")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyCopyright("Copyright © 2015")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. Only Windows 19 | // assemblies support COM. 20 | [assembly: ComVisible(false)] 21 | 22 | // On Windows, the following GUID is for the ID of the typelib if this 23 | // project is exposed to COM. On other platforms, it unique identifies the 24 | // title storage container when deploying this assembly to the device. 25 | [assembly: Guid("99ca530b-f73b-4e7d-aa35-93dfd36f2522")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | [assembly: AssemblyVersion("1.0.0.0")] -------------------------------------------------------------------------------- /DesignPatternsGame.Observer/DesignPatternsGame.Observer.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | {B436989F-9008-4251-9885-80417201752A} 5 | {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 6 | Debug 7 | x86 8 | Library 9 | Properties 10 | DesignPatternsGame.Observer 11 | DesignPatternsGame.Observer 12 | v4.0 13 | Client 14 | v4.0 15 | Windows 16 | Reach 17 | e397a465-1af0-40b1-99b1-babb56f122ab 18 | Library 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\x86\Debug 25 | DEBUG;TRACE;WINDOWS 26 | prompt 27 | 4 28 | true 29 | false 30 | x86 31 | false 32 | 33 | 34 | pdbonly 35 | true 36 | bin\x86\Release 37 | TRACE;WINDOWS 38 | prompt 39 | 4 40 | true 41 | false 42 | x86 43 | true 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 4.0 55 | 56 | 57 | 4.0 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | {af729afb-a869-4656-8453-03ffd407775d} 71 | DesignPatternsGame.Common 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 87 | -------------------------------------------------------------------------------- /DesignPatternsGame.Observer/Follower.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Common; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Graphics; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | 9 | namespace DesignPatternsGame.Observer 10 | { 11 | public class Follower : GameSprite, IGodEmperorObserver 12 | { 13 | public Follower(Texture2D spriteTexture, Vector2 spritePosition) 14 | : base(spriteTexture, spritePosition) 15 | { 16 | SpritePosition = spritePosition; 17 | } 18 | 19 | public void Update(Vector2 godPosition) 20 | { 21 | SpritePosition = new Vector2(godPosition.X - 40, SpritePosition.Y); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /DesignPatternsGame.Observer/Foulu.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | using DesignPatternsGame.Common; 12 | 13 | namespace DesignPatternsGame.Observer 14 | { 15 | public class Foulu : GameSprite, IGodEmperor 16 | { 17 | private IList observers; 18 | 19 | public Foulu(Texture2D spriteTexture, Vector2 spritePosition) 20 | : base(spriteTexture, spritePosition) 21 | { 22 | this.observers = new List(); 23 | } 24 | 25 | public void Subscribe(IGodEmperorObserver observer) 26 | { 27 | this.observers.Add(observer); 28 | } 29 | 30 | public void Unsubscribe(IGodEmperorObserver observer) 31 | { 32 | this.observers.Remove(observer); 33 | } 34 | 35 | public void Notify() 36 | { 37 | foreach (var item in this.observers) 38 | { 39 | item.Update(SpritePosition); 40 | } 41 | } 42 | 43 | 44 | public override void Move(GamePadState Controller1) 45 | { 46 | SpritePosition += 2 * new Vector2(Controller1.ThumbSticks.Left.X, 0); 47 | Notify(); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /DesignPatternsGame.Observer/IGodEmperor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DesignPatternsGame.Observer 7 | { 8 | public interface IGodEmperor 9 | { 10 | void Subscribe(IGodEmperorObserver observer); 11 | void Unsubscribe(IGodEmperorObserver observer); 12 | void Notify(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DesignPatternsGame.Observer/IGodEmperorObserver.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace DesignPatternsGame.Observer 8 | { 9 | public interface IGodEmperorObserver 10 | { 11 | void Update(Vector2 godPosition); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DesignPatternsGame.Observer/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DesignPatternsGame.Observer")] 9 | [assembly: AssemblyProduct("DesignPatternsGame.Observer")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyCopyright("Copyright © 2014")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. Only Windows 19 | // assemblies support COM. 20 | [assembly: ComVisible(false)] 21 | 22 | // On Windows, the following GUID is for the ID of the typelib if this 23 | // project is exposed to COM. On other platforms, it unique identifies the 24 | // title storage container when deploying this assembly to the device. 25 | [assembly: Guid("ec003671-691a-4334-a721-af24e91ddc69")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | [assembly: AssemblyVersion("1.0.0.0")] -------------------------------------------------------------------------------- /DesignPatternsGame.Observer/README.md: -------------------------------------------------------------------------------- 1 | Observer Pattern 2 | ================ 3 | 4 | This pattern allows parts of the system to be updated when a subject class broadcast that something has been changed. 5 | 6 | In this example one character is watching the character I move and then follows. 7 | http://youtu.be/w5AYBp_LX_U -------------------------------------------------------------------------------- /DesignPatternsGame.Prototype/DesignPatternsGame.Prototype.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | {2111B996-F896-444A-972D-3AC7EABBE3CB} 5 | {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 6 | Debug 7 | x86 8 | Library 9 | Properties 10 | DesignPatternsGame.Prototype 11 | DesignPatternsGame.Prototype 12 | v4.0 13 | Client 14 | v4.0 15 | Windows 16 | Reach 17 | 3613649c-8a2f-40f0-9498-1e44a62692d5 18 | Library 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\x86\Debug 25 | DEBUG;TRACE;WINDOWS 26 | prompt 27 | 4 28 | true 29 | false 30 | x86 31 | false 32 | 33 | 34 | pdbonly 35 | true 36 | bin\x86\Release 37 | TRACE;WINDOWS 38 | prompt 39 | 4 40 | true 41 | false 42 | x86 43 | true 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 4.0 55 | 56 | 57 | 4.0 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | {af729afb-a869-4656-8453-03ffd407775d} 68 | DesignPatternsGame.Common 69 | 70 | 71 | 72 | 73 | 81 | -------------------------------------------------------------------------------- /DesignPatternsGame.Prototype/Foulu.cs: -------------------------------------------------------------------------------- 1 | namespace DesignPatternsGame.Prototype 2 | { 3 | using DesignPatternsGame.Common; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Content; 6 | using Microsoft.Xna.Framework.Graphics; 7 | 8 | public class Foulu : GameSprite 9 | { 10 | public Foulu(ContentManager content) 11 | : base(content.Load("Foulu"), Vector2.Zero) 12 | { 13 | Animation = new Animation(300, 48, 48, 5, offsetY: 48); 14 | } 15 | 16 | public Foulu Clone() 17 | { 18 | return (Foulu)this.MemberwiseClone(); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /DesignPatternsGame.Prototype/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DesignPatternsGame.Prototype")] 9 | [assembly: AssemblyProduct("DesignPatternsGame.Prototype")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyCopyright("Copyright © 2015")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. Only Windows 19 | // assemblies support COM. 20 | [assembly: ComVisible(false)] 21 | 22 | // On Windows, the following GUID is for the ID of the typelib if this 23 | // project is exposed to COM. On other platforms, it unique identifies the 24 | // title storage container when deploying this assembly to the device. 25 | [assembly: Guid("859d388c-de58-4fd9-9f28-d93daf7e2edd")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | [assembly: AssemblyVersion("1.0.0.0")] -------------------------------------------------------------------------------- /DesignPatternsGame.Proxy/DesignPatternsGame.Proxy.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | {9D382531-D8C5-49B9-8561-D00633CFD8B4} 5 | {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 6 | Debug 7 | x86 8 | Library 9 | Properties 10 | DesignPatternsGame.Proxy 11 | DesignPatternsGame.Proxy 12 | v4.0 13 | Client 14 | v4.0 15 | Windows 16 | Reach 17 | 86729694-7380-4368-a857-7dcedffa712a 18 | Library 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\x86\Debug 25 | DEBUG;TRACE;WINDOWS 26 | prompt 27 | 4 28 | true 29 | false 30 | x86 31 | false 32 | 33 | 34 | pdbonly 35 | true 36 | bin\x86\Release 37 | TRACE;WINDOWS 38 | prompt 39 | 4 40 | true 41 | false 42 | x86 43 | true 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 4.0 55 | 56 | 57 | 4.0 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | {af729afb-a869-4656-8453-03ffd407775d} 69 | DesignPatternsGame.Common 70 | 71 | 72 | 73 | 74 | 82 | -------------------------------------------------------------------------------- /DesignPatternsGame.Proxy/Foulu.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | using DesignPatternsGame.Common; 12 | 13 | namespace DesignPatternsGame.Proxy 14 | { 15 | public class Foulu : GameSprite 16 | { 17 | public Foulu(ContentManager content) 18 | : base(content.Load("Foulu"), Vector2.Zero) 19 | { 20 | Animation = new Animation(300, 48, 48, 5, offsetY: 48); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /DesignPatternsGame.Proxy/FouluProxy.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | using Microsoft.Xna.Framework.Content; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace DesignPatternsGame.Proxy 9 | { 10 | public class FouluProxy 11 | { 12 | public Foulu Create(ContentManager content, GameTime gameTime) 13 | { 14 | if (gameTime.TotalGameTime.TotalSeconds > 5) 15 | return new Foulu(content); 16 | 17 | return null; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /DesignPatternsGame.Proxy/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DesignPatternsGame.Proxy")] 9 | [assembly: AssemblyProduct("DesignPatternsGame.Proxy")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyCopyright("Copyright © 2015")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. Only Windows 19 | // assemblies support COM. 20 | [assembly: ComVisible(false)] 21 | 22 | // On Windows, the following GUID is for the ID of the typelib if this 23 | // project is exposed to COM. On other platforms, it unique identifies the 24 | // title storage container when deploying this assembly to the device. 25 | [assembly: Guid("0d7f6490-9684-44c3-8e9c-4a7e3756a7fb")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | [assembly: AssemblyVersion("1.0.0.0")] -------------------------------------------------------------------------------- /DesignPatternsGame.Singleton/DesignPatternsGame.Singleton.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | {33F202F5-1733-49DE-B618-692EC23AF2F4} 5 | {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 6 | Debug 7 | x86 8 | Library 9 | Properties 10 | DesignPatternsGame.Singleton 11 | DesignPatternsGame.Singleton 12 | v4.0 13 | Client 14 | v4.0 15 | Windows 16 | Reach 17 | f62e81f7-1654-426d-a6f4-9970f7d33454 18 | Library 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\x86\Debug 25 | DEBUG;TRACE;WINDOWS 26 | prompt 27 | 4 28 | true 29 | false 30 | x86 31 | false 32 | 33 | 34 | pdbonly 35 | true 36 | bin\x86\Release 37 | TRACE;WINDOWS 38 | prompt 39 | 4 40 | true 41 | false 42 | x86 43 | true 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 4.0 55 | 56 | 57 | 4.0 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | {af729afb-a869-4656-8453-03ffd407775d} 68 | DesignPatternsGame.Common 69 | 70 | 71 | 72 | 73 | 81 | -------------------------------------------------------------------------------- /DesignPatternsGame.Singleton/Foulu.cs: -------------------------------------------------------------------------------- 1 | namespace DesignPatternsGame.Singleton 2 | { 3 | using DesignPatternsGame.Common; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Content; 6 | using Microsoft.Xna.Framework.Graphics; 7 | 8 | public class Foulu : GameSprite 9 | { 10 | private static Foulu foulu; 11 | 12 | private Foulu(ContentManager content) 13 | : base(content.Load("Foulu"), Vector2.Zero) 14 | { 15 | Animation = new Animation(300, 48, 48, 5, offsetY: 48); 16 | } 17 | 18 | public static ContentManager Content { get; set; } 19 | 20 | public static Foulu Instance 21 | { 22 | get 23 | { 24 | return foulu ?? (foulu = new Foulu(Content)); 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /DesignPatternsGame.Singleton/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DesignPatternsGame.Singleton")] 9 | [assembly: AssemblyProduct("DesignPatternsGame.Singleton")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyCopyright("Copyright © 2015")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. Only Windows 19 | // assemblies support COM. 20 | [assembly: ComVisible(false)] 21 | 22 | // On Windows, the following GUID is for the ID of the typelib if this 23 | // project is exposed to COM. On other platforms, it unique identifies the 24 | // title storage container when deploying this assembly to the device. 25 | [assembly: Guid("39357fdb-44ac-4ce8-9c19-b5b6b147e644")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | [assembly: AssemblyVersion("1.0.0.0")] -------------------------------------------------------------------------------- /DesignPatternsGame.State/DesignPatternsGame.State.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | {C7F98C9F-DBC3-4151-A09C-A2F52A19AD33} 5 | {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 6 | Debug 7 | x86 8 | Library 9 | Properties 10 | DesignPatternsGame.State 11 | DesignPatternsGame.State 12 | v4.0 13 | Client 14 | v4.0 15 | Windows 16 | Reach 17 | 93b3e0cb-8164-4c9c-a6ef-ab7f3ea54110 18 | Library 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\x86\Debug 25 | DEBUG;TRACE;WINDOWS 26 | prompt 27 | 4 28 | true 29 | false 30 | x86 31 | false 32 | 33 | 34 | pdbonly 35 | true 36 | bin\x86\Release 37 | TRACE;WINDOWS 38 | prompt 39 | 4 40 | true 41 | false 42 | x86 43 | true 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 4.0 55 | 56 | 57 | 4.0 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | {af729afb-a869-4656-8453-03ffd407775d} 71 | DesignPatternsGame.Common 72 | 73 | 74 | 75 | 76 | 84 | -------------------------------------------------------------------------------- /DesignPatternsGame.State/Foulu.cs: -------------------------------------------------------------------------------- 1 | namespace DesignPatternsGame.State 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using Microsoft.Xna.Framework; 7 | using Microsoft.Xna.Framework.Audio; 8 | using Microsoft.Xna.Framework.Content; 9 | using Microsoft.Xna.Framework.GamerServices; 10 | using Microsoft.Xna.Framework.Graphics; 11 | using Microsoft.Xna.Framework.Input; 12 | using Microsoft.Xna.Framework.Media; 13 | using DesignPatternsGame.Common; 14 | 15 | public class Foulu : GameSprite 16 | { 17 | public Foulu(ContentManager content) 18 | : base(content.Load("Foulu"), Vector2.Zero) 19 | { 20 | State = new WalkingState(); 21 | } 22 | 23 | public IMoveState State { get; set; } 24 | 25 | public override Animation Animation 26 | { 27 | get 28 | { 29 | return State.Animation; 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /DesignPatternsGame.State/IMoveState.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Common; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace DesignPatternsGame.State 8 | { 9 | public interface IMoveState 10 | { 11 | Animation Animation { get; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DesignPatternsGame.State/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DesignPatternsGame.State")] 9 | [assembly: AssemblyProduct("DesignPatternsGame.State")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyCopyright("Copyright © 2015")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. Only Windows 19 | // assemblies support COM. 20 | [assembly: ComVisible(false)] 21 | 22 | // On Windows, the following GUID is for the ID of the typelib if this 23 | // project is exposed to COM. On other platforms, it unique identifies the 24 | // title storage container when deploying this assembly to the device. 25 | [assembly: Guid("6ab24d62-058a-4a42-afd0-7860811e2d9a")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | [assembly: AssemblyVersion("1.0.0.0")] -------------------------------------------------------------------------------- /DesignPatternsGame.State/RunningState.cs: -------------------------------------------------------------------------------- 1 | namespace DesignPatternsGame.State 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using Microsoft.Xna.Framework; 7 | using Microsoft.Xna.Framework.Audio; 8 | using Microsoft.Xna.Framework.Content; 9 | using Microsoft.Xna.Framework.GamerServices; 10 | using Microsoft.Xna.Framework.Graphics; 11 | using Microsoft.Xna.Framework.Input; 12 | using Microsoft.Xna.Framework.Media; 13 | using DesignPatternsGame.Common; 14 | 15 | public class RunningState : IMoveState 16 | { 17 | private Common.Animation animation; 18 | 19 | public Common.Animation Animation 20 | { 21 | get 22 | { 23 | return animation ?? (animation = new Animation(100, 48, 48, 5, 0, 48 * 4)); 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /DesignPatternsGame.State/WalkingState.cs: -------------------------------------------------------------------------------- 1 | namespace DesignPatternsGame.State 2 | { 3 | using DesignPatternsGame.Common; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | 9 | public class WalkingState : IMoveState 10 | { 11 | private Common.Animation animation; 12 | 13 | public Common.Animation Animation 14 | { 15 | get 16 | { 17 | return animation ?? (animation = new Animation(300, 48, 48, 5, offsetY: 48)); 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /DesignPatternsGame.Strategy/DesignPatternsGame.Strategy.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | {232EDD69-7028-42FE-95F0-B6BCF1AD5E62} 5 | {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 6 | Debug 7 | x86 8 | Library 9 | Properties 10 | DesignPatternsGame.Strategy 11 | DesignPatternsGame.Strategy 12 | v4.0 13 | Client 14 | v4.0 15 | Windows 16 | Reach 17 | 358a3265-5163-47e6-a7cc-22e748e90dfb 18 | Library 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\x86\Debug 25 | DEBUG;TRACE;WINDOWS 26 | prompt 27 | 4 28 | true 29 | false 30 | x86 31 | false 32 | 33 | 34 | pdbonly 35 | true 36 | bin\x86\Release 37 | TRACE;WINDOWS 38 | prompt 39 | 4 40 | true 41 | false 42 | x86 43 | true 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 4.0 55 | 56 | 57 | 4.0 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | {af729afb-a869-4656-8453-03ffd407775d} 71 | DesignPatternsGame.Common 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 87 | -------------------------------------------------------------------------------- /DesignPatternsGame.Strategy/IMoveStrategy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | 12 | namespace DesignPatternsGame.Strategy 13 | { 14 | public interface IMoveStrategy 15 | { 16 | Vector2 Move(Vector2 spritePosition, GamePadState controllerState); 17 | 18 | void Draw(GameTime gameTime, SpriteBatch spriteBatch, Texture2D texture, Vector2 position); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /DesignPatternsGame.Strategy/MovableCharacter.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Common; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Graphics; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | 9 | namespace DesignPatternsGame.Strategy 10 | { 11 | public class MovableCharacter : GameSprite 12 | { 13 | public IMoveStrategy MoveStrategy { get; set; } 14 | 15 | public MovableCharacter(Texture2D spriteTexture, Vector2 spritePosition) 16 | : base(spriteTexture, spritePosition) 17 | { 18 | MoveStrategy = new WalkStrategy(); 19 | } 20 | 21 | public override void Move(Microsoft.Xna.Framework.Input.GamePadState Controller1) 22 | { 23 | SpritePosition = this.MoveStrategy.Move(SpritePosition, Controller1); 24 | } 25 | 26 | public override void Draw(GameTime gameTime, SpriteBatch spriteBatch) 27 | { 28 | this.MoveStrategy.Draw(gameTime, spriteBatch, SpriteTexture, SpritePosition); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /DesignPatternsGame.Strategy/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DesignPatternsGame.Strategy")] 9 | [assembly: AssemblyProduct("DesignPatternsGame.Strategy")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyCopyright("Copyright © 2014")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. Only Windows 19 | // assemblies support COM. 20 | [assembly: ComVisible(false)] 21 | 22 | // On Windows, the following GUID is for the ID of the typelib if this 23 | // project is exposed to COM. On other platforms, it unique identifies the 24 | // title storage container when deploying this assembly to the device. 25 | [assembly: Guid("b5c8edd7-6652-42c2-aaa2-8baa3546dafb")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | [assembly: AssemblyVersion("1.0.0.0")] -------------------------------------------------------------------------------- /DesignPatternsGame.Strategy/README.md: -------------------------------------------------------------------------------- 1 | Strategy Pattern 2 | ================ 3 | 4 | This pattern assign a behavior to a class accordingly to the context. 5 | 6 | In this example the character will walk when I move normally and run when hold B, the move strategy changes accordingly. 7 | http://youtu.be/IyrjnIGBeyw 8 | 9 | 10 | Another example can be found here: https://www.youtube.com/watch?v=MOEsKHqLiBM 11 | 12 | This guy used a unit called "Valkirie" from Starcraft to demonstrate how this pattern can be applied to the unit movements. 13 | 14 | -------------------------------------------------------------------------------- /DesignPatternsGame.Strategy/RunStrategy.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Common; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Graphics; 4 | using Microsoft.Xna.Framework.Input; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | 10 | namespace DesignPatternsGame.Strategy 11 | { 12 | public class RunStrategy : IMoveStrategy 13 | { 14 | private Animation animation; 15 | 16 | public RunStrategy() 17 | { 18 | this.animation = new Animation(100, 48, 48, 5, 0, 48 * 4); 19 | } 20 | 21 | public Vector2 Move(Vector2 spritePosition, GamePadState controllerState) 22 | { 23 | return spritePosition + 7 * new Vector2(controllerState.ThumbSticks.Left.X, -controllerState.ThumbSticks.Left.Y); 24 | } 25 | 26 | public void Draw(GameTime gameTime, SpriteBatch spriteBatch, Texture2D texture, Vector2 position) 27 | { 28 | this.animation.Draw(gameTime, spriteBatch, texture, position); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /DesignPatternsGame.Strategy/WalkStrategy.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Common; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Graphics; 4 | using Microsoft.Xna.Framework.Input; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | 10 | namespace DesignPatternsGame.Strategy 11 | { 12 | public class WalkStrategy : IMoveStrategy 13 | { 14 | private Animation animation; 15 | 16 | public WalkStrategy() 17 | { 18 | this.animation = new Animation(100, 48, 48, 5, offsetY: 48); 19 | } 20 | 21 | public Vector2 Move(Vector2 spritePosition, GamePadState controllerState) 22 | { 23 | return spritePosition + 2 * new Vector2(controllerState.ThumbSticks.Left.X, -controllerState.ThumbSticks.Left.Y); 24 | } 25 | 26 | public void Draw(GameTime gameTime, SpriteBatch spriteBatch, Texture2D texture, Vector2 position) 27 | { 28 | this.animation.Draw(gameTime, spriteBatch, texture, position); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /DesignPatternsGame.Visitor/Boost.cs: -------------------------------------------------------------------------------- 1 | namespace DesignPatternsGame.Visitor 2 | { 3 | using Microsoft.Xna.Framework; 4 | 5 | public class Boost : IVisitor 6 | { 7 | public void Visit(IAccept obj) where T : IVisitor 8 | { 9 | if (obj is Foulu) 10 | { 11 | var foulu = obj as Foulu; 12 | 13 | foulu.SpritePosition += new Vector2(1, 1); 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /DesignPatternsGame.Visitor/DesignPatternsGame.Visitor.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | {290D2955-CE89-4C87-B287-EEF67CB54F0B} 5 | {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 6 | Debug 7 | x86 8 | Library 9 | Properties 10 | DesignPatternsGame.Visitor 11 | DesignPatternsGame.Visitor 12 | v4.0 13 | Client 14 | v4.0 15 | Windows 16 | Reach 17 | 7916ee3b-2aab-458f-81ff-bf23f55e1af8 18 | Library 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\x86\Debug 25 | DEBUG;TRACE;WINDOWS 26 | prompt 27 | 4 28 | true 29 | false 30 | x86 31 | false 32 | 33 | 34 | pdbonly 35 | true 36 | bin\x86\Release 37 | TRACE;WINDOWS 38 | prompt 39 | 4 40 | true 41 | false 42 | x86 43 | true 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 4.0 55 | 56 | 57 | 4.0 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | {af729afb-a869-4656-8453-03ffd407775d} 71 | DesignPatternsGame.Common 72 | 73 | 74 | 75 | 76 | 84 | -------------------------------------------------------------------------------- /DesignPatternsGame.Visitor/Foulu.cs: -------------------------------------------------------------------------------- 1 | namespace DesignPatternsGame.Visitor 2 | { 3 | using DesignPatternsGame.Common; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Content; 6 | using Microsoft.Xna.Framework.Graphics; 7 | 8 | public class Foulu : GameSprite, IAccept 9 | { 10 | public Foulu(ContentManager content) 11 | : base(content.Load("Foulu"), Vector2.Zero) 12 | { 13 | Animation = new Animation(300, 48, 48, 5, offsetY: 48); 14 | } 15 | 16 | public void Accept(Boost boost) 17 | { 18 | boost.Visit(this); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /DesignPatternsGame.Visitor/IAccept.cs: -------------------------------------------------------------------------------- 1 | namespace DesignPatternsGame.Visitor 2 | { 3 | public interface IAccept where T: IVisitor 4 | { 5 | void Accept(T boost); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /DesignPatternsGame.Visitor/IVisitor.cs: -------------------------------------------------------------------------------- 1 | namespace DesignPatternsGame.Visitor 2 | { 3 | public interface IVisitor 4 | { 5 | void Visit(IAccept obj) where T : IVisitor; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /DesignPatternsGame.Visitor/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DesignPatternsGame.Visitor")] 9 | [assembly: AssemblyProduct("DesignPatternsGame.Visitor")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyCopyright("Copyright © 2015")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. Only Windows 19 | // assemblies support COM. 20 | [assembly: ComVisible(false)] 21 | 22 | // On Windows, the following GUID is for the ID of the typelib if this 23 | // project is exposed to COM. On other platforms, it unique identifies the 24 | // title storage container when deploying this assembly to the device. 25 | [assembly: Guid("1569b308-fa7d-416f-bf1a-ff07bce50048")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | [assembly: AssemblyVersion("1.0.0.0")] -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGame/AbstractFactoryGame.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.AbstractFactory; 2 | using DesignPatternsGame.Common; 3 | using Microsoft.Xna.Framework; 4 | using Microsoft.Xna.Framework.Input; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.ComponentModel.Composition; 8 | using System.Linq; 9 | using System.Text; 10 | 11 | namespace DesignPatternsGame 12 | { 13 | [Export(typeof(BaseGame))] 14 | 15 | public class AbstractFactoryGame : BaseGame 16 | { 17 | private IList enemies = new List(); 18 | 19 | private Spawner spawner = null; 20 | 21 | protected override void LoadContent() 22 | { 23 | base.LoadContent(); 24 | 25 | this.CustomDrawing += AbstractFactoryGame_CustomDrawing; 26 | 27 | spawner = new Spawner(Content); 28 | } 29 | 30 | protected override void Update(GameTime gameTime) 31 | { 32 | if (Controller1.Buttons.A == ButtonState.Pressed) 33 | { 34 | spawner.EnemyFactory = new GreenGooFactory(); 35 | } 36 | else if (Controller1.Buttons.B == ButtonState.Pressed) 37 | { 38 | spawner.EnemyFactory = new RedGooFactory(); 39 | } 40 | else if (Controller1.Buttons.X == ButtonState.Pressed) 41 | { 42 | spawner.EnemyFactory = new BlueGooFactory(); 43 | } 44 | else if (Controller1.Buttons.Y == ButtonState.Pressed) 45 | { 46 | spawner.EnemyFactory = new BrownGooFactory(); 47 | } 48 | 49 | if (Controller1.Buttons.RightShoulder == ButtonState.Pressed) 50 | { 51 | enemies.Add(spawner.Spawn()); 52 | } 53 | 54 | base.Update(gameTime); 55 | } 56 | 57 | void AbstractFactoryGame_CustomDrawing(GameTime gameTime) 58 | { 59 | foreach (var item in enemies) 60 | { 61 | item.Draw(gameTime, SpriteBatch); 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGame/AdapterGame.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Adapter; 2 | using DesignPatternsGame.Common; 3 | using Microsoft.Xna.Framework; 4 | using Microsoft.Xna.Framework.Audio; 5 | using Microsoft.Xna.Framework.Content; 6 | using Microsoft.Xna.Framework.GamerServices; 7 | using Microsoft.Xna.Framework.Graphics; 8 | using Microsoft.Xna.Framework.Input; 9 | using Microsoft.Xna.Framework.Media; 10 | using System; 11 | using System.Collections.Generic; 12 | using System.ComponentModel.Composition; 13 | using System.Linq; 14 | 15 | namespace DesignPatternsGame 16 | { 17 | [Export] 18 | [Export(typeof(BaseGame))] 19 | public class AdapterGame : BaseGame 20 | { 21 | private Foulu fouLu; 22 | private ZeroAdapter zero; 23 | 24 | protected override void LoadContent() 25 | { 26 | base.LoadContent(); 27 | 28 | this.CustomDrawing += ObserverGame_CustomDrawing; 29 | 30 | fouLu = new Foulu(Content.Load("Foulu"), new Vector2(40, 100)); 31 | zero = new ZeroAdapter(new Zero(), Content.Load("Zero"), new Vector2(40, 150)); 32 | 33 | fouLu.Animation = new Animation(250, 48, 48, 5, offsetY: 48); 34 | zero.Animation = new Animation(250, 48, 48, 9); 35 | } 36 | 37 | protected override void Update(GameTime gameTime) 38 | { 39 | fouLu.Move(Controller1); 40 | zero.Move(Controller1); 41 | 42 | base.Update(gameTime); 43 | } 44 | 45 | void ObserverGame_CustomDrawing(GameTime gameTime) 46 | { 47 | fouLu.Draw(gameTime, SpriteBatch); 48 | zero.Draw(gameTime, SpriteBatch); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGame/BridgeGame.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using DesignPatternsGame.Bridge; 3 | using DesignPatternsGame.Common; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Graphics; 6 | using Microsoft.Xna.Framework.Input; 7 | using System.ComponentModel.Composition; 8 | 9 | namespace DesignPatternsGame 10 | { 11 | [Export] 12 | [Export(typeof(BaseGame))] 13 | public class BridgeGame : BaseGame 14 | { 15 | private Foulu fouLu; 16 | 17 | private WalkController walkController = new WalkController(); 18 | private RunController runController = new RunController(); 19 | 20 | protected override void LoadContent() 21 | { 22 | base.LoadContent(); 23 | 24 | this.CustomDrawing += ObserverGame_CustomDrawing; 25 | 26 | fouLu = new Foulu(Content.Load("Foulu"), new Vector2(40, 100)); 27 | } 28 | 29 | protected override void Update(GameTime gameTime) 30 | { 31 | if (Controller1.Buttons.B == ButtonState.Pressed) 32 | { 33 | runController.Move(fouLu, Controller1); 34 | } 35 | else 36 | { 37 | walkController.Move(fouLu, Controller1); 38 | } 39 | 40 | base.Update(gameTime); 41 | } 42 | 43 | void ObserverGame_CustomDrawing(GameTime gameTime) 44 | { 45 | fouLu.Draw(gameTime, SpriteBatch); 46 | } 47 | } 48 | 49 | public interface IMoveCotroller 50 | { 51 | void Move(Foulu character, GamePadState gamePadState); 52 | } 53 | 54 | public class WalkController : IMoveCotroller 55 | { 56 | public void Move(Foulu character, GamePadState gamePadState) 57 | { 58 | if (character.MoveStrategy.GetType() != typeof(WalkStrategy)) 59 | character.MoveStrategy = new WalkStrategy(); 60 | 61 | character.Move(gamePadState); 62 | } 63 | } 64 | 65 | public class RunController : IMoveCotroller 66 | { 67 | public void Move(Foulu character, GamePadState gamePadState) 68 | { 69 | if (character.MoveStrategy.GetType() != typeof(RunStrategy)) 70 | character.MoveStrategy = new RunStrategy(); 71 | 72 | character.Move(gamePadState); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGame/BuilderGame.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Builder; 2 | using DesignPatternsGame.Common; 3 | using Microsoft.Xna.Framework; 4 | using Microsoft.Xna.Framework.Audio; 5 | using Microsoft.Xna.Framework.Content; 6 | using Microsoft.Xna.Framework.GamerServices; 7 | using Microsoft.Xna.Framework.Graphics; 8 | using Microsoft.Xna.Framework.Input; 9 | using Microsoft.Xna.Framework.Media; 10 | using System; 11 | using System.Collections.Generic; 12 | using System.ComponentModel.Composition; 13 | using System.Linq; 14 | 15 | namespace DesignPatternsGame 16 | { 17 | [Export] 18 | [Export(typeof(BaseGame))] 19 | public class BuilderGame : BaseGame 20 | { 21 | private MainCharacterBuilder mainCharBuilder; 22 | private GameCharacter character; 23 | 24 | protected override void LoadContent() 25 | { 26 | base.LoadContent(); 27 | 28 | this.CustomDrawing += BuilderGame_CustomDrawing; 29 | 30 | this.mainCharBuilder = new MainCharacterBuilder(Content); 31 | 32 | this.mainCharBuilder.BuildGod(); 33 | 34 | this.character = mainCharBuilder.Result; 35 | } 36 | 37 | protected override void Update(GameTime gameTime) 38 | { 39 | if (Controller1.Buttons.A == ButtonState.Pressed) 40 | { 41 | this.mainCharBuilder.BuildGod(); 42 | this.character = this.mainCharBuilder.Result; 43 | } 44 | else if (Controller1.Buttons.B == ButtonState.Pressed) 45 | { 46 | this.mainCharBuilder.BuildRobot(); 47 | this.character = this.mainCharBuilder.Result; 48 | } 49 | 50 | this.character.Move(Controller1); 51 | 52 | base.Update(gameTime); 53 | } 54 | 55 | void BuilderGame_CustomDrawing(GameTime gameTime) 56 | { 57 | this.character.Draw(gameTime, SpriteBatch); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGame/ChainOfResponsibilityGame.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.ChainOfResponsibility; 2 | using DesignPatternsGame.Common; 3 | using Microsoft.Xna.Framework; 4 | using Microsoft.Xna.Framework.Audio; 5 | using Microsoft.Xna.Framework.Content; 6 | using Microsoft.Xna.Framework.GamerServices; 7 | using Microsoft.Xna.Framework.Graphics; 8 | using Microsoft.Xna.Framework.Input; 9 | using Microsoft.Xna.Framework.Media; 10 | using System; 11 | using System.Collections.Generic; 12 | using System.ComponentModel.Composition; 13 | using System.Linq; 14 | 15 | namespace DesignPatternsGame 16 | { 17 | [Export] 18 | [Export(typeof(BaseGame))] 19 | public class ChainOfResponsibilityGame : BaseGame 20 | { 21 | private NormalCharger normalCharger; 22 | private UltraCharger ultraCharger; 23 | private Megaman character; 24 | 25 | protected override void LoadContent() 26 | { 27 | base.LoadContent(); 28 | 29 | this.CustomDrawing += ChainOfResponsibilityGame_CustomDrawing; 30 | 31 | this.character = new Megaman(Content.Load("Megaman"), new Vector2(40, 100)); 32 | 33 | this.normalCharger = new NormalCharger(character); 34 | this.ultraCharger = new UltraCharger(character); 35 | 36 | this.normalCharger.Next = this.ultraCharger; 37 | } 38 | 39 | protected override void Update(GameTime gameTime) 40 | { 41 | this.character.Move(Controller1); 42 | 43 | base.Update(gameTime); 44 | } 45 | 46 | double elapsed = 0; 47 | void ChainOfResponsibilityGame_CustomDrawing(GameTime gameTime) 48 | { 49 | elapsed += gameTime.ElapsedGameTime.TotalMilliseconds; 50 | 51 | this.normalCharger.Charge(SpriteBatch, gameTime, elapsed); 52 | 53 | if (elapsed > 15000) 54 | { 55 | elapsed = 0; 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGame/CommandGame.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Command; 2 | using DesignPatternsGame.Common; 3 | using DesignPatternsGame.Strategy; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | using System; 12 | using System.Collections.Generic; 13 | using System.ComponentModel.Composition; 14 | using System.Linq; 15 | 16 | namespace DesignPatternsGame 17 | { 18 | [Export(typeof(BaseGame))] 19 | public class CommandGame : BaseGame 20 | { 21 | private GameSprite character; 22 | 23 | private ICommand creationCommand; 24 | 25 | private CreateGodCommand createGodCommand = new CreateGodCommand(); 26 | private CreateRobotCommand createRobotCommand = new CreateRobotCommand(); 27 | 28 | public CommandGame() 29 | { 30 | } 31 | 32 | protected override void LoadContent() 33 | { 34 | base.LoadContent(); 35 | 36 | this.CustomDrawing += CommandGame_CustomDrawing; 37 | 38 | character = new GameSprite(Content.Load("Foulu"), Vector2.Zero); 39 | creationCommand = createGodCommand; 40 | } 41 | 42 | protected override void Update(GameTime gameTime) 43 | { 44 | if (Controller1.Buttons.A == ButtonState.Pressed) 45 | { 46 | creationCommand = createGodCommand; 47 | } 48 | else if (Controller1.Buttons.B == ButtonState.Pressed) 49 | { 50 | creationCommand = createRobotCommand; 51 | } 52 | 53 | character = creationCommand.Execute(Content); 54 | 55 | base.Update(gameTime); 56 | } 57 | 58 | void CommandGame_CustomDrawing(GameTime gameTime) 59 | { 60 | character.Draw(gameTime, SpriteBatch); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGame/CompositeGame.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | using DesignPatternsGame.Strategy; 12 | using DesignPatternsGame.Common; 13 | using System.ComponentModel.Composition; 14 | using DesignPatternsGame.Composite; 15 | 16 | namespace DesignPatternsGame 17 | { 18 | [Export(typeof(BaseGame))] 19 | public class CompositeGame : BaseGame 20 | { 21 | private CompositeGameSprite gameSpriteComposition; 22 | 23 | public CompositeGame() 24 | { 25 | this.gameSpriteComposition = new CompositeGameSprite(); 26 | } 27 | 28 | protected override void LoadContent() 29 | { 30 | base.LoadContent(); 31 | 32 | this.CustomDrawing += CompositeGame_CustomDrawing; 33 | 34 | this.gameSpriteComposition.Add(new MovableCharacter(Content.Load("Foulu"), Vector2.Zero)); 35 | this.gameSpriteComposition.Add(new MovableCharacter(Content.Load("Foulu"), new Vector2(0, 60))); 36 | this.gameSpriteComposition.Add(new MovableCharacter(Content.Load("Foulu"), new Vector2(0, 120))); 37 | } 38 | 39 | protected override void Update(GameTime gameTime) 40 | { 41 | this.gameSpriteComposition.Move(Controller1); 42 | 43 | base.Update(gameTime); 44 | } 45 | 46 | void CompositeGame_CustomDrawing(GameTime gameTime) 47 | { 48 | this.gameSpriteComposition.Draw(gameTime, SpriteBatch); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGame/DecoratorGame.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | using DesignPatternsGame.Strategy; 12 | using DesignPatternsGame.Common; 13 | using System.ComponentModel.Composition; 14 | using DesignPatternsGame.Decorator; 15 | 16 | namespace DesignPatternsGame 17 | { 18 | [Export(typeof(BaseGame))] 19 | public class DecoratorGame : BaseGame 20 | { 21 | private GameSprite character; 22 | 23 | public DecoratorGame() 24 | { 25 | } 26 | 27 | protected override void LoadContent() 28 | { 29 | base.LoadContent(); 30 | 31 | this.CustomDrawing += DecoratorGame_CustomDrawing; 32 | 33 | character = new GameSprite(Content.Load("Foulu"), Vector2.Zero); 34 | character.Animation = new Animation(100, 48, 48, 5, offsetY: 48); 35 | } 36 | 37 | protected override void Update(GameTime gameTime) 38 | { 39 | if (Controller1.Buttons.X == ButtonState.Pressed) 40 | { 41 | character = new GameSpriteSlowDecorator(character); 42 | } 43 | else if (Controller1.Buttons.B == ButtonState.Pressed) 44 | { 45 | character = new GameSpriteFastDecorator(character); 46 | } 47 | 48 | character.Move(Controller1); 49 | 50 | base.Update(gameTime); 51 | } 52 | 53 | void DecoratorGame_CustomDrawing(GameTime gameTime) 54 | { 55 | character.Draw(gameTime, SpriteBatch); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGame/FacadeGame.cs: -------------------------------------------------------------------------------- 1 | namespace DesignPatternsGame 2 | { 3 | using DesignPatternsGame.Common; 4 | using DesignPatternsGame.Facade; 5 | using DesignPatternsGame.Strategy; 6 | using Microsoft.Xna.Framework; 7 | using Microsoft.Xna.Framework.Graphics; 8 | using Microsoft.Xna.Framework.Input; 9 | using System; 10 | using System.ComponentModel.Composition; 11 | 12 | [Export(typeof(BaseGame))] 13 | public class FacadeGame : BaseGame 14 | { 15 | private FouluFacade fouluFacade; 16 | private GameSprite character; 17 | 18 | public FacadeGame() 19 | { 20 | fouluFacade = new FouluFacade(Content, "Foulu", new Vector2(20, 20)); 21 | } 22 | 23 | protected override void LoadContent() 24 | { 25 | base.LoadContent(); 26 | 27 | this.CustomDrawing += FacadeGame_CustomDrawing; 28 | 29 | character = fouluFacade.AssemblyCharacter(); 30 | } 31 | 32 | protected override void Update(GameTime gameTime) 33 | { 34 | character.Move(Controller1); 35 | 36 | base.Update(gameTime); 37 | } 38 | 39 | void FacadeGame_CustomDrawing(GameTime gameTime) 40 | { 41 | character.Draw(gameTime, SpriteBatch); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGame/FactoryGame.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | using DesignPatternsGame.Strategy; 12 | using DesignPatternsGame.Common; 13 | using System.ComponentModel.Composition; 14 | using DesignPatternsGame.Factory; 15 | 16 | namespace DesignPatternsGame 17 | { 18 | [Export(typeof(BaseGame))] 19 | public class FactoryGame : BaseGame 20 | { 21 | private GameSpriteFactory gameSpriteFactory; 22 | private GameSprite character; 23 | 24 | public FactoryGame() 25 | { 26 | this.gameSpriteFactory = new GameSpriteFactory(Content); 27 | } 28 | 29 | protected override void LoadContent() 30 | { 31 | base.LoadContent(); 32 | 33 | this.CustomDrawing += FactoryGame_CustomDrawing; 34 | 35 | character = this.gameSpriteFactory.Create(); 36 | } 37 | 38 | protected override void Update(GameTime gameTime) 39 | { 40 | if (Controller1.Buttons.A == ButtonState.Pressed) 41 | { 42 | character = this.gameSpriteFactory.Create(); 43 | } 44 | else if (Controller1.Buttons.B == ButtonState.Pressed) 45 | { 46 | character = this.gameSpriteFactory.Create(); 47 | } 48 | 49 | character.Move(Controller1); 50 | 51 | base.Update(gameTime); 52 | } 53 | 54 | void FactoryGame_CustomDrawing(GameTime gameTime) 55 | { 56 | character.Draw(gameTime, SpriteBatch); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGame/FlyweightGame.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | using DesignPatternsGame.Strategy; 12 | using DesignPatternsGame.Common; 13 | using System.ComponentModel.Composition; 14 | using DesignPatternsGame.Factory; 15 | 16 | namespace DesignPatternsGame 17 | { 18 | [Export(typeof(BaseGame))] 19 | public class FlyweightGame : BaseGame 20 | { 21 | private GameSpriteFactory gameSpriteFactory; 22 | private GameSprite character; 23 | 24 | public FlyweightGame() 25 | { 26 | this.gameSpriteFactory = new GameSpriteFactory(Content); 27 | } 28 | 29 | protected override void LoadContent() 30 | { 31 | base.LoadContent(); 32 | 33 | this.CustomDrawing += FlyweightGame_CustomDrawing; 34 | 35 | character = this.gameSpriteFactory.Create(); 36 | } 37 | 38 | protected override void Update(GameTime gameTime) 39 | { 40 | if (Controller1.Buttons.A == ButtonState.Pressed) 41 | { 42 | character = this.gameSpriteFactory.Create(); 43 | } 44 | else if (Controller1.Buttons.B == ButtonState.Pressed) 45 | { 46 | character = this.gameSpriteFactory.Create(); 47 | } 48 | 49 | character.Move(Controller1); 50 | 51 | base.Update(gameTime); 52 | } 53 | 54 | void FlyweightGame_CustomDrawing(GameTime gameTime) 55 | { 56 | character.Draw(gameTime, SpriteBatch); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGame/Game.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brunolm/DesignPatternsGame/109ddeaba9e7041c8fb28a41acb3023627a8a7d3/DesignPatternsGame/DesignPatternsGame/Game.ico -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGame/GameMenu.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Common; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Graphics; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | 9 | namespace DesignPatternsGame 10 | { 11 | public class GameMenu : BaseGame 12 | { 13 | private SpriteFont optionFont; 14 | 15 | protected override void LoadContent() 16 | { 17 | base.LoadContent(); 18 | 19 | this.CustomDrawing += GameMenu_CustomDrawing; 20 | 21 | optionFont = Content.Load("Courier New"); 22 | } 23 | 24 | void GameMenu_CustomDrawing(Microsoft.Xna.Framework.GameTime gameTime) 25 | { 26 | SpriteBatch.DrawString(optionFont, "Game name", Vector2.Zero, Color.White, 0, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGame/GameThumbnail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brunolm/DesignPatternsGame/109ddeaba9e7041c8fb28a41acb3023627a8a7d3/DesignPatternsGame/DesignPatternsGame/GameThumbnail.png -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGame/MediatorGame.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | using DesignPatternsGame.Strategy; 12 | using DesignPatternsGame.Common; 13 | using System.ComponentModel.Composition; 14 | using DesignPatternsGame.Mediator; 15 | 16 | namespace DesignPatternsGame 17 | { 18 | [Export(typeof(BaseGame))] 19 | public class MediatorGame : BaseGame 20 | { 21 | private GameSpriteMediator mediator; 22 | private Foulu character; 23 | private Foulu character2; 24 | 25 | public MediatorGame() 26 | { 27 | this.mediator = new GameSpriteMediator(); 28 | } 29 | 30 | protected override void LoadContent() 31 | { 32 | base.LoadContent(); 33 | 34 | this.CustomDrawing += MediatorGame_CustomDrawing; 35 | 36 | character = new Foulu(Content, mediator); 37 | character2 = new Foulu(Content, mediator); 38 | character2.SpritePosition = new Vector2(0, 60); 39 | } 40 | 41 | protected override void Update(GameTime gameTime) 42 | { 43 | if (Controller1.Buttons.A == ButtonState.Pressed) 44 | { 45 | character.CallFollowers(Controller1); 46 | } 47 | 48 | character.Move(Controller1); 49 | 50 | base.Update(gameTime); 51 | } 52 | 53 | void MediatorGame_CustomDrawing(GameTime gameTime) 54 | { 55 | character.Draw(gameTime, SpriteBatch); 56 | character2.Draw(gameTime, SpriteBatch); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGame/MementoGame.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | using DesignPatternsGame.Strategy; 12 | using DesignPatternsGame.Common; 13 | using System.ComponentModel.Composition; 14 | using DesignPatternsGame.Memento; 15 | 16 | namespace DesignPatternsGame 17 | { 18 | [Export(typeof(BaseGame))] 19 | public class MementoGame : BaseGame 20 | { 21 | private FouluRecorder recorder; 22 | private Foulu character; 23 | 24 | public MementoGame() 25 | { 26 | } 27 | 28 | protected override void LoadContent() 29 | { 30 | base.LoadContent(); 31 | 32 | this.CustomDrawing += MementoGame_CustomDrawing; 33 | 34 | this.character = new Foulu(Content); 35 | this.recorder = new FouluRecorder(character); 36 | } 37 | 38 | protected override void Update(GameTime gameTime) 39 | { 40 | if (Controller1.Buttons.A == ButtonState.Pressed) 41 | { 42 | this.recorder.Record(); 43 | } 44 | else if (Controller1.Buttons.X == ButtonState.Pressed) 45 | { 46 | this.recorder.Rewind(); 47 | } 48 | else if (Controller1.Buttons.B == ButtonState.Pressed) 49 | { 50 | this.recorder.Foward(); 51 | } 52 | 53 | character.Move(Controller1); 54 | 55 | base.Update(gameTime); 56 | } 57 | 58 | void MementoGame_CustomDrawing(GameTime gameTime) 59 | { 60 | character.Draw(gameTime, SpriteBatch); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGame/ObserverGame.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | using DesignPatternsGame.Strategy; 12 | using DesignPatternsGame.Common; 13 | using System.ComponentModel.Composition; 14 | 15 | namespace DesignPatternsGame 16 | { 17 | [Export] 18 | [Export(typeof(BaseGame))] 19 | [Export(typeof(ObserverGame))] 20 | public class ObserverGame : BaseGame 21 | { 22 | private DesignPatternsGame.Observer.Foulu fouLu; 23 | private DesignPatternsGame.Observer.Follower follower; 24 | 25 | protected override void LoadContent() 26 | { 27 | base.LoadContent(); 28 | 29 | this.CustomDrawing += ObserverGame_CustomDrawing; 30 | 31 | fouLu = new DesignPatternsGame.Observer.Foulu(Content.Load("Foulu"), new Vector2(40, 100)); 32 | follower = new DesignPatternsGame.Observer.Follower(Content.Load("Ryu"), new Vector2(0, 100)); 33 | 34 | fouLu.Animation = new Animation(250, 48, 48, 5, offsetY: 48); 35 | follower.Animation = new Animation(250, 48, 48, 5, offsetY: 48); 36 | 37 | fouLu.Subscribe(follower); 38 | } 39 | 40 | protected override void Update(GameTime gameTime) 41 | { 42 | fouLu.Move(Controller1); 43 | 44 | base.Update(gameTime); 45 | } 46 | 47 | void ObserverGame_CustomDrawing(GameTime gameTime) 48 | { 49 | fouLu.Draw(gameTime, SpriteBatch); 50 | follower.Draw(gameTime, SpriteBatch); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGame/Program.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Common; 2 | using System; 3 | using System.Linq; 4 | using System.Collections.Generic; 5 | using System.ComponentModel.Composition; 6 | using System.ComponentModel.Composition.Hosting; 7 | using System.Reflection; 8 | 9 | namespace DesignPatternsGame 10 | { 11 | #if WINDOWS || XBOX 12 | 13 | static class Program 14 | { 15 | static void Main(string[] args) 16 | { 17 | var container = new CompositionContainer(new AssemblyCatalog(Assembly.GetExecutingAssembly())); 18 | container.ComposeParts(GameIndex.Instance); 19 | 20 | BaseGame game = null; 21 | try 22 | { 23 | game = GameIndex.Instance[args[0]]; 24 | } 25 | catch 26 | { 27 | game = new VisitorGame(); 28 | } 29 | 30 | try 31 | { 32 | game.Run(); 33 | } 34 | catch (Exception ex) 35 | { 36 | System.Diagnostics.Debugger.Break(); 37 | game.Dispose(); 38 | } 39 | } 40 | } 41 | #endif 42 | 43 | public class GameIndex 44 | { 45 | [ImportMany(typeof(BaseGame))] 46 | private IEnumerable games = null; 47 | 48 | public BaseGame this[string itemName] 49 | { 50 | get 51 | { 52 | return games.FirstOrDefault(o => o.GetType().Name.Equals(itemName, StringComparison.OrdinalIgnoreCase)); 53 | } 54 | } 55 | 56 | private GameIndex() 57 | { 58 | 59 | } 60 | 61 | private static GameIndex instance; 62 | public static GameIndex Instance 63 | { 64 | get 65 | { 66 | return instance ?? (instance = new GameIndex()); 67 | } 68 | } 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGame/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DesignPatternsGame")] 9 | [assembly: AssemblyProduct("DesignPatternsGame")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyCopyright("Copyright © 2014")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. Only Windows 19 | // assemblies support COM. 20 | [assembly: ComVisible(false)] 21 | 22 | // On Windows, the following GUID is for the ID of the typelib if this 23 | // project is exposed to COM. On other platforms, it unique identifies the 24 | // title storage container when deploying this assembly to the device. 25 | [assembly: Guid("ab5daa02-b130-4378-90bf-d80cded7f996")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | [assembly: AssemblyVersion("1.0.0.0")] -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGame/PrototypeGame.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | using DesignPatternsGame.Strategy; 12 | using DesignPatternsGame.Common; 13 | using System.ComponentModel.Composition; 14 | using DesignPatternsGame.Prototype; 15 | 16 | namespace DesignPatternsGame 17 | { 18 | [Export(typeof(BaseGame))] 19 | public class PrototypeGame : BaseGame 20 | { 21 | private Foulu character; 22 | private Foulu character2; 23 | 24 | public PrototypeGame() 25 | { 26 | } 27 | 28 | protected override void LoadContent() 29 | { 30 | base.LoadContent(); 31 | 32 | this.CustomDrawing += PrototypeGame_CustomDrawing; 33 | 34 | character = new Foulu(Content); 35 | character2 = character.Clone(); 36 | character2.SpritePosition += new Vector2(0, 60); 37 | } 38 | 39 | protected override void Update(GameTime gameTime) 40 | { 41 | if (Controller1.Buttons.A == ButtonState.Pressed) 42 | { 43 | character2.SpritePosition += new Vector2(2, 1); 44 | } 45 | 46 | character.Move(Controller1); 47 | 48 | base.Update(gameTime); 49 | } 50 | 51 | void PrototypeGame_CustomDrawing(GameTime gameTime) 52 | { 53 | character.Draw(gameTime, SpriteBatch); 54 | character2.Draw(gameTime, SpriteBatch); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGame/ProxyGame.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | using DesignPatternsGame.Strategy; 12 | using DesignPatternsGame.Common; 13 | using System.ComponentModel.Composition; 14 | using DesignPatternsGame.Proxy; 15 | 16 | namespace DesignPatternsGame 17 | { 18 | [Export(typeof(BaseGame))] 19 | public class ProxyGame : BaseGame 20 | { 21 | private FouluProxy proxy; 22 | private Foulu character; 23 | 24 | public ProxyGame() 25 | { 26 | this.proxy = new FouluProxy(); 27 | } 28 | 29 | protected override void LoadContent() 30 | { 31 | base.LoadContent(); 32 | 33 | this.CustomDrawing += ProxyGame_CustomDrawing; 34 | } 35 | 36 | protected override void Update(GameTime gameTime) 37 | { 38 | if (character == null) 39 | character = proxy.Create(Content, gameTime); 40 | 41 | if (character != null) 42 | { 43 | character.Move(Controller1); 44 | 45 | base.Update(gameTime); 46 | } 47 | } 48 | 49 | void ProxyGame_CustomDrawing(GameTime gameTime) 50 | { 51 | if (character != null) 52 | character.Draw(gameTime, SpriteBatch); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGame/SingletonGame.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | using DesignPatternsGame.Strategy; 12 | using DesignPatternsGame.Common; 13 | using System.ComponentModel.Composition; 14 | using DesignPatternsGame.Singleton; 15 | 16 | namespace DesignPatternsGame 17 | { 18 | [Export(typeof(BaseGame))] 19 | public class SingletonGame : BaseGame 20 | { 21 | private Foulu character; 22 | 23 | public SingletonGame() 24 | { 25 | Foulu.Content = Content; 26 | } 27 | 28 | protected override void LoadContent() 29 | { 30 | base.LoadContent(); 31 | 32 | this.CustomDrawing += SingletonGame_CustomDrawing; 33 | 34 | character = Foulu.Instance; 35 | //character = new Foulu(Content); 36 | } 37 | 38 | protected override void Update(GameTime gameTime) 39 | { 40 | character.Move(Controller1); 41 | 42 | base.Update(gameTime); 43 | } 44 | 45 | void SingletonGame_CustomDrawing(GameTime gameTime) 46 | { 47 | character.Draw(gameTime, SpriteBatch); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGame/StateGame.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | using DesignPatternsGame.Strategy; 12 | using DesignPatternsGame.Common; 13 | using System.ComponentModel.Composition; 14 | using DesignPatternsGame.State; 15 | 16 | namespace DesignPatternsGame 17 | { 18 | [Export(typeof(BaseGame))] 19 | public class StateGame : BaseGame 20 | { 21 | private Foulu character; 22 | 23 | public StateGame() 24 | { 25 | } 26 | 27 | protected override void LoadContent() 28 | { 29 | base.LoadContent(); 30 | 31 | this.CustomDrawing += StateGame_CustomDrawing; 32 | 33 | character = new Foulu(Content); 34 | } 35 | 36 | protected override void Update(GameTime gameTime) 37 | { 38 | if (Controller1.Buttons.B == ButtonState.Pressed) 39 | { 40 | if (character.State.GetType() != typeof(RunningState)) 41 | character.State = new RunningState(); 42 | } 43 | else if (Controller1.Buttons.A == ButtonState.Pressed) 44 | { 45 | if (character.State.GetType() != typeof(WalkingState)) 46 | character.State = new WalkingState(); 47 | } 48 | 49 | character.Move(Controller1); 50 | 51 | base.Update(gameTime); 52 | } 53 | 54 | void StateGame_CustomDrawing(GameTime gameTime) 55 | { 56 | character.Draw(gameTime, SpriteBatch); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGame/StrategyGame.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | using DesignPatternsGame.Strategy; 12 | using DesignPatternsGame.Common; 13 | using System.ComponentModel.Composition; 14 | 15 | namespace DesignPatternsGame 16 | { 17 | [Export(typeof(BaseGame))] 18 | public class StrategyGame : BaseGame 19 | { 20 | private MovableCharacter character; 21 | 22 | public StrategyGame() 23 | { 24 | } 25 | 26 | protected override void LoadContent() 27 | { 28 | base.LoadContent(); 29 | 30 | this.CustomDrawing += StrategyGame_CustomDrawing; 31 | 32 | character = new MovableCharacter(Content.Load("Foulu"), Vector2.Zero); 33 | } 34 | 35 | protected override void Update(GameTime gameTime) 36 | { 37 | if (Controller1.Buttons.B == ButtonState.Pressed) 38 | { 39 | if (character.MoveStrategy.GetType() != typeof(RunStrategy)) 40 | character.MoveStrategy = new RunStrategy(); 41 | } 42 | else 43 | { 44 | if (character.MoveStrategy.GetType() != typeof(WalkStrategy)) 45 | character.MoveStrategy = new WalkStrategy(); 46 | } 47 | 48 | character.Move(Controller1); 49 | 50 | base.Update(gameTime); 51 | } 52 | 53 | void StrategyGame_CustomDrawing(GameTime gameTime) 54 | { 55 | character.Draw(gameTime, SpriteBatch); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGame/VisitorGame.cs: -------------------------------------------------------------------------------- 1 | using DesignPatternsGame.Common; 2 | using DesignPatternsGame.Visitor; 3 | using Microsoft.Xna.Framework; 4 | using Microsoft.Xna.Framework.Input; 5 | using System.ComponentModel.Composition; 6 | 7 | namespace DesignPatternsGame 8 | { 9 | [Export(typeof(BaseGame))] 10 | public class VisitorGame : BaseGame 11 | { 12 | private Foulu character; 13 | 14 | public VisitorGame() 15 | { 16 | } 17 | 18 | protected override void LoadContent() 19 | { 20 | base.LoadContent(); 21 | 22 | this.CustomDrawing += VisitorGame_CustomDrawing; 23 | 24 | character = new Foulu(Content); 25 | } 26 | 27 | protected override void Update(GameTime gameTime) 28 | { 29 | if (Controller1.Buttons.B == ButtonState.Pressed) 30 | { 31 | character.Accept(new Boost()); 32 | } 33 | 34 | character.Move(Controller1); 35 | 36 | base.Update(gameTime); 37 | } 38 | 39 | void VisitorGame_CustomDrawing(GameTime gameTime) 40 | { 41 | character.Draw(gameTime, SpriteBatch); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGameContent/DesignPatternsGameContent.contentproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | {F37B2CF1-1740-4705-9291-58B5BE006964} 5 | {96E2B04D-8817-42c6-938A-82C39BA4D311};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 6 | Debug 7 | x86 8 | Library 9 | Properties 10 | v4.0 11 | v4.0 12 | bin\$(Platform)\$(Configuration) 13 | Content 14 | 15 | 16 | x86 17 | 18 | 19 | x86 20 | 21 | 22 | DesignPatternsGameContent 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | Foulu 35 | TextureImporter 36 | TextureProcessor 37 | 38 | 39 | 40 | 41 | Ryu 42 | TextureImporter 43 | TextureProcessor 44 | 45 | 46 | 47 | 48 | MorphGoo 49 | TextureImporter 50 | TextureProcessor 51 | 52 | 53 | 54 | 55 | Zero 56 | TextureImporter 57 | TextureProcessor 58 | 59 | 60 | 61 | 62 | Megaman 63 | TextureImporter 64 | TextureProcessor 65 | 66 | 67 | 68 | 75 | -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGameContent/Foulu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brunolm/DesignPatternsGame/109ddeaba9e7041c8fb28a41acb3023627a8a7d3/DesignPatternsGame/DesignPatternsGameContent/Foulu.png -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGameContent/Megaman.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brunolm/DesignPatternsGame/109ddeaba9e7041c8fb28a41acb3023627a8a7d3/DesignPatternsGame/DesignPatternsGameContent/Megaman.png -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGameContent/MorphGoo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brunolm/DesignPatternsGame/109ddeaba9e7041c8fb28a41acb3023627a8a7d3/DesignPatternsGame/DesignPatternsGameContent/MorphGoo.png -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGameContent/Ryu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brunolm/DesignPatternsGame/109ddeaba9e7041c8fb28a41acb3023627a8a7d3/DesignPatternsGame/DesignPatternsGameContent/Ryu.png -------------------------------------------------------------------------------- /DesignPatternsGame/DesignPatternsGameContent/Zero.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brunolm/DesignPatternsGame/109ddeaba9e7041c8fb28a41acb3023627a8a7d3/DesignPatternsGame/DesignPatternsGameContent/Zero.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Design Patterns in Games 2 | ======================== 3 | 4 | Using mini-games to show how design patterns work. Made with XNA. --------------------------------------------------------------------------------