diff --git a/Application/Common/IRepository.cs b/Application/Common/IRepository.cs
index 31a5ce8..a03d471 100644
--- a/Application/Common/IRepository.cs
+++ b/Application/Common/IRepository.cs
@@ -17,177 +17,4 @@ public interface ICommandRepository : IRepository
public interface IQueryRepository : IRepository
{
-}
-
-internal static class RepositoryExtensions
-{
- internal static string Save(this IRepository repository, Domain.Monopoly domainMonopoly)
- {
- var monopoly = domainMonopoly.ToApplication();
- return repository.Save(monopoly);
- }
- ///
- /// (Monopoly) Domain to Application
- ///
- ///
- ///
- private static Monopoly ToApplication(this Domain.Monopoly domainMonopoly)
- {
- var players = domainMonopoly.Players.Select(player =>
- {
- var playerChess = player.Chess;
-
- Chess chess = new(playerChess.CurrentBlockId, playerChess.CurrentDirection.ToApplicationDirection());
-
- var landContracts = player.LandContractList.Select(contract =>
- new LandContract(contract.Land.Id, contract.InMortgage, contract.Deadline)).ToArray();
-
- return new Player(
- player.Id,
- player.Money,
- chess,
- landContracts,
- player.State,
- player.BankruptRounds,
- player.LocationId,
- player.RoleId
- );
- }).ToArray();
-
- Map map = new(domainMonopoly.Map.Id, domainMonopoly.Map.Blocks
- .Select(row =>
- {
- return row.Select(block => block?.ToApplicationBlock()).ToArray();
- }).ToArray()
- );
- var gamestage = domainMonopoly.GameStage switch
- {
- Domain.GameStage.Ready => GameStage.Preparing,
- Domain.GameStage.Gaming => GameStage.Gaming,
- _ => throw new NotImplementedException(),
- };
- if (gamestage == GameStage.Preparing)
- {
- return new Monopoly(domainMonopoly.Id, [..players], map, domainMonopoly.HostId, null!, null!, gamestage);
- }
- var currentPlayer = domainMonopoly.Players.First(player => player.Id == domainMonopoly.CurrentPlayerState.PlayerId);
- var auction = domainMonopoly.CurrentPlayerState.Auction;
- var currentPlayerState = new CurrentPlayerState(
- domainMonopoly.CurrentPlayerState.PlayerId,
- domainMonopoly.CurrentPlayerState.IsPayToll,
- domainMonopoly.CurrentPlayerState.IsBoughtLand,
- domainMonopoly.CurrentPlayerState.IsUpgradeLand,
- domainMonopoly.CurrentPlayerState.Auction is null ? null : new Auction(auction!.LandContract.Land.Id, auction.HighestBidder?.Id, auction.HighestPrice),
- domainMonopoly.CurrentPlayerState.RemainingSteps,
- domainMonopoly.CurrentPlayerState.HadSelectedDirection
- );
- var LandHouses = domainMonopoly.Map.Blocks.SelectMany(block => block).OfType()
- .Where(land => land.House > 0)
- .Select(land => new LandHouse(land.Id, land.House)).ToArray();
-
-
- return new Monopoly(domainMonopoly.Id, players, map, domainMonopoly.HostId, currentPlayerState, LandHouses, gamestage);
- }
- private static Block ToApplicationBlock(this Domain.Block domainBlock)
- {
- return domainBlock switch
- {
- Domain.StartPoint startBlock => new StartPoint(startBlock.Id),
- Domain.Station stationBlock => new Station(stationBlock.Id),
- Domain.Land landBlock => new Land(landBlock.Id),
- Domain.ParkingLot parkingLotBlock => new ParkingLot(parkingLotBlock.Id),
- Domain.Jail prisonBlock => new Jail(prisonBlock.Id),
- Domain.Road roadBlock => new Road(roadBlock.Id),
- null => new EmptyBlock(),
- _ => throw new NotImplementedException(),
- };
- }
- ///
- /// (Monopoly) Application to Domain
- ///
- ///
- ///
- internal static Domain.Monopoly ToDomain(this Monopoly monopoly)
- {
- //Domain.Map map = new(monopoly.Map.Id, monopoly.Map.Blocks
- // .Select(row =>
- // {
- // return row.Select(block => block?.ToDomainBlock()).ToArray();
- // }).ToArray()
- // );
- Domain.Map map = new SevenXSevenMap();
- var builder = new Domain.Builders.MonopolyBuilder()
- .WithId(monopoly.Id)
- .WithHost(monopoly.HostId)
- .WithMap(map);
- monopoly.Players.ToList().ForEach(
- p => builder.WithPlayer(p.Id, playerBuilder =>
- playerBuilder.WithMoney(p.Money)
- .WithPosition(p.Chess.CurrentPosition, p.Chess.Direction.ToString())
- .WithLandContracts(p.LandContracts)
- .WithBankrupt(p.BankruptRounds)
- .WithLocation(p.LocationId)
- .WithRole(p.RoleId)
- .WithState(p.PlayerState)
- ));
- builder.WithGameStage(monopoly.GameStage switch
- {
- GameStage.Preparing => Domain.GameStage.Ready,
- GameStage.Gaming => Domain.GameStage.Gaming,
- _ => throw new NotImplementedException(),
- });
- if (monopoly.GameStage == GameStage.Preparing)
- {
- return builder.Build();
- }
- var cps = monopoly.CurrentPlayerState;
- if (cps.Auction is null)
- {
- builder.WithCurrentPlayer(cps.PlayerId, x => x.WithBoughtLand(cps.IsBoughtLand)
- .WithUpgradeLand(cps.IsUpgradeLand)
- .WithPayToll(cps.IsPayToll)
- .WithSelectedDirection(cps.HadSelectedDirection));
- }
- else
- {
- builder.WithCurrentPlayer(cps.PlayerId, x => x.WithAuction(
- cps.Auction.LandId, cps.Auction.HighestBidderId, cps.Auction.HighestPrice));
- }
- monopoly.LandHouses.ToList().ForEach(LandHouse => builder.WithLandHouse(LandHouse.LandId, LandHouse.House));
-
- return builder.Build();
- }
- private static Domain.Builders.PlayerBuilder WithLandContracts(this Domain.Builders.PlayerBuilder builder, LandContract[] landContracts)
- {
- landContracts.ToList().ForEach(landContract =>
- {
- builder.WithLandContract(landContract.LandId, landContract.InMortgage, landContract.Deadline);
- });
- return builder;
- }
- private static Domain.Block? ToDomainBlock(this Block? block)
- {
- return block switch
- {
- StartPoint startBlock => new Domain.StartPoint(startBlock.Id),
- Station stationBlock => new Domain.Station(stationBlock.Id),
- Land landBlock => new Domain.Land(landBlock.Id),
- ParkingLot parkingLotBlock => new Domain.ParkingLot(parkingLotBlock.Id),
- Jail prisonBlock => new Domain.Jail(prisonBlock.Id),
- Road roadBlock => new Domain.Road(roadBlock.Id),
- EmptyBlock => null,
- _ => throw new NotImplementedException(),
- };
- }
- private static Direction ToApplicationDirection(this Domain.Map.Direction direction)
- {
- return direction switch
- {
- Domain.Map.Direction.Up => Direction.Up,
- Domain.Map.Direction.Down => Direction.Down,
- Domain.Map.Direction.Left => Direction.Left,
- Domain.Map.Direction.Right => Direction.Right,
- _ => throw new NotImplementedException(),
- };
- }
}
\ No newline at end of file
diff --git a/Application/Common/RepositoryExtensions.cs b/Application/Common/RepositoryExtensions.cs
index 0f15426..3f1bce4 100644
--- a/Application/Common/RepositoryExtensions.cs
+++ b/Application/Common/RepositoryExtensions.cs
@@ -87,6 +87,7 @@ private static Block ToApplicationBlock(this Domain.Block domainBlock)
Domain.Land landBlock => new Land(landBlock.Id),
Domain.ParkingLot parkingLotBlock => new ParkingLot(parkingLotBlock.Id),
Domain.Jail prisonBlock => new Jail(prisonBlock.Id),
+ Domain.Road roadBlock => new Road(roadBlock.Id),
null => new EmptyBlock(),
_ => throw new NotImplementedException(),
};
@@ -169,6 +170,7 @@ private static Domain.Builders.PlayerBuilder WithLandContracts(this Domain.Build
Land landBlock => new Domain.Land(landBlock.Id),
ParkingLot parkingLotBlock => new Domain.ParkingLot(parkingLotBlock.Id),
Jail prisonBlock => new Domain.Jail(prisonBlock.Id),
+ Road roadBlock => new Domain.Road(roadBlock.Id),
EmptyBlock => null,
_ => throw new NotImplementedException(),
};
diff --git a/Domain/Block.cs b/Domain/Block.cs
index f1f2cbd..24dd3f6 100644
--- a/Domain/Block.cs
+++ b/Domain/Block.cs
@@ -318,8 +318,8 @@ internal override void DoBlockAction(Player player)
{
}
- internal override DomainEvent OnBlockEvent(Player player)
+ internal override DomainEvent? OnBlockEvent(Player player)
{
- return DomainEvent.EmptyEvent;
+ return null;
}
}
\ No newline at end of file
diff --git a/Monopoly.Web/Pages/Ready/Components/ColorChoicePanel.razor.cs b/Monopoly.Web/Pages/Ready/Components/ColorChoicePanel.razor.cs
index 1ef5e95..c71fe00 100644
--- a/Monopoly.Web/Pages/Ready/Components/ColorChoicePanel.razor.cs
+++ b/Monopoly.Web/Pages/Ready/Components/ColorChoicePanel.razor.cs
@@ -1,7 +1,8 @@
using Client.Pages.Enums;
using System.Collections.Immutable;
-using Client.Pages.Ready.Entities;
using Microsoft.AspNetCore.Components;
+using SharedLibrary.ResponseArgs.ReadyRoom.Models;
+using Player = Client.Pages.Ready.Entities.Player;
namespace Client.Pages.Ready.Components;
@@ -54,4 +55,17 @@ public static string ToLowerCaseName(this ColorEnum color)
_ => throw new ArgumentOutOfRangeException(nameof(color), color, null)
};
}
+
+ public static LocationEnum ToLocationEnum(this ColorEnum color)
+ {
+ return color switch
+ {
+ ColorEnum.None => LocationEnum.None,
+ ColorEnum.Red => LocationEnum.First,
+ ColorEnum.Blue => LocationEnum.Second,
+ ColorEnum.Green => LocationEnum.Third,
+ ColorEnum.Yellow => LocationEnum.Fourth,
+ _ => throw new ArgumentOutOfRangeException(nameof(color), color, null)
+ };
+ }
}
\ No newline at end of file
diff --git a/Monopoly.Web/Pages/Ready/ReadyPage.razor.cs b/Monopoly.Web/Pages/Ready/ReadyPage.razor.cs
index 0d1561d..d6bbca5 100644
--- a/Monopoly.Web/Pages/Ready/ReadyPage.razor.cs
+++ b/Monopoly.Web/Pages/Ready/ReadyPage.razor.cs
@@ -2,7 +2,6 @@
using Client.Options;
using Client.Pages.Enums;
using Client.Pages.Ready.Components;
-using Client.Pages.Ready.Entities;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.Options;
@@ -11,7 +10,7 @@
using SharedLibrary.ResponseArgs.ReadyRoom.Models;
using Player = Client.Pages.Ready.Entities.Player;
using ResponseRoleEnum = SharedLibrary.ResponseArgs.ReadyRoom.Models.RoleEnum;
-using PageRoleEnum = Client.Pages.Ready.Entities.RoleEnum;
+using PageRoleEnum = Client.Pages.Enums.RoleEnum;
namespace Client.Pages.Ready;
@@ -131,7 +130,7 @@ await Popup.Show(new Popup.PopupParameter
private async Task OnSelectColor(ColorEnum color)
{
- await Connection.SelectLocation(color);
+ await Connection.SelectLocation(color.ToLocationEnum());
}
private async Task OnSelectRole(string role)
diff --git a/Monopoly.Web/Pages/Ready/ReadyRoomHubConnection.cs b/Monopoly.Web/Pages/Ready/ReadyRoomHubConnection.cs
index 0bdd926..8d42c91 100644
--- a/Monopoly.Web/Pages/Ready/ReadyRoomHubConnection.cs
+++ b/Monopoly.Web/Pages/Ready/ReadyRoomHubConnection.cs
@@ -1,5 +1,4 @@
-using Client.Pages.Ready.Entities;
-using SharedLibrary;
+using SharedLibrary;
using SharedLibrary.ResponseArgs.ReadyRoom.Models;
using SignalR.Client.Generator;
@@ -12,7 +11,7 @@ public interface IReadyRoomRequests
{
Task StartGame();
Task PlayerReady();
- Task SelectLocation(ColorEnum location);
+ Task SelectLocation(LocationEnum location);
Task SelectRole(string role);
Task GetReadyRoomInfos();
}