CS 112 - Introduction to Computer Science II
4th Hour Project: Unity Traffic Lights Game

Due: Monday April 20 27 before class 37.

NOTE: This work is to be done in pairs.  I strongly recommend the practice of Pair Programming described simply here.  Although team members are permitted to divide work, each team member should be able to informally present all work of his/her teammate.

Unity Development of the Traffic Lights Game

There is only one actual due date for this project (see above).  Part of the learning experience here is to pace your own work towards a larger goal.  I'll make suggestions as to how one might break up the work and spread out your effort, but a large part of successful work practice is the ability to give priority to important, non-urgent tasks over unimportant, urgent tasks. This point is well-described in Covey, Merrill, and Merrill's book First Things First, where they assert that work effectiveness is highly correlated with predominance of "compass-driven" important, non-urgent activity over "clock-driven" unimportant, urgent activity.  For larger college projects, especially those that will develop important skills or open new doors, one needs to develop an ability to plan and track important tasks so as to avoid procrastination and thus reduce resulting important, urgent activity.  See also Brian Tracy's relevant book Eat That Frog!: 21 Great Ways to Stop Procrastinating and Get More Done in Less Time.

Suggested Outline of Work:

Objectives

Traffic Lights Game

The game Traffic Lights, originally called Semaphore, was invented by Alan Parr.  Reported years of invention/publication vary from 1985 to 1992 to 1998.  We will focus on the 3-by-4 version of the game.

Each square of a 3-by-4 grid is considered to be a light, initially off.  Players alternate selecting a square that does not show a red light.

The first player that makes three lights on in a row/column/diagonal of the same green/yellow/red color wins.  (Played perfectly, 3-by-4 Traffic Lights is a 2nd-player win.)

Here are sources where you can learn more about the game:

Using Unity on our system

To start Unity on our system, the command is "unity3d".  (Warning: The "unity" command starts the graphical shell for the Linux GNOME desktop environment.)

When you are prompted to sign in you can use the shared account (available to everyone) with the username and password provided to you via email. Single-click the desired project name to open, as double-clicks seem to crash Unity's attempt to open the project twice in rapid succession.

You can also log with your own account, or just click the "Skip" button. This last option prevents one from accessing the Asset Store in Unity. There are some good free resource in the Asset store, but it is not necessary.  

REMINDER: When you open an existing file, click it ONCE. (double clicking causes the project to open and then abort the program)

To Select a Unity script editor:

(You only have to do this once.)

You may select a different editor if you prefer.

Unity Tic-Tac-Toe Tutorial

Do the Unity Tic Tac Toe tutorial up through at least step 9.  Your work here should be available for demonstration during your grading demo appointment.  I've written up some notes on my own experience with the tutorial, and you'll be well-advised to note how I check for the winning condition in Tic Tac Toe.

You may optionally obtain Unity and develop on your own machine with a student license.  Details on how to start Unity on our own department system will be provided after Spring Break.

A Unity Tic Tac Toe tutorial YouTube playlist is also available.

Images and Game Layout

Create/obtain your project images for your green, yellow, and red lights. Your design should be color-blind-friendly in some form and should respect copyright.  Color differentiability can be tested through sites such as the Colblindor Color Blindness Simulator (Coblis), but you may also address this design concern through the use of shapes as seen in this game image.  (Note how the shapes are cleverly iconic, bringing to mind a circular green light, a triangular yellow yield sign, and an octagonal red stop sign.  For more on color palette design for the color blind, see this article.

Create the 3x4 Unity project layout, modeling your process after that of the Unity Tic Tac Toe tutorial through about step 5.  In addition, develop enough of the game controller to cause each grid cell light to pass from off to green to yellow to red.

Game End and Restart

Add to your game logic the ability to detect a winning three-in-a-row in any row, column, or diagonal line of the board.  Note that there are 14 3-in-a-row possibilities for each of 3 colors, so you'll want to write better game-end code than in the tutorial.  (See my tutorial notes above.)

Clearly indicate a win. This can be through display of a message.  It's even better to programmatically render line(s) added dynamically by your controller code.

Allow the user a means of restarting the game, resetting all grid cell lights to off, removing any game end message(s)/line(s). 

Always have Player 1 start the game.  That's what makes them Player 1. :)  Players can always change their role.  The end of the Tic Tac Toe tutorial where one chooses whether to start with X or O is just silly.

Add a Player Turn Indicator

Clearly indicate whether it is Player 1's turn or Player 2's turn.

Critique and Improve

Playtest your game a lot.  Make it a game implementation you would want to play.  This is the Golden Rule of programming.

HTML Deployment and Testing

When deploying to HTML.  You'll select menu items File -> Build Settings..., select "WebGL" (with the HTML5 logo).  Click "Build" and direct the .html file to be placed somewhere within your ~/public_html folder to allow me to easily browse and play it.  Note this location.

To set permissions such that everything in your public_html folder is publicly accessible, use the recursive command "chmod -R 755 ~/public_html".  Whatever is in your public_html folder will be visible via "http://cs.gettysburg.edu/~<your username>".

Android Deployment and Testing

When deploying to an Android .apk file, one must first define Android settings.  Through menu option Edit -> Project Settings... -> Player, set Company Name to "Gettysburg College" and Product Name to "Traffic Lights".  Next, select the android icon tab midway down, select "Other Settings" and set the Package Name to "edu.gettysburg.<username>.trafficlights" where <username> is a unique identifier for your team starting with characters and possibly including digits and underscores. 

(Note that there are other "Settings for Android" that allow you to create app icons, a splash screen, etc.  These are optional for this project.)

Under File -> Build Settings..., select Android, and set Build System to "Internal".  Our Android SDK is installed in "/usr/local/android-sdk-linux".  Click "Build" and direct the .apk file to be placed somewhere within your ~/public_html folder to allow me to easily download, install, and play it.  Note this location.

To set permissions such that everything in your public_html folder is publicly accessible, use the recursive command "chmod -R 755 ~/public_html".

"Error: It looks like another Unity instance is running with this project open"

If you get this error and you do not have the project open already on some computer, it is likely that a Unity lock file has been left behind after a Unity crash. (See https://forum.unity.com/threads/error-it-looks-like-another-unity-instance-is-running-with-this-project-open.458280/)

The solution is to delete this file: [ProjectRootFolder]/Temp/UnityLockFile

Sample Builds

Grading Demo Appointment

During the week of the due date, teams will schedule a 30-minute appointment for demonstration and testing of:

Grading Rubric (20 points total):