mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-25 12:25:10 -08:00
8
20_Buzzword/csharp/Buzzword.csproj
Normal file
8
20_Buzzword/csharp/Buzzword.csproj
Normal file
@@ -0,0 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
25
20_Buzzword/csharp/Buzzword.sln
Normal file
25
20_Buzzword/csharp/Buzzword.sln
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.810.15
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Buzzword", "Buzzword.csproj", "{E342DEB2-F009-47FD-85F6-E84965EAAB56}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{E342DEB2-F009-47FD-85F6-E84965EAAB56}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E342DEB2-F009-47FD-85F6-E84965EAAB56}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E342DEB2-F009-47FD-85F6-E84965EAAB56}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E342DEB2-F009-47FD-85F6-E84965EAAB56}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {52F15A7F-671A-470D-91CE-F3B629B989B7}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
115
20_Buzzword/csharp/Program.cs
Normal file
115
20_Buzzword/csharp/Program.cs
Normal file
@@ -0,0 +1,115 @@
|
||||
using System;
|
||||
|
||||
namespace Buzzword
|
||||
{
|
||||
class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// Displays header.
|
||||
/// </summary>
|
||||
static void Header()
|
||||
{
|
||||
Console.WriteLine("Buzzword generator".PadLeft(26));
|
||||
Console.WriteLine("Creating Computing Morristown, New Jersey".PadLeft(15));
|
||||
Console.WriteLine();
|
||||
Console.WriteLine();
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
// Information for the user about possible key input.
|
||||
static string keys = "type a 'Y' for another phrase or 'N' to quit";
|
||||
|
||||
/// <summary>
|
||||
/// Displays instructions.
|
||||
/// </summary>
|
||||
static void Instructions()
|
||||
{
|
||||
Console.WriteLine("This program prints highly acceptable phrases in\n"
|
||||
+ "'educator-speak' that you can work into reports\n"
|
||||
+ "and speeches. Whenever a question mark is printed,\n"
|
||||
+ $"{keys}.");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine();
|
||||
Console.Write("Here's the first phrase:");
|
||||
}
|
||||
|
||||
static string[] Words = new[]
|
||||
{ "ability", "basal", "behavioral", "child-centered",
|
||||
"differentiated", "discovery", "flexible", "heterogenous",
|
||||
"homogeneous", "manipulative", "modular", "tavistock",
|
||||
"individualized", "learning", "evaluative", "objective",
|
||||
"cognitive", "enrichment", "scheduling", "humanistic",
|
||||
"integrated", "non-graded", "training", "vertical age",
|
||||
"motivational", "creative", "grouping", "modification",
|
||||
"accountability", "process", "core curriculum", "algorithm",
|
||||
"performance", "reinforcement", "open classroom", "resource",
|
||||
"structure", "facility", "environment" };
|
||||
|
||||
/// <summary>
|
||||
/// Capitalizes first letter of given string.
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns>string</returns>
|
||||
static string Capitalize(string input)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(input))
|
||||
return string.Empty;
|
||||
|
||||
return char.ToUpper(input[0]) + input[1..];
|
||||
}
|
||||
|
||||
// Seed has been calculated to get the same effect as in original,
|
||||
// at least in first phrase
|
||||
static readonly Random rnd = new Random(1486);
|
||||
|
||||
/// <summary>
|
||||
/// Generates random phrase from words available in Words array.
|
||||
/// </summary>
|
||||
/// <returns>String representing random phrase where first letter is capitalized.</returns>
|
||||
static string GeneratePhrase()
|
||||
{
|
||||
// Indexing from 0, so had to decrease generated numbers
|
||||
return $"{Capitalize(Words[rnd.Next(13)])} "
|
||||
+ $"{Words[rnd.Next(13, 26)]} "
|
||||
+ $"{Words[rnd.Next(26, 39)]}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles user input. On wrong input it displays information about
|
||||
/// valid keys in infinite loop.
|
||||
/// </summary>
|
||||
/// <returns>True if user pressed 'Y', false if 'N'.</returns>
|
||||
static bool Decision()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
Console.Write("?");
|
||||
var answer = Console.ReadKey();
|
||||
if (answer.Key == ConsoleKey.Y)
|
||||
return true;
|
||||
else if (answer.Key == ConsoleKey.N)
|
||||
return false;
|
||||
else
|
||||
Console.WriteLine($"\n{keys}");
|
||||
}
|
||||
}
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Header();
|
||||
Instructions();
|
||||
|
||||
while (true)
|
||||
{
|
||||
Console.WriteLine();
|
||||
Console.WriteLine(GeneratePhrase());
|
||||
Console.WriteLine();
|
||||
|
||||
if (!Decision())
|
||||
break;
|
||||
}
|
||||
|
||||
Console.WriteLine("\nCome back when you need help with another report!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user