Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
StackEgg core game logic, and a minimal console app to play it
- Loading branch information
Benjamin Dumke-von der Ehe
committed
Apr 2, 2015
0 parents
commit 7b36785
Showing
10 changed files
with
874 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,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 2013 | ||
VisualStudioVersion = 12.0.30723.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StackEgg", "StackEgg\StackEgg.csproj", "{DA42D659-D5F3-47D8-958E-0555A499B40A}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{DA42D659-D5F3-47D8-958E-0555A499B40A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{DA42D659-D5F3-47D8-958E-0555A499B40A}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{DA42D659-D5F3-47D8-958E-0555A499B40A}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{DA42D659-D5F3-47D8-958E-0555A499B40A}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
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,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> | ||
</startup> | ||
</configuration> |
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,112 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace StackEgg | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
var game = new StackEggGame().Initialize(); | ||
|
||
while (true) | ||
{ | ||
if (game.CurrentPhase == null) | ||
{ | ||
switch (game.CurrentPhaseId) | ||
{ | ||
case StackEggPhase.Id.WonTheInternet: | ||
Console.WriteLine("Congratulations, your site has won the internet!"); | ||
break; | ||
case StackEggPhase.Id.Failed: | ||
Console.WriteLine("Oops, your site was shut down."); | ||
break; | ||
} | ||
return; | ||
} | ||
|
||
var sb = new StringBuilder(); | ||
sb.AppendFormat("{0} day{1} elapsed, your Site is ", game.DaysElapsed, game.DaysElapsed == 1 ? "" : "s"); | ||
switch (game.CurrentPhaseId) | ||
{ | ||
case StackEggPhase.Id.PrivateBeta: | ||
sb.Append("in private beta"); | ||
break; | ||
case StackEggPhase.Id.PublicBeta: | ||
sb.Append("in public beta"); | ||
break; | ||
case StackEggPhase.Id.Launched: | ||
sb.Append("fully graduated"); | ||
break; | ||
} | ||
sb.AppendFormat(", phase progress: {0}%", (int)(game.GetPhaseProgress() * 100)); | ||
sb.AppendLine(); | ||
sb.AppendLine("Site stats:"); | ||
foreach (var stat in game.CurrentPhase.AvailableStats) | ||
{ | ||
var exact = game.Stats[stat]; | ||
var hearts = StackEggGame.HeartRound(exact); | ||
sb.AppendFormat(" {0, -10} {1}{2}", stat, new String('#', hearts), new String('.', 4 - hearts)); | ||
if (StackEggGame.HeartRoundExtended(exact) < 0) | ||
sb.Append(" (dangerously low!)"); | ||
sb.AppendLine(); | ||
} | ||
if (game.ModeratorFlags > 0) | ||
{ | ||
sb.AppendLine(); | ||
sb.AppendLine(" Mod flags " + game.ModeratorFlags); | ||
} | ||
|
||
sb.AppendLine(); | ||
if (game.IsFailing) | ||
{ | ||
sb.AppendLine("Your Site is on the verge of being shut down!"); | ||
sb.AppendLine("Only flagging for moderator attention can save it now."); | ||
sb.AppendLine(); | ||
} | ||
|
||
sb.AppendLine("Choose your action:"); | ||
|
||
foreach (var action in game.AvailableActions()) | ||
{ | ||
sb.AppendFormat("{0}: {1}", (int)action, action); | ||
sb.AppendLine(); | ||
} | ||
sb.AppendLine("q: Quit"); | ||
|
||
Console.Write(sb.ToString()); | ||
|
||
var validAction = false; | ||
StackEggAction chosenAction = StackEggAction.Nothing; | ||
|
||
while (!validAction) | ||
{ | ||
var s = Console.ReadLine(); | ||
if (s == "q" || s == "Q") | ||
{ | ||
Console.WriteLine("Good bye."); | ||
return; | ||
} | ||
else | ||
{ | ||
int num; | ||
if (int.TryParse(s, out num)) | ||
{ | ||
chosenAction = (StackEggAction)num; | ||
if (game.ActionIsLegal(chosenAction)) | ||
validAction = true; | ||
} | ||
} | ||
if (!validAction) | ||
Console.WriteLine("That's not a valid action, choose again:"); | ||
} | ||
Console.WriteLine(); | ||
Console.WriteLine(); | ||
game.AdvanceDay(chosenAction); | ||
} | ||
} | ||
} | ||
} |
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,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("StackEgg")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("Stack Exchange Inc.")] | ||
[assembly: AssemblyProduct("StackEgg")] | ||
[assembly: AssemblyCopyright("Copyright © Stack Exchange Inc. 2015")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("1ac6139c-7415-4295-8d9d-488b7db7e0d8")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
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,63 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{DA42D659-D5F3-47D8-958E-0555A499B40A}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>StackEgg</RootNamespace> | ||
<AssemblyName>StackEgg</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="StackEggAction.cs" /> | ||
<Compile Include="StackEggGame.cs" /> | ||
<Compile Include="StackEggPhase.cs" /> | ||
<Compile Include="StackEggStat.cs" /> | ||
<Compile Include="StackEggStatInfluence.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</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,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace StackEgg | ||
{ | ||
public enum StackEggAction | ||
{ | ||
Nothing = 0, | ||
|
||
// the follwing five are the "base actions" | ||
Ask, | ||
Answer, | ||
Upvote, | ||
Downvote, | ||
Close, | ||
|
||
FlagForModerator | ||
} | ||
} |
Oops, something went wrong.