Web Development – Case-Sensitivity

My client’s final website was ready to be deployed. Everything was going according to plan. The team had put several hours of meetings into this final product. After getting some great feedback on each iteration of the site, we were happy and ready to show it to the world. Moments after deploying the site, however, I noticed that a few bits of media (some images and a couple HTML5-embedded videos) were not being found by the browser, despite other images on the site being found without any problems. I knew I needed to solve this problem as quickly as possible!

But what could the problem be? My final development tests all worked. My development machine was running Windows and I used a small Node.js server to host the site and test it on several devices and browsers. Everything seemed fine—until I deployed it to the Web host’s server. I inspected the img tags for the elusive images and I noticed something interesting.

While my code read something like this…

<img src="image.jpg">

…the name of the corresponding file was image.JPG, with a capitalized file extension. While my Windows testing environment never complained about a file extension’s case, the Web server’s Unix-like OS was of course case-sensitive. I changed the file extension to match its lowercase attribute value in the code and the media was found by the browser. All was well, though for next time…there’s a module (perhaps more than a few) for that!

LRDL2 – Creating a Roguelike Engine – Part 2 – A TileMap

<-Take me to Part 1!                                   Take me to Part 3!->

We have a Tile class and a few derived classes, but we need to organize them somehow into a “map” the player can navigate. We can use an array for this–essentially we arrange our tiles of content (floors with monsters, walls, floor with a player, etc.) into a miniature “level” with the map of tiles having a maximum width and height. LRDL2 uses a 2D rectangular array to hold the tiles that are written to the console. The Map property is the container for this array. It also has a print method that renders this view. Since it is a very light console application, having a dedicated Model-View-Controller architecture might not be necessary, though that is still on the table, especially if the code base grows[Edit: MVC is now on the table]! For now, the print class simply writes the symbols for each tile directly to the console to give the user a representation of the game world (see the PrintMap method below). The current repository for this project can be found here.


/// <summary>
/// A 2D map holding floor tiles.
/// </summary>
public class TileMap
{
  /// <summary>
  /// Creates the floor tiles for the engine.
  /// </summary>
  public Tile[,] Map { get; set; }

  /// <summary>
  /// Creates a tile map of the specified dimensions.
  /// </summary>
  public TileMap ()
  {
    //Initialize "blank" floor of tiles of the preset dimensions.
    Map = new Tile[Configuration.MapWidth, Configuration.MapHeight];

    //Instantiate each Tile for this TileMap with a FloorTile as default.
    for (int width = 0; width < Configuration.MapWidth; width++)
    {
      for (int height = 0; height < Configuration.MapHeight; height++)
      {
        Map[width, height] = new FloorTile();
      }
    }
  }

  /// <summary>
  /// Prints the contents of Map directly to console.
  /// </summary>
  public void PrintMap ()
  {
    //Manually printing the TileMap
    for (int height = 0; height < Configuration.MapHeight - 1; height++)
    {
      for (int width = 0; width < Configuration.MapWidth - 1; width++)
      {
        Console.Write(Map[width, height].MySymbol);

        if (width == Configuration.MapWidth - 2)
        {
          Console.WriteLine();
        }
      }
    }
  }
}

 

<-Take me to Part 1!                                   Take me to Part 3!->

 

 

LRDL2 – Creating a Roguelike Engine – Part 1 – Design and Tiles

Take me to Part 2!->

Roguelikes are a genre of games based on the classic game Rogue. They usually include random generation, permanent death, and turn-based movement/combat, though there are many more contenders for inclusion here. LRDL2 is a roguelike engine that will run in a console window and allow players to traverse random dungeons looking for loot, talking to characters, and fighting and scavenging for survival.

Choice of Tech: C#. Though it’s built as an ASP.NET Core project (in case heavier Web functionality is needed), it’s currently using only .NET/C# conventions. This choice of ASP.NET Core is primarily motivated by the fact that it leaves room for some Web functionality if development goes that way, though I think plain C#/.NET is already showing some benefits, even relative to its older cousin Java (Console.Clear() is very convenient!).

Design Philosophy: LRDL2 is a roguelike engine designed to give developers a template to use for their own custom roguelikes. In roguelike fashion, the engine is built for games using the console window, though output for other formats that could be more easily plugged into a GUI might be useful down the road as well. The base engine will include basics for creating maps, adding layers, loot, enemies, player control, and a longest-lived/high score table. The engine will be based on “tiles” which are essentially blocks of content that serve as the basic unit of the game’s movement and display. One tile may be a wall, or another, a section of floor. A tile might also contain things, such as a your player, a monster, a fellow traveler, or loot (project README as of this writing).

You can find this project here.

Creating Tiles: Tiles are an abstract class which allow tiles such as FloorTile and WallTile to inherit fields but still retain certain differences in implementation (such as different default values for MySymbol in the derived classes’ default constructors (see below).

public abstract class Tile
{
  public char MySymbol { get; set; }
  public ConsoleColor MyColor { get; set; }
}

public class FloorTile : Tile
{
  public FloorTile()
  {
    MySymbol = '.';
    MyColor = ConsoleColor.DarkGray;
  }
}

public class WallTile : Tile
{
  public WallTile()
  {
    MySymbol = '#';
    MyColor = ConsoleColor.Gray;
  }
}

Tutoring Programming: Some Notes

Computer programming is a fairly logical activity, right? We proceed step-wise (or at least piecemeal) using a finite set of tools to create a virtual machine that accomplishes…something. But how do we teach programming to a newcomer? Do we assume they have come in to the office with prior programming experience? Do we assume they think about the problem the same way we do? The answer to the last two questions should generally be no.

Do we assume they have come in to the office with prior programming experience?

We should always try to get a grasp on the most fundamental programming issue the learner needs help with as soon as possible. Many of us forget what it is like to be a learner—we teach a->b while assuming a. In my experience, total newcomers are understandably confused by why we currently wrangle with computer memory in languages like C to do simple tasks. One place to start is to remind them that solving problems with computer programming is often not purely logical—our solutions must conform to the rules of whatever language we are using, limitations of our machine’s memory, and many other factors. Often our solutions are approximations. Once they hear that there is no magical undertone to be attuned to in programming and it’s more a matter of study (and practice), the worry about programming usually diminishes a bit!

Do we assume they think about the problem the same way we do?

A student’s first coding exposure is probably not the best time to rant too harshly about overly-busy functions. If their program is one very busy function it’s often best to focus on helping them understand that function, with a passing mention that separating functionality out will be unavoidable as their programs get more complex. Building something that works and seeing their virtual machine complete its tasks is usually a much better alternative (and motivator!) than being stylistically perfect—at least at this stage.

Simple Recursion

Recursion in programming means a method calls itself. To build a method like this, you need a base case—a value for which we know the answer, and that forms the basis of the rest of the recursion’s general cases (cases that we process in order to reduce our problem to a base case). A method calling itself is a pretty wild concept, but it makes much more sense once we get a few basic recursive techniques under our belt.

Read More