Initial version of Craps game.

This commit is contained in:
rbamforth
2021-04-10 23:27:22 +01:00
parent bf1fa58a7d
commit c675cd3af8
6 changed files with 126 additions and 0 deletions

View 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

View File

@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
</Project>

View 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);
}
}

View File

@@ -0,0 +1,12 @@
using System;
namespace Craps
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}

View 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>

View 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);
}
}
}
}