Tic-Tac-Toe Android App 0

November 25, 2017

Sharing is caring:

After a two-week crash course in Java we were assigned Tic-Tac-Toe (TTT) as our first Android application. At that point in the bootcamp, my diet consisted of anxiety, dread, and spurts of sleep. And even though I had completed the labs and homework, confidence and I weren’t not friends. Frequently, I found myself questioning my sanity at quitting my job to attend the bootcamp. The only saving grace was that TTT was a homework assignment and not a project.

As a homework assignment Tic-Tac-Toe had fewer technical requirements compared to later projects. The assignment required a functional game app with three main user features.

Users can enter their names on the first screen. Once entered username will appear on the screen during their turn.

Two people can play a game. Users will be able to touch a square on the Tic-Tac-Toe board and the corresponding X or O will appear. After each turn the game will check to determine if there is a winner.

Display the winner. When there is a winner the username will appear with a congratulatory message on the screen.

Success

Initially, only two features were functional.

Users can enter their names on the first screen. Friday night, I began the app by coding the ability to input the user name and pass it to the next activity.

Intent intent = new Intent(MainActivity.this, GameActivity.class);

EditText editText = (EditText) findViewById(R.id.player_one_name);
       
      
mplyrOne = editText.getText().toString();
        
       
intent.putExtra("Player One",mplyrOne);
        

startActivity(intent);

Display the winner. Following that, I coded the determine winner combinations.

if ((a1.getText().toString().equals(a2.getText().toString())) && (a2.getText().toString().equals(a3.getText().toString())) && !a1.getText().toString().equals("")) {
            return true;
        } 
else if ((b1.getText().toString().equals(b2.getText().toString())) && (b2.getText().toString().equals(b3.getText().toString())) && !b1.getText().toString().equals("")) {
            return true;
        } 
else if ((c1.getText().toString().equals(c2.getText().toString())) && (c2.getText().toString().equals(c3.getText().toString())) && !c1.getText().toString().equals("")) {
            return true;
        }

Failure

Two people can play a game. Finally, Saturday afternoon I started working on the game. Unsure about the code, I googled Tic-Tac-Toe in Android and Java. Plenty of results were provided, and while none matched my exact needs, they did provide me with an idea of what my code should look like and with that I started coding. By Saturday night I was optimistic, I could figure it out.

However, by Sunday evening, I was less confident. With each new set of errors my confidence dwindled and my anxiety grew. Feeling that I was too dumb to understand kept me from seeking assistance from my instructor. Eventually, the frustration lead to tears at which point I decided to call it quit. A couple of weeks later, my classmate/mentor showed me the error in my code and it turned out I was close.

  if (mgameStart) {
          
      if (gamePlay.getText().equals("")) {
       
         if (mgameMessage) {
 
               gamePlay.setText("X");
           
               draw=noWinner();
                 
               if(!draw) {
            
                  mgameEnd = determineWinner();
    
                  if (mgameEnd) {
                        
                      mnamePlyr.setText("X wins");

   
                  } else
             
                      mnamePlyr.setText(mplyrTwo + "'s turn");
       
                  mgameMessage = !mgameMessage;
                    
               }
                  
               else {
                        
                  mnamePlyr.setText("draw");
  
                  
               } 
               
          }

Reflection

The process of creating Tic-Tac-Toe was emotionally transformative. After three emotionally charged weeks, Tic-Tac-Toe was my breaking point and saving grace. Once all the stress and anxiety were gone, I could think clearly. The fog of panic along with the paralyzing fear of appearing stupid was lifted. I found a balance between the immersive and everything else. I was renergized.

Aside from emotional growth, I learned four key lessons to being a programmer. First, nothing is simple, assume complicated until completed. Second, if I’m stuck on the same concept after fifteen minutes and several blog posts, ask for help or move on. Third, there are two types of stuck: mud and quicksand stuck. Mud stuck is the best, push through the problem and you’ll succeed. Quicksand stuck is the worst, your every attempt to solve the problem only leads to being more stuck until you are buried. Fourth, most importantly, there is no shame in not knowing only not asking for assistance.

 

 

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.