Our Excel RPG has come a long way since we first drew a map onto a worksheet. We now have a structured world, a movable adventurer, independent monster objects and a game clock that determines when each creature can act. The inhabitants of Old Fort Approach have even started moving around on their own. Goblins wander through the ruins, and our wolf moves twice as quickly as a normal-speed adventurer. There is, however, one rather conspicuous limitation: none of these creatures can actually hurt anybody. A goblin can approach the player, but it cannot attack. Our adventurer has health and damage statistics, but those numbers don't affect the game. The wolf can act twice as frequently as the player, yet its speed offers little practical advantage beyond giving it more opportunities to wander around.
Today, we're going to change that. We'll introduce melee combat, allow creatures to inflict and receive damage, handle monster deaths and end the adventure when the player dies. We'll also expand our message system into a searchable, time-stamped event history, making it possible to follow what happened during a fight rather than seeing only the most recent attack. By the end of this instalment, our game will have its first complete combat loop. Monsters will be able to kill the player, the player will be able to kill monsters, and our turn scheduler will determine exactly when each attack takes place. We'll keep the actual combat calculations deliberately simple, as our focus is on establishing reliable relationships between character state, action scheduling, world rendering and the interface. More elaborate mechanics—armour, accuracy, critical hits, equipment and special abilities—can be introduced once that foundation is working.
The previous instalment also marked a change in how we're distributing the project. Alongside the instructional workbook and exported VBA modules, we are now providing a complete, playable macro-enabled version of the game at the end of each development milestone. Readers can therefore follow the implementation themselves or simply open the current build and see what we've created.
One of the most useful decisions we made in Part 5 was separating action scheduling from the actions themselves. Our turn engine doesn't need to know how a goblin decides where to move - it only needs to determine when the goblin may act and when it becomes eligible again. We'll follow the same principle for combat.
An attack is another action performed by an actor. It has a cost, changes the state of the world and may generate messages. Once the action is complete, the same turn engine calculates when the attacker may act again. This means a wolf with speed 200 can attack twice as frequently as an adventurer with speed 100, just as it can move twice as frequently. We don't need a special combat timer.
For our first implementation, every melee attack has the standard action cost of 1,000, and an actor's effective speed determines the delay before its next action. Our original creature statistics remain unchanged. The adventurer begins with 24 HP and deals four damage. A goblin has eight HP and deals two damage, while the wolf has eleven HP and deals three damage. Attacks will always hit for now, and damage will be fixed. A character with four damage therefore subtracts four HP from its target, unless the target has fewer than four HP remaining.
These are temporary combat-balance values, but they make the system particularly easy to test. We can predict the result of every attack and verify that the correct character's HP changes.
Our game already supports movement in eight directions, including diagonals. We'll use the same neighbourhood for melee combat. Any living creature in one of the eight tiles immediately surrounding an attacker can be targeted. We won't impose diagonal corner restrictions and, as a matter of fact, we are removing this restriction from the previous code. If two walls meet at a corner but the diagonal destination is otherwise traversable, a walking actor can pass between them. An actor can likewise attack a diagonally adjacent creature, regardless of the terrain forming that corner.
There is another important distinction: the terrain beneath a target does not determine whether it can be attacked. A bat flying above a river might occupy a tile that the adventurer cannot enter. A water-dwelling creature might inhabit a lake. Neither should automatically be protected from a melee attack merely because the player cannot walk onto its tile. We therefore keep movement permissions and attack permissions separate.
For ordinary movement, the destination must be traversable by the moving actor and must not be occupied by another living creature. For melee combat, the target must be a different, living actor in an adjacent tile.
Our initial walking monsters still use the ordinary IsTileWalkable rule when wandering. We'll extend movement permissions when we introduce creatures that can fly, swim or move through other kinds of terrain. For now, the combat engine itself is ready to attack such creatures regardless of their location's terrain.
We'll create a new standard VBA module named modCombat. Its purpose is to determine whether a melee attack is legal, apply damage and report the result. The module won't decide when the attacker acts, how monsters choose targets or how the game interface is displayed. Those responsibilities remain with the turn engine, actor system and interface modules we've already developed. This separation will become increasingly useful as we add combat mechanics.
First, add a function named CanMeleeAttack.
The function is intentionally uncomplicated. It first confirms that both actor objects exist, that neither has died and that the attacker and defender are not the same object, and then it calculates the relative X and Y distances between them. For a melee attack to be valid, neither distance may exceed one tile. The two actors must also occupy different positions. This is equivalent to checking whether the defender lies within the eight-cell neighbourhood surrounding the attacker.
Notice that we don't call IsTileWalkable, nor do we examine BlocksVision. Those properties belong to terrain traversal and perception, not this basic melee-distance calculation. We'll eventually introduce ranged attacks and other abilities, each with its own range and targeting requirements. Keeping the rules in a dedicated function means other modules won't have to reproduce those calculations.
Knowing that an attack is possible is only half the problem; we also need to calculate its effect. Add the following procedure to modCombat, beneath CanMeleeAttack.
The first meaningful operation is another call to CanMeleeAttack. Even if the calling procedure has already checked the attack, it's sensible to validate it again at the point where damage is actually applied. This makes the combat module usable by future AI, scripts and special actions without depending on every caller performing its own checks.
We then retrieve the attacker's damage and cap the amount actually inflicted at the defender's remaining HP. Suppose a goblin has only two HP remaining and the adventurer attacks for four damage. The goblin loses its remaining two HP, reaching zero. We record two HP lost rather than reporting damage beyond the creature's remaining health. The defender's current HP belongs to its individual clsActor instance. Attacking one goblin therefore doesn't change the HP of another goblin created from the same definition.
Next, the procedure constructs a message appropriate to the participants. When the player attacks, the message begins with "You attack". When a monster attacks the player, the message identifies the monster and says that it attacks "you". When two non-player creatures fight, both are named. This last case is important for our longer-term design. Our initial monsters will attack the adventurer rather than one another, but the combat resolver itself shouldn't assume that every fight must involve the player.
We also need to distinguish between resolving an event and reporting it. Any combat involving the player is always recorded. Combat between other actors is recorded when it occurs within the area the player can currently observe. For the moment, we'll approximate observability using the four-tile neighbourhood introduced in the previous milestone. Once we build our field-of-vision system, the reporting function will be able to use actual visibility instead.
Finally, if the defender reaches zero HP, the procedure calls RedrawWorldTile. That function already knows how to reconstruct a displayed tile from the underlying terrain and living actors. Since our renderer ignores actors with zero HP, a dead monster disappears and the terrain beneath it becomes visible again. We don't need to replace the cell manually with a floor character or remember what symbol used to appear there. That separation between the displayed worksheet and the underlying world state is paying off again.
Traditional roguelikes often use a convenient interaction known as bump-to-attack. Rather than requiring a separate attack button and target-selection interface, the player attacks a creature by attempting to move into its occupied tile. We'll use the same behaviour. If the player clicks East and the tile to the east contains a living goblin, the movement command becomes a melee attack against that goblin. The player doesn't actually enter the goblin's tile - attacking and moving remain distinct actions, each with its own time cost. Even if an attack kills the goblin, the player stays in their original position. Moving onto the newly unoccupied tile requires another command.
We'll implement this in modPlayer, reusing the existing movement controls from Part 2. Replace the current private MovePlayer procedure with the following complete version.
The order of checks deserves attention. We first ask whether a monster occupies the requested destination. If it does, we consider combat immediately. Only when the destination contains no living monster do we check the terrain's walkability. This allows us to attack a creature occupying a non-walkable tile without permitting the player to enter that tile.
For ordinary movement, we still require a walkable destination. There is no additional restriction on moving diagonally between two obstructed orthogonal neighbours, which keeps the rule consistent with our eight-direction combat system.
A legal attack calls BeginPlayerAction, resolves the attack and then calls CompletePlayerAction. These are the same scheduler functions used for movement and waiting. Consequently, melee attacks participate naturally in the timing system introduced in Part 5. If the player has normal speed, an attack delays their next action by 1,000 time units. If their effective speed changes later, the scheduler can calculate the corresponding delay without changing MovePlayer. The eight public directional procedures, their button assignments and our existing WaitTurn procedure remain unchanged.
Our monsters already have a simple decision-making procedure named PerformMonsterAction. In Part 5, it examined the surrounding tiles, identified legal movements and selected randomly from those available destinations. If no movement was possible, the creature waited. We'll retain that behaviour for monsters that aren't currently able to attack, but when the player enters melee range, attacking will take priority over wandering.
Open modActors and replace PerformMonsterAction with the following implementation.
The first new decision occurs near the beginning of the procedure. When CanMeleeAttack(actor, player) returns True, the monster attacks and the procedure ends; otherwise, it proceeds with its usual wandering behaviour. That makes attacking deterministic when the player is adjacent, even though wandering remains random. It also means the same melee-range rules apply to monsters and the player. Diagonal attacks are permitted, terrain doesn't grant accidental immunity, and movement into occupied cells remains prohibited.
There is no direct manipulation of the game clock in this procedure. The turn engine invokes PerformMonsterAction when the monster is ready, and the monster's action is scheduled again afterwards. Our wolf's speed advantage therefore applies automatically to combat.
At this stage, monsters won't deliberately pursue the player across the map. They wander until the player enters their immediate melee range, at which point they attack. Proper pursuit will come later, when monsters have perception and awareness rules. Similarly, we haven't introduced faction hostility between monsters. Our combat module is capable of resolving non-player fights, but the present AI doesn't select other monsters as targets. These are intentional limits on monster intelligence, not limits on the combat system itself.
When a monster dies, we need more than a message. It must stop appearing on the screen, stop blocking movement and stop receiving scheduled actions. At the same time, we don't want to corrupt the terrain array or interfere with references held by the turn engine. Fortunately, much of this behaviour is already supported by our actor system. MonsterAt searches for living monsters, ignoring instances whose HP is zero or below. NextScheduledMonster likewise selects only living actors, and our rendering procedures don't draw dead actors. Consequently, when ResolveMeleeAttack reduces a monster to zero HP, calling RedrawWorldTile is enough to make it disappear from the display. The map engine restores the underlying terrain, and the actor renderer no longer overlays that monster.
The object itself remains in the active monster collection. This is useful because other parts of the game may still hold a reference to it during the current action. We don't need to remove elements from a collection while other procedures are iterating over it. Later, those retained objects might also help with corpses, death effects, dropped possessions or resurrection mechanics, although we haven't implemented any of those features yet. For this milestone, zero HP represents death, and dead actors are inactive. The same basic HP rule applies to the player, but player death has much broader consequences.
Our game is intended to be a roguelike with permadeath, which means that when the adventurer reaches zero HP, the current run ends. This needs to happen immediately.
Suppose several monsters have actions scheduled before the player's next turn. If the first monster kills the adventurer, the remaining monsters must not continue attacking or moving as though the player were still alive. The turn scheduler is the appropriate place to enforce this. We'll add a separate session-ended state, ensuring that no further gameplay actions are accepted after death. We'll also preserve the final game time and message history so the player can review the events leading to their defeat.
Open modTurnEngine. Alongside its existing module-level declarations, add:
Then replace ResetTurnSession with:
We'll explain mPlayerActionCount shortly, when we develop the expanded message history. It is a separate count of player actions rather than simulated game time. The existing StartTurnSession procedure can continue calling ResetTurnSession when a new game begins.
We also need to prevent commands from being accepted outside the active gameplay screen. Our new history viewer will live on another worksheet, and opening that viewer must not accidentally allow the game to advance.
Replace CanPlayerAct with:
This becomes our central check for whether the player may submit an action. It checks that a player exists, that the game session is active, that the correct worksheet is displayed, that the scheduler is awaiting input and that the player is alive. This is more reliable than letting individual movement procedures independently determine whether a game is currently playable.
Now replace the existing private AdvanceToPlayerTurn procedure in modTurnEngine with the following version:
Most of the scheduler remains the same as in Part 5. It continues finding the earliest scheduled monster, jumping to that monster's action time and processing the event. The significant addition comes immediately after PerformMonsterAction: we check the player's HP before scheduling any further monster activity. If the player is dead, we terminate the session, update the final status and display the Game Over interface. The procedure then exits.
This preserves the exact simulated time at which the fatal attack occurred. It also ensures that a wolf with another action pending doesn't continue attacking a corpse, and that other monsters don't continue wandering while the game is supposed to be over.
If the player survives, the scheduler continues normally.
The player still has priority when action times are equal. This means an adventurer ready at exactly the same time as a wolf gets to act first, which can be important when a single attack might decide the fight.
We already have a central interface module, modInterface, that creates and manages the game's navigation buttons using Excel shapes. We'll use the same approach for the Game Over screen. Rather than switching to a separate worksheet or deleting the map, we'll overlay a few shapes over the visible game area. This allows the player to see the location where the adventure ended, while clearly indicating that ordinary gameplay is no longer available.
The Game Over display will contain a large "YOU DIED" title and two buttons: New Game and Main Menu. New Game will immediately initialise a fresh run, while Main Menu will return to the startup screen introduced in Part 3. Both options will discard the dead session, but only when the player actually selects one of them.
In BuildGameInterface, add this local variable to the existing declarations:
Then, after the existing interface buttons have been created, add:
We're reusing the existing GetOrCreateButton, FormatButton and MacroReference helpers. This means repeated initialisation doesn't create duplicate controls, and the shapes retain the visual style we've already established for the interface.
The controls are positioned relative to MapArea(), so their placement remains independent of the exact worksheet coordinates.
At the end of SetGameplayControlsVisible, add the following instructions to keep the Game Over overlay hidden during normal gameplay and on the main menu:
Next, add a public procedure to modInterface that reveals the overlay when the player's HP reaches zero.
The procedure hides normal gameplay controls and reveals the Game Over interface. Notice that it doesn't reset the player, clear the monsters or discard the message log. The current run has ended, but we deliberately preserve its final state until the player chooses what to do next. This is particularly important for the event history we're about to introduce.
Combat introduces a new challenge for our user interface: a single player action can now trigger several consequences. For example, the adventurer might attack a wolf. The wolf could retaliate immediately, attack again at its next scheduled time, and another nearby goblin might move towards the player. If every event simply replaced the previous message, the player would have no way to reconstruct what happened.
We already introduced accumulated messages in Part 5. We'll now extend that system to maintain a broader event history across the adventure: there will be two separate views of the same information. The ordinary message panel will show recent events belonging to the current player-action cycle. It remains compact enough to fit beneath the map, while a dedicated GameLog worksheet will display the retained history, including the player turn, exact game time and event description. Players will be able to scroll through it, filter individual turns and review the final attacks after death.
We'll retain the most recent 100 player turns, with all messages generated during each of those turns. This is different from retaining 100 individual messages. A single turn might generate several attacks, movement messages and trap events. We want to keep those events together.
In Part 5, we introduced a game clock measured in simulated time units. That clock is useful for scheduling, but it isn't the same thing as a count of player decisions. A normal-speed player might perform one action every 1,000 game-time units, but that relationship won't always hold. Different action costs and speed modifiers will eventually affect how much time passes between decisions.
We'll therefore track the number of accepted player actions separately. In modTurnEngine, add:
We already included the reset of this counter in ResetTurnSession.
Now replace BeginPlayerAction with:
The counter increases only when the player submits a valid timed action. Movement, attacking and waiting each count as one turn. Attempting to enter an impassable empty tile doesn't count, and neither does opening Options or viewing the event history.
The distinction gives us two useful measurements: the number of actions the player has taken and the amount of simulated time that has passed. We'll display both in the status panel and record both in the detailed log.
Open modMessages, which we introduced in Part 5. We'll keep the current-action message collection and add a second collection that stores the adventure's retained event history. Each history entry will contain the player-turn number, the simulated game time and the event text. The module will also provide a common way for other game systems to report events occurring near the player.
That last detail matters beyond combat. When we introduce traps, environmental effects or monsters fighting one another, those events should use the same reporting system.
Add the following declarations near the top of modMessages, retaining the existing mTurnMessages declaration:
We'll also define the temporary observation range centrally. In modGlobals, add:
Add these two procedures to modMessages:
The current observation rule uses a square neighbourhood extending four tiles in each direction. This is only an approximation; it doesn't yet consider intervening walls or other opaque terrain. When we implement field of vision, we'll replace the internal logic of IsEventNearPlayer with a genuine visibility check.
The useful architectural point is that other modules won't need to change. They can continue calling LogWorldEvent with the location and message. For example, a future trap system might use:
The trap system will be responsible for triggering the trap and applying its effects. The message module will decide whether the event should be reported to the player. Likewise, our combat resolver can report fighting between two monsters when it occurs in the observable area, even though the player isn't one of the participants.
We haven't implemented traps or monster factions yet; we're establishing a common interface that those future systems can use.
Replace LogGameMessage with:
Every recorded event is now stored in two places. The current-action collection determines what the player sees beneath the map, while the session-history collection preserves the event with its turn number and timestamp. The collections serve different purposes, but both are maintained through one procedure. This means combat code doesn't need to understand how the log is stored or displayed - it simply submits a message.
Replace StartMessageBatch with:
The history is pruned whenever a new player-action cycle begins. Suppose the player begins turn 250. The retained history will cover turns 151 through 250, including every event generated within those turns.
We don't impose an arbitrary maximum number of messages per turn. If a particularly eventful action generates several attacks or environmental effects, all of them can remain together. This makes the log more useful than a fixed limit of 100 individual messages; it also ensures that memory usage doesn't grow indefinitely during a long adventure.
The full history may contain many events, but we don't want the ordinary game interface to become dominated by text. We'll keep the compact message panel at K23:X26.
Replace RefreshMessagePanel with:
For short message batches, all events are displayed. If the batch becomes too long for the compact panel, the function displays the most recent three messages and indicates that earlier events can be found through LOG. The complete session history remains available separately.
We'll retain the PrepareMessagePanel procedure from Part 5, which merges and formats the message region. Similarly, ClearGameMessages continues clearing the message collections and the full MESSAGE_PANEL_ADDRESS range. Its updated implementation is:
The message system is now independent of the individual game mechanics generating its content. Combat can produce attack and death message, monster movement can report nearby activity, future traps can report triggering and damage, and spells can report their effects. All of those systems can use the same logging interface.
A compact message panel works well during ordinary movement, but it's not particularly suitable for reviewing a long fight. We want to be able to inspect exactly what happened, identify which player action produced a sequence of events and see the game-time interval between those events.
We'll create a dedicated worksheet named GameLog. The worksheet will be generated when the player first opens the history, and it will display a three-column table containing player turn, game time and event description. We'll also make the history practical to navigate. The headings will remain visible while scrolling, Excel's AutoFilter will allow events to be filtered, and opening the log will automatically position the view at the newest entry. A Back to Game button will return to the current game screen without consuming any simulated time.
Add the following constant to modGlobals:
Add this procedure to modMessages:
The underlying history is a collection of small arrays, but Excel's worksheet display works best when we prepare a two-dimensional array and transfer its contents in a single operation. We already used a similar technique in our map renderer, where bulk writing greatly reduced worksheet operations. Here, we construct an eventData array with one row per retained message and three columns for turn number, game time and event text. We then write the array to the history worksheet in one assignment. The result is a familiar Excel table-like view, even though we don't need to create another structured ListObject for it.
Column headings are formatted for readability and an AutoFilter is applied. The user can filter by turn number, time or particular event descriptions. We also freeze the headings and select the newest event when opening the viewer. That combination makes it straightforward to inspect the events immediately preceding a player's death or scroll backwards to an earlier turn.
The Back to Game shape is created only once and reused on subsequent visits.
Add the following procedure beneath ShowMessageHistory:
Opening the history viewer doesn't advance the game clock or change actor state. The game isn't running on a continuous timer, so there is no background simulation to suspend. The worksheet simply changes while the player reviews the events. When the Back to Game button is clicked, the player returns to the same gameplay or Game Over screen. The history worksheet is then made VeryHidden, keeping it out of the ordinary worksheet interface until the LOG button is used again.
We now have a detailed record of the recent adventure without enlarging the game screen indefinitely.
As the game grows, the status area must display more than a pair of coordinates. We now have health, damage, position, player turn number and simulated game time. Rather than concatenate everything into one long line, we'll distribute those values vertically within the existing status area.
In modGlobals, retain STATUS_CELL_ADDRESS = "B23" and add:
Then replace UpdatePlayerStatus in modPlayer with:
The player status now occupies four short lines, leaving the adjacent message panel independent. TURN represents the number of accepted player actions. TIME represents simulated game time, which advances according to the action scheduler. Keeping these separate will become increasingly important when we introduce haste, slowing and actions with different time costs. The displayed damage is labelled Dmg, making it easier to distinguish from the other statistics.
When returning to the main menu, we'll clear the additional status lines. Because the layout may contain merged cells, we'll clear the complete merged area belonging to each status address. Inside ShowMainMenu, after setting the main status to "MAIN MENU", add:
This allows the status layout to use merged cells for formatting while keeping the worksheet-reset logic consistent.
We now have a detailed history viewer, but the player needs a convenient way to open it. In Part 5, we added an Options button to the game interface. We'll keep that feature and place a smaller LOG button directly beneath it, using the narrow black border on the right side of the worksheet. The controls will be arranged vertically in column AH. The Options button will occupy AH2:AH3, while LOG will occupy AH4:AH5. The expandable Main Menu entry will appear immediately to the left of Options, at AB2:AG3. This arrangement keeps both controls readily available without occupying space inside the map or covering the main message panel.
Add or update the following constants in modGlobals:
Our existing BuildGameInterface procedure already positions the Options and Main Menu controls using their corresponding range constants, so those controls will use the revised positions when the interface is built. We only need to create the new LOG button. Inside BuildGameInterface, after the existing Options controls have been created, add:
The shape is created using the same reusable button helpers as the rest of our interface. Because the control is positioned using a named worksheet range, its location can be adjusted through modGlobals without changing the shape-generation logic. The button calls ShowMessageHistory, which prepares the log worksheet and opens it at the newest retained event.
We'll also make the button available on the Game Over screen. This allows the player to inspect the final combat sequence before deciding whether to start another game.
Near the end of SetGameplayControlsVisible, add:
During ordinary gameplay, the button remains visible alongside Options. When we return to the main menu, it is hidden. During Game Over, ShowGameOverScreen explicitly makes it visible again, preserving access to the events leading to the player's death.
Our growing game now maintains several kinds of session state: the actor system holds the player and monster instances, the turn engine stores the current game time, player readiness and completed-action count, the message module stores both the current message batch and the retained adventure history. Starting a new game must reset all these systems consistently.
Open modGame and replace StartNewGame with:
The sequence is important: we first discard the previous game's state, including its messages; we then load the map and create the player and monsters; only once those objects exist do we start the turn engine; and finally, we display the gameplay controls.
The existing ShowMainMenu procedure continues to handle returning to the introductory screen. It resets the active game, clears the message history, rebuilds the interface and presents New Game. Because our status display now occupies several lines, it also clears the additional status fields introduced earlier. The Game Over buttons call these existing startup procedures, so we don't need a separate mechanism for restarting after death. This is another benefit of keeping application startup separate from the systems it initialises.
With the implementation in place, we can test the game using the three monsters already present on Old Fort Approach. Compile the VBA project, save the workbook as .xlsm and reopen it with macros enabled, and the main menu should appear automatically. Clicking New Game should load the starting location, create our adventurer and three monsters, initialise the game clock and display the navigation, Options and LOG controls. The player should begin at full health, with turn number zero and game time zero.
Move around the map until one of the monsters approaches. When the player attempts to move into the monster's tile, the command should perform an attack instead. The player's coordinates remain unchanged, the monster loses HP and the message panel records the damage. Subsequent monster actions should occur according to their existing schedule.
A goblin with speed 100 attacks once per standard 1,000-unit action interval. Our wolf, with speed 200, can attack twice during the same period. The precise sequence depends on when each creature becomes adjacent and which other actions are scheduled, but the relative timing should remain consistent.
Our adventurer deals four damage, while a goblin begins with eight HP. Two successful attacks should therefore be sufficient to kill a full-health goblin. Once its HP reaches zero, its symbol should disappear from the map. The underlying terrain should be restored, and the tile should become available for ordinary movement. The goblin should no longer appear in the active scheduler or perform any further actions.
To test deaths more quickly, we can temporarily change the Damage value in tblActorTypes. Giving the player a damage value of 500 makes the next valid attack lethal to any of our existing monsters. After changing the definition, start a new game so that the actor objects are recreated using the new values. This is a convenient advantage of our data-driven design. We can vary gameplay statistics directly in an Excel Table without modifying the combat implementation.
We can perform a similar test by temporarily increasing the wolf's damage to 500. Start a new game, move near the wolf and allow it to attack. The player's HP should immediately reach zero, the scheduler should stop and the Game Over display should appear. The ordinary navigation controls should no longer accept actions. The final status should preserve the time of death, and the message panel should contain the fatal attack and death message. Clicking LOG should reveal the retained history, including the final combat events. Returning from the history should bring us back to the same Game Over screen. The player can then choose New Game or Main Menu.
Neither option should leave behind old monster instances, stale turn data or duplicate interface controls.
The detailed log can be checked independently of combat. As the adventure progresses, each accepted player action should increase the turn number by one. Messages generated by monsters between two player decisions should share the same player-turn number but retain their individual game-time values. Opening LOG should display the latest retained event at the bottom of the history, with earlier events available by scrolling upwards. The filter controls should allow individual turns and event descriptions to be examined. After more than 100 player turns, the oldest event groups should drop out of the retained history, while all messages belonging to the most recent 100 turns remain available. The compact message panel should continue to display recent events without obscuring the rest of the status information.
Once the tests are complete, restore the initial damage values: four for the adventurer, two for goblins and three for the wolf. These values are sufficient for our current demonstration, although we'll revisit combat balance as more creatures, equipment and player abilities are introduced.
Going forward, every completed development milestone will be accompanied by a playable version of the game. The download package for Part 6 consists of the complete macro-enabled .xlsm workbook, a macro-free .xlsx workbook for readers following the build tutorial, and separately exported VBA modules. The VBA exports include our standard modules and the clsActor class, using the appropriate .bas and .cls file formats. This gives readers two ways to explore the project. Those primarily interested in playing can open the macro-enabled workbook and start a game through the main menu, while those interested in VBA development can use the instructional workbook and exported source modules to follow the implementation themselves. We will continue explaining the architecture, data structures and code throughout the series, even though a ready-to-play build is now available. The purpose of the project remains both educational and recreational.
Because our game is written in VBA, the playable workbook requires macros to run. Excel applies security restrictions to macro-enabled files, particularly those downloaded from the internet. This is appropriate: VBA is capable of interacting with the local computer, and macros in untrusted workbooks can be dangerous. Readers should therefore enable macros only after confirming that the workbook comes from a source they trust.
Download the project from the intended website and keep the original archive or files available for reference. The separately provided source modules can be inspected in a text editor, while the VBA contained in the workbook can be examined through the Visual Basic Editor using Alt+F11.
On Windows, Excel may block macros in a downloaded workbook even when the file has been opened successfully. If the source has been verified and the reader has decided to trust the file, they can close Excel, right-click the downloaded .xlsm file in File Explorer, select Properties and look for an Unblock option near the bottom of the General tab. If that option is present, selecting it and reopening the workbook may allow Excel to use its normal macro security process. The option isn't displayed for every file, and organisational security policies may still prevent macros from running.
Where Excel presents a security warning offering to enable content, readers should proceed only if they've established that the workbook and its code are trustworthy. There is no need to select a global setting that enables all macros in every workbook, nor should Excel's general security protections be disabled to play the game.
Once the workbook has been opened with its macros permitted, our Auto_Open procedure displays the main menu automatically. The player can then click New Game and begin exploring Old Fort Approach.
Our Excel RPG now has something resembling a complete gameplay cycle. The player can explore the map, encounter moving monsters, attack them and receive damage in return. Creatures act according to the individual schedules established in Part 5, so speed differences affect combat as well as movement. A living actor's HP changes independently of other characters, and reaching zero HP has a defined consequence. Dead monsters disappear from the map, stop taking turns and no longer block movement. Player death terminates the adventure immediately, preserving the final state long enough for the player to examine what happened.
We've also significantly improved our interface. The status display now distinguishes health, damage, coordinates, player turns and simulated game time. The compact message panel reports the most recent events, while the detailed history provides a chronological record of the last 100 player turns. The LOG button offers access to that history during gameplay and after death, while Options continues to provide a straightforward way to return to the main menu.
Most importantly, these systems remain separated by responsibility. modCombat resolves attacks and damage. modActors manages individual creatures and their behaviour. modTurnEngine controls when actions occur. modMessages records relevant events. modInterface handles the player-facing controls and Game Over display. The terrain engine doesn't need to understand combat, and the combat engine doesn't need to know how an Excel button is created. That modular structure will help us considerably as the game becomes more sophisticated.
There are, of course, many mechanics we haven't introduced yet. Our monsters still wander rather than deliberately pursue the player. Attacks always hit, and damage doesn't account for armour, equipment or character attributes. Creature movement remains limited to the terrain permissions we've already implemented, even though the combat engine can target actors on non-walkable tiles. We also have no way to collect treasure from defeated enemies, obtain better equipment or restore health using consumable items.
Those are natural next steps.
In the next instalment, we'll begin building the item system. Our current adventurer has a fixed damage value and no possessions. Defeating a goblin offers the satisfaction of survival, but no reward beyond clearing the path. We'll change that by introducing reusable item definitions and individual item instances, following a similar approach to the character system developed in Part 4.
Items will need to exist on the ground, be collected into an inventory and eventually be equipped or consumed. We'll also need to decide how multiple objects can occupy the same tile. A potion might lie beneath a monster, a dropped sword might share a tile with another item, and the renderer must know which symbol to display. The layered world model we've been developing since Part 1 was designed with exactly these situations in mind.
Once we have equipment, we can begin making combat statistics depend on weapons and armour rather than fixed actor definitions. Consumables will also give the player ways to recover from combat, making the game considerably more interesting than a simple contest of who can inflict damage fastest.
For now, though, Old Fort Approach is no longer the harmless place it once was. The goblins can fight back, the wolf's speed has become genuinely dangerous, and careless movement can bring an adventure to an abrupt end. Our spreadsheet has acquired a combat system, a functioning game clock, a record of its own events and a permanent consequence for defeat. The world is still small, but it has finally become dangerous.
And that seems like a reasonable point at which to start giving our adventurer a sword.
This article is Part 6 of the Building an RPG in Excel series. The accompanying project downloads found here include the instructional workbook, exported VBA source modules and a playable macro-enabled workbook containing the completed and tested Milestone 6 implementation.
Cat On A Spreadsheet