mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-23 07:29:02 -08:00
Merge pull request #90 from BrianWhy/main
Added csharp version of Russion Roulette
This commit is contained in:
106
76 Russian Roulette/csharp/RussianRoulette/Program.cs
Normal file
106
76 Russian Roulette/csharp/RussianRoulette/Program.cs
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace RussianRoulette
|
||||||
|
{
|
||||||
|
public class Program
|
||||||
|
{
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
PrintTitle();
|
||||||
|
|
||||||
|
var includeRevolver = true;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
PrintInstructions(includeRevolver);
|
||||||
|
switch (PlayGame())
|
||||||
|
{
|
||||||
|
case GameResult.Win:
|
||||||
|
includeRevolver = true;
|
||||||
|
break;
|
||||||
|
case GameResult.Chicken:
|
||||||
|
case GameResult.Dead:
|
||||||
|
includeRevolver = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void PrintTitle()
|
||||||
|
{
|
||||||
|
Console.WriteLine(" Russian Roulette");
|
||||||
|
Console.WriteLine("Creative Computing Morristown, New Jersey");
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("This is a game of >>>>>>>>>>Russian Roulette.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void PrintInstructions(bool includeRevolver)
|
||||||
|
{
|
||||||
|
Console.WriteLine();
|
||||||
|
if (includeRevolver)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Here is a revolver.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("...Next Victim...");
|
||||||
|
}
|
||||||
|
Console.WriteLine("Type '1' to spin chamber and pull trigger.");
|
||||||
|
Console.WriteLine("Type '2' to give up.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GameResult PlayGame()
|
||||||
|
{
|
||||||
|
var rnd = new Random();
|
||||||
|
var round = 0;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
round++;
|
||||||
|
Console.Write("Go: ");
|
||||||
|
var input = Console.ReadKey().KeyChar;
|
||||||
|
Console.WriteLine();
|
||||||
|
if (input != '2')
|
||||||
|
{
|
||||||
|
// Random.Next will retun a value that is the same or greater than the minimum and
|
||||||
|
// less than the maximum.
|
||||||
|
// A revolver has 6 rounds.
|
||||||
|
if (rnd.Next(1, 7) == 6)
|
||||||
|
{
|
||||||
|
Console.WriteLine(" Bang!!!!! You're dead!");
|
||||||
|
Console.WriteLine("Condolences will be sent to your relatives.");
|
||||||
|
return GameResult.Dead;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (round > 10)
|
||||||
|
{
|
||||||
|
Console.WriteLine("You win!!!!!");
|
||||||
|
Console.WriteLine("Let someone else blow their brains out.");
|
||||||
|
return GameResult.Win;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("- CLICK -");
|
||||||
|
Console.WriteLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine(" CHICKEN!!!!!");
|
||||||
|
return GameResult.Chicken;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum GameResult
|
||||||
|
{
|
||||||
|
Win,
|
||||||
|
Chicken,
|
||||||
|
Dead
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 16
|
||||||
|
VisualStudioVersion = 16.0.31019.35
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RussianRoulette", "RussianRoulette.csproj", "{9F052B4A-FA33-4BBE-9D9D-3CF8152569F1}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{9F052B4A-FA33-4BBE-9D9D-3CF8152569F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{9F052B4A-FA33-4BBE-9D9D-3CF8152569F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{9F052B4A-FA33-4BBE-9D9D-3CF8152569F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{9F052B4A-FA33-4BBE-9D9D-3CF8152569F1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {97F5B1B0-A80A-4C1F-9F76-8D68B4A49E82}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
Reference in New Issue
Block a user