fixed a couple of minor issues

This commit is contained in:
Pecha 2020-09-27 16:50:09 +10:00
parent dd7ab78096
commit 500ae171fc
5 changed files with 73 additions and 47 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
bin/
obj/

View file

@ -2,7 +2,7 @@ using System;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace creachopedia { namespace creachopedia {
enum Locomotion { internal enum Locomotion {
None, //barnacles, plants and so on None, //barnacles, plants and so on
Walker, Walker,
Swimmer, Swimmer,
@ -11,22 +11,22 @@ namespace creachopedia {
Slitherer, Slitherer,
Incher // snails et al Incher // snails et al
} }
enum SurfaceRel {
internal enum SurfaceRel {
Below, Below,
At, At,
Above Above
} }
class Creacher {
internal class Creacher {
public string name {get; set;} public string name {get; set;}
// public int kingdom;
// public string description;
[JsonProperty] [JsonProperty]
private int _footsies { get; set; } private int _footsies { get; set; }
[JsonIgnore] [JsonIgnore]
public int footsies {get { return this._footsies; } set { Console.WriteLine("What do you think you're doing?! 0uo Leave those footsies alone!!!"); }} public int footsies {get { return this._footsies; } set { Console.WriteLine("What do you think you're doing?! 0uo Leave those footsies alone!!!"); }}
public string type = "simple creacher"; public string type = "simple creacher";
Locomotion locoStyle {get; set;} private Locomotion locoStyle {get; set;}
SurfaceRel height {get; set;} private SurfaceRel height {get; set;}
public Creacher(string name, int footsyCount = 4, string biome = "land", Locomotion locoStyle = Locomotion.Walker, SurfaceRel height = SurfaceRel.At) { public Creacher(string name, int footsyCount = 4, string biome = "land", Locomotion locoStyle = Locomotion.Walker, SurfaceRel height = SurfaceRel.At) {
this.name = name; this.name = name;

View file

@ -62,41 +62,40 @@ namespace creachopedia {
string userin = Console.ReadLine(); string userin = Console.ReadLine();
string luserin = userin.ToLower(); string luserin = userin.ToLower();
if (status == "base") { switch (status)
if (luserin == "q" || luserin == "quit") { {
case "base" when luserin == "q" || luserin == "quit":
Console.WriteLine("Thank you for using the CreachoPedia, please come again!!!!"); Console.WriteLine("Thank you for using the CreachoPedia, please come again!!!!");
return; return;
} case "base" when creacherdict.ContainsKey(userin):
if (creacherdict.ContainsKey(userin)) {
creacherdict[userin].Introduce(); creacherdict[userin].Introduce();
creacherdict[userin].Step(); creacherdict[userin].Step();
} break;
else if (luserin == "heenlo!" || luserin == "henlo" || luserin == "heenlo" || luserin == "henlo!") { case "base" when luserin == "heenlo!" || luserin == "henlo" || luserin == "heenlo" || luserin == "henlo!":
Console.WriteLine("Well heenlo to you too! 0u0"); Console.WriteLine("Well heenlo to you too! 0u0");
} break;
else if (userin == "*pats*") { case "base" when userin == "*pats*":
Console.WriteLine("Oh! Thank you!"); Console.WriteLine("Oh! Thank you!");
} break;
else if (luserin == "a" || luserin == "add") { case "base" when luserin == "a" || luserin == "add":
status = "add"; status = "add";
} break;
else { case "base":
Console.WriteLine($"I don't know what {userin} is! What on boo Earth?!!?!?!?"); Console.WriteLine($"I don't know what {userin} is! What on boo Earth?!!?!?!?");
} break;
} case "add" when luserin == "x":
else if (status == "add") {
if (luserin == "x") {
substatus--; substatus--;
luserin = ""; luserin = "";
} break;
else if (luserin == "q") { case "add" when luserin == "q":
status = "base"; status = "base";
} break;
else if (substatus == 0) { case "add" when substatus == 0:
status = "base"; status = "base";
substatus = 1; substatus = 1;
} break;
else if (substatus == 1) { case "add" when substatus == 1:
{
tempdict = new Dictionary<string, string>(); tempdict = new Dictionary<string, string>();
var namematcher = new Regex(@"[^ ].[A-Za-z\- ]{2,}(?<! )"); var namematcher = new Regex(@"[^ ].[A-Za-z\- ]{2,}(?<! )");
if (namematcher.Match(userin).Success) { if (namematcher.Match(userin).Success) {
@ -106,8 +105,11 @@ namespace creachopedia {
else { else {
Console.WriteLine("Sorry, this name is invalid, please try again."); Console.WriteLine("Sorry, this name is invalid, please try again.");
} }
break;
} }
else if (substatus == 2) { case "add" when substatus == 2:
{
if (int.TryParse(userin, out int footsiecounter)) { if (int.TryParse(userin, out int footsiecounter)) {
tempdict.Add("footsies", userin); tempdict.Add("footsies", userin);
if (footsiecounter >= 5) { if (footsiecounter >= 5) {
@ -121,12 +123,15 @@ namespace creachopedia {
else { else {
Console.WriteLine("Sorry, this is not a number!"); Console.WriteLine("Sorry, this is not a number!");
} }
break;
} }
else if (substatus == 3) { case "add" when substatus == 3:
tempdict.Add("biome", luserin); tempdict.Add("biome", luserin);
substatus ++; substatus ++;
} break;
else if (substatus == 4) { case "add" when substatus == 4:
{
var locomatcher = new Regex(@"^[nwshfli]$"); var locomatcher = new Regex(@"^[nwshfli]$");
if (locomatcher.Match(userin).Success) { if (locomatcher.Match(userin).Success) {
tempdict.Add("locomethod", userin); tempdict.Add("locomethod", userin);
@ -135,8 +140,11 @@ namespace creachopedia {
else { else {
Console.WriteLine("Sorry, this type is invalid, please try again."); Console.WriteLine("Sorry, this type is invalid, please try again.");
} }
break;
} }
else if (substatus == 5) { case "add" when substatus == 5:
{
var relsurfacematcher = new Regex(@"^[abv]$"); var relsurfacematcher = new Regex(@"^[abv]$");
if (relsurfacematcher.Match(luserin).Success) { if (relsurfacematcher.Match(luserin).Success) {
tempdict.Add("surfacerel", luserin); tempdict.Add("surfacerel", luserin);
@ -145,19 +153,25 @@ namespace creachopedia {
else { else {
Console.WriteLine("Sorry, this surface relation did not match one of the three listed above. Please try again."); Console.WriteLine("Sorry, this surface relation did not match one of the three listed above. Please try again.");
} }
}
else if (substatus == 6) { break;
Console.WriteLine("test0");
var tempcreach = new Creacher(tempdict["name"], int.Parse(tempdict["footsies"]), tempdict["biome"], (Locomotion)Enum.Parse(typeof(Locomotion), shortdefs[tempdict["locomethod"]]), (SurfaceRel)Enum.Parse(typeof(SurfaceRel), shortdefs[tempdict["surfacerel"]]));
creacherdict.Add(tempdict["name"], tempcreach);
File.WriteAllText("creachopedia.json", JsonConvert.SerializeObject(creacherdict, Formatting.Indented));
Console.WriteLine("Creacher adde! 0u0");
status = "base";
substatus = 1;
} }
// foreach (var i in tempdict) { // foreach (var i in tempdict) {
// Console.WriteLine("{0}:{1}", i.Key, i.Value); // Console.WriteLine("{0}:{1}", i.Key, i.Value);
// } // }
case "add":
{
if (substatus == 6) {
var tempcreach = new Creacher(tempdict["name"], int.Parse(tempdict["footsies"]), tempdict["biome"], (Locomotion)Enum.Parse(typeof(Locomotion), shortdefs[tempdict["locomethod"]]), (SurfaceRel)Enum.Parse(typeof(SurfaceRel), shortdefs[tempdict["surfacerel"]]));
creacherdict.Add(tempdict["name"], tempcreach);
File.WriteAllText("creachopedia.json", JsonConvert.SerializeObject(creacherdict, Formatting.Indented));
Console.WriteLine("Creacher added! 0u0");
status = "base";
substatus = 1;
}
break;
}
} }
Console.WriteLine(""); Console.WriteLine("");

View file

@ -5,8 +5,8 @@
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View file

@ -14,9 +14,19 @@
"name": "stingray", "name": "stingray",
"_footsies": 0 "_footsies": 0
}, },
"Snool": { "snool": {
"type": "creacher of the urban", "type": "creacher of the urban",
"name": "Snool", "name": "snool",
"_footsies": 1 "_footsies": 1
},
"aquapig": {
"type": "creacher of the sea",
"name": "aquapig",
"_footsies": 4
},
"croncher the crab": {
"type": "creacher of the sea",
"name": "croncher the crab",
"_footsies": 6
} }
} }