-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
809 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -448,4 +448,4 @@ $RECYCLE.BIN/ | |
## Visual Studio Code | ||
## | ||
.vscode/* | ||
|
||
.editorconfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
namespace DaresGacha; | ||
|
||
public class Calculator | ||
{ | ||
public static double[] GetProbability(int done) | ||
{ | ||
//chance for difficulty level jump, tie, slap, kiss, sex | ||
//every 10 dares increase difficulty | ||
var list = new double[,] | ||
{ | ||
{80, 15, 2, 0, 0}, //start | ||
{70, 23.2, 3.5, 0.3, 0}, //-10 +8.2 +1.5 +0.3 | ||
{57, 30, 8, 1, 0.0}, //-13 +7.8 +4.5 +0.7 | ||
{29.7, 45, 18, 3, 0.3}, //-27.3 +15 +10 +2 +0.3 | ||
{0, 52, 40.5, 10, 1.5}, //-29.7 +7 +22.5 +7 +1.2 | ||
{0, 6, 50, 38, 6}, //-0 -46 +9.5 +28 +4.5 | ||
{0, 0, 20, 60, 20}, //-0 -6 -30 +22 +14 | ||
{0, 0, 0, 20, 80}, //-0 -0 -20 -40 +60 | ||
}; | ||
|
||
int i = Math.Min(list.Length, (int)(done / 10)); | ||
return Enumerable.Range(0, list.GetLength(1)) | ||
.Select(x => list[i, x]) | ||
.ToArray(); | ||
} | ||
|
||
public static int GetLvl(double[] probability) | ||
{ | ||
//sum probabilities | ||
var chance = new double[probability.Length]; | ||
probability.CopyTo(chance, 0); | ||
for (int i = 1; i < chance.Length; i++) | ||
chance[i] += chance[i - 1]; | ||
|
||
int random = new Random().Next(0, 100); | ||
|
||
for (int j = 0; j < chance.Length; j++) | ||
if (random <= chance[j]) return j; | ||
|
||
return chance.Length - 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,66 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using DaresGacha.Dtos; | ||
using DaresGacha.Services; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace DaresGacha.Controllers | ||
{ | ||
[ApiController] | ||
[Route("[controller]")] | ||
public class DareController : ControllerBase | ||
{ | ||
private readonly ILogger<DareController> _logger; | ||
private readonly IDareService _dareService; | ||
|
||
public DareController(ILogger<DareController> logger) | ||
public DareController(IDareService dareService) | ||
{ | ||
_logger = logger; | ||
_dareService = dareService; | ||
} | ||
|
||
|
||
[HttpPatch] | ||
public async Task<IActionResult> Add(DareAddDto newDare) | ||
{ | ||
var response = await _dareService.Add(newDare); | ||
if (response.Success == true) | ||
return Ok(response.Data); | ||
return (BadRequest(response.Exception)); | ||
} | ||
|
||
[HttpDelete("{id}")] | ||
public async Task<IActionResult> Delete(int id) | ||
{ | ||
var response = await _dareService.Delete(id); | ||
if (response.Success == true) | ||
return Ok(); | ||
return (BadRequest(response.Exception)); | ||
} | ||
|
||
[HttpGet] | ||
public IActionResult Get() | ||
public async Task<IActionResult> GetAll(int? lvl = null, bool? done = null, bool? isDeleted = null) | ||
{ | ||
return Ok("xd lalala"); | ||
var response = await _dareService.GetAll(lvl, done, isDeleted); | ||
if (response.Success == true) | ||
return Ok(response.Data); | ||
return (BadRequest(response.Exception)); | ||
} | ||
|
||
[HttpGet("random")] | ||
public async Task<IActionResult> GetRandom() | ||
{ | ||
var response = await _dareService.GetRandom(); | ||
if (response.Success == true) | ||
return Ok(response.Data); | ||
return (BadRequest(response.Exception)); | ||
} | ||
|
||
[HttpPut("{id}")] | ||
public async Task<IActionResult> UpdateLvl(int id, DareUpdateDto newDare) | ||
{ | ||
newDare.Id = id; | ||
var response = await _dareService.Update(newDare); | ||
|
||
if (response.Success == true) | ||
return Ok(); | ||
return (BadRequest(response.Exception)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace DaresGacha.Data | ||
{ | ||
public class DataContext : DbContext | ||
{ | ||
public DataContext(DbContextOptions<DataContext> options) : base(options) | ||
{ | ||
|
||
} | ||
|
||
public DbSet<Dare> Dares { get; set; } = null!; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace DaresGacha.Dtos; | ||
|
||
public class DareAddDto | ||
{ | ||
public string Text { get; set; } = string.Empty; | ||
public int Level { get; set; } | ||
public bool Done { get; set; } = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace DaresGacha.Dtos; | ||
|
||
public class DareGetDto | ||
{ | ||
public int Id { get; set; } | ||
public string Text { get; set; } = string.Empty; | ||
public int Level { get; set; } | ||
public bool Done { get; set; } = false; | ||
public bool IsDeleted { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace DaresGacha.Dtos; | ||
|
||
public class DareGetRandomDto | ||
{ | ||
public int Id { get; set; } | ||
public string Text { get; set; } = string.Empty; | ||
public int Level { get; set; } | ||
public double[] Difficulty { get; set; } = { }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace DaresGacha.Dtos; | ||
|
||
public class DareUpdateDto | ||
{ | ||
public int Id { get; set; } | ||
public string Text { get; set; } = string.Empty; | ||
public int Level { get; set; } | ||
public bool Done { get; set; } = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using AutoMapper; | ||
using DaresGacha.Dtos; | ||
|
||
namespace DaresGacha | ||
{ | ||
public class MapperProfile : Profile | ||
{ | ||
public MapperProfile() | ||
{ | ||
CreateMap<Dare, DareGetDto>().ReverseMap(); | ||
CreateMap<Dare, DareAddDto>().ReverseMap(); | ||
CreateMap<Dare, DareUpdateDto>().ReverseMap(); | ||
CreateMap<Dare, DareGetRandomDto>().ReverseMap(); | ||
|
||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
|
||
#nullable disable | ||
|
||
namespace DaresGacha.Migrations | ||
{ | ||
/// <inheritdoc /> | ||
public partial class InitialCreate : Migration | ||
{ | ||
/// <inheritdoc /> | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.CreateTable( | ||
name: "Dares", | ||
columns: table => new | ||
{ | ||
Id = table.Column<int>(type: "int", nullable: false) | ||
.Annotation("SqlServer:Identity", "1, 1"), | ||
Text = table.Column<string>(type: "nvarchar(max)", nullable: false), | ||
Level = table.Column<int>(type: "int", nullable: false) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_Dares", x => x.Id); | ||
}); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.DropTable( | ||
name: "Dares"); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.