Skip to content

Instantly share code, notes, and snippets.

View ScottLilly's full-sized avatar

Scott Lilly ScottLilly

View GitHub Profile
@ScottLilly
ScottLilly / MainWindow.xaml
Created June 7, 2022 16:35
DataContext in 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:SOSCSRPG.ViewModels;assembly=SOSCSRPG.ViewModels"
d:DataContext="{d:DesignInstance viewModels:GameSession}"
mc:Ignorable="d"
FontSize="11pt"
Title="{Binding GameDetails.Title}" Height="768" Width="1024"
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 March 5, 2021 21:38
Lesson 18.5: Update game loading and saving
<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 July 26, 2022 00:17
Lesson 18.4: Adding Player Attributes to Living Entities
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 November 4, 2013 14:37
Sample of how to start building an RPG, with rooms that have different (and common) actions you can perform in them.
namespace BusinessObjects.RedditZorkQuestion
{
public class Bedroom : Room, ICanSleepHere
{
public Bedroom(string name) : base(name)
{
}
public void Sleep(Character character)
{
@ScottLilly
ScottLilly / SortedListWithFloorAndCeilingIntegerKey.cs
Created October 18, 2013 12:48
Specialized SortedList classes to let you search for the entry immediately before, or after, the requested key value.
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 October 14, 2013 14:02
Source code for my "How to build a fluent interface in C#" blog post.
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 October 11, 2013 18:40
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).
using System;
using System.Collections.Generic;
using System.Linq;
namespace BusinessObjects.RedditRPGQuestion
{
public class InventorySystem
{
private const int MAXIMUM_SPACES_IN_INVENTORY = 10;