Yahtzee with ReactJS

If you’ve been following my blog, its no secret that I like games. And while it is my goal to create something more exciting than a basic board game, I wanted to keep things simple for this project to try some new things out.

For those that don’t wish to read further, you can play the game here! I haven’t added any instructions yet, so if you aren’t familiar with Yahtzee, you might want to brush up on how to play before you dive in.

When I started this project I had a few goals in mind: ReactJS practice, utilize styled components, explore react context for state management. As I was getting closer to completion, I had some roadblocks that shifted what I wanted to learn, and the actual outcomes were much different than I intended.

State Management
Initially, I just used local state on the game component to keep track of everything and passed props where I needed to. This was good for my first iteration, but I knew it wasn’t going to be a final solution. Anytime there is a change in state, the entire tree rendered. This meant that when I clicked a die to lock it in, everything on the page would re-render, even though the only thing that changed was the die. To solve this, I decided to add redux. On a previous project, I was introduced to redux and it was complicated and intimidating. So naturally for this project, I wanted to explore other state options. After looking into it though, redux made sense for this project. Being a bit more simplistic application (and making sure I used the redux toolkit), it was a bit easier to understand how the pieces were working. I do not think I would have used this if the toolkit was not available.

Styles
I decided to add Material UI to my project so that didn’t have to manually style everything. I wanted to deliver the MVP in a way that was presentable, but mainly focus on the functionality. For some of the components that would need a touch up, I found that you could used styled component syntax. This was great, as I was hoping to do some CSS in JS practice and I was curious how this would work. After getting everything wired up, I played a few games and noticed performance issues. It took a bit of tracking down, because the application wasn’t that complicated. After eliminated refresh issues and running timers on my roll dice calculations, I found an issue in MUI v4 around styled components. Needless to say, I tore all of it out and just used stylesheets.

Possible Next Steps:
I would like to enhance this project with some multiplayer, much like I did with Connect 4. Hopefully this will help make it a bit more exciting for people to get into. It would also be useful to add some How to play instructions for beginner users and also add the Yahtzee Bonus category into the game, as it is in the real version of the game. I also would like to explore updating the UI and making it more responsive for mobile/desktop. Right now, its really mobile first, and the experience is ok for both environments, but could be improved.

Just for fun: Battery Level with CSS/JS

I was messing around on codepen last night to create some custom styles. At some point, I messed up the CSS and my div ended up looking like a phone battery icon. So I thought it would be fun to continue with that and have it adjust colors based on the battery level. Enjoy!

Getting Started in IoT: Part 3

In the final part of this IoT series, we will connect our light switch to a CloudMQTT broker. Then we will make an iOS app using Xamarin, and a web application with Blazor that connect to the cloud and send/receive messages so that we can control our light switch over the internet.

Resources:
iOS App/Web App code
Arduino code
Mqtt Documentation
PubsubClient Documentation (Arduino Library)
MqttNet Examples (C# Library)

Where to go from here
This series was an intro to IoT and while turning an LED bulb on and off isn’t that useful on its own, it laid the groundwork for applications that do more exciting things. One goal for the year for me is to make an IoT cat feeder that will automate feeding and give alerts when the food is running low. Other examples that you could try could be an app to control your garage door, weather station monitor, or home automation system.

Getting Started in IoT: Part 2

After a bit of a break with the holidays, it’s time to pick back up on part 2 of the IoT series. In this video, we’ll take a look at how to wire up the button and start to push code to our microcontroller so that we can keep state of the light being on and off.

Here is the link to the code that I uploaded to the board.

In our final segment, we will wrap up by communicating with a message broker so that we can publish/subscribe updates from our microcontroller and make a mobile application that will communicate via the internet to control the light.

Getting Started in IoT: Part 1

I’ve been working a bit lately with ESP32 microcontrollers and thought it would be fun to do a series on IoT (Internet of Things). In this project, we are going to control an LED from our physical device, and then also spin up a mobile application so that we can control it from anywhere. To get started, you’ll need some sort of microcontroller with wifi. I have an ESP32 Heltec LoRa, but there are several others out there. You could also use an Arduino Uno or an ESP8266 with wifi adapter. You’ll also want to look into some sort of accessory/sensor kit for these so that you have plenty of jumper wires, a breadboard, and some LED’s, and a button. In the future, you might want to mess around with other projects that use ultrasonic sensors or temperature monitors, so just keep that in mind as you make your purchases so that you can do more in the future.

To get started, I will go over a basic setup so that we are more familiar with how to wire up our LED. Here’s a quick video I made to get you up to speed.

In the next segment, we will set up our physical button so we can physically power on and off the LED.