Expert review 4 4 2024
K3 Je hebt een infrastructuur ontworpen en gebouwd volgens de gegeven specificaties.¶
Infrastructuur¶
Ik heb zelf 2 JSON paketten gemaakt en verzonden.
De code hieronder gaat over of er een piece is geselecteerd of niet.
namespace Blok3Game.Engine.JSON
{
public class PieceIsSelected : DataPacket
{
public string SessionId { get; set; }
public string UserId { get; set; }
public string RoomId { get; set; }
public bool PieceSelected { get; set; }
public PieceIsSelected() : base()
{
EventName = "Piece is selected";
}
}
}
private void CheckPieceMovement()
{
if (inputHelper.MouseLeftButtonPressed)
{
Vector2 mousePosition = inputHelper.MousePosition;
clickedTile = GetTileUnderMouse(mousePosition);
if (clickedTile != null)
{
if (SelectedPiece != null)
{
SendPieceSelectedDataPacket();
Console.WriteLine($"Selected Piece: {SelectedPiece.ID}, Tile ID: {SelectedPiece.TileID}");
if (SelectedPiece.TileID != clickedTile.ID)
{
Tile currentTile = FindTileById(SelectedPiece.TileID);
bool canMove = SelectedPiece.GetPossibleMoves(currentTile, clickedTile);
if (!canMove)
{
Console.WriteLine("Selected piece has no possible moves.");
SelectedPiece = null;
if (previousTile != null)
{
previousTile.OccupyingPiece = null;
}
return;
}
De code hieronder gaat over of een card geselecteerd is of niet
public override void HandleInput(InputHelper inputHelper)
{
base.HandleInput(inputHelper);
if (inputHelper.MouseLeftButtonPressed)
{
TileUnderMouse = GetTileUnderMouse(inputHelper.MousePosition);
foreach (Card card in cards.Children)
{
if (card.CardMouseCollision(inputHelper.MousePosition))
{
SendCardSelectedDataPacket();
//switches card states between selected and not selected, depending on selected state and mouse position
card.IsSelected = !card.IsSelected;
}
//happens when a card is deselected
else if (card.IsSelected)
{
//moves the top-left of the card to the mouse
card.IsSelected = false;
card.Position = new Vector2(inputHelper.MousePosition.X - card.StartOffsetX,
inputHelper.MousePosition.Y - card.StartOffsetY);
if (TileUnderMouse != null)
{
card.CardUsed((int)TileUnderMouse.CenterPosition.X, (int)TileUnderMouse.CenterPosition.Y, TileUnderMouse.ID);
}
}
}
}
}
Hieronder heb ik alle methodes gezet die voor beide datapackets gelden.
handleIncomingMessages(socket) {
this.#handleIncomingStartGameMessages(socket);
//this.#handleIncomingPositionMessages(socket);
this.#handleIncomingCardMessages(socket);
this.#handleIncomingPieceSelectedMessages(socket);
}
#handleIncomingStartGameMessages(socket) {
socket.on('start game', (data) => {
this._rooms[data.roomId].started = true;
//send a message to all players that the game has started.
//the client in the specific room can then start the game.
//other clients can remove the game from the list of active games.
this._io.emit('start game', { roomId: data.roomId });
});
}
#handleIncomingCardMessages(socket) {
socket.on("Card is selected", (data) => {
this._io.to(socket.roomId).emit("Card is selected", data);
});
}
#handleIncomingPieceSelectedMessages(socket) {
socket.on("Piece is selected", (data) => {
this._io.to(socket.roomId).emit("Piece is selected", data);
});
}
Netwerk diagram¶
Verder heb ik een netwerk diagram gemaakt van het project. een netwerkdiagram is een visuele voorstelling van een computer- of telecommuncatienetwerk (luchidchart.com)
Sequence diagram¶
Ook is er een sequence diagram gemaakt voor dit project om de flow van data visueel te maken.
Last update:
April 4, 2024