Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dotnet.defaultSolution": "Codele.sln"
}
28 changes: 28 additions & 0 deletions Codele.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Codele", "Codele\Codele.csproj", "{65D36224-59C2-4612-A624-5E5A8F30308D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeleLogic", "CodeleLogic\CodeleLogic.csproj", "{A77EC610-941F-4C7C-A3FC-97A9A29266BE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{65D36224-59C2-4612-A624-5E5A8F30308D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{65D36224-59C2-4612-A624-5E5A8F30308D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{65D36224-59C2-4612-A624-5E5A8F30308D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{65D36224-59C2-4612-A624-5E5A8F30308D}.Release|Any CPU.Build.0 = Release|Any CPU
{A77EC610-941F-4C7C-A3FC-97A9A29266BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A77EC610-941F-4C7C-A3FC-97A9A29266BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A77EC610-941F-4C7C-A3FC-97A9A29266BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A77EC610-941F-4C7C-A3FC-97A9A29266BE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
12 changes: 12 additions & 0 deletions Codele/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
18 changes: 18 additions & 0 deletions Codele/Codele.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.11" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.11" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CodeleLogic\CodeleLogic.csproj" />
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions Codele/Pages/Counter.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@page "/counter"

<PageTitle>Counter</PageTitle>

<h1>Counter</h1>

<p role="status">Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
private int currentCount = 0;

private void IncrementCount()
{
currentCount++;
}
}
57 changes: 57 additions & 0 deletions Codele/Pages/FetchData.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
@page "/fetchdata"
@inject HttpClient Http

<PageTitle>Weather forecast</PageTitle>

<h1>Weather forecast</h1>

<p>This component demonstrates fetching data from the server.</p>

@if (forecasts == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Temp. (C)</th>
<th>Temp. (F)</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
@foreach (var forecast in forecasts)
{
<tr>
<td>@forecast.Date.ToShortDateString()</td>
<td>@forecast.TemperatureC</td>
<td>@forecast.TemperatureF</td>
<td>@forecast.Summary</td>
</tr>
}
</tbody>
</table>
}

@code {
private WeatherForecast[]? forecasts;

protected override async Task OnInitializedAsync()
{
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json");
}

public class WeatherForecast
{
public DateOnly Date { get; set; }

public int TemperatureC { get; set; }

public string? Summary { get; set; }

public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
}
9 changes: 9 additions & 0 deletions Codele/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@page "/"

<PageTitle>Index</PageTitle>

<h1>Hello, world!</h1>

Welcome to your new app.

<SurveyPrompt Title="How is Blazor working for you?" />
156 changes: 156 additions & 0 deletions Codele/Pages/PlayCodele.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
@page "/playcodele"
@inject HttpClient Http
@using CodeleLogic

<h3>Play Codele</h3>
<p>Guess the 5 letter, coding-related word in 5 tries or less!</p>

<br>

<p><strong>Attempt #: @attempts</strong></p>

<!-- display the player's guesses -->
<table>
@foreach (var guess in guesses)
{
List<(char, LetterStatus)>? statuses = guess.GuessStatus;
<tr>
<div class="btn-group" role="group" aria-label="Basic example">
@if (statuses != null) {
foreach (var status in statuses) {
char letter = Char.ToUpper(status.Item1);
if (status.Item2 == LetterStatus.Correct) {<button type="button" class="btn btn-success">@letter</button>}
else if (status.Item2 == LetterStatus.IncorrectPosition) {<button type="button" class="btn btn-warning">@letter</button>}
else {<button type="button" class="btn btn-secondary">@letter</button>}
}
}
</div>
</tr>
<br>
}
</table>
<br>

<!-- input box for the player to type and submit a guess -->
<input placeholder="Type your guess" @bind="newGuess" />
<button @onclick="SubmitGuess">Submit</button>

<!-- display message if guess is not 5 characters long -->
@if (displayGuessSizeMsg == true) {
<p style="color: rgb(197, 3, 3);">Guess must be 5 characters long</p>
}

<!-- modal popup to display the game outcome -->
@if (showModal == true) {
<div class="modal fade show" id="myModal" style="display:block; background-color: rgba(10,10,10,.8);"
aria-modal="true" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">@gameStatusMessage</h4>
</div>
<div class="modal-body">
<p><strong>Correct Answer: </strong> @answer</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success" @onclick="StartNewGame">New Game?</button>
</div>
</div>
</div>
</div>
}

@code {

// list of guesses the player has made so far
private List<Guess> guesses = new();

// the player's current guess
private string? newGuess;

// list of potential game answers (pulled from a json file)
private string[]? answers;

// the answer for the current game
private string? answer;

// # of tries the player has to guess the word
private int attempts;

// message to display in the modal popup depending on the game outcome
private string? gameStatusMessage;

// modal popup to display the game outcome
private bool showModal { get; set; }

// display message if guess is not 5 characters long
private bool displayGuessSizeMsg { get; set; }

// On load, set up the game
protected override async Task OnInitializedAsync()
{
showModal = false;
attempts = 1;
answers = await Http.GetFromJsonAsync<string[]>("sample-data/codele-word-library.json");
Random randomGenerator = new Random();
answer = answers[randomGenerator.Next(0, answers.Length)];
}

// use as Copilot example
// Reset and start a new game
private void StartNewGame() {
showModal = false;
guesses.Clear();
newGuess = string.Empty;
attempts = 1;
Random randomGenerator = new Random();
answer = answers[randomGenerator.Next(0, answers.Length)];
}

// Close the game status modal
private void ModalClose() {
showModal = false;
}

// Submit and evaluate the player's guess
private void SubmitGuess() {
// check if guess is 5 characters long, display message if not
if (newGuess.Length != 5) displayGuessSizeMsg = false;
else {
displayGuessSizeMsg = false;
if (!string.IsNullOrEmpty(newGuess))
{
Guess guess = new Guess(newGuess);

// if the player still has attempts left, evaluate their guess, otherwise display loss message
if (attempts < 5) {
guess.GetGuessStatuses(answer);

// check if the player guessed correctly, display win message if true
if (guess.IsWinningGuess(answer)) {
showModal = true;
gameStatusMessage = "You Won!";
}
// if the player did not guess correctly, increment the attempt #
else {
attempts++;
}
}
else {
guess.GetGuessStatuses(answer);

showModal = true;
gameStatusMessage = "You Lost!";
}

// add current guess to the player's list of guesses
guesses.Add(guess);

// clear the input box
newGuess = string.Empty;
}
}
}
}


11 changes: 11 additions & 0 deletions Codele/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Codele;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

await builder.Build().RunAsync();
40 changes: 40 additions & 0 deletions Codele/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:38486",
"sslPort": 44391
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "http://localhost:5243",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:7059;http://localhost:5243",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
17 changes: 17 additions & 0 deletions Codele/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@inherits LayoutComponentBase

<div class="page">
<div class="sidebar">
<NavMenu />
</div>

<main>
<div class="top-row px-4">
<a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a>
</div>

<article class="content px-4">
@Body
</article>
</main>
</div>
Loading