Skip to content

Commit

Permalink
eval
Browse files Browse the repository at this point in the history
  • Loading branch information
kenny516 committed Jun 13, 2024
1 parent db8ebac commit 1a87085
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 32 deletions.
25 changes: 10 additions & 15 deletions Controllers/GameController .cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@ public JsonResult Index()
GameModel? game = new GameModel
{
TargetNumber = _random.Next(1, 1001),
Numbers = GenerateNumbers(7, 1, 101),
Numbers = Tools.GenerateNumbers(7, 1, 101),
Players = players,
Winner_not_verify = 10,
};

return Json(game);
}

[HttpPost("api/game/eval")]
public JsonResult Evaluate([FromBody] dynamic data)
{
string eval = data.eval;
return Json(Tools.EvaluateExpression(eval));
}


[HttpPost("api/game/newGame")]
public JsonResult NewGame([FromBody] GameModel game)
{
Expand All @@ -36,7 +44,7 @@ public JsonResult NewGame([FromBody] GameModel game)

game.Winner_not_verify = 10;
game.Value_verify = 0;
game.Numbers = GenerateNumbers(7, 1, 101);
game.Numbers = Tools.GenerateNumbers(7, 1, 101);
return Json(game);
}

Expand All @@ -61,16 +69,13 @@ public JsonResult Verify([FromBody] GameModel game)
}

// Action pour retourner la vue Game.cshtml

public IActionResult Game()
{
return View();
}


//// FONCTION


// Fonction pour afficher les données du jeu
private void LogGameData(GameModel game)
{
Expand All @@ -92,16 +97,6 @@ private void LogGameData(GameModel game)



// Méthode pour générer des nombres aléatoires
private List<int> GenerateNumbers(int count, int min, int max)
{
var numbers = new List<int>();
for (var i = 0; i < count; i++)
{
numbers.Add(_random.Next(min, max));
}
return numbers;
}
}

}
13 changes: 13 additions & 0 deletions Models/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,17 @@ private static bool IsValidExpression(string expression)
}
return true;
}


// Méthode pour générer des nombres aléatoires
public static List<int> GenerateNumbers(int count, int min, int max)
{
Random _random = new Random();
var numbers = new List<int>();
for (var i = 0; i < count; i++)
{
numbers.Add(_random.Next(min, max));
}
return numbers;
}
}
Binary file modified bin/Debug/net8.0/Dechiffre.dll
Binary file not shown.
Binary file modified bin/Debug/net8.0/Dechiffre.exe
Binary file not shown.
Binary file modified bin/Debug/net8.0/Dechiffre.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion obj/Debug/net8.0/Dechiffre.AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[assembly: System.Reflection.AssemblyCompanyAttribute("Dechiffre")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+053fc31ebe4407792828d735440937698429c583")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+db8ebacf269e6e420d68aaba9ef0cbbf580ca53f")]
[assembly: System.Reflection.AssemblyProductAttribute("Dechiffre")]
[assembly: System.Reflection.AssemblyTitleAttribute("Dechiffre")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
Expand Down
2 changes: 1 addition & 1 deletion obj/Debug/net8.0/Dechiffre.AssemblyInfoInputs.cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
868cf2bc12bb26d8b8769179f66a398c9229b752cb63761c72121c0241d5989c
e47a6370ad6476711762755df41c5f32abf9e060dcb7d086b5726a8ae66b1fe8
Binary file modified obj/Debug/net8.0/Dechiffre.dll
Binary file not shown.
Binary file modified obj/Debug/net8.0/Dechiffre.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion obj/Debug/net8.0/Dechiffre.sourcelink.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"documents":{"D:\\S4\\MrTahina\\Des-Chiffres\\*":"https://raw.githubusercontent.com/kenny516/Des-Chiffres/053fc31ebe4407792828d735440937698429c583/*"}}
{"documents":{"D:\\S4\\MrTahina\\Des-Chiffres\\*":"https://raw.githubusercontent.com/kenny516/Des-Chiffres/db8ebacf269e6e420d68aaba9ef0cbbf580ca53f/*"}}
Binary file modified obj/Debug/net8.0/apphost.exe
Binary file not shown.
Binary file modified obj/Debug/net8.0/ref/Dechiffre.dll
Binary file not shown.
Binary file modified obj/Debug/net8.0/refint/Dechiffre.dll
Binary file not shown.
44 changes: 30 additions & 14 deletions wwwroot/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ app.config(function ($routeProvider) {


app.controller('GameController', function ($scope, $interval, $http) {
$scope.timeLeft = 60; // Set the timer to 60 seconds
$scope.timeLeft = 20; // Set the timer to 60 seconds
$scope.timeFormat = formatTime($scope.timeLeft);
$scope.isTimeUp = false;
$scope.game = {};
Expand All @@ -28,14 +28,15 @@ app.controller('GameController', function ($scope, $interval, $http) {

$scope.finishGame = false;
$scope.playerWin = null;

$http.get('/api/game/index').then(function (response) {
$scope.game = response.data;
$scope.choice = angular.copy($scope.game.numbers);
});

var timer = $interval(function () {
if ($scope.timeLeft > 0) {
$scope.timeFormat = formatTime($scope.timeLeft);
$scope.timeLeft--;
$scope.timeFormat = formatTime($scope.timeLeft);
} else {
Expand All @@ -44,22 +45,22 @@ app.controller('GameController', function ($scope, $interval, $http) {
$scope.timeIsUpFunction();
}
}, 1000);

// fontion valider reponse d un joueur
$scope.submitResults = function (playerIndex) {
$scope.game.players[playerIndex].Temps = 60 - $scope.timeLeft; // Calculer le temps de soumission pour le joueur
$scope.game.players[playerIndex].Temps = 20 - $scope.timeLeft; // Calculer le temps de soumission pour le joueur
};

//fonction rejouer avec nouveau nombre
$scope.newGame = function (){
$http.post("api/game/newGame",$scope.game).then(function (response){
$scope.newGame = function () {
$http.post("api/game/newGame", $scope.game).then(function (response) {
console.log("atoo zaaa");
$scope.timeLeft = 60;
$scope.timeLeft = 20;
$scope.game = response.data;
$scope.choice = angular.copy($scope.game.numbers);
})
}




// Fonction à appeler lorsque le temps est écoulé
$scope.timeIsUpFunction = function () {
Expand All @@ -76,24 +77,37 @@ app.controller('GameController', function ($scope, $interval, $http) {
if (index !== -1) { // Vérifier si l'élément existe dans le tableau
$scope.choice.splice(index, 1); // Retirer l'élément du tableau
}
console.log("ajout de" + valueOp)
console.log("verifChoice ajout de " + valueOp)
$scope.verifChoice += valueOp.toString(); // Ajouter l'élément à la chaîne verifChoice
}

////////
$scope.verify = function () {
$scope.verifvalue = eval($scope.verifChoice);
$scope.verifvalue = $scope.callEval();
console.log("value int final " + $scope.verifvalue);
$scope.game.value_verify = $scope.verifvalue;

$http.post('/api/game/verify', $scope.game).then(function (response) {
$scope.playerWin = response.data;
$scope.finishGame = true;
console.log("gagnant "+response.data);
console.log("gagnant " + response.data);
});
};
}
$scope.callEval = function () {
return $http.post('api/game/eval', { eval: $scope.verifChoice })
.then(function (response) {
return response.data;
})
.catch(function (error) {
console.error("Error occurred while fetching data: ", error);
throw error;
});
}


});


function formatTime(seconds) {
const minutes = Math.floor(seconds / 60);
const remainingSeconds = seconds % 60;
Expand All @@ -102,3 +116,5 @@ function formatTime(seconds) {





0 comments on commit 1a87085

Please sign in to comment.