Skip to content

Commit

Permalink
Adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasCancio committed Jan 13, 2021
1 parent 3fa1152 commit 6e555b2
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 0 deletions.
8 changes: 8 additions & 0 deletions PatternsEstruturais/Adapter/Adapter.csproj
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>
11 changes: 11 additions & 0 deletions PatternsEstruturais/Adapter/IAtaqueInimigo.cs
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);
}
}
36 changes: 36 additions & 0 deletions PatternsEstruturais/Adapter/Program.cs
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();

}
}
}
29 changes: 29 additions & 0 deletions PatternsEstruturais/Adapter/RoboInimigo.cs
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}!");
}
}
}
31 changes: 31 additions & 0 deletions PatternsEstruturais/Adapter/RoboInimigoAdapter.cs
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);
}
}
}
26 changes: 26 additions & 0 deletions PatternsEstruturais/Adapter/TanqueInimigo.cs
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!");
}
}
}
25 changes: 25 additions & 0 deletions PatternsEstruturais/PatternsEstruturais.sln
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

0 comments on commit 6e555b2

Please sign in to comment.