Skip to content

Commit

Permalink
fix: 修復衝突
Browse files Browse the repository at this point in the history
  • Loading branch information
aa89227 committed Jun 2, 2024
1 parent 03575be commit c1ac1ae
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 182 deletions.
173 changes: 0 additions & 173 deletions Application/Common/IRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
/// <summary>
/// (Monopoly) Domain to Application
/// </summary>
/// <param name="domainMonopoly"></param>
/// <returns></returns>
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<Domain.Land>()
.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(),
};
}
/// <summary>
/// (Monopoly) Application to Domain
/// </summary>
/// <param name="monopoly"></param>
/// <returns></returns>
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(),
};
}
}
2 changes: 2 additions & 0 deletions Application/Common/RepositoryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
Expand Down Expand Up @@ -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(),
};
Expand Down
4 changes: 2 additions & 2 deletions Domain/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
16 changes: 15 additions & 1 deletion Monopoly.Web/Pages/Ready/Components/ColorChoicePanel.razor.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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)
};
}
}
5 changes: 2 additions & 3 deletions Monopoly.Web/Pages/Ready/ReadyPage.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions Monopoly.Web/Pages/Ready/ReadyRoomHubConnection.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Client.Pages.Ready.Entities;
using SharedLibrary;
using SharedLibrary;
using SharedLibrary.ResponseArgs.ReadyRoom.Models;
using SignalR.Client.Generator;

Expand All @@ -12,7 +11,7 @@ public interface IReadyRoomRequests
{
Task StartGame();
Task PlayerReady();
Task SelectLocation(ColorEnum location);
Task SelectLocation(LocationEnum location);
Task SelectRole(string role);
Task<ReadyRoomInfos> GetReadyRoomInfos();
}

0 comments on commit c1ac1ae

Please sign in to comment.