Github Slots

admin
  1. Github Slatejs
  2. Github Slots App
  3. Github Slate Theme
  4. Github Sloth

A couple of years ago, when I was learning Java programming, I thought of testing myself and my programming skills by writing a game in Java. Now, I'm not going to call it 'game programming', since game programming is way more than what I did. In fact, what I did was just a test for me. So I decided to write a game I was playing on my old Nokia E50 phone, a Slot Game.

I am deploying my application from Github and I have three different deployment slot(Dev/Staging/prod) and would like to deploy the code only to Dev and swap the deployed code to the rest of the st. Fan run database for One Piece Treasure Cruise. Includes a character database with all unit captain abilities, descriptions, sailor abilities, and special abilities. Digital Slot Inspection - jcsmileyjr.github.io.

This slot game I was playing on my phone was really simple. It had only 3 slots with different items in each. You had to push the Spin button in order to spin the slots, and you would win a small amount of coins if two or three slots were alike. Of course, 3 slots were better than 2. It is not really hard to make a game like this, but for a beginner it is good to start with. As I remember, this was probably the first program that I could tell others: “Look at what I just did!”

Slate

So I started working on it (I remember using NetBeans at that time), firstly as console-only, and then using GUI. The first thing I did, was deciding what kind of images (actually their names, not the images themselves) I would use. I wrote this line of code:

I also decided what would be the amount of “money” that the user would win if he matched two or three symbols:

After that, I went on writing the code that was suposed to randomly choose one of the elements in the symbols array. This could be done by using the Math.random() method, or by calling the nextInt() method at a Random instance, or by the wrong way I used to do at the beginning:

Of course, I soon switched to calling Math.random(), and in order to get a number that I could use as an index for my array, I wrote this block of code:

So the variable choice was the random index that I could use to get a random item from the array (keep in mind that Math.random() returns a double between 0.0 and 1.0)

So after choosing 3 random items, I just printed them out at the console, saying whether there were none, two or three matches, and calculating the amount of money won, if there was any, with the given coefficient. It was a good start; I only had to think of the UI, and I suck at UI design. But for this one, all that I needed was a really simple design which I managed to code as I was planning.

For the items to show at slots, I just googled them and found 12 of them in a single sprite. I downloaded the sprite and started my old photo editing software which sometimes can really be magical; Microsoft Paint! I started cropping images from the sprite, paying attention to their dimensions that should be the same, 122px by 114px. Why these magical values? Just because!

What was left to do, was the UI. I could use the really-helpful drag-and-drop UI builder that ships with NetBeans, but I wanted to do it myself. I had a really hard time figuring out which kind of layout to use, since the only one I really knew was GridLayout. Anyway beside that, I managed to use FlowLayout and BorderLayout. There is a difference between them, but I’m not really capable of pointing that out, so you can check the online JavaDoc for them.

Slots github

I managed to build the game, and started to play it. I figured out that the coefficients for multiplying the bet were too damn high, but I didn’t care as long as I knew that the game worked.

My bad practices

As you can see, the source code of this simple game is in only one file. This is something that I don’t like to do anymore. A better way to do it is by making the code as modular as it can be. By building small modular elements, dividing the UI from the logic of the application, you help yourself during the testing and debugging phase. So the first thing that I would like to change, is dividing the whole class Slots extends JFrame from the class that calls it.

This is done by firstly creating a file called Slots.java that will contain only the code for the UI. Then, creating an ActionListener that will listen to different button clicks (there are 5 different buttons). Finally, creating a class called App.java that will only create a Slots instance and make it run.

Basically, the App.java would look like this:

As I remember, SwingUtilities.invokeLater() is used to divide the UI thread from other threads, so if any UI changes are needed, they won’t stall the application.

The Listener class, which might be called something like SlotButtonListener, might be something like this:

And finally, in the Slots class there would be only the code for defining the UI of the game. All the buttons would have SlotButtonListener as action listener.

Anyone who wants to change the code following these advices is free to do it. You can fork it anytime you want.

Do you have any Java programming advice for me? Feel free to comment below


I have a handful of web projects that I maintain. Some of these are sites like the one for my films (Hello World Film and Don't Worry, I'm Fine) but some others are community projects like Atlanta Code Camp. I've battled with the best way to develop and deploy these projects for quite a while.

The problem has been that for a long time I've just been checking into a main branch in Git and publishing that on every check-in. That's caused me some down time over the years. Maybe with these small projects it doesn't matter, but I like to keep these up (especially this blog) so I wanted to make a change that would address it.

First thing I did was create a branch in Git for working on the project. I thought about doing Pull Requests but since I'm the only dev on most of these, it felt a little to over-complicated. So instead I have a branch I call 'next' that I do active development into:

I've set up an Action to automatically build and deploy the project on every build. If you're curious how to do this in GitHub Actions, see my blog post about it.

Github Slots

The difference here is that on every 'Next' deployment I'm building a 'next' container. If we look in Azure container registry, we can see that there are tags for latest (my released version) and next (my test version):

With that in place, let's look at slots. Azure slots are a way to have multiple versions of your site running at once. One reason for this is what we're using it for. You can have a separate versions for testing, development, etc. Another common reason is to support A/B testing. It allows you to swap slots instantly (to prevent downtime) for those different scenarios. Let's see what it looks like.

In the App Service for this blog, there is an item for 'Deployment Slots':

Opening this you may get the dreaded 'You're not paying enough for this project' notification:

But if you're on a Standard (or better), you'll be greeted by this page:

Note that your main site is already running as the first 'slot'. It's your 'production' slot and 100% of the traffic is going to it. You can add a new slot and this will make a copy of your project, but it's a completely separate (but related) App Service.

Note: you can use this whether you're using containers or not. Just in this example I'm using container deployment

Let's create a new slot. Click on the 'Add Slot' button:

Enter a name for the slot and Click Add (you can clone the settings from the original site if you are using settings). Each slot gets it's own App Service so separate settings and configuration.

The name of the slot becomes a new AzureWebSites.net address so you can view it directly using that domain. For my use, I use the 'sitename.azurewebsites.net' address as my testing address.

Once you have a slot configured, it'll look like this:

Github Slatejs

While, in my case, I'm always leaving the traffic to the main site at 100%, you could also use it to do A/B testing by having two versions of the site running and sharing the traffic to test how well the sites compare.

Now that I have the slot, I just configure it to use my testing (or next) container:

This image is doing a lot of heavy lifting. Note on the top-right that this is showing that it is an App Service Slot. So while it is an App Service it it's own right, it's related to the main App Service.

Github Slots App

By looking at the container settings, I'm setting the container to use a 'next' tag so that this is the test version of this blog. I can view it and be sure that I didn't break anything. Now I'm ready to push this to the live version.

To do this, I go back into GitHub and create a Pull Request:

Once I merge the changes from my 'next' branch to 'main', the GitHub actions take over and create a new 'latest' version of my container.

Github Slate Theme

You can see my actions and source code for this blog if you're curious how it works:

Github

Github Sloth

Is this something like what you're already doing in real production environments?