getting closer
This commit is contained in:
parent
fea4785655
commit
f581786ec5
@ -9,7 +9,7 @@ public static class CardUtility
|
||||
[13] = "K"
|
||||
};
|
||||
|
||||
public static ICollection<Card> GenerateDeck()
|
||||
public static ICollection<Card> GenerateCards()
|
||||
{
|
||||
var cards = new List<Card>();
|
||||
var suits = Enum.GetValues<Suit>();
|
||||
|
@ -1,5 +1,7 @@
|
||||
using System.Diagnostics;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Sequence.Entities;
|
||||
using Sequence.Models;
|
||||
|
||||
namespace Sequence.Controllers;
|
||||
@ -7,10 +9,12 @@ namespace Sequence.Controllers;
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
private readonly DbContext dbContext;
|
||||
|
||||
public HomeController(ILogger<HomeController> logger)
|
||||
public HomeController(ILogger<HomeController> logger, DbContext dbContext)
|
||||
{
|
||||
_logger = logger;
|
||||
this.dbContext = dbContext;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
@ -18,6 +22,87 @@ public class HomeController : Controller
|
||||
return View();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> CreateMatch([FromServices] UserManager<User> userManager)
|
||||
{
|
||||
var userOne = new User
|
||||
{
|
||||
Name = "Krystle",
|
||||
UserName = "krystle",
|
||||
Email = "krystle@allwillynilly.com"
|
||||
};
|
||||
|
||||
var userTwo = new User
|
||||
{
|
||||
Name = "Ryan",
|
||||
UserName = "ryan",
|
||||
Email = "ryan@binarydad.com"
|
||||
};
|
||||
|
||||
var resultKrystle = await userManager.CreateAsync(userOne, "C0urtY@rd");
|
||||
var resultRyan = await userManager.CreateAsync(userTwo, "C0urtY@rd");
|
||||
|
||||
var playerOne = new Player
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Alias = "SwiggitySwooty",
|
||||
UserId = resultKrystle
|
||||
};
|
||||
|
||||
var playerTwo = new Player
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Alias = "BabeFoy",
|
||||
UserId = Guid.Parse("08db3712-7c5f-430b-882e-44abd63b5324")
|
||||
};
|
||||
|
||||
var players = new[] { playerOne, playerTwo };
|
||||
|
||||
var match = new Match
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Created = DateTime.Now,
|
||||
CurrentTurnPlayerId = playerOne.Id,
|
||||
PlayerOneId = playerOne.Id,
|
||||
PlayerTwoId = playerTwo.Id
|
||||
};
|
||||
|
||||
var deck = cards
|
||||
.OrderBy(c => Guid.NewGuid())
|
||||
.Select(c => new DeckCard
|
||||
{
|
||||
CardId = c.Id,
|
||||
MatchId = match.Id,
|
||||
Id = Guid.NewGuid()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
var handCards = new List<HandCard>();
|
||||
|
||||
for (var i = 1; i <= 14; i += 2)
|
||||
{
|
||||
var deckCard = deck[i];
|
||||
var deckCard2 = deck[i + 1];
|
||||
|
||||
deck.Remove(deckCard);
|
||||
|
||||
handCards.Add(new HandCard
|
||||
{
|
||||
DeckCardId = deckCard.Id,
|
||||
PlayerId = playerOne.Id,
|
||||
Id = Guid.NewGuid()
|
||||
});
|
||||
|
||||
deck.Remove(deckCard2);
|
||||
|
||||
handCards.Add(new HandCard
|
||||
{
|
||||
DeckCardId = deckCard2.Id,
|
||||
PlayerId = playerTwo.Id,
|
||||
Id = Guid.NewGuid()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
|
@ -5,4 +5,6 @@ public class Card
|
||||
public Guid Id { get; set; }
|
||||
public Suit Suit { get; set; }
|
||||
public string Value { get; set; }
|
||||
public int PositionX { get; set; }
|
||||
public int PositionY { get; set; }
|
||||
}
|
||||
|
@ -3,7 +3,9 @@ namespace Sequence.Entities;
|
||||
public class DeckCard
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid MatchId { get; set; }
|
||||
public Match Match { get; set; }
|
||||
public Guid CardId { get; set; }
|
||||
public Card Card { get; set; }
|
||||
public int Order { get; set; }
|
||||
}
|
@ -3,6 +3,8 @@ namespace Sequence.Entities;
|
||||
public class HandCard
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid PlayerId { get; set; }
|
||||
public Player Player { get; set; }
|
||||
public Card Card { get; set; }
|
||||
public Guid DeckCardId { get; set; }
|
||||
public DeckCard DeckCard { get; set; }
|
||||
}
|
@ -4,7 +4,10 @@ public class Match
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public DateTime Created { get; set; }
|
||||
public Guid PlayerOneId { get; set; }
|
||||
public Player PlayerOne { get; set; }
|
||||
public Guid PlayerTwoId { get; set; }
|
||||
public Player PlayerTwo { get; set; }
|
||||
public Guid CurrentTurnPlayerId { get; set; }
|
||||
public ICollection<DeckCard> Deck { get; set; }
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace Sequence.Entities;
|
||||
|
||||
public class MatchCard
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Match Match { get; set; }
|
||||
public Card Card { get; set; }
|
||||
public int PositionX { get; set; }
|
||||
public int PositionY { get; set; }
|
||||
}
|
@ -3,7 +3,9 @@ namespace Sequence.Entities;
|
||||
public class Player
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid UserId { get; set; }
|
||||
public User User { get; set; }
|
||||
public string Alias { get; set; }
|
||||
public ICollection<HandCard> HandCards { get; set; }
|
||||
public ICollection<PlayerCard> PlayerCards { get; set; }
|
||||
}
|
@ -4,7 +4,5 @@ public class PlayerCard
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Player Player { get; set; }
|
||||
public Card Card { get; set; }
|
||||
public int PositionX { get; set; }
|
||||
public int PositionY { get; set; }
|
||||
public DeckCard DeckCard { get; set; }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user