Making a Dice Game pt 2

January 12th, 2025


Hey there! Welcome back to another one of my blog posts! When I started trying to make this Farkle game I figured it would take me a few days at most and then I could move on to another project. Well...not only did it take longer than a few days, but it looks like it's going to take over 2 blog posts to finish this. So this is part 2 of what will become at least a three part series as I try to struggle my way through making something as basic as a dice game.


Before we get into the nitty gritty of this I'm pretty sure I've left out some pretty important information up until this point. I know I've spoken about coding plenty of times thus far and I know I've even included different code snippets. That being said I don't think I've ever actually talked about what language I am writing this in. For this project I ended up going with Next.js as it is the same framework I used to code this website. Now, for those of you familiar with Next.js you might be wondering why I'm using a framework that is designed around making different components on either the server side or client side. Well to be honest when I first started this I thought I made a mistake with that decision. I thought it would have been smarter to just make this in plain React and leave out Next.js...also being that this will most likely be a single page application the extra perks that come with Next.js are not really necessary. That's when I realized I could be dreaming a bit bigger. Sure I could use this just as a quick app to practice coding in React but what if I expanded the scope and actually made this a full game that could be played online between two or more people. What if I added a chat mechanic? What if I added the ability to save a game and come back to it later? Why limit myself to something like React, where this could still be possible sure, when I have Next.js available to me as well. So I kept with the Next.js build and I'm excited to see where this project goes.


Alright, with that out of the way let's take a look at where we left off. If it wasn't completely clear with my last post I kind of let things get away from me. I started building this game with a false sense of over-confidence without the real skills to back that up. I remember thinking that I could build this app within a day or two without any complications or real planning. "It's just Farkle...you've played it for years, plus didn't you make that dice game in that Scrimba course?". Yeah I did make a dice game, but it was so plain and simple. Get 10 dice to all be the same value and you win. No scoring, no different combinations, no weird rules about turns and points and held dice vs live dice. Without a solid plan and me just winging it my entire attempt was almost destined to fail.


I remember thinking that I could always rely on copilot. Which yes I did...I did try to use AI to bail me out of any holes or errors I would encounter. I don't think using AI as a tool is a bad thing, especially in today's world, but I was using it as a crutch and a catch all. That's kind of a problem. Take that and combine it with no real plan and yeah it became a mess, which was also obvious in my last post about how I let the scoring component get so away from me so fast.


tldraw pic

My flowchart from TLDRAW


So, I made the decision to start over. Yeah, that's right, I started again from scratch. This time I was going to code this entire project different from anything I have done before. I actually came up with a plan. A full plan. At the advice of someone else I ended up using TLDRAW.com. As you can see from the picture above I made quite the flowchart. After making the flowchart I then spelled out each and every rule of Farkle to the best of my ability and left the list commented out on my main page. I would use that as a reference when necessary, but more than anything it was to help me think out exactly what would need to be done.


I also made the decision to do as much coding myself as possible. I knew that I had the skills necessary to make this app. Considering I just attempted at doing it with help, then I must have a decent idea how to do it myself. Instead of relying solely on CoPilot or AI I wanted to use as many of the tools I've learned since starting this journey and fallback on Google/the MDN docs. I also decided that I would make this code as meticulously as possible and make different components for each major function, I.E the scoring functions. Not only would I break up each scoring function but I would also state exactly what the intention of that function would be. See below for how I broke this down for my three of a kind scoring function.


three of a kind scoring function breakdown

My three of a kind logic


It might seem rudimentary to some but I have never coded something like this before. Even when I made my game for the REACT Game Jam I basically was just winging it the entire time. I had little rhyme or reason and constantly jumped from one file to another fixing little bits of code at a time but never really doing one entire task at a time. It is a hard habit to break but I hope this will help me in the future. The weirdest thing, is that I'm actually enjoying that part of the process. The planning part. I've always been more of a go with the flow kind of person and would just face/fix any issues as they arose. But this...this is not in my nature...but it really helps so far. I know I say that before finishing this app. I KNOW I'm going to have more issues moving forward. I know I will have some unexpected bugs. But I also know exactly where I am at in this process so far, which is not where I ended with my previous attempt. I couldn't even tell you where I was at with the last one since I was basically just constantly jumping to something else instead of dealing with the issue at hand.


farkle screen 1

How it's looking at the moment.


I still have a lot of work to do, but I have a pretty good amount done. The scoring is done. I'm 90% sure I figured out how to declare a Farkle properly. I can roll the dice and start a game. I am at a much better spot than I was before. I hope that by me doing some proper planning and by breaking down the code into smaller, easier to identify pieces that I can actually finish this project the way I would like to. When it's done I hope you get the chance to check it out too! Well...thanks for sticking it out to the end of this post too. I really appreciate it and honestly, doing this is really helping me stay sane through this process.


Until next time!
-Craig

AKA: Virtual Sobriety