-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from javithegreat35/main
merge Dice Game
- Loading branch information
Showing
13 changed files
with
292 additions
and
0 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 |
---|---|---|
@@ -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 |
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
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 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>disable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
</Project> |
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,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); |
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,30 @@ | ||
<h1 align="center"> | ||
Dice Game | ||
</h1> | ||
|
||
<p align="center"> | ||
<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> | ||
<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> | ||
<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> | ||
<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> | ||
<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> | ||
<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> | ||
</p> | ||
|
||
**[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 | ||
|
||
<p align="center"> | ||
You can play this game in your browser: | ||
<br /> | ||
<a href="https://zacharypatten.github.io/dotnet-console-games/Dice Game" alt="Play Now"> | ||
<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> | ||
</a> | ||
<br /> | ||
<sup>Hosted On GitHub Pages</sup> | ||
</p> |
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,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(); | ||
} | ||
} |
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,47 @@ | ||
@using System | ||
|
||
@page "/Dice Game" | ||
|
||
<PageTitle>Dice Game</PageTitle> | ||
|
||
<h1>Dice Game</h1> | ||
|
||
<a href="https://github.com/ZacharyPatten/dotnet-console-games/tree/main/Projects/Dice%20Game" alt="Go To Readme"> | ||
<img title="Go To Readme" alt="Go To Readme" src="https://raw.githubusercontent.com/ZacharyPatten/dotnet-console-games/main/.github/resources/readme-black.svg"> | ||
</a> | ||
|
||
<div class="console-window text-center my-3" @onkeydown="@Console.OnKeyDown" tabindex="0"> | ||
<div class="d-inline-block bg-dark text-light border p-2 text-start shadow padding-0"> | ||
<pre class="console"> | ||
<code>@Console.State</code> | ||
</pre> | ||
</div> | ||
<div> | ||
<button class="btn btn-primary" @onclick="() => Console.EnqueueInput(ConsoleKey.Enter) ">enter</button> | ||
</div> | ||
</div> | ||
|
||
<div class="alert alert-secondary" role="alert"> | ||
⌨ Keyboard input is supported if you <strong>click</strong> on the game. | ||
</div> | ||
|
||
<div class="alert alert-secondary" role="alert"> | ||
↻ You can restart the game by <strong>refreshing</strong> the page. | ||
</div> | ||
|
||
@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); | ||
} |
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
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