Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions enumStruct/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;

namespace enumStruct
{
class Program
{
//Bunch of loosely related stuff in a struct.
public struct Monster
{
public string name;
public int health;
public int damage;
public Element element;
//Example type comparison
public static bool compareType(Element e1, Element e2)
{
if (e1 == Element.Fire)
{
if (e2 == Element.Water)
{
return "Fire is weak against water.";
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, for extra bonus points, how would you create an app, where the code is the same to play RockPaperScissors, but i get to choose what the "characters" are (ie, rock/paper/scissors, wate/fire/nature, cockroach/boot/nuclearBomb") etc ...


//etc, etc...
}

//etc, etc...


return null;
}

override
public string ToString()
{
return string.Format("{0}s have {1} health, do {2} damage and have {3} as their element.", name, health, damage, element);
}
}
//Rock, Paper, Scissors-esque elements.
public enum Element
{
Fire, Water, Nature
}

static void Main(string[] args)
{
Monster fireDragon = new Monster();
fireDragon.name = "Fire Dragon";
fireDragon.element = Element.Fire;

Monster kraken = new Monster();
kraken.name = "Kraken";
kraken.element = Element.Water;

Console.WriteLine(fireDragon);
Console.WriteLine("The Dragon and Kraken fight.");
Console.WriteLine(Monster.compareType(fireDragon.element, kraken.element));
}
}
}
8 changes: 8 additions & 0 deletions enumStruct/enumStruct.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

</Project>