forked from LucasCancio/design-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3fa1152
commit 6e555b2
Showing
7 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
|
||
namespace Adapter | ||
{ | ||
public interface IAtaqueInimigo | ||
{ | ||
void ArmaFogo(); | ||
void Movimenta(); | ||
void Pilotar(String piloto); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
|
||
namespace Adapter | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
TanqueInimigo tanqueRx2021 = new TanqueInimigo(); | ||
|
||
RoboInimigo r2d2 = new RoboInimigo(); | ||
|
||
IAtaqueInimigo r2d2Adaptado = new RoboInimigoAdapter(r2d2); | ||
|
||
Console.WriteLine(" ===== ROBO ===== "); | ||
r2d2.ReagirContraHumano("Rodrigo"); | ||
r2d2.AndarFrente(); | ||
r2d2.EsgamarComMaos(); | ||
|
||
Console.WriteLine("\n"); | ||
|
||
Console.WriteLine(" ===== TANQUE ===== "); | ||
tanqueRx2021.Pilotar("João"); | ||
tanqueRx2021.Movimenta(); | ||
tanqueRx2021.ArmaFogo(); | ||
|
||
Console.WriteLine("\n"); | ||
|
||
Console.WriteLine(" ===== ROBO ADAPATDO ===== "); | ||
r2d2Adaptado.Pilotar("Maria"); | ||
r2d2Adaptado.Movimenta(); | ||
r2d2Adaptado.ArmaFogo(); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
|
||
namespace Adapter | ||
{ | ||
// é o nosso Adaptee -> ele é o objeto que será adaptado | ||
public class RoboInimigo | ||
{ | ||
Random gerador = new Random(); | ||
|
||
public void EsgamarComMaos() | ||
{ | ||
int danoAataque = this.gerador.Next(10) + 1; | ||
|
||
Console.WriteLine($"O Robo inimigo causou {danoAataque} de dano com o ataque Esmgar com as Mãoes!"); | ||
} | ||
|
||
public void AndarFrente() | ||
{ | ||
int movimento = this.gerador.Next(10) + 1; | ||
|
||
Console.WriteLine($"O Robo inimigo andou {movimento} passos para frente!"); | ||
} | ||
|
||
public void ReagirContraHumano(String piloto) | ||
{ | ||
Console.WriteLine($"O robo inimigo vai contra {piloto}!"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Adapter | ||
{ | ||
public class RoboInimigoAdapter : IAtaqueInimigo | ||
{ | ||
public RoboInimigo Robo { get; set; } | ||
|
||
public RoboInimigoAdapter(RoboInimigo robo) | ||
{ | ||
Robo = robo; | ||
} | ||
|
||
public void ArmaFogo() | ||
{ | ||
this.Robo.EsgamarComMaos(); | ||
} | ||
|
||
public void Movimenta() | ||
{ | ||
this.Robo.AndarFrente(); | ||
} | ||
|
||
public void Pilotar(string piloto) | ||
{ | ||
this.Robo.ReagirContraHumano(piloto); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
namespace Adapter | ||
{ | ||
public class TanqueInimigo : IAtaqueInimigo | ||
{ | ||
Random gerador = new Random(); | ||
|
||
public void ArmaFogo() | ||
{ | ||
int danoAtaque = this.gerador.Next(10) + 1; | ||
Console.WriteLine($"Tanque inimigo fez {danoAtaque} de dano!"); | ||
} | ||
|
||
public void Movimenta() | ||
{ | ||
int movimento = this.gerador.Next(5) + 1; | ||
|
||
Console.WriteLine($"Tanque inimigo andou {movimento} passos!"); | ||
} | ||
|
||
public void Pilotar(string piloto) | ||
{ | ||
Console.WriteLine($"{piloto} está no comando do tanque agora!"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.30804.86 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Adapter", "Adapter\Adapter.csproj", "{55F89ED5-E95B-4392-8320-C47E32B860B7}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{55F89ED5-E95B-4392-8320-C47E32B860B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{55F89ED5-E95B-4392-8320-C47E32B860B7}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{55F89ED5-E95B-4392-8320-C47E32B860B7}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{55F89ED5-E95B-4392-8320-C47E32B860B7}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {8DDD6375-8009-4458-B450-D19DE86A3E4C} | ||
EndGlobalSection | ||
EndGlobal |