Implement Number Guessing Game
This commit is contained in:
parent
d736420986
commit
f90f2399cf
@ -1,6 +1,7 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using qtc_api.Services.CurrencyGamesService;
|
||||
using System.Security.Claims;
|
||||
using static qtc_api.Services.CurrencyGamesService.CurrencyGamesService;
|
||||
|
||||
namespace qtc_api.Controllers
|
||||
{
|
||||
@ -16,6 +17,8 @@ namespace qtc_api.Controllers
|
||||
_currencyGamesService = currencyGamesService;
|
||||
}
|
||||
|
||||
// Stock Market
|
||||
|
||||
[HttpGet("stock-market/current-price")]
|
||||
public ActionResult<ServiceResponse<int>> GetCurrentPricePerStock()
|
||||
{
|
||||
@ -91,5 +94,21 @@ namespace qtc_api.Controllers
|
||||
}
|
||||
else return Ok(new ServiceResponse<UserStockActionResultDto> { Success = false, Message = "No Identity" });
|
||||
}
|
||||
|
||||
// Number Guess
|
||||
|
||||
[HttpGet("number-guess/get-number")]
|
||||
[Authorize]
|
||||
public ActionResult<ServiceResponse<int>> GetRandomNumber()
|
||||
{
|
||||
return Ok(_currencyGamesService.GetRandomNumber());
|
||||
}
|
||||
|
||||
[HttpGet("number-guess/guess-number")]
|
||||
[Authorize]
|
||||
public ActionResult<ServiceResponse<NumberGuessResult>> GuessNumber(int original, int guess)
|
||||
{
|
||||
return Ok(_currencyGamesService.GuessRandomNumber(original, guess));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -86,11 +86,39 @@ namespace qtc_api.Services.CurrencyGamesService
|
||||
}
|
||||
}
|
||||
|
||||
// Number Guess
|
||||
|
||||
public ServiceResponse<int> GetRandomNumber()
|
||||
{
|
||||
Random rnd = new Random();
|
||||
return new ServiceResponse<int> { Success = true, Data = rnd.Next(1, 500) };
|
||||
}
|
||||
|
||||
public ServiceResponse<NumberGuessResult> GuessRandomNumber(int original, int guess)
|
||||
{
|
||||
var response = new ServiceResponse<NumberGuessResult> { Success = true };
|
||||
|
||||
if (original - guess == 10) response.Data = NumberGuessResult.Lower;
|
||||
else if (guess - original == 10) response.Data = NumberGuessResult.Higher;
|
||||
else if (guess == original) response.Data = NumberGuessResult.Correct;
|
||||
else response.Data = NumberGuessResult.Incorrect;
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
private void Timer_Elapsed(object? state)
|
||||
{
|
||||
Random rnd = new Random();
|
||||
CurrentPricePerStock = rnd.Next(5, 200);
|
||||
logger.LogInformation($"Current Price Per Stock - {CurrentPricePerStock}");
|
||||
}
|
||||
|
||||
public enum NumberGuessResult
|
||||
{
|
||||
Higher,
|
||||
Lower,
|
||||
Correct,
|
||||
Incorrect
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user