initial commit =u=

This commit is contained in:
Lynne Megido 2020-09-10 02:59:50 +10:00
commit 2ee8bf73ec
Signed by: lynnesbian
GPG Key ID: F0A184B5213D9F90
6 changed files with 345 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
bin/
obj/
wikicreachia.json

27
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,27 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/wikicreachia.dll",
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}

42
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,42 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/wikicreachia.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/wikicreachia.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/wikicreachia.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}

66
Creacher.cs Normal file
View File

@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
namespace wikicreachia {
enum Locomotion {
None,
Walker,
Swimmer,
Hopper,
Flier,
Slitherer,
Incher
}
enum RelativeElevation {
Below,
At,
Above
}
class Creacher {
public string name { get; set; }
public string biome { get; set; }
public int footsies { get; set; }
public Locomotion locomotion { get; set; }
public RelativeElevation elevation { get; set; }
public Creacher(string name, int footsies, string biome, Locomotion locomotion, RelativeElevation elevation) {
this.name = name;
this.footsies = footsies;
this.locomotion = locomotion;
this.elevation = elevation;
}
public Creacher() {
// empty constructor for deserialisation
}
public override string ToString() {
var rng = new Random();
string RandomItem(List<string> list) {
return list[rng.Next(list.Count)];
}
string RandomCompliment() {
return RandomItem(new List<string> { "wonderful", "gorgeous", "spectacular", "iconic", "precious", "amazing", "incredible", "wondrous", "fantastic", "impeccable", "admirable", "long" });
}
string output = RandomItem(new List<string> { "Coming up next, we have", "And here we have", "Oh look, it's", "Here comes that", "Look out! It's" });
output += $" {this.name}! With ";
if (this.footsies > 5) {
output += $"a whopping {this.footsies} footsies";
}
else if (this.footsies > 0) {
output += $"{this.footsies} footsies";
}
else {
output += "not one footsy in sight";
}
output += $", this {RandomCompliment()} creacher ";
output += RandomItem(new List<string> { "usually finds itself in the", "makes its home in the", "truly rules the", "will often be found in the", "loves the", "can't get enough of the", "finds itself most comfortable in the" });
output += $" {this.biome}. The {this.name} is a {RandomCompliment()} {this.locomotion}, usually found {this.elevation.ToString().ToLower()} sea level. ";
output += RandomItem(new List<string> { "Isn't it", "Truly", "Simply", "Absolutely", "Definitively", "Inspiringly", "Indescribably" });
output += $" {RandomCompliment()}.";
return output;
}
}
}

199
Program.cs Normal file
View File

@ -0,0 +1,199 @@
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.IO;
using System.Text.RegularExpressions;
namespace wikicreachia {
class Program {
static void Main(string[] args) {
(string major, int minor) status = ("base", 0);
var creachers = new Dictionary<string, Creacher>();
var userCreacher = new Dictionary<string, object>();
string prompt = "";
string input;
string inputLower;
bool readKey;
Regex inputTrimmer = new Regex(@" *(.+) *");
if (File.Exists("wikicreachia.json")) {
using (var sr = new StreamReader("wikicreachia.json")) {
creachers = JsonSerializer.Deserialize<Dictionary<string, Creacher>>(sr.ReadToEnd());
}
}
while (true) {
readKey = false;
switch (status.major) {
case "base":
prompt = "Welcome to Wikicreachia! Type 'help' for help, or 'q' to quit.";
break;
case "add":
if (status.minor <= 2) {
string[] prompts = {
"Input the name of your creacher, or 'c' to cancel.",
"Input the desired number of footsies (number).",
"Input the biome your creacher inhabits most often (freeform text).",
};
prompt = prompts[status.minor];
}
else if (status.minor == 3) {
prompt = "Press the number corresponding to your creacher's primary method of locomotion:";
foreach (Locomotion option in Enum.GetValues(typeof(Locomotion))) {
prompt += $"\n{(int)option + 1}. {option}";
}
readKey = true;
}
else if (status.minor == 4) {
prompt = "Press the number corresponding to the elevation level your creacher is usually found at:\n1. Below sea level\n2. At sea level\n3. Above sea level";
readKey = true;
}
break;
default:
prompt = $"Unknown status {status.major}!";
break;
}
Console.Write($"\n{prompt}\n> ");
if (readKey) {
input = Console.ReadKey().KeyChar.ToString();
Console.WriteLine(); // insert a newline after the character
}
else {
input = Console.ReadLine();
if (input.Length > 0) {
input = inputTrimmer.Match(input).Groups[1].Value; // trim leading/traling whitespace
}
}
inputLower = input.ToLower();
// general cases - commands that can be used at any time, such as "quit"
if (String.IsNullOrWhiteSpace(input)) {
Console.WriteLine("I can't hear you!");
continue;
}
if (inputLower == "q" || inputLower == "quit") {
Console.WriteLine("Thanks for using WikiCreachia!");
using (var sw = new StreamWriter("wikicreachia.json")) {
sw.Write(JsonSerializer.Serialize(creachers));
}
return;
}
else if (new List<string> { "h", "help", "?" }.Contains(inputLower)) {
Console.WriteLine("WikiCreachia is a program for creating and viewing info about creachers.");
Console.WriteLine("To add a new creacher, type 'add'.");
Console.WriteLine("To view info about a creacher, type its name.");
Console.WriteLine("To see the list of creachers, type 'list'.");
Console.WriteLine();
continue;
}
// specific cases - commands that depend on status.major
if (status.major == "base") {
if (input == "add") {
status.major = "add";
continue;
}
else if (input == "list") {
if (creachers.Count == 0) {
Console.WriteLine("We don't have even a single creacher! 0uo\nWhy not crete one?");
}
else {
Console.WriteLine("Here comes the creacher parade!");
foreach (Creacher entry in creachers.Values) {
Console.WriteLine(entry);
}
}
}
else if (creachers.ContainsKey(input)) {
Console.WriteLine(creachers[input]);
}
else {
Console.WriteLine($"I don't have any info on \"{input}\".");
}
}
else if (status.major == "add") {
if (input == "c") {
Console.WriteLine("Creacher creation cancelled.");
status.major = "base";
continue;
}
if (status.minor == 0) {
if (creachers.ContainsKey(input)) {
Console.WriteLine("Such a creacher already exists! 0uo");
}
else {
// create new dict to ensure all values are empty
userCreacher = new Dictionary<string, object>();
userCreacher["name"] = input;
status.minor++;
}
}
else if (status.minor == 1) {
if (int.TryParse(input, out int footsies) && footsies >= 0) {
userCreacher["footsies"] = footsies;
status.minor++;
}
else {
Console.WriteLine("Please enter a valid number.");
}
}
else if (status.minor == 2) {
userCreacher["biome"] = input;
status.minor++;
}
else if (status.minor == 3) {
if (int.TryParse(input, out int choice) && Enum.IsDefined(typeof(Locomotion), choice - 1)) {
userCreacher["locomotion"] = (Locomotion)choice - 1;
status.minor++;
}
else {
Console.WriteLine("Invalid choice - please try again.");
}
}
else if (status.minor == 4) {
if (int.TryParse(input, out int choice) && Enum.IsDefined(typeof(RelativeElevation), choice - 1)) {
userCreacher["elevation"] = (RelativeElevation)choice - 1;
// try to create the new creacher
creachers.Add(
(string)userCreacher["name"], new Creacher(
(string)userCreacher["name"],
(int)userCreacher["footsies"],
(string)userCreacher["biome"],
(Locomotion)userCreacher["locomotion"],
(RelativeElevation)userCreacher["elevation"]
)
);
Console.WriteLine("Added {0}!", userCreacher["name"]);
using (var sw = new StreamWriter("wikicreachia.json")) {
sw.Write(JsonSerializer.Serialize(creachers));
}
status.major = "base";
status.minor = 0;
}
else {
Console.WriteLine("Invalid choice - please try again.");
}
}
}
}
}
}
}

8
wikicreachia.csproj Normal file
View File

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