Skip to content

Commit 8daddd0

Browse files
Merge pull request #31 from javithegreat35/main
merge Dice Game
2 parents 07716f6 + 43d9c5f commit 8daddd0

13 files changed

+292
-0
lines changed

.github/workflows/Dice Game Build.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Dice Game Build
2+
on:
3+
push:
4+
paths:
5+
- 'Projects/Dice Game/**'
6+
pull_request:
7+
paths:
8+
- 'Projects/Dice Game/**'
9+
workflow_dispatch:
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v1
15+
- name: setup dotnet
16+
uses: actions/setup-dotnet@v1
17+
with:
18+
dotnet-version: 6.0.x
19+
- name: dotnet build
20+
run: dotnet build "Projects\Dice Game\Dice Game.csproj" --configuration Release

.vscode/launch.json

+10
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
"console": "externalTerminal",
2323
"stopAtEntry": false,
2424
},
25+
{
26+
"name": "Dice Game",
27+
"type": "coreclr",
28+
"request": "launch",
29+
"preLaunchTask": "Build Dice Game",
30+
"program": "${workspaceFolder}/Projects/Dice Game/bin/Debug/Dice Game.dll",
31+
"cwd": "${workspaceFolder}/Projects/Dice Game/bin/Debug",
32+
"console": "externalTerminal",
33+
"stopAtEntry": false,
34+
},
2535
{
2636
"name": "Quick Draw",
2737
"type": "coreclr",

.vscode/tasks.json

+13
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,19 @@
457457
],
458458
"problemMatcher": "$msCompile",
459459
},
460+
{
461+
"label": "Build Dice Game",
462+
"command": "dotnet",
463+
"type": "process",
464+
"args":
465+
[
466+
"build",
467+
"${workspaceFolder}/Projects/Dice Game/Dice Game.csproj",
468+
"/property:GenerateFullPaths=true",
469+
"/consoleloggerparameters:NoSummary",
470+
],
471+
"problemMatcher": "$msCompile",
472+
},
460473
{
461474
"label": "Build Solution",
462475
"command": "dotnet",

Projects/Dice Game/Dice Game.csproj

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>disable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
</Project>

Projects/Dice Game/Program.cs

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System;
2+
3+
int playerPoints = 0;
4+
int rivalPoints = 0;
5+
6+
Random random = new();
7+
8+
Console.WriteLine("Dice Game");
9+
Console.WriteLine();
10+
Console.WriteLine("In this game you and a computer Rival will play 10 rounds");
11+
Console.WriteLine("where you will each roll a 6-sided dice, and the player");
12+
Console.WriteLine("with the highest dice value will win the round. The player");
13+
Console.WriteLine("who wins the most rounds wins the game. Good luck!");
14+
Console.WriteLine();
15+
Console.Write("Press any key to start...");
16+
Console.ReadKey(true);
17+
Console.WriteLine();
18+
Console.WriteLine();
19+
for (int i = 0; i < 10; i++)
20+
{
21+
Console.WriteLine($"Round {i + 1}");
22+
int rivalRandomNum = random.Next(1, 7);
23+
Console.WriteLine("Rival rolled a " + rivalRandomNum);
24+
Console.Write("Press any key to roll the dice...");
25+
Console.ReadKey(true);
26+
Console.WriteLine();
27+
int playerRandomNum = random.Next(1, 7);
28+
Console.WriteLine("You rolled a " + playerRandomNum);
29+
if (playerRandomNum > rivalRandomNum)
30+
{
31+
playerPoints++;
32+
Console.WriteLine("You won this round.");
33+
}
34+
else if (playerRandomNum < rivalRandomNum)
35+
{
36+
rivalPoints++;
37+
Console.WriteLine("The Rival won this round.");
38+
}
39+
else
40+
{
41+
Console.WriteLine("This round is a draw!");
42+
}
43+
Console.WriteLine($"The score is now - You : {playerPoints}. Rival : {rivalPoints}.");
44+
Console.Write("Press any key to continue...");
45+
Console.ReadKey(true);
46+
Console.WriteLine();
47+
Console.WriteLine();
48+
}
49+
Console.WriteLine("Game over.");
50+
Console.WriteLine($"The score is now - You : {playerPoints}. Rival : {rivalPoints}.");
51+
if (playerPoints > rivalPoints)
52+
{
53+
Console.WriteLine("You won!");
54+
}
55+
else if (playerPoints < rivalPoints)
56+
{
57+
Console.WriteLine("You lost!");
58+
}
59+
else
60+
{
61+
Console.WriteLine("This game is a draw.");
62+
}
63+
Console.Write("Press any key to exit...");
64+
Console.ReadKey(true);

Projects/Dice Game/README.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<h1 align="center">
2+
Dice Game
3+
</h1>
4+
5+
<p align="center">
6+
<a href="https://github.com./ZacharyPatten/dotnet-console-games" alt="GitHub repo"><img alt="flat" src="https://raw.githubusercontent.com/ZacharyPatten/dotnet-console-games/main/.github/resources/github-repo-black.svg"></a>
7+
<a href="https://docs.microsoft.com/en-us/dotnet/csharp/" alt="GitHub repo"><img alt="Language C#" src="https://raw.githubusercontent.com/ZacharyPatten/dotnet-console-games/main/.github/resources/language-csharp.svg"></a>
8+
<a href="https://dotnet.microsoft.com/download"><img src="https://raw.githubusercontent.com/ZacharyPatten/dotnet-console-games/main/.github/resources/dotnet-badge.svg" title="Target Framework" alt="Target Framework"></a>
9+
<a href="https://github.com./ZacharyPatten/dotnet-console-games/actions"><img src="https://github.com./ZacharyPatten/dotnet-console-games/workflows/Dice%20Game%20Build/badge.svg" title="Goto Build" alt="Build"></a>
10+
<a href="https://discord.gg/4XbQbwF" alt="Discord"><img src="https://raw.githubusercontent.com/ZacharyPatten/dotnet-console-games/main/.github/resources/discord-badge.svg" title="Go To Discord Server" alt="Discord"/></a>
11+
<a href="https://github.com./ZacharyPatten/dotnet-console-games/blob/master/LICENSE" alt="license"><img src="https://raw.githubusercontent.com/ZacharyPatten/dotnet-console-games/main/.github/resources/license-MIT-green.svg" /></a>
12+
</p>
13+
14+
**[Source Code](Program.cs)**
15+
16+
In Dice Game you and a computer Rival will play 10 rounds where you will each roll a 6-sided dice, and the player with the highest dice value will win the round. The player who wins the most rounds wins the game. Good luck!
17+
18+
## Input
19+
20+
- any key press to confirm prompts
21+
22+
<p align="center">
23+
You can play this game in your browser:
24+
<br />
25+
<a href="https://zacharypatten.github.io/dotnet-console-games/Dice Game" alt="Play Now">
26+
<sub><img height="40"src="https://raw.githubusercontent.com/ZacharyPatten/dotnet-console-games/main/.github/resources/play-badge.svg" title="Play Now" alt="Play Now"/></sub>
27+
</a>
28+
<br />
29+
<sup>Hosted On GitHub Pages</sup>
30+
</p>

Projects/Website/BlazorConsole.cs

+9
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,15 @@ public void WriteNoRefresh(char c)
302302
View[row, column] = View[row + 1, column];
303303
}
304304
}
305+
for (int column = 0; column < View.GetLength(1); column++)
306+
{
307+
View[View.GetLength(0) - 1, column] = new()
308+
{
309+
Char = ' ',
310+
BackgroundColor = BackgroundColor,
311+
ForegroundColor = ForegroundColor
312+
};
313+
}
305314
CursorTop--;
306315
}
307316
View[CursorTop, CursorLeft] = new()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
4+
namespace Website.Games.Dice_Game;
5+
6+
public class Dice_Game
7+
{
8+
public readonly BlazorConsole Console = new();
9+
10+
public async Task Run()
11+
{
12+
int playerPoints = 0;
13+
int rivalPoints = 0;
14+
15+
Random random = new();
16+
17+
await Console.WriteLine("Dice Game");
18+
await Console.WriteLine();
19+
await Console.WriteLine("In this game you and a computer Rival will play 10 rounds");
20+
await Console.WriteLine("where you will each roll a 6-sided dice, and the player");
21+
await Console.WriteLine("with the highest dice value will win the round. The player");
22+
await Console.WriteLine("who wins the most rounds wins the game. Good luck!");
23+
await Console.WriteLine();
24+
await Console.Write("Press any key to start...");
25+
await Console.ReadKey(true);
26+
await Console.WriteLine();
27+
await Console.WriteLine();
28+
for (int i = 0; i < 10; i++)
29+
{
30+
await Console.WriteLine($"Round {i + 1}");
31+
int rivalRandomNum = random.Next(1, 7);
32+
await Console.WriteLine("Rival rolled a " + rivalRandomNum);
33+
await Console.Write("Press any key to roll the dice...");
34+
await Console.ReadKey(true);
35+
await Console.WriteLine();
36+
int playerRandomNum = random.Next(1, 7);
37+
await Console.WriteLine("You rolled a " + playerRandomNum);
38+
if (playerRandomNum > rivalRandomNum)
39+
{
40+
playerPoints++;
41+
await Console.WriteLine("You won this round.");
42+
}
43+
else if (playerRandomNum < rivalRandomNum)
44+
{
45+
rivalPoints++;
46+
await Console.WriteLine("The Rival won this round.");
47+
}
48+
else
49+
{
50+
await Console.WriteLine("This round is a draw!");
51+
}
52+
await Console.WriteLine($"The score is now - You : {playerPoints}. Rival : {rivalPoints}.");
53+
await Console.Write("Press any key to continue...");
54+
await Console.ReadKey(true);
55+
await Console.WriteLine();
56+
await Console.WriteLine();
57+
}
58+
await Console.WriteLine("Game over.");
59+
await Console.WriteLine($"The score is now - You : {playerPoints}. Rival : {rivalPoints}.");
60+
if (playerPoints > rivalPoints)
61+
{
62+
await Console.WriteLine("You won!");
63+
}
64+
else if (playerPoints < rivalPoints)
65+
{
66+
await Console.WriteLine("You lost!");
67+
}
68+
else
69+
{
70+
await Console.WriteLine("This game is a draw.");
71+
}
72+
await Console.Write("Press any key to exit...");
73+
await Console.ReadKey(true);
74+
await Console.Clear();
75+
await Console.Write("Dice Game was closed.");
76+
await Console.Refresh();
77+
}
78+
}
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
@using System
2+
3+
@page "/Dice Game"
4+
5+
<PageTitle>Dice Game</PageTitle>
6+
7+
<h1>Dice&nbsp;Game</h1>
8+
9+
<a href="https://github.com./ZacharyPatten/dotnet-console-games/tree/main/Projects/Dice%20Game" alt="Go To Readme">
10+
<img title="Go To Readme" alt="Go To Readme" src="https://raw.githubusercontent.com/ZacharyPatten/dotnet-console-games/main/.github/resources/readme-black.svg">
11+
</a>
12+
13+
<div class="console-window text-center my-3" @onkeydown="@Console.OnKeyDown" tabindex="0">
14+
<div class="d-inline-block bg-dark text-light border p-2 text-start shadow padding-0">
15+
<pre class="console">
16+
<code>@Console.State</code>
17+
</pre>
18+
</div>
19+
<div>
20+
<button class="btn btn-primary" @onclick="() => Console.EnqueueInput(ConsoleKey.Enter) ">enter</button>
21+
</div>
22+
</div>
23+
24+
<div class="alert alert-secondary" role="alert">
25+
&#9000; Keyboard input is supported if you <strong>click</strong> on the game.
26+
</div>
27+
28+
<div class="alert alert-secondary" role="alert">
29+
&#8635; You can restart the game by <strong>refreshing</strong> the page.
30+
</div>
31+
32+
@code
33+
{
34+
Games.Dice_Game.Dice_Game Game;
35+
BlazorConsole Console;
36+
37+
public Dice_Game()
38+
{
39+
Game = new();
40+
Console = Game.Console;
41+
Console.WindowWidth = 60;
42+
//Console.WindowHeight = PLACEHOLDER;
43+
Console.StateHasChanged = StateHasChanged;
44+
}
45+
46+
protected override void OnInitialized() => InvokeAsync(Game.Run);
47+
}

Projects/Website/Shared/NavMenu.razor

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
<span class="oi oi-play-circle" aria-hidden="true"></span> Rock Paper Scissors
1919
</NavLink>
2020
</div>
21+
<div class="nav-item px-3">
22+
<NavLink class="nav-link" href="Dice Game">
23+
<span class="oi oi-play-circle" aria-hidden="true"></span> Dice Game
24+
</NavLink>
25+
</div>
2126
<div class="nav-item px-3">
2227
<NavLink class="nav-link" href="Quick Draw">
2328
<span class="oi oi-play-circle" aria-hidden="true"></span> Quick Draw

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
|:-|:-|:-|
2222
|[Guess&nbsp;A&nbsp;Number](https://github.com./ZacharyPatten/dotnet-console-games/tree/main/Projects/Guess%20A%20Number)|0|<sub><a href="https://zacharypatten.github.io/dotnet-console-games/Guess%20A%20Number" alt="Play Now"><img src="https://raw.githubusercontent.com/ZacharyPatten/dotnet-console-games/main/.github/resources/play-badge.svg" title="Play Now" alt="Play Now"/></a>&nbsp;<a href="https://github.com./ZacharyPatten/dotnet-console-games/actions"><img src="https://github.com./ZacharyPatten/dotnet-console-games/workflows/Guess%20A%20Number%20Build/badge.svg" title="Go to Action" alt="Go to Action"></a></sub>|
2323
|[Rock&nbsp;Paper&nbsp;Scissors](https://github.com./ZacharyPatten/dotnet-console-games/tree/main/Projects/Rock%20Paper%20Scissors)|0|<sub><a href="https://zacharypatten.github.io/dotnet-console-games/Rock%20Paper%20Scissors" alt="Play Now"><img src="https://raw.githubusercontent.com/ZacharyPatten/dotnet-console-games/main/.github/resources/play-badge.svg" title="Play Now" alt="Play Now"/></a>&nbsp;<a href="https://github.com./ZacharyPatten/dotnet-console-games/actions"><img src="https://github.com./ZacharyPatten/dotnet-console-games/workflows/Rock%20Paper%20Scissors%20Build/badge.svg" title="Go to Action" alt="Go to Action"></a></sub>|
24+
|[Dice&nbsp;Game](https://github.com./ZacharyPatten/dotnet-console-games/tree/main/Projects/Dice%20Game)|0|<sub><a href="https://zacharypatten.github.io/dotnet-console-games/Dice%20Game" alt="Play Now"><img src="https://raw.githubusercontent.com/ZacharyPatten/dotnet-console-games/main/.github/resources/play-badge.svg" title="Play Now" alt="Play Now"/></a>&nbsp;<a href="https://github.com./ZacharyPatten/dotnet-console-games/actions"><img src="https://github.com./ZacharyPatten/dotnet-console-games/workflows/Dice%20Game%20Build/badge.svg" title="Go to Action" alt="Go to Action"></a></sub>|
2425
|[Quick&nbsp;Draw](https://github.com./ZacharyPatten/dotnet-console-games/tree/main/Projects/Quick%20Draw)|0|<sub><a href="https://zacharypatten.github.io/dotnet-console-games/Quick%20Draw" alt="Play Now"><img src="https://raw.githubusercontent.com/ZacharyPatten/dotnet-console-games/main/.github/resources/play-badge.svg" title="Play Now" alt="Play Now"/></a>&nbsp;<a href="https://github.com./ZacharyPatten/dotnet-console-games/actions"><img src="https://github.com./ZacharyPatten/dotnet-console-games/workflows/Quick%20Draw%20Build/badge.svg" title="Go to Action" alt="Go to Action"></a></sub>|
2526
|[Whack&nbsp;A&nbsp;Mole](https://github.com./ZacharyPatten/dotnet-console-games/tree/main/Projects/Whack%20A%20Mole)|1|<sub><a href="https://zacharypatten.github.io/dotnet-console-games/Whack%20A%20Mole" alt="Play Now"><img src="https://raw.githubusercontent.com/ZacharyPatten/dotnet-console-games/main/.github/resources/play-badge.svg" title="Play Now" alt="Play Now"/></a>&nbsp;<a href="https://github.com./ZacharyPatten/dotnet-console-games/actions"><img src="https://github.com./ZacharyPatten/dotnet-console-games/workflows/Whack%20A%20Mole%20Build/badge.svg" title="Go to Action" alt="Go to Action"></a></sub>|
2627
|[Tic&nbsp;Tac&nbsp;Toe](https://github.com./ZacharyPatten/dotnet-console-games/tree/main/Projects/Tic%20Tac%20Toe)|1|<sub><a href="https://zacharypatten.github.io/dotnet-console-games/Tic%20Tac%20Toe" alt="Play Now"><img src="https://raw.githubusercontent.com/ZacharyPatten/dotnet-console-games/main/.github/resources/play-badge.svg" title="Play Now" alt="Play Now"/></a>&nbsp;<a href="https://github.com./ZacharyPatten/dotnet-console-games/actions"><img src="https://github.com./ZacharyPatten/dotnet-console-games/workflows/Tic%20Tac%20Toe%20Build/badge.svg" title="Go to Action" alt="Go to Action"></a></sub>|

dotnet-console-games-and-website.sln

+6
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tents", "Projects\Tents\Ten
7575
EndProject
7676
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Guess A Number", "Projects\Guess A Number\Guess A Number.csproj", "{63300EAA-2013-43F4-8628-9FA979C83E44}"
7777
EndProject
78+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DiceGame", "Projects\Dice Game\Dice Game.csproj", "{89EBF300-0A28-4054-A807-D6A67544CE4B}"
79+
EndProject
7880
Global
7981
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8082
Debug|Any CPU = Debug|Any CPU
@@ -225,6 +227,10 @@ Global
225227
{63300EAA-2013-43F4-8628-9FA979C83E44}.Debug|Any CPU.Build.0 = Debug|Any CPU
226228
{63300EAA-2013-43F4-8628-9FA979C83E44}.Release|Any CPU.ActiveCfg = Release|Any CPU
227229
{63300EAA-2013-43F4-8628-9FA979C83E44}.Release|Any CPU.Build.0 = Release|Any CPU
230+
{89EBF300-0A28-4054-A807-D6A67544CE4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
231+
{89EBF300-0A28-4054-A807-D6A67544CE4B}.Debug|Any CPU.Build.0 = Debug|Any CPU
232+
{89EBF300-0A28-4054-A807-D6A67544CE4B}.Release|Any CPU.ActiveCfg = Release|Any CPU
233+
{89EBF300-0A28-4054-A807-D6A67544CE4B}.Release|Any CPU.Build.0 = Release|Any CPU
228234
EndGlobalSection
229235
GlobalSection(SolutionProperties) = preSolution
230236
HideSolutionNode = FALSE

dotnet-console-games.slnf

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"Projects\\Beep Pad\\Beep Pad.csproj",
77
"Projects\\Bound\\Bound.csproj",
88
"Projects\\Connect 4\\Connect 4.csproj",
9+
"Projects\\Dice Game\\Dice Game.csproj",
910
"Projects\\Draw\\Draw.csproj",
1011
"Projects\\Drive\\Drive.csproj",
1112
"Projects\\Fighter\\Fighter.csproj",

0 commit comments

Comments
 (0)