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 a0b6f65 + 9b29ed7 commit efdbfb9
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 27 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/azure-static-web-apps-mango-water-0ba859b03.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Azure Static Web Apps CI/CD

on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, closed]
branches:
- main

jobs:
build_and_deploy_job:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
runs-on: ubuntu-latest
name: Build and Deploy Job
steps:
- uses: actions/checkout@v3
with:
submodules: true
lfs: false
- name: Build And Deploy
id: builddeploy
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_MANGO_WATER_0BA859B03 }}
repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments)
action: "upload"
###### Repository/Build Configurations - These values can be configured to match your app requirements. ######
# For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
app_location: "/client" # App source code path
api_location: "" # Api source code path - optional
output_location: "" # Built app content directory - optional
###### End of Repository/Build Configurations ######

close_pull_request_job:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
name: Close Pull Request Job
steps:
- name: Close Pull Request
id: closepullrequest
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_MANGO_WATER_0BA859B03 }}
action: "close"
57 changes: 57 additions & 0 deletions .github/workflows/main_magicthememeingapiprod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: Build and deploy ASP.Net Core app to Azure Web App - magicthememeingapiprod

on:
push:
branches:
- main
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '8.x'
include-prerelease: true

- name: Build with dotnet
run: dotnet build --configuration Release

- name: dotnet publish
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp

- name: Upload artifact for deployment job
uses: actions/upload-artifact@v3
with:
name: .net-app
path: ${{env.DOTNET_ROOT}}/myapp

deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

steps:
- name: Download artifact from build job
uses: actions/download-artifact@v3
with:
name: .net-app

- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: 'magicthememeingapiprod'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_77A194824F824B37818FD3C0F15D3D48 }}
package: .
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# KJ2024
# KJ2024

REEEEEEEEEEEEEEEEEEEEEEEEE
46 changes: 29 additions & 17 deletions backend/MemeBE/Models/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ public Result AddCardToPersistentSlot(Card card)

public int PrepareLaugh(int value, out List<int?> cardsToDelete)
{
cardsToDelete = new List<int?>();
int result = value;
foreach (var card in PersistentSlot)
cardsToDelete = new List<int?>();
var cardsCopy = new List<Card>(PersistentSlot);
PersistentSlot.Clear();
foreach (var card in cardsCopy)
{
foreach (Effect effect in card.EffectList)
{
Expand All @@ -47,6 +49,10 @@ public int PrepareLaugh(int value, out List<int?> cardsToDelete)
result += effect.Value;
cardsToDelete.Add(card.DeckId);
}
else
{
PersistentSlot.Add(card);
}

}
}
Expand All @@ -55,52 +61,58 @@ public int PrepareLaugh(int value, out List<int?> cardsToDelete)
return result;
}

public void ReceiveLaugh(int laughValue,out List<int?> cardsToDelete)
public int PrepareGrumpy(int value, out List<int?> cardsToDelete)
{
var laughReceived = laughValue;
int result = value;
cardsToDelete = new List<int?>();
var cardsCopy = new List<Card>(PersistentSlot);
PersistentSlot.Clear();
foreach (var card in cardsCopy)
{
foreach (Effect effect in card.EffectList)
{
if (effect.EffectName.Equals("Shield"))
if (effect.EffectName.Equals("Buff"))
{
Console.WriteLine("Shiled used laugh");
laughReceived -= effect.Value;
result += effect.Value;
cardsToDelete.Add(card.DeckId);
}
else
{
PersistentSlot.Add(card);
}

}
}
laughReceived = laughReceived < 0 ? 0 : laughReceived;
LaughPoints += laughReceived;

return result;
}

public int PrepareGrumpy(int value, out List<int?> cardsToDelete)
public void ReceiveLaugh(int laughValue,out List<int?> cardsToDelete)
{
int result = value;
var laughReceived = laughValue;
cardsToDelete = new List<int?>();
foreach (var card in PersistentSlot)
var cardsCopy = new List<Card>(PersistentSlot);
PersistentSlot.Clear();
foreach (var card in cardsCopy)
{
foreach (Effect effect in card.EffectList)
{
if (effect.EffectName.Equals("Buff"))
if (effect.EffectName.Equals("Shield"))
{
result += effect.Value;
Console.WriteLine("Shiled used laugh");
laughReceived -= effect.Value;
cardsToDelete.Add(card.DeckId);
}
else
{
PersistentSlot.Add(card);
}

}
}

return result;
laughReceived = laughReceived < 0 ? 0 : laughReceived;
LaughPoints += laughReceived;

}

public void ReceiveGrumpy(int grumpyValue,out List<int?> cardsToDelete)
Expand Down
2 changes: 1 addition & 1 deletion backend/MemeBE/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{
options.AddPolicy("MyCorsPolicy", builder =>
{
builder.WithOrigins("https://nice-water-0ee9aa403.4.azurestaticapps.net", "http://localhost:63342", "https://memethegathering.wielki.ch", "https://mtg.wielki.ch/") // URL innego serwera
builder.WithOrigins("https://nice-water-0ee9aa403.4.azurestaticapps.net", "http://localhost:63342", "https://memethegathering.wielki.ch", "https://mtg.wielki.ch") // URL innego serwera
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials(); // Ważne dla SignalR
Expand Down
6 changes: 3 additions & 3 deletions backend/MemeBE/hubs/GameHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public async Task SendCard(int cardId, string targetNick)
// tutaj jest aktywny gracz w odpowiednim pokoju
// Wyliczanie akcjki
var activeCard = room.ActivePlayer.CardsOnHand.SingleOrDefault(card => card.DeckId == cardId);
Clients.Group(room.RoomId).SendAsync("LastCard", activeCard.URL);

foreach (var effect in activeCard.EffectList)
{
Expand Down Expand Up @@ -340,7 +341,7 @@ public async Task MakeGrumpy(Room room, int value, string? targetNick = null)
Console.WriteLine("MakeGrumpy - To All");
foreach (var player in room.Players.Values)
{
Console.WriteLine("Player " +player.Nick +" is gone take laugh: " + grumpyValue);
Console.WriteLine("Player " +player.Nick +" is gone take grumpy: " + grumpyValue);
player.ReceiveGrumpy(grumpyValue, out List<int?> cardsToDeleteFromShieldBuff);
// Emit
await Clients.Client(player.ConnectionID).SendAsync("TakeGrumpy",player.LaughPoints);
Expand All @@ -359,8 +360,7 @@ await Clients.Group(room.RoomId)
}
else // Single player
{
Console.WriteLine("MakeGrumpy - To: " + targetNick);
Console.WriteLine("Player " +targetNick +" is gone take laugh: " + grumpyValue);
Console.WriteLine("Player " +targetNick +" is gone take grumpy " + grumpyValue);
var targetPlayer = room.GetPlayerByNick(targetNick);
targetPlayer.ReceiveGrumpy(grumpyValue,out List<int?> cardsToDeleteFromShieldBuff);
// emit
Expand Down
15 changes: 11 additions & 4 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</head>
<body>
<div id="lobby">
<h1 class="rotating-text game-title" >Meme: The Gathering</h1>
<h1 class="rotating-text game-title">Meme: The Gathering</h1>
<div id="games-list"></div>
<input type="text" id="player-name-input" placeholder="Player Name"/>
<input type="text" id="room-id-input" placeholder="Room ID"/>
Expand All @@ -36,9 +36,16 @@ <h1 class="rotating-text game-title" >Meme: The Gathering</h1>

</ul>
</div>
<div class="lastMessage">
<div class="roomIdContainer">Invite your friends - Room ID: <span data-type="roomID"></span></div>
<div><button id="startGameButton">Start Game</button></div>
<div class="lastDetails">
<div id="lastCard">

</div>
<div class="lastMessage">
<div class="roomIdContainer">Invite your friends - Room ID: <span data-type="roomID"></span></div>
<div>
<button id="startGameButton">Start Game</button>
</div>
</div>
</div>
</div>

Expand Down
15 changes: 15 additions & 0 deletions client/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,21 @@ body {
flex-direction: row;
}

.middle .lastDetails {
display: flex;
flex-direction: row;
flex-grow: 1;
}

.middle #lastCard {
width: 250px;
}

.middle #lastCard img {
width: 200px;
margin: 25px;
}

.middle .lastMessage {
flex-grow: 1;
display: flex;
Expand Down
19 changes: 18 additions & 1 deletion client/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ $(document).ready(function () {

function initServer() {
connection = new signalR.HubConnectionBuilder()
//.withUrl("https://memethegatheringapi.azurewebsites.net/GameHub")
.withUrl("https://578d-87-206-130-93.ngrok-free.app/GameHub")
//.withUrl("https://memethegatheringapi.azurewebsites.net/GameHub")
// .withUrl("https://578d-87-206-130-93.ngrok-free.app/GameHub")
.withAutomaticReconnect()
.configureLogging(signalR.LogLevel.Information)
.build();
Expand Down Expand Up @@ -121,6 +122,15 @@ function initReceiveMethods() {
document.querySelector('#playersZones .other.player[data-player-name="' + target + '"] .points').innerHTML = points;
});

connection.on("GameEnded", function (message) {
yourTurn = false;
ShowEndGameScreen(message);
});

connection.on("LastCard", function (url) {
ShowLastPlayedCard(url);
});

connection.on("TurnStarted", function () {
yourTurn = true;
});
Expand Down Expand Up @@ -296,6 +306,13 @@ function PlacePersistentCard(deckId, url, target, owner) {
}
}

function ShowLastPlayedCard(url){
let card = CreateCard('', url, '');

document.querySelector('#lastCard').innerHTML = card.innerHTML;

}

function RemoveCard(deckId, handOnly) {
if(handOnly){
$("#playerHand .card[data-deck-id='" + deckId + "']").remove();
Expand Down

0 comments on commit efdbfb9

Please sign in to comment.