-
Notifications
You must be signed in to change notification settings - Fork 83
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
nmzgnv
committed
Oct 18, 2024
1 parent
db60afa
commit b5bd333
Showing
8 changed files
with
137 additions
and
22 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
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
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 |
---|---|---|
@@ -1,7 +1,43 @@ | ||
using MongoDB.Bson.Serialization.Attributes; | ||
using System; | ||
|
||
namespace Game.Domain | ||
{ | ||
public class GameTurnEntity | ||
{ | ||
//TODO: Придумать какие свойства должны быть в этом классе, чтобы сохранять всю информацию о закончившемся туре. | ||
[BsonConstructor] | ||
public GameTurnEntity(Guid id, int turn, PlayerDecision firstPlayerDecision, | ||
PlayerDecision secondPlayerDecision, Guid firstPlayer, Guid secondPlayer) | ||
{ | ||
FirstPlayerDecision = firstPlayerDecision; | ||
SecondPlayerDecision = secondPlayerDecision; | ||
FirstPlayer = firstPlayer; | ||
SecondPlayer = secondPlayer; | ||
Turn = turn; | ||
GameId = id; | ||
Winner = firstPlayerDecision.Beats(secondPlayerDecision) | ||
? 1 : secondPlayerDecision.Beats(firstPlayerDecision) | ||
? 2 : 0; | ||
} | ||
public Guid Id | ||
{ | ||
get; | ||
private set; | ||
} | ||
[BsonElement] | ||
public PlayerDecision FirstPlayerDecision { get; } | ||
[BsonElement] | ||
public PlayerDecision SecondPlayerDecision { get; } | ||
[BsonElement] | ||
public Guid FirstPlayer { get; } | ||
[BsonElement] | ||
public Guid SecondPlayer { get; } | ||
[BsonElement] | ||
public Guid GameId { get; } | ||
[BsonElement] | ||
public int Turn { get; } | ||
[BsonElement] | ||
public int Winner { get; } | ||
} | ||
} |
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 |
---|---|---|
@@ -1,7 +1,12 @@ | ||
using System.Collections.Generic; | ||
using System; | ||
|
||
namespace Game.Domain | ||
{ | ||
public interface IGameTurnRepository | ||
{ | ||
// TODO: Спроектировать интерфейс исходя из потребностей ConsoleApp | ||
GameTurnEntity Insert(GameTurnEntity turn); | ||
List<GameTurnEntity> GetLastTurns(Guid gameId); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,6 +1,33 @@ | ||
using MongoDB.Bson; | ||
using MongoDB.Driver; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Game.Domain | ||
{ | ||
public class MongoGameTurnRepository : IGameTurnRepository | ||
{ | ||
private readonly IMongoCollection<GameTurnEntity> gameTurnCollection; | ||
public const string CollectionName = "gameTurns"; | ||
|
||
public GameTurnEntity Insert(GameTurnEntity turn) | ||
{ | ||
gameTurnCollection.InsertOne(turn); | ||
return turn; | ||
} | ||
|
||
public List<GameTurnEntity> GetLastTurns(Guid gameId) | ||
{ | ||
var filter = new BsonDocument("GameId", gameId); | ||
return gameTurnCollection.Find(filter) | ||
.SortByDescending(x => x.Turn) | ||
.Limit(5) | ||
.ToList(); | ||
} | ||
|
||
public MongoGameTurnRepository(IMongoDatabase db) | ||
{ | ||
gameTurnCollection = db.GetCollection<GameTurnEntity>(CollectionName); | ||
} | ||
} | ||
} |
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
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