Getting Started in iOS Development

Getting Started

First, let’s start with the prerequisites. We’ll be using Xcode 10 for this tutorial, which  requires a Mac running MacOS 10.13.6 or later. To get started, go to the App Store and download Xcode. You’ll also need an account with Apple to download this so if you don’t have one, you can create it from the store. One other thing to note ahead of time, you won’t be able to publish an app on the App Store without a developer license…and that costs $99/year. We can still create an app and run it on the emulator or on your phone, but if your end goal is to publish something, it will cost you. Not that you would want to publish what we are making, but just something to know for future development.

Creating the Project

For our first project, we are just going to create a read-only clone of the iOS Notes app. If at anytime you get stuck in the tutorial, you can pull down the source code for the clone project here.

Continue reading “Getting Started in iOS Development”

Now Live: Connect Four with Friends

ConnectFourScreenshot

Over the weekend, I was able to take the UI from the previous post and connect it to SignalR, which will allow you to play with anyone online. So send a link to your friends and give it a try. And I guess if you are lacking friends, just open 2 browsers and see if you can outsmart yourself (there is no AI yet).

Play Connect Four

Currently there is only one game room, so if more than 2 people join, the extra players will be on the spectator list until a seat is open.

Future enhancements:
Show toast messages when players enter/leave the room
Better turn notifications to alert you when its your turn
Find a way to display the last opponent move so that it stands out better
Make it so that there is more than one game room.
Add a timer so that users are forced to play a move within a certain timeframe.

Any feedback/bug reports would be appreciated! And any ideas for the next game would be awesome too.

Creating a UI for Connect Four

In developing my next game, I decided on Connect Four. It is still a fairly simple game with just a bit more validation logic, but more fun to play than tic tac toe. Since I am setting up a SignalR project for all of the games, I did not include logic for the game play in javascript with the exception of switching colors from red to yellow to alternate turns. Any game winning logic will be connected to the hub in the back end (currently in progress and even with unit tests!). Here is a code pen to preview the UI.

Once again, I used CSS Grid to set up my game board. Using some of my tic tac toe classes, I was able to easily set up the grid right away. One of the unique challenges for this was creating the transparent circle in each grid. There are a few ways this can be achieved, but I found one of the easiest was to use a box shadow in CSS and hiding the overflow of the div. Here is the code that helps with this- it is a class I’ve added to every square in the grid:

.grid-item {
position:relative;
overflow:hidden;
}

.grid-item::before {
content:'';
position:absolute;
bottom:10%;
left: 10%;
width:80%;
height:80%;
border-radius:100%;
box-shadow: 0px 0px 0px 50px #448CCB;
}

Tic Tac Toe with CSS Grid

I love games and as a developer it has always been my goal to create my own game at some point. Tic Tac Toe…honestly not a super fun game. But here’s the deal: as a developer, it’s easy to get ahead of yourself and come up with grand projects that you either don’t have time for or are too big and overwhelming to accomplish. My advice to beginner developers: start small. Choosing something simple allows you to focus on the concepts you want to learn, accomplish it in a short amount of time, and have something fun to share with others when you are done. It also can lead to those bigger projects that you originally wanted to make. In this case, my next step for this project is to set up SignalR so people can play against each other. And after that, I can make other board games or card games. Then after that, move beyond to something more advanced like an RPG or shooter. But the point is, you have to start somewhere. It makes it easier when your goals are realistic but can evolve and grow into bigger things.

The Project

CSS Grid makes creating layouts extremely easy, and while it might not be the ideal choice for creating a game, it allowed me to have some fun while learning about it. I also had a few challenges that allowed me to dive into some new solutions I have never used before.

tictactoescreen

Before I get into that, here is the link to the game. You can play with someone sharing a phone or desktop.

Challenge 1: Responsive Design with Aspect Ratio

I have seen examples with CSS Grid without media queries and I was hoping I could do the same for Tic Tac Toe while keeping it responsive. Yet, when it came time to maintaining the square while scaling up or down, it was a bit more challenging than I imagined. Looking for alternatives to media queries, I found something that would help.

Viewport Units
Of course, the first step for looking for solutions was Stackoverflow. This led me to some code that used viewwidths (vw). 1vw is equal to 1% of the width of the viewport (browser) and 1vh is 1% of the height of the viewport. So in the examples, the code I ended up with looked something like this:

grid-template: repeat(3, 30vw) / repeat (3, 30vw);

At first appearance, this seemed to solve the entire issue. Unfortunately, it didn’t do anything on vertical scaling and it also caused some problems with a wider monitor because its based off width. This lead me to vmin.

1 vmin is equal to 1% of the smallest viewwidth or viewheight. So for example, on a phone the width is smaller than the height, so vmin would go off of vw and if it was desktop, 1vmin would be equal to 1vh because the smaller side is the height. It took me a bit to wrap my head around it too, but this ended up working great for this project because it would always scale to the smallest size.

I still ended up using media queries in the end for some of the fonts, but I kept the viewports for the grid because they work out well. It isn’t perfect for vertical scaling- there is still overflow when vertically adjusting the browser, but with some more time on it using vmins, it could be improved.

Note: compatibility for viewport units is pretty good, but not perfect. Here is a browser list for reference.

Mobile Devices and Hover

After deployment, one of the first things I always do is open up the app on my phone. There is something satisfying about seeing your work in your hands. Yet, this is also where it can cause some disappointment. During development, I’m always working to make my designs responsive and verify this with resizing the browser or an emulator. But even with all of that, you can still end up with some surprises.
In this case, I have hover effect over the grid. On the desktop, it makes it easy to see where you will be marking your spot. This is not critical to the game, but it does provide a nice touch to the desktop users. For mobile, it caused an unintended side effect. When the user would touch the screen, it would apply the hover effect to the square, which highlighted it. Some might have let this go, it wasn’t the end of the world. Being a perfectionist though, I had to figure out how to get rid of it.

The Javascript Fix

if (!!('ontouchstart' in window)) {
//logic for mobile devices
} else {
//non-mobile
}

The ontouchstart is a javascript event that occurs with touch screens. One thing that you probably notice is the double bang (!!). It took me some headscratching as well on that, but this will take an object with falsey values (null, undefined, 0) and convert them to a boolean value of true/false. More on that here.
I did not go crazy testing this with tablets or different browsers because this app is really just a test project, but I will have to explore this more in the future.

Next Steps:
As mentioned above, I’m already looking into evolving this project into its next phase of converting to a web app and using SignalR for real time gameplay that will hopefully be a good foundation for future games. In the meantime, I’m just going to start small, and take it one step at a time 🙂

New Year, New Code

2019 has arrived and with a new year comes a time for reflection. As a developer, that should be no different. It is a good time to reflect on the previous year and start setting goals to accomplish in the new one.

2018 was a big year for me as I left my first development job to go to a new company. Making a move isn’t an easy decision, but one that I hope will bring new skills and challenges that will help me grow as a developer. In my new position, I’ve been working with .NET MVC and some legacy webforms, but looking forward to learning more about .NET Core.

It’s been 7 months since my last post (yikes) but even with the lack of posts, I have been busy working on some personal projects. First off, I have started the Javascript 30 course from Wes Bos. I mentioned it in my last post about CSS grid, but it has been a fun way to just play around with plain ol JS. I will post some reflections of that on here throughout my journey. I have some more CSS Grid content to post, including a version of Tic Tac Toe that I made awhile back. Finally, one of the bigger personal projects I am working on is a sports registration site (using Angular 6, .NET Core, SQL Server in Azure). And with that, hopefully I’ll produce some more blog posts. I need to continue to write more content in addition to coding.

Fun fact of the day- I’m writing this on the coldest day in Des Moines since 1965. Stay warm and happy coding.