Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/Timmlion/KJ2024 into dev…
Browse files Browse the repository at this point in the history
…elop
  • Loading branch information
amaz-e committed Jan 28, 2024
2 parents bb393aa + 2b1a9e5 commit a0b6f65
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 12 deletions.
16 changes: 13 additions & 3 deletions backend/MemeBE/Models/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ public int PrepareLaugh(int value, out List<int?> cardsToDelete)
return result;
}

public void ReceiveLaugh(int laughValue)
public void ReceiveLaugh(int laughValue,out List<int?> cardsToDelete)
{
var laughReceived = laughValue;
cardsToDelete = new List<int?>();
var cardsCopy = new List<Card>(PersistentSlot);
PersistentSlot.Clear();
foreach (var card in cardsCopy)
Expand All @@ -66,7 +67,9 @@ public void ReceiveLaugh(int laughValue)
{
if (effect.EffectName.Equals("Shield"))
{
Console.WriteLine("Shiled used laugh");
laughReceived -= effect.Value;
cardsToDelete.Add(card.DeckId);
}
else
{
Expand Down Expand Up @@ -100,9 +103,10 @@ public int PrepareGrumpy(int value, out List<int?> cardsToDelete)
return result;
}

public void ReceiveGrumpy(int grumpyValue)
public void ReceiveGrumpy(int grumpyValue,out List<int?> cardsToDelete)
{
var grumpyReceived = grumpyValue;
cardsToDelete = new List<int?>();
var cardsCopy = new List<Card>(PersistentSlot);
PersistentSlot.Clear();
foreach (var card in cardsCopy)
Expand All @@ -111,7 +115,9 @@ public void ReceiveGrumpy(int grumpyValue)
{
if (effect.EffectName.Equals("Shield"))
{
Console.WriteLine("Shiled used - Grumpy");
grumpyReceived -= effect.Value;
cardsToDelete.Add(card.DeckId);
}
else
{
Expand All @@ -120,7 +126,11 @@ public void ReceiveGrumpy(int grumpyValue)

}
}
grumpyReceived = grumpyReceived < 0 ? 0 : grumpyReceived;

if (grumpyReceived < 0)
{
grumpyReceived = 0;
}
LaughPoints -= grumpyReceived;
if (LaughPoints < 0)
{
Expand Down
13 changes: 12 additions & 1 deletion backend/MemeBE/cards.csv
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
27;SurprisedPikachu;/static/jpg/SurprisedPikachu.png;MakeLaugh,1;1
28;SurprisedKirk;/static/jpg/SurprisedKirk.png;MakeLaugh,2;0
29;Takemymoney;/static/jpg/Takemymoney.png;MakeLaugh,2;1
30;RollSafeThink;/static/jpg/OhGodNo.png;Shield,1;2
30;RollSafeThink;/static/jpg/RollSafeThink.png;Shield,1;2
31;Thatsnoneofmybuisness;/static/jpg/Thatsnoneofmybuisness.png;MakeLaugh,1;1
32;TheWhat;/static/jpg/TheWhat.png;MakeLaugh,2;1
33;Thisisfine;/static/jpg/Thisisfine.png;MakeLaugh,1;1
Expand All @@ -38,3 +38,14 @@
38;WeedGuy;/static/jpg/WeedGuy.png;MakeLaugh,1;1
39;WillyWonka;/static/jpg/WillyWonka.png;MakeLaugh,1;1
40;Duckface;/static/jpg/Duckface.png;MakeGrumpy,1;1
41;Emotionaldamage;/static/jpg/Emotionaldamage.png;MakeGrumpy,3;1
42;Facepalm;/static/jpg/Facepalm.png;MakeGrumpy,2;1
43;Foreveralone;/static/jpg/Foreveralone.png;MakeGrumpy,1;1
44;Genius;/static/jpg/Genius.png;MakeGrumpy,1;1
45;GoodGuy;/static/jpg/GoodGuy.png;MakeGrumpy,2;0
46;DistractedBoyfriend;/static/jpg/DistractedBoyfriend.png;MakeLaugh,1;1
47;CryingCat;/static/jpg/CryingCat.png;MakeGrumpy,2;0
48;All;/static/jpg/All.png;MakeLaugh,1;0
49;AwkwardLittleGirl;/static/jpg/AwkwardLittleGirl.png;MakeGrumpy,1;1
50;Buffeddoge;/static/jpg/Buffeddoge.png;Buff,2;2
51;Cheers;/static/jpg/Cheers.png;MakeLaugh,1;1
40 changes: 33 additions & 7 deletions backend/MemeBE/hubs/GameHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ public async Task EndTurn(Room room)
{
Console.WriteLine("End turn - start");
await Clients.Client(room.ActivePlayer.ConnectionID).SendAsync("TurnEnd");
await Clients.Group(room.RoomId)
.SendAsync("ReceiveServerRoomMessage", room.ActivePlayer.Nick + " - turn Ended");
// await Clients.Group(room.RoomId)
// .SendAsync("ReceiveServerRoomMessage", room.ActivePlayer.Nick + " - turn Ended");

if (room.GameStarted)
{
Expand All @@ -220,6 +220,7 @@ await Clients.Group(room.RoomId)
{
GameEnded(room);
}
Console.WriteLine("######################");
}
public async Task DrawCard(Player player, Room room)
{
Expand Down Expand Up @@ -275,12 +276,15 @@ public List<Player> GetOtherPlayers(Room room, string connId)

public async Task MakeLaugh(Room room, int value, string? targetNick = null)
{

int laughValue = room.ActivePlayer.PrepareLaugh(value, out List<int?> cardsToDelete);
if (string.IsNullOrEmpty(targetNick)) // all players
{
Console.WriteLine("Make laugh to all");
foreach (var player in room.Players.Values)
{
player.ReceiveLaugh(laughValue);
Console.WriteLine("Player " +player.Nick +" is gone take laugh: " + laughValue);
player.ReceiveLaugh(laughValue,out List<int?> cardsToDeleteFromShieldBuff);
// Emit
await Clients.Client(player.ConnectionID).SendAsync("TakeLaugh",player.LaughPoints);
var otherPlayers = GetOtherPlayers(room, player.ConnectionID);
Expand All @@ -290,12 +294,18 @@ public async Task MakeLaugh(Room room, int value, string? targetNick = null)
}
await Clients.Group(room.RoomId)
.SendAsync("ReceiveServerRoomMessage", Helpers.GetLaughMessage(player.Nick, laughValue));
foreach (var cardId in cardsToDeleteFromShieldBuff)
{
Clients.Group(room.RoomId).SendAsync("RemoveCard", cardId);
}
}
}
else // Single player
{
Console.WriteLine("Make laugh to " + targetNick);
var targetPlayer = room.GetPlayerByNick(targetNick);
targetPlayer.ReceiveLaugh(laughValue);
Console.WriteLine("Player " +targetPlayer.Nick +" is gone take laugh: " + laughValue);
targetPlayer.ReceiveLaugh(laughValue, out List<int?> cardsToDeleteFromShieldBuff);
// emit
await Clients.Client(targetPlayer.ConnectionID).SendAsync("TakeLaugh",targetPlayer.LaughPoints);
var otherPlayers = GetOtherPlayers(room, targetPlayer.ConnectionID);
Expand All @@ -305,12 +315,17 @@ await Clients.Group(room.RoomId)
}
await Clients.Group(room.RoomId)
.SendAsync("ReceiveServerRoomMessage", Helpers.GetLaughMessage(targetPlayer.Nick, laughValue));
foreach (var cardId in cardsToDeleteFromShieldBuff)
{
Clients.Group(room.RoomId).SendAsync("RemoveCard", cardId);
}
}

foreach (var cardId in cardsToDelete)
{
Clients.Group(room.RoomId).SendAsync("RemoveCard", cardId);
}

EndTurn(room);
}

Expand All @@ -325,7 +340,8 @@ public async Task MakeGrumpy(Room room, int value, string? targetNick = null)
Console.WriteLine("MakeGrumpy - To All");
foreach (var player in room.Players.Values)
{
player.ReceiveGrumpy(grumpyValue);
Console.WriteLine("Player " +player.Nick +" is gone take laugh: " + grumpyValue);
player.ReceiveGrumpy(grumpyValue, out List<int?> cardsToDeleteFromShieldBuff);
// Emit
await Clients.Client(player.ConnectionID).SendAsync("TakeGrumpy",player.LaughPoints);
var otherPlayers = GetOtherPlayers(room, player.ConnectionID);
Expand All @@ -335,13 +351,18 @@ public async Task MakeGrumpy(Room room, int value, string? targetNick = null)
}
await Clients.Group(room.RoomId)
.SendAsync("ReceiveServerRoomMessage", Helpers.GetGrumpyMessage(player.Nick, grumpyValue));
foreach (var cardId in cardsToDeleteFromShieldBuff)
{
Clients.Group(room.RoomId).SendAsync("RemoveCard", cardId);
}
}
}
else // Single player
{
Console.WriteLine("MakeGrumpy - To target");
Console.WriteLine("MakeGrumpy - To: " + targetNick);
Console.WriteLine("Player " +targetNick +" is gone take laugh: " + grumpyValue);
var targetPlayer = room.GetPlayerByNick(targetNick);
targetPlayer.ReceiveGrumpy(grumpyValue);
targetPlayer.ReceiveGrumpy(grumpyValue,out List<int?> cardsToDeleteFromShieldBuff);
// emit
await Clients.Client(targetPlayer.ConnectionID).SendAsync("TakeGrumpy",targetPlayer.LaughPoints);
var otherPlayers = GetOtherPlayers(room, targetPlayer.ConnectionID);
Expand All @@ -351,6 +372,10 @@ await Clients.Group(room.RoomId)
}
await Clients.Group(room.RoomId)
.SendAsync("ReceiveServerRoomMessage", Helpers.GetGrumpyMessage(targetPlayer.Nick, grumpyValue));
foreach (var cardId in cardsToDeleteFromShieldBuff)
{
Clients.Group(room.RoomId).SendAsync("RemoveCard", cardId);
}
}
foreach (var cardId in cardsToDelete)
{
Expand All @@ -361,6 +386,7 @@ await Clients.Group(room.RoomId)

public async Task PlacePersistentCard(Room room, Card card, String targetNick)
{
Console.WriteLine("Place persistant to "+ targetNick);
var targetPlayer = room.GetPlayerByNick(targetNick);
if (targetPlayer.AddCardToPersistentSlot(card).Sucess)
{
Expand Down
1 change: 1 addition & 0 deletions client/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ body {
border-radius: 6px;
display: inline-block;
flex: 0 0 auto;
cursor: pointer;

}

Expand Down
Binary file added client/static/jpg/All.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/AwkwardLittleGirl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/Buffeddoge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/Cheers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/CryingCat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/DistractedBoyfriend.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/Emotionaldamage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/Facepalm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/Foreveralone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/Genius.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/GoodGuy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion client/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function initReceiveMethods() {
$("#startGameButton").show();
}
$("#playerName").text(playerName);
$("#playerPersistentCards").data('player-name', playerName);
document.querySelector("#playerPersistentCards").setAttribute('data-player-name', playerName);
otherPlayers.forEach((playerName) => addPlayerZone(playerName));
});

Expand Down Expand Up @@ -113,6 +113,14 @@ function initReceiveMethods() {
document.querySelector('#playersZones .other.player[data-player-name="' + target + '"] .points').innerHTML = points;
});

connection.on("TakeGrumpy", function (points) {
$("#playerHP").text(points);
});

connection.on("OtherTookGrumpy", function (target, points) {
document.querySelector('#playersZones .other.player[data-player-name="' + target + '"] .points').innerHTML = points;
});

connection.on("TurnStarted", function () {
yourTurn = true;
});
Expand Down

0 comments on commit a0b6f65

Please sign in to comment.