mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-29 14:15:08 -08:00
Initial version of Craps game.
This commit is contained in:
31
29 Craps/csharp/Craps/Craps.sln
Normal file
31
29 Craps/csharp/Craps/Craps.sln
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.31112.23
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Craps", "Craps\Craps.csproj", "{783A49D7-DADE-477A-9973-D9457258573B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CrapsTester", "CrapsTester\CrapsTester.csproj", "{44DFE8DB-715F-428E-992D-A97C34D47B98}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{783A49D7-DADE-477A-9973-D9457258573B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{783A49D7-DADE-477A-9973-D9457258573B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{783A49D7-DADE-477A-9973-D9457258573B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{783A49D7-DADE-477A-9973-D9457258573B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{44DFE8DB-715F-428E-992D-A97C34D47B98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{44DFE8DB-715F-428E-992D-A97C34D47B98}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{44DFE8DB-715F-428E-992D-A97C34D47B98}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{44DFE8DB-715F-428E-992D-A97C34D47B98}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {871679FF-B86C-468B-960E-DFC625CDB5D0}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
8
29 Craps/csharp/Craps/Craps/Craps.csproj
Normal file
8
29 Craps/csharp/Craps/Craps/Craps.csproj
Normal file
@@ -0,0 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
24
29 Craps/csharp/Craps/Craps/Dice.cs
Normal file
24
29 Craps/csharp/Craps/Craps/Dice.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Craps
|
||||
{
|
||||
public class Dice
|
||||
{
|
||||
private Random rand = new Random();
|
||||
public readonly int sides;
|
||||
|
||||
public Dice()
|
||||
{
|
||||
sides = 6;
|
||||
}
|
||||
|
||||
public Dice(int sides)
|
||||
{
|
||||
this.sides = sides;
|
||||
}
|
||||
|
||||
public int Roll() => rand.Next(1, sides);
|
||||
}
|
||||
}
|
||||
12
29 Craps/csharp/Craps/Craps/Program.cs
Normal file
12
29 Craps/csharp/Craps/Craps/Program.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace Craps
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello World!");
|
||||
}
|
||||
}
|
||||
}
|
||||
20
29 Craps/csharp/Craps/CrapsTester/CrapsTester.csproj
Normal file
20
29 Craps/csharp/Craps/CrapsTester/CrapsTester.csproj
Normal file
@@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="2.1.0" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="2.1.0" />
|
||||
<PackageReference Include="coverlet.collector" Version="1.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Craps\Craps.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
31
29 Craps/csharp/Craps/CrapsTester/CrapsTests.cs
Normal file
31
29 Craps/csharp/Craps/CrapsTester/CrapsTests.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Craps;
|
||||
|
||||
namespace CrapsTester
|
||||
{
|
||||
[TestClass]
|
||||
public class DiceTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void SixSidedDiceReturnsValidRolls()
|
||||
{
|
||||
var dice = new Dice();
|
||||
for (int i = 0; i < 100000; i++)
|
||||
{
|
||||
var roll = dice.Roll();
|
||||
Assert.IsTrue(roll >= 1 && roll <= dice.sides);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TwentySidedDiceReturnsValidRolls()
|
||||
{
|
||||
var dice = new Dice(20);
|
||||
for (int i = 0; i < 100000; i++)
|
||||
{
|
||||
var roll = dice.Roll();
|
||||
Assert.IsTrue(roll >= 1 && roll <= dice.sides);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user