Skip to content

Commit

Permalink
controller and view
Browse files Browse the repository at this point in the history
  • Loading branch information
kenny516 committed Jun 10, 2024
1 parent 902b142 commit f968b14
Show file tree
Hide file tree
Showing 27 changed files with 219 additions and 140 deletions.
Binary file modified .vs/Dechiffre/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified .vs/Dechiffre/v17/.futdcache.v2
Binary file not shown.
Binary file modified .vs/Dechiffre/v17/.suo
Binary file not shown.
133 changes: 99 additions & 34 deletions .vs/Dechiffre/v17/DocumentLayout.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,40 @@
"RelativeMoniker": "D:0:0:{A3CDACDB-AD78-4F00-B75C-254020C2BAE2}|Dechiffre.csproj|solutionrelative:wwwroot\\js\\app.js||{14D17961-FE51-464D-9111-C4AF11D7D99A}"
},
{
"AbsoluteMoniker": "D:0:0:{A3CDACDB-AD78-4F00-B75C-254020C2BAE2}|Dechiffre.csproj|d:\\s4\\mrtahina\\des-chiffres\\controllers\\gamecontroller .cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{A3CDACDB-AD78-4F00-B75C-254020C2BAE2}|Dechiffre.csproj|solutionrelative:controllers\\gamecontroller .cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
"AbsoluteMoniker": "D:0:0:{A3CDACDB-AD78-4F00-B75C-254020C2BAE2}|Dechiffre.csproj|d:\\s4\\mrtahina\\des-chiffres\\views\\shared\\_layout.cshtml||{40D31677-CBC0-4297-A9EF-89D907823A98}",
"RelativeMoniker": "D:0:0:{A3CDACDB-AD78-4F00-B75C-254020C2BAE2}|Dechiffre.csproj|solutionrelative:views\\shared\\_layout.cshtml||{40D31677-CBC0-4297-A9EF-89D907823A98}"
},
{
"AbsoluteMoniker": "D:0:0:{A3CDACDB-AD78-4F00-B75C-254020C2BAE2}|Dechiffre.csproj|d:\\s4\\mrtahina\\des-chiffres\\views\\game\\game.cshtml||{40D31677-CBC0-4297-A9EF-89D907823A98}",
"RelativeMoniker": "D:0:0:{A3CDACDB-AD78-4F00-B75C-254020C2BAE2}|Dechiffre.csproj|solutionrelative:views\\game\\game.cshtml||{40D31677-CBC0-4297-A9EF-89D907823A98}"
"AbsoluteMoniker": "D:0:0:{A3CDACDB-AD78-4F00-B75C-254020C2BAE2}|Dechiffre.csproj|d:\\s4\\mrtahina\\des-chiffres\\views\\home\\index.cshtml||{40D31677-CBC0-4297-A9EF-89D907823A98}",
"RelativeMoniker": "D:0:0:{A3CDACDB-AD78-4F00-B75C-254020C2BAE2}|Dechiffre.csproj|solutionrelative:views\\home\\index.cshtml||{40D31677-CBC0-4297-A9EF-89D907823A98}"
},
{
"AbsoluteMoniker": "D:0:0:{A3CDACDB-AD78-4F00-B75C-254020C2BAE2}|Dechiffre.csproj|d:\\s4\\mrtahina\\des-chiffres\\models\\gamemodel.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{A3CDACDB-AD78-4F00-B75C-254020C2BAE2}|Dechiffre.csproj|solutionrelative:models\\gamemodel.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{A3CDACDB-AD78-4F00-B75C-254020C2BAE2}|Dechiffre.csproj|d:\\s4\\mrtahina\\des-chiffres\\controllers\\homecontroller.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{A3CDACDB-AD78-4F00-B75C-254020C2BAE2}|Dechiffre.csproj|solutionrelative:controllers\\homecontroller.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
"AbsoluteMoniker": "D:0:0:{A3CDACDB-AD78-4F00-B75C-254020C2BAE2}|Dechiffre.csproj|d:\\s4\\mrtahina\\des-chiffres\\views\\game\\game.cshtml||{40D31677-CBC0-4297-A9EF-89D907823A98}",
"RelativeMoniker": "D:0:0:{A3CDACDB-AD78-4F00-B75C-254020C2BAE2}|Dechiffre.csproj|solutionrelative:views\\game\\game.cshtml||{40D31677-CBC0-4297-A9EF-89D907823A98}"
},
{
"AbsoluteMoniker": "D:0:0:{A3CDACDB-AD78-4F00-B75C-254020C2BAE2}|Dechiffre.csproj|d:\\s4\\mrtahina\\des-chiffres\\models\\player.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{A3CDACDB-AD78-4F00-B75C-254020C2BAE2}|Dechiffre.csproj|solutionrelative:models\\player.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{A3CDACDB-AD78-4F00-B75C-254020C2BAE2}|Dechiffre.csproj|d:\\s4\\mrtahina\\des-chiffres\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{A3CDACDB-AD78-4F00-B75C-254020C2BAE2}|Dechiffre.csproj|solutionrelative:program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{A3CDACDB-AD78-4F00-B75C-254020C2BAE2}|Dechiffre.csproj|d:\\s4\\mrtahina\\des-chiffres\\views\\home\\home.cshtml||{40D31677-CBC0-4297-A9EF-89D907823A98}",
"RelativeMoniker": "D:0:0:{A3CDACDB-AD78-4F00-B75C-254020C2BAE2}|Dechiffre.csproj|solutionrelative:views\\home\\home.cshtml||{40D31677-CBC0-4297-A9EF-89D907823A98}"
},
{
"AbsoluteMoniker": "D:0:0:{A3CDACDB-AD78-4F00-B75C-254020C2BAE2}|Dechiffre.csproj|d:\\s4\\mrtahina\\des-chiffres\\controllers\\gamecontroller .cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{A3CDACDB-AD78-4F00-B75C-254020C2BAE2}|Dechiffre.csproj|solutionrelative:controllers\\gamecontroller .cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{A3CDACDB-AD78-4F00-B75C-254020C2BAE2}|Dechiffre.csproj|d:\\s4\\mrtahina\\des-chiffres\\controllers\\homecontroller.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{A3CDACDB-AD78-4F00-B75C-254020C2BAE2}|Dechiffre.csproj|solutionrelative:controllers\\homecontroller.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
}
],
"DocumentGroupContainers": [
Expand All @@ -33,13 +49,64 @@
"VerticalTabListWidth": 256,
"DocumentGroups": [
{
"DockedWidth": 302,
"SelectedChildIndex": 1,
"DockedWidth": 259,
"SelectedChildIndex": 5,
"Children": [
{
"$type": "Bookmark",
"Name": "ST:0:0:{b1e99781-ab81-11d0-b683-00aa00a3ee26}"
},
{
"$type": "Document",
"DocumentIndex": 6,
"Title": "Program.cs",
"DocumentMoniker": "D:\\S4\\MrTahina\\Des-Chiffres\\Program.cs",
"RelativeDocumentMoniker": "Program.cs",
"ToolTip": "D:\\S4\\MrTahina\\Des-Chiffres\\Program.cs",
"RelativeToolTip": "Program.cs",
"ViewState": "AQIAABUAAAAAAAAAAAAAADQAAAAXAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2024-06-10T09:34:57.437Z"
},
{
"$type": "Document",
"DocumentIndex": 3,
"Title": "GameModel.cs",
"DocumentMoniker": "D:\\S4\\MrTahina\\Des-Chiffres\\Models\\GameModel.cs",
"RelativeDocumentMoniker": "Models\\GameModel.cs",
"ToolTip": "D:\\S4\\MrTahina\\Des-Chiffres\\Models\\GameModel.cs",
"RelativeToolTip": "Models\\GameModel.cs",
"ViewState": "AQIAACsAAAAAAAAAAADwvzsAAAAnAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2024-06-09T06:48:03.892Z",
"EditorCaption": ""
},
{
"$type": "Document",
"DocumentIndex": 2,
"Title": "Index.cshtml",
"DocumentMoniker": "D:\\S4\\MrTahina\\Des-Chiffres\\Views\\Home\\Index.cshtml",
"RelativeDocumentMoniker": "Views\\Home\\Index.cshtml",
"ToolTip": "D:\\S4\\MrTahina\\Des-Chiffres\\Views\\Home\\Index.cshtml",
"RelativeToolTip": "Views\\Home\\Index.cshtml",
"ViewState": "AQIAAAAAAAAAAAAAAAAAAAAAAAAcAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000759|",
"WhenOpened": "2024-06-10T09:34:33.052Z",
"EditorCaption": ""
},
{
"$type": "Document",
"DocumentIndex": 1,
"Title": "_Layout.cshtml",
"DocumentMoniker": "D:\\S4\\MrTahina\\Des-Chiffres\\Views\\Shared\\_Layout.cshtml",
"RelativeDocumentMoniker": "Views\\Shared\\_Layout.cshtml",
"ToolTip": "D:\\S4\\MrTahina\\Des-Chiffres\\Views\\Shared\\_Layout.cshtml",
"RelativeToolTip": "Views\\Shared\\_Layout.cshtml",
"ViewState": "AQIAAAAAAAAAAAAAAAAAABoAAAAHAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000759|",
"WhenOpened": "2024-06-10T09:34:15.114Z",
"EditorCaption": ""
},
{
"$type": "Document",
"DocumentIndex": 0,
Expand All @@ -48,14 +115,27 @@
"RelativeDocumentMoniker": "wwwroot\\js\\app.js",
"ToolTip": "D:\\S4\\MrTahina\\Des-Chiffres\\wwwroot\\js\\app.js",
"RelativeToolTip": "wwwroot\\js\\app.js",
"ViewState": "AQIAADUAAAAAAAAAAAA8wFgAAAAAAAAA",
"ViewState": "AQIAADAAAAAAAAAAAAAkwEkAAAAcAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.001646|",
"WhenOpened": "2024-06-07T19:02:33.829Z",
"EditorCaption": ""
},
{
"$type": "Document",
"DocumentIndex": 5,
"Title": "Player.cs",
"DocumentMoniker": "D:\\S4\\MrTahina\\Des-Chiffres\\Models\\Player.cs",
"RelativeDocumentMoniker": "Models\\Player.cs",
"ToolTip": "D:\\S4\\MrTahina\\Des-Chiffres\\Models\\Player.cs",
"RelativeToolTip": "Models\\Player.cs",
"ViewState": "AQIAAAAAAAAAAAAAAAAAAAYAAAAcAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2024-06-10T09:40:35.643Z",
"EditorCaption": ""
},
{
"$type": "Document",
"DocumentIndex": 7,
"Title": "Home.cshtml",
"DocumentMoniker": "D:\\S4\\MrTahina\\Des-Chiffres\\Views\\Home\\Home.cshtml",
"RelativeDocumentMoniker": "Views\\Home\\Home.cshtml",
Expand All @@ -68,60 +148,45 @@
]
},
{
"DockedWidth": 286,
"SelectedChildIndex": 0,
"DockedWidth": 329,
"SelectedChildIndex": 1,
"Children": [
{
"$type": "Document",
"DocumentIndex": 1,
"DocumentIndex": 8,
"Title": "GameController .cs",
"DocumentMoniker": "D:\\S4\\MrTahina\\Des-Chiffres\\Controllers\\GameController .cs",
"RelativeDocumentMoniker": "Controllers\\GameController .cs",
"ToolTip": "D:\\S4\\MrTahina\\Des-Chiffres\\Controllers\\GameController .cs",
"RelativeToolTip": "Controllers\\GameController .cs",
"ViewState": "AQIAAHkAAAAAAAAAAAAUwIQAAABQAAAA",
"ViewState": "AQIAABkAAAAAAAAAAAAwwCoAAAAJAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2024-06-09T06:58:05.585Z",
"EditorCaption": ""
"WhenOpened": "2024-06-09T06:58:05.585Z"
},
{
"$type": "Document",
"DocumentIndex": 2,
"DocumentIndex": 4,
"Title": "Game.cshtml",
"DocumentMoniker": "D:\\S4\\MrTahina\\Des-Chiffres\\Views\\Game\\Game.cshtml",
"RelativeDocumentMoniker": "Views\\Game\\Game.cshtml",
"ToolTip": "D:\\S4\\MrTahina\\Des-Chiffres\\Views\\Game\\Game.cshtml",
"RelativeToolTip": "Views\\Game\\Game.cshtml",
"ViewState": "AQIAACUAAAAAAAAAAAAywGAAAAAAAAAA",
"ViewState": "AQIAAAAAAAAAAAAAAAAAAAUAAAAbAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000759|",
"WhenOpened": "2024-06-09T10:37:42.103Z",
"EditorCaption": ""
},
{
"$type": "Document",
"DocumentIndex": 3,
"Title": "GameModel.cs",
"DocumentMoniker": "D:\\S4\\MrTahina\\Des-Chiffres\\Models\\GameModel.cs",
"RelativeDocumentMoniker": "Models\\GameModel.cs",
"ToolTip": "D:\\S4\\MrTahina\\Des-Chiffres\\Models\\GameModel.cs",
"RelativeToolTip": "Models\\GameModel.cs",
"ViewState": "AQIAAAAAAAAAAAAAAAAAAAoAAAAFAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2024-06-09T06:48:03.892Z",
"EditorCaption": ""
},
{
"$type": "Document",
"DocumentIndex": 4,
"DocumentIndex": 9,
"Title": "HomeController.cs",
"DocumentMoniker": "D:\\S4\\MrTahina\\Des-Chiffres\\Controllers\\HomeController.cs",
"RelativeDocumentMoniker": "Controllers\\HomeController.cs",
"ToolTip": "D:\\S4\\MrTahina\\Des-Chiffres\\Controllers\\HomeController.cs",
"RelativeToolTip": "Controllers\\HomeController.cs",
"ViewState": "AQIAABMAAAAAAAAAAAAwwCQAAAAkAAAA",
"ViewState": "AQIAAAAAAAAAAAAAAAAAAA8AAAAkAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2024-06-07T18:46:35.112Z",
"EditorCaption": ""
"WhenOpened": "2024-06-07T18:46:35.112Z"
}
]
}
Expand Down
Binary file modified .vs/ProjectEvaluation/dechiffre.metadata.v7.bin
Binary file not shown.
Binary file modified .vs/ProjectEvaluation/dechiffre.projects.v7.bin
Binary file not shown.
80 changes: 4 additions & 76 deletions Controllers/GameController .cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public JsonResult Index(int minNbr = 1, int maxNbr = 1001, int nbrChoice = 7)
Numbers = GenerateNumbers(nbrChoice, 1, 101),
players = players,
winner_not_verify = 10,
Winner = ""
};

return Json(game);
Expand All @@ -37,12 +36,14 @@ public JsonResult SubmitResults([FromBody] GameModel game)
LogGameData(game);

// Déterminer le gagnant en fonction des choix des joueurs
DetermineWinner(game);
game.DetermineWinner(game);
Console.WriteLine("winer not verifyyy "+game.winner_not_verify);

return Json(game);
}

//// FONCTION

// Fonction pour afficher les données du jeu
private void LogGameData(GameModel game)
{
Expand All @@ -62,61 +63,6 @@ private void LogGameData(GameModel game)
}
}

// Fonction pour déterminer le gagnant
private void DetermineWinner(GameModel game)
{
Player j1 = game.players[0];
Player j2 = game.players[1];
// si un joueur n a pas donne de reponse
if (IsOneChoicePositive(j1, j2))
{
game.winner_not_verify = j1.nbrChoice > 0 ? 0 : 1;
}
// sinon
else if (AreBothChoicesPositive(j1, j2))
{
int diffj1 = Math.Abs(j1.nbrChoice - game.TargetNumber);
int diffj2 = Math.Abs(j2.nbrChoice - game.TargetNumber);
game.winner_not_verify = DetermineClosestPlayer(diffj1, diffj2, j1, j2);
}
else
{
game.winner_not_verify = -1;
}
}

// Vérifier si l'un des joueurs a un choix positif et l'autre négatif
private bool IsOneChoicePositive(Player j1, Player j2)
{
return (j1.nbrChoice > 0 && j2.nbrChoice < 0) || (j1.nbrChoice < 0 && j2.nbrChoice > 0);
}

// Vérifier si les deux joueurs ont des choix positifs
private bool AreBothChoicesPositive(Player j1, Player j2)
{
return j1.nbrChoice > 0 && j2.nbrChoice > 0;
}

// Déterminer le joueur le plus proche du nombre cible
private int DetermineClosestPlayer(int diffj1, int diffj2, Player j1, Player j2)
{
if (diffj1 < diffj2)
{
return 0; // j1 plus proche
}
else if (diffj1 > diffj2)
{
return 1; // j2 plus proche
}
else
{
// Les deux joueurs sont à égale distance du nombre cible
return j1.temps < j2.temps ? 0 : 1;
}
}



// Action pour retourner la vue Game.cshtml
public IActionResult Game()
{
Expand All @@ -127,20 +73,7 @@ public IActionResult Game()
[HttpPost("api/game/verify")]
public JsonResult Verify([FromBody] GameModel game)
{
int IDwinner_not_verify = game.winner_not_verify;
Console.WriteLine("verify nbr " + game.value_verify);

if (game.players[IDwinner_not_verify].nbrChoice == game.value_verify)
{
return Json(game.players[IDwinner_not_verify]);
}
else
{
// Find the ID of the other player
int otherPlayerID = (IDwinner_not_verify + 1) % game.players.Count;
// Return the other player
return Json(game.players[otherPlayerID]);
}
return Json(game.VerifyWinner());
}


Expand All @@ -156,10 +89,5 @@ private List<int> GenerateNumbers(int count, int min, int max)
return numbers;
}
}
public class VerifyRequestModel
{
public GameModel Game { get; set; }
public int NbrVerify { get; set; }
}

}
Loading

0 comments on commit f968b14

Please sign in to comment.