added JSON dict reading; working on JSON writing

This commit is contained in:
Pecha 2020-09-09 19:56:39 +10:00
parent 570560a202
commit 6cdec74132
17 changed files with 164 additions and 37 deletions

View File

@ -1,11 +1,14 @@
using System;
using Newtonsoft.Json;
namespace creachopedia {
class Creacher {
public string name {get; set;}
// public int kingdom;
// public string description;
private int _footsies;
[JsonProperty]
private int _footsies { get; set; }
[JsonIgnore]
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";
@ -19,7 +22,7 @@ namespace creachopedia {
}
public void Step(){
if(this.footsies == 0){
Console.WriteLine("I cannot stip or step! I have 0 footsies!!!!");
Console.WriteLine("I cannot stip or step! I have 0 footsies! I am however quite powerful in my own way 0u0");
Console.WriteLine("Silly creacher...");
} else {
Console.WriteLine($"The {this.name} steps, and rather well I might add.");

View File

@ -1,41 +1,68 @@
using System;
using System.Collections.Generic;
using System.Threading;
using Newtonsoft.Json;
using System.IO;
namespace creachopedia {
class Program {
static void Main(string[] args) {
var creacherdict = new Dictionary<string, Creacher>();
creacherdict.Add("paca", new GroundCreacher("paca", 4));
creacherdict.Add("llama", new GroundCreacher("llama", 4));
creacherdict.Add("stingray", new WaterCreacher("stingray", 0));
while (true) {
Console.WriteLine("Please input a creacher name, or (q) to quit 0u0");
string userin = Console.ReadLine();
if (creacherdict.ContainsKey(userin)) {
creacherdict[userin].Introduce();
creacherdict[userin].Step();
creacherdict[userin].footsies = 2;
}
else if(userin == "q"){
Console.WriteLine("Thank you for using the CreachoPedia!!!!");
return;
}
else if(userin == "heenlo!" || userin == "henlo" || userin == "heenlo"){
Console.WriteLine("Well heenlo to you too! 0u0");
}
else {
Console.WriteLine("I don't know what that is! What on boo Earth?!!?!?!?");
}
Console.WriteLine("");
Thread.Sleep(1000);
}
class Program {
static void Main(string[] args) {
var creacherdict = JsonConvert.DeserializeObject<Dictionary<string, Creacher>>(File.ReadAllText("creachopedia.json"));
// creacherdict.Add("paca", new GroundCreacher("paca", 4));
// creacherdict.Add("llama", new GroundCreacher("llama", 4));
// creacherdict.Add("stingray", new WaterCreacher("stingray", 0));
// var jsonsettings = new JsonSerializerSettings{
// TypeNameHandling = TypeNameHandling.Auto
// };
// string jsonstring = JsonConvert.SerializeObject(creacherdict, Formatting.Indented, jsonsettings);
// File.WriteAllText("creachopedia.json", jsonstring);
while (true) {
var status = "base";
Console.WriteLine("Please input a creacher name, or (q) to quit 0u0");
string userin = Console.ReadLine();
string luserin = userin.ToLower();
if(userin == "q"){
Console.WriteLine("Thank you for using the CreachoPedia, please come again!!!!");
status = "quit";
}
if (status == "base"){
if (creacherdict.ContainsKey(userin)) {
creacherdict[userin].Introduce();
creacherdict[userin].Step();
}
else if(luserin == "heenlo!" || luserin == "henlo" || luserin == "heenlo" || luserin == "henlo!"){
Console.WriteLine("Well heenlo to you too! 0u0");
}
else if(userin == "*pats*"){
Console.WriteLine("Oh! Thank you!");
}
else if(userin == "a"){
Console.WriteLine("Please enter a new creacher! Or type (b) for previous category, or (q) to cancel addition entirely.");
status = "add";
}
}
else if (status == "add") {
} else if (status == "quit") {
return;
}
else {
Console.WriteLine($"I don't know what {userin} is! What on boo Earth?!!?!?!?");
}
Console.WriteLine("");
Thread.Sleep(1000);
}
}
}
}

Binary file not shown.

View File

@ -7,9 +7,20 @@
"targets": {
".NETCoreApp,Version=v3.1": {
"creachopedia/1.0.0": {
"dependencies": {
"Newtonsoft.Json": "12.0.3"
},
"runtime": {
"creachopedia.dll": {}
}
},
"Newtonsoft.Json/12.0.3": {
"runtime": {
"lib/netstandard2.0/Newtonsoft.Json.dll": {
"assemblyVersion": "12.0.0.0",
"fileVersion": "12.0.3.23909"
}
}
}
}
},
@ -18,6 +29,13 @@
"type": "project",
"serviceable": false,
"sha512": ""
},
"Newtonsoft.Json/12.0.3": {
"type": "package",
"serviceable": true,
"sha512": "sha512-6mgjfnRB4jKMlzHSl+VD+oUc1IebOZabkbyWj2RiTgWwYPPuaK1H97G1sHqGwPlS5npiF5Q0OrxN1wni2n5QWg==",
"path": "newtonsoft.json/12.0.3",
"hashPath": "newtonsoft.json.12.0.3.nupkg.sha512"
}
}
}

View File

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

View File

@ -1,3 +1,20 @@
{
"paca": {
"$type": "creachopedia.GroundCreacher, creachopedia",
"type": "creacher of the land",
"name": "paca",
"_footsies": 4
},
"llama": {
"$type": "creachopedia.GroundCreacher, creachopedia",
"type": "creacher of the land",
"name": "llama",
"_footsies": 4
},
"stingray": {
"$type": "creachopedia.WaterCreacher, creachopedia",
"type": "creacher of the water",
"name": "stingray",
"_footsies": 0
}
}

View File

@ -9,3 +9,5 @@
/home/petra/Documents/Code/C#/creachopedia/obj/Debug/netcoreapp3.1/creachopedia.AssemblyInfo.cs
/home/petra/Documents/Code/C#/creachopedia/obj/Debug/netcoreapp3.1/creachopedia.dll
/home/petra/Documents/Code/C#/creachopedia/obj/Debug/netcoreapp3.1/creachopedia.pdb
/home/petra/Documents/Code/C#/creachopedia/bin/Debug/netcoreapp3.1/Newtonsoft.Json.dll
/home/petra/Documents/Code/C#/creachopedia/obj/Debug/netcoreapp3.1/creachopedia.csproj.CopyComplete

View File

@ -1,5 +1,5 @@
{
"version": 1,
"dgSpecHash": "viHAytpAeRg2rkbruTDcJ80nPro+N0eKDnZUSYFqFnBGsO01NYPadOgHvE4Ch/dYKOVhrBHUt+HiRD1b/WDXmQ==",
"dgSpecHash": "JCtwJT93h17o7iSWXfYXu/UDvwAFtE0LJP/QdZxWN5h/fsMhZ5JJzGNmdfs2YFbkbtCv3zTB0K/E3q4+9ORe1g==",
"success": true
}

View File

@ -35,6 +35,12 @@
},
"frameworks": {
"netcoreapp3.1": {
"dependencies": {
"Newtonsoft.Json": {
"target": "Package",
"version": "[12.0.3, )"
}
},
"imports": [
"net461",
"net462",

View File

@ -1,11 +1,55 @@
{
"version": 3,
"targets": {
".NETCoreApp,Version=v3.1": {}
".NETCoreApp,Version=v3.1": {
"Newtonsoft.Json/12.0.3": {
"type": "package",
"compile": {
"lib/netstandard2.0/Newtonsoft.Json.dll": {}
},
"runtime": {
"lib/netstandard2.0/Newtonsoft.Json.dll": {}
}
}
}
},
"libraries": {
"Newtonsoft.Json/12.0.3": {
"sha512": "6mgjfnRB4jKMlzHSl+VD+oUc1IebOZabkbyWj2RiTgWwYPPuaK1H97G1sHqGwPlS5npiF5Q0OrxN1wni2n5QWg==",
"type": "package",
"path": "newtonsoft.json/12.0.3",
"files": [
".nupkg.metadata",
".signature.p7s",
"LICENSE.md",
"lib/net20/Newtonsoft.Json.dll",
"lib/net20/Newtonsoft.Json.xml",
"lib/net35/Newtonsoft.Json.dll",
"lib/net35/Newtonsoft.Json.xml",
"lib/net40/Newtonsoft.Json.dll",
"lib/net40/Newtonsoft.Json.xml",
"lib/net45/Newtonsoft.Json.dll",
"lib/net45/Newtonsoft.Json.xml",
"lib/netstandard1.0/Newtonsoft.Json.dll",
"lib/netstandard1.0/Newtonsoft.Json.xml",
"lib/netstandard1.3/Newtonsoft.Json.dll",
"lib/netstandard1.3/Newtonsoft.Json.xml",
"lib/netstandard2.0/Newtonsoft.Json.dll",
"lib/netstandard2.0/Newtonsoft.Json.xml",
"lib/portable-net40+sl5+win8+wp8+wpa81/Newtonsoft.Json.dll",
"lib/portable-net40+sl5+win8+wp8+wpa81/Newtonsoft.Json.xml",
"lib/portable-net45+win8+wp8+wpa81/Newtonsoft.Json.dll",
"lib/portable-net45+win8+wp8+wpa81/Newtonsoft.Json.xml",
"newtonsoft.json.12.0.3.nupkg.sha512",
"newtonsoft.json.nuspec",
"packageIcon.png"
]
}
},
"libraries": {},
"projectFileDependencyGroups": {
".NETCoreApp,Version=v3.1": []
".NETCoreApp,Version=v3.1": [
"Newtonsoft.Json >= 12.0.3"
]
},
"packageFolders": {
"/home/petra/.nuget/packages/": {}
@ -41,6 +85,12 @@
},
"frameworks": {
"netcoreapp3.1": {
"dependencies": {
"Newtonsoft.Json": {
"target": "Package",
"version": "[12.0.3, )"
}
},
"imports": [
"net461",
"net462",