diff --git a/.github/workflows/Dice Game Build.yml b/.github/workflows/Dice Game Build.yml new file mode 100644 index 00000000..34ae6831 --- /dev/null +++ b/.github/workflows/Dice Game Build.yml @@ -0,0 +1,20 @@ +name: Dice Game Build +on: + push: + paths: + - 'Projects/Dice Game/**' + pull_request: + paths: + - 'Projects/Dice Game/**' + workflow_dispatch: +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: setup dotnet + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 6.0.x + - name: dotnet build + run: dotnet build "Projects\Dice Game\Dice Game.csproj" --configuration Release diff --git a/.vscode/launch.json b/.vscode/launch.json index 7474cac3..36db9238 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -22,6 +22,16 @@ "console": "externalTerminal", "stopAtEntry": false, }, + { + "name": "Dice Game", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "Build Dice Game", + "program": "${workspaceFolder}/Projects/Dice Game/bin/Debug/Dice Game.dll", + "cwd": "${workspaceFolder}/Projects/Dice Game/bin/Debug", + "console": "externalTerminal", + "stopAtEntry": false, + }, { "name": "Quick Draw", "type": "coreclr", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 40ee42d7..56532810 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -457,6 +457,19 @@ ], "problemMatcher": "$msCompile", }, + { + "label": "Build Dice Game", + "command": "dotnet", + "type": "process", + "args": + [ + "build", + "${workspaceFolder}/Projects/Dice Game/Dice Game.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary", + ], + "problemMatcher": "$msCompile", + }, { "label": "Build Solution", "command": "dotnet", diff --git a/Projects/Dice Game/Dice Game.csproj b/Projects/Dice Game/Dice Game.csproj new file mode 100644 index 00000000..89193e26 --- /dev/null +++ b/Projects/Dice Game/Dice Game.csproj @@ -0,0 +1,8 @@ + + + Exe + net6.0 + disable + enable + + diff --git a/Projects/Dice Game/Program.cs b/Projects/Dice Game/Program.cs new file mode 100644 index 00000000..56e6db04 --- /dev/null +++ b/Projects/Dice Game/Program.cs @@ -0,0 +1,64 @@ +using System; + +int playerPoints = 0; +int rivalPoints = 0; + +Random random = new(); + +Console.WriteLine("Dice Game"); +Console.WriteLine(); +Console.WriteLine("In this game you and a computer Rival will play 10 rounds"); +Console.WriteLine("where you will each roll a 6-sided dice, and the player"); +Console.WriteLine("with the highest dice value will win the round. The player"); +Console.WriteLine("who wins the most rounds wins the game. Good luck!"); +Console.WriteLine(); +Console.Write("Press any key to start..."); +Console.ReadKey(true); +Console.WriteLine(); +Console.WriteLine(); +for (int i = 0; i < 10; i++) +{ + Console.WriteLine($"Round {i + 1}"); + int rivalRandomNum = random.Next(1, 7); + Console.WriteLine("Rival rolled a " + rivalRandomNum); + Console.Write("Press any key to roll the dice..."); + Console.ReadKey(true); + Console.WriteLine(); + int playerRandomNum = random.Next(1, 7); + Console.WriteLine("You rolled a " + playerRandomNum); + if (playerRandomNum > rivalRandomNum) + { + playerPoints++; + Console.WriteLine("You won this round."); + } + else if (playerRandomNum < rivalRandomNum) + { + rivalPoints++; + Console.WriteLine("The Rival won this round."); + } + else + { + Console.WriteLine("This round is a draw!"); + } + Console.WriteLine($"The score is now - You : {playerPoints}. Rival : {rivalPoints}."); + Console.Write("Press any key to continue..."); + Console.ReadKey(true); + Console.WriteLine(); + Console.WriteLine(); +} +Console.WriteLine("Game over."); +Console.WriteLine($"The score is now - You : {playerPoints}. Rival : {rivalPoints}."); +if (playerPoints > rivalPoints) +{ + Console.WriteLine("You won!"); +} +else if (playerPoints < rivalPoints) +{ + Console.WriteLine("You lost!"); +} +else +{ + Console.WriteLine("This game is a draw."); +} +Console.Write("Press any key to exit..."); +Console.ReadKey(true); diff --git a/Projects/Dice Game/README.md b/Projects/Dice Game/README.md new file mode 100644 index 00000000..97ca63eb --- /dev/null +++ b/Projects/Dice Game/README.md @@ -0,0 +1,30 @@ +

+ Dice Game +

+ +

+ flat + Language C# + Target Framework + Build + Discord + +

+ +**[Source Code](Program.cs)** + +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! + +## Input + +- any key press to confirm prompts + +

+ You can play this game in your browser: +
+ + Play Now + +
+ Hosted On GitHub Pages +

diff --git a/Projects/Website/BlazorConsole.cs b/Projects/Website/BlazorConsole.cs index 56ccf0b3..3ee16d65 100644 --- a/Projects/Website/BlazorConsole.cs +++ b/Projects/Website/BlazorConsole.cs @@ -302,6 +302,15 @@ public void WriteNoRefresh(char c) View[row, column] = View[row + 1, column]; } } + for (int column = 0; column < View.GetLength(1); column++) + { + View[View.GetLength(0) - 1, column] = new() + { + Char = ' ', + BackgroundColor = BackgroundColor, + ForegroundColor = ForegroundColor + }; + } CursorTop--; } View[CursorTop, CursorLeft] = new() diff --git a/Projects/Website/Games/Dice Game/Dice Game.cs b/Projects/Website/Games/Dice Game/Dice Game.cs new file mode 100644 index 00000000..5c1cc769 --- /dev/null +++ b/Projects/Website/Games/Dice Game/Dice Game.cs @@ -0,0 +1,78 @@ +using System; +using System.Threading.Tasks; + +namespace Website.Games.Dice_Game; + +public class Dice_Game +{ + public readonly BlazorConsole Console = new(); + + public async Task Run() + { + int playerPoints = 0; + int rivalPoints = 0; + + Random random = new(); + + await Console.WriteLine("Dice Game"); + await Console.WriteLine(); + await Console.WriteLine("In this game you and a computer Rival will play 10 rounds"); + await Console.WriteLine("where you will each roll a 6-sided dice, and the player"); + await Console.WriteLine("with the highest dice value will win the round. The player"); + await Console.WriteLine("who wins the most rounds wins the game. Good luck!"); + await Console.WriteLine(); + await Console.Write("Press any key to start..."); + await Console.ReadKey(true); + await Console.WriteLine(); + await Console.WriteLine(); + for (int i = 0; i < 10; i++) + { + await Console.WriteLine($"Round {i + 1}"); + int rivalRandomNum = random.Next(1, 7); + await Console.WriteLine("Rival rolled a " + rivalRandomNum); + await Console.Write("Press any key to roll the dice..."); + await Console.ReadKey(true); + await Console.WriteLine(); + int playerRandomNum = random.Next(1, 7); + await Console.WriteLine("You rolled a " + playerRandomNum); + if (playerRandomNum > rivalRandomNum) + { + playerPoints++; + await Console.WriteLine("You won this round."); + } + else if (playerRandomNum < rivalRandomNum) + { + rivalPoints++; + await Console.WriteLine("The Rival won this round."); + } + else + { + await Console.WriteLine("This round is a draw!"); + } + await Console.WriteLine($"The score is now - You : {playerPoints}. Rival : {rivalPoints}."); + await Console.Write("Press any key to continue..."); + await Console.ReadKey(true); + await Console.WriteLine(); + await Console.WriteLine(); + } + await Console.WriteLine("Game over."); + await Console.WriteLine($"The score is now - You : {playerPoints}. Rival : {rivalPoints}."); + if (playerPoints > rivalPoints) + { + await Console.WriteLine("You won!"); + } + else if (playerPoints < rivalPoints) + { + await Console.WriteLine("You lost!"); + } + else + { + await Console.WriteLine("This game is a draw."); + } + await Console.Write("Press any key to exit..."); + await Console.ReadKey(true); + await Console.Clear(); + await Console.Write("Dice Game was closed."); + await Console.Refresh(); + } +} diff --git a/Projects/Website/Pages/Dice Game.razor b/Projects/Website/Pages/Dice Game.razor new file mode 100644 index 00000000..28216960 --- /dev/null +++ b/Projects/Website/Pages/Dice Game.razor @@ -0,0 +1,47 @@ +@using System + +@page "/Dice Game" + +Dice Game + +

Dice Game

+ + + Go To Readme + + +
+
+
+			@Console.State
+		
+
+
+ +
+
+ + + + + +@code +{ + Games.Dice_Game.Dice_Game Game; + BlazorConsole Console; + + public Dice_Game() + { + Game = new(); + Console = Game.Console; + Console.WindowWidth = 60; + //Console.WindowHeight = PLACEHOLDER; + Console.StateHasChanged = StateHasChanged; + } + + protected override void OnInitialized() => InvokeAsync(Game.Run); +} diff --git a/Projects/Website/Shared/NavMenu.razor b/Projects/Website/Shared/NavMenu.razor index ac5199e9..6f836c32 100644 --- a/Projects/Website/Shared/NavMenu.razor +++ b/Projects/Website/Shared/NavMenu.razor @@ -18,6 +18,11 @@ Rock Paper Scissors +