Claude Code and AI

So we recently got Claude Code at work, and I’ve been using it a bit. I’ve been pleasantly surprised with how well it’s been working so far. I decided to go and use it for some of my side projects that I haven’t messed around with in a while to see how well it works. Specifically, I want to get Intergalactics working again. I had created a version from the decompiled code a long time ago, but I never finished it. Partially because webapps are the more modern way of handling simple games like this, partially because I haven’t used Java much over the past few years.

This is mostly a guide in how I did the conversion, along with the prompts to Claude that I used.

Step 1: Turn it into a web app

After installing Claude code on my machine, I pointed it at the source code and gave it the prompt:

this is an old java project. I want to turn it into a web based game instead of using java swing. to start out, create an interactive UI using html/javascript

After it thought for less than 10 minutes, it came back with what is arguably a functional game. You can start the game and play against some AIs:

There are a few problems with this of course, but the basic functionality is there and it’s all contained within a single file. Some problems that can be seen:

  • You can see the enemy fleets, unlike the original version
  • There’s no sound
  • Everything is run locally in a single file, so maintenance is difficult
  • You can’t play against other people
  • The game runs very fast
  • Attacking fleets are not shown on planets

Overall though, this is a remarkably functional game. Granted Intergalactics is not a particularly complicated game, but this perfectly captures the original spirit of the game.

Step 2: Making it more maintainable

A functional game is nice, but we need to be able to maintain it better. So let’s just ask Claude to do that in two steps:

good. now please split up the CSS and javascript from the HTML in order to make it easier to maintain in the future

This properly prompted Claude to move the CSS and Javascript out to new files. We could also ask it to make it more object-oriented, but for now let’s just go with this single-player version.

Now that the basic functonality is working, I just asked Claude to play the sounds at the appropriate time:

Step 3: Playing sounds

With the code functional, it’s now time to add more functionality. Time to prompt Claude to add in the sounds(after converting the original .au files to .mp3 files):

okay, now can you play the audio for the correct events? the MP3 files are in src/main/resources

This did add in the sounds, with Claude printing out a nice overview of the sounds:

● Done. Here's the complete sound mapping:             
                                              
  ┌───────────────┬───────────────────────────────────────────────────────────────────────────────┐
  │  Sound file   │                                 When it plays                                 │                                                                                                                
  ├───────────────┼───────────────────────────────────────────────────────────────────────────────┤
  │ soundon.mp3   │ Game starts                                                                   │                                                                                                                
  ├───────────────┼───────────────────────────────────────────────────────────────────────────────┤
  │ combat.mp3    │ You dispatch a fleet to an enemy/neutral planet                               │
  ├───────────────┼───────────────────────────────────────────────────────────────────────────────┤
  │ attack.mp3    │ An enemy fleet arrives at one of your planets                                 │
  ├───────────────┼───────────────────────────────────────────────────────────────────────────────┤
  │ victory.mp3   │ You successfully invade a planet                                              │
  ├───────────────┼───────────────────────────────────────────────────────────────────────────────┤
  │ invaded.mp3   │ One of your planets is captured                                               │
  ├───────────────┼───────────────────────────────────────────────────────────────────────────────┤
  │ repelled.mp3  │ An enemy attack on your planet is beaten back                                 │
  ├───────────────┼───────────────────────────────────────────────────────────────────────────────┤
  │ lose.mp3      │ Your attack is repelled                                                       │
  ├───────────────┼───────────────────────────────────────────────────────────────────────────────┤
  │ reinforce.mp3 │ Your own fleet arrives as reinforcements                                      │
  ├───────────────┼───────────────────────────────────────────────────────────────────────────────┤
  │ nothing.mp3   │ Your fleet is lost to a black hole                                            │
  ├───────────────┼───────────────────────────────────────────────────────────────────────────────┤
  │ event.mp3     │ Any random special event fires (production change, revolt, crazy event, etc.) │
  ├───────────────┼───────────────────────────────────────────────────────────────────────────────┤
  │ quit.mp3      │ A player is eliminated                                                        │
  └───────────────┴───────────────────────────────────────────────────────────────────────────────┘

  initAudio() is called on the "START GAME" button click, which satisfies the browser's user-interaction requirement for audio playback.

This did result in one bug, that is very clearly shown in the table above. The combat.mp3 file should be played whenever your fleet arrives at another planet, not when your fleet leaves. We then prompt Claude to fix it:

❯ combat.mp3 plays when the fleet arrives at an enemy/neutral planet, not when the fleet leaves

This now fixes it so that the combat audio is played at the correct time.

Step 4: Combat Fixes

Now that the sounds are working, we need to fix the combat. There are two problems here:

  • The combat is too fast, it resolves immediately
  • The attacking fleet ships are not shown on the planet

I prompted Claude to fix it:

there are two problems with fleet combat: it should not resolve immediately, and the attacking fleet number should be shown on the planet

Claude was then able to fix it:

● Done. Here's what changed:          
                                                                                                              
  Combat is now segment-based, matching the original:
  - Fleets stay in G.fleets at distance <= 0 instead of being removed on arrival                                                                                                                                   
  - Each segment: attackers get one round of firing (runAttackRound), then defenders fire back (runDefenseRound) — same order as the Java FleetQueue.update() → Planet.update() sequence
  - A fleet only leaves G.fleets when it invades, is destroyed, or reinforces                                                                                                                                      
                                                            
  Attacking ships shown on the planet:
  - planet.attackers is rebuilt each segment from all engaged fleets
  - After the defense round, updateAttackDisplay computes totalAttackingShips and attackingPlayer from those fleets
  - The existing render code already draws >{count} on the planet when totalAttackingShips > 0

  Sound timing is also corrected — combat.mp3 / attack.mp3 now play on first arrival (firstArrival flag), and outcome sounds (victory, invaded, lose, repelled) play when ships actually reach zero.

There was still just one last fix to make:

attacking fleets do not show up on neutral planets

Now with this fix, the attacking fleet number now shows up

Conclusion

I’ve been very impressed with Claude and how it handles the conversion part of the code. It is able to use the original Java code and have enough context to create a completely new version. For me, it also makes generating the Javascript/HTML easy, as I know only the very basics of how all of the web stuff works.

Play this new version of Intergalactics here: https://rm5248.com/intergalactics/

What should be changed next? Should I actually add in a server system so that you can play against other people?

Leave a Reply

Your email address will not be published. Required fields are marked *