Skip to content

Instantly share code, notes, and snippets.

Avatar

Scott Lilly ScottLilly

View GitHub Profile
View ConsoleUpdateExtensions.cs
public static class ConsoleUpdateExtensions
{
internal static readonly Dictionary<IConsole, Dictionary<string, Func>> LineUpdates
= new Dictionary<IConsole, Dictionary<string, Func>>();
public static Dictionary<string, Func> GetUpdates(this IConsole console) => LineUpdates.ContainsKey(console) ? LineUpdates[console] : null;
public static void AddLineUpdate(this IConsole console, string key, Func value)
{
if (!LineUpdates.ContainsKey(console))
{
LineUpdates.Add(console, new Dictionary<string, Func>());
@ScottLilly
ScottLilly / MainWindow.xaml
Created Mar 5, 2021
Lesson 18.5: Update game loading and saving
View MainWindow.xaml
<Window x:Class="WPFUI.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewModels="clr-namespace:Engine.ViewModels;assembly=Engine"
d:DataContext="{d:DesignInstance viewModels:GameSession}"
mc:Ignorable="d"
FontSize="11pt"
Title="{Binding GameDetails.Title}" Height="768" Width="1024"
@ScottLilly
ScottLilly / CharacterCreationViewModel.cs
Last active Feb 22, 2021
Lesson 18.4: Adding Player Attributes to Living Entities
View CharacterCreationViewModel.cs
using System.Collections.ObjectModel;
using System.Linq;
using Engine.Factories;
using Engine.Models;
using Engine.Services;
namespace Engine.ViewModels
{
public class CharacterCreationViewModel : BaseNotificationClass
{
@ScottLilly
ScottLilly / Bedroom.cs
Created Nov 4, 2013
Sample of how to start building an RPG, with rooms that have different (and common) actions you can perform in them.
View Bedroom.cs
namespace BusinessObjects.RedditZorkQuestion
{
public class Bedroom : Room, ICanSleepHere
{
public Bedroom(string name) : base(name)
{
}
public void Sleep(Character character)
{
@ScottLilly
ScottLilly / SortedListWithFloorAndCeilingIntegerKey.cs
Created Oct 18, 2013
Specialized SortedList classes to let you search for the entry immediately before, or after, the requested key value.
View SortedListWithFloorAndCeilingIntegerKey.cs
using System;
using System.Collections.Generic;
namespace DotNetToolBox.Collections
{
public class SortedListWithFloorAndCeilingIntegerKey<TV> : SortedList<Int32, TV>
{
#region Floor object methods
public int FloorIndexFor(Int32 searchKey)
@ScottLilly
ScottLilly / DeleteQueryWithGrammar.cs
Created Oct 14, 2013
Source code for my "How to build a fluent interface in C#" blog post.
View DeleteQueryWithGrammar.cs
using System.Collections.Generic;
using BuildAFluentInterface.Interfaces;
namespace BuildAFluentInterface
{
public class DeleteQueryWithGrammar : ICanAddCondition, ICanAddWhereValue, ICanAddWhereOrRun
{
private readonly string _tableName;
private readonly List<WhereCondition> _whereConditions = new List<WhereCondition>();
@ScottLilly
ScottLilly / InventorySystem.cs
Created Oct 11, 2013
C# code for inventory system that has a limited number of slots, and the ability to stack some items (with a different maximum size stack for different items).
View InventorySystem.cs
using System;
using System.Collections.Generic;
using System.Linq;
namespace BusinessObjects.RedditRPGQuestion
{
public class InventorySystem
{
private const int MAXIMUM_SPACES_IN_INVENTORY = 10;