Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Sunday, March 4, 2018

2048 Clone in Java, a Journal

I am revitalizing this blog to try and keep track (and think through) design choices with my next project in Programming 2. The first two projects were mostly a flop, and I wondered out loud to my friends if doing this would help me stay on track. This is essentially a rubber-ducky journal. If it helps anyone else, that's awesome, but it is mostly for me.

Our goal is to create a version of the math game 2048 with a themed spin on it. The theme we are assigned as default is Star Wars, but if we can come up with another theme, it will be an extra 5 points.

The original 2048 can be found here: http://2048game.com/
The Star Wars version we are mimicking is here: https://0x0800.github.io/2048-STARWARS/

I'm only starting to set up my class structure, of which I've determined I need at least 3 things.

  • The Game class will handle:
    • Game States - currentGame, gameOver (gameWin and gameLost), restartGame
    • Current score and best overall score
  • The Tile class will handle:
    • Tile borders and whether a tile can combine with another tile
    • Tile values
    • Tile colors/symbols
  • The Board class will handle: 
    • Number of tiles on the board
    • Tracking tile positions
    • Tracking empty tiles
    • Spawning new tiles
There is also an FXML document and a Controller class, since we're using JavaFX and SceneBuilder to create the UI and handle animations, soundFX, and music. Here's a rundown of what the game should have:

  1. Background music
  2. Animations
  3. Sound effects for each piece
  4. Tile must be abstract
  5. Must use an interface
  6. Must correctly keep track of current score, high score, and if the game was won or lost
  7. Bonus: A HELP function that will highlight possible moves
  8. Bonus: A theme other than Star Wars
  9. Bonus: A SWAP (cheat) function to allow for the swapping of two tiles
What I would like to add is an extendable panel that will display the values of the pieces, since we'll be working strictly with symbols. I think I can do so with the Gluon Navigation Drawer, but I'll need to research how it works and make sure it will do what I'm envisioning.

I'll update with my progress as this week goes on. Hopefully, with it being Spring Break for the next week, I'll have plenty of time to get some of the structure hammered out!

Thursday, August 21, 2014

New Program to Oggle

I finally hammered out the computational error in the program project I've been working on this week the past day or two. As with most of the programs out of this book, it is riddled with specific tools the author wants to be used at this point, and arbitrary numbers (which, are hopefully less-arbitrary with the comments I've written). Have a gander:

/* Programming Project #8 Chapter 5                                *
* Write a program that asks the user to enter a time (expressed in *
* hours and minutes, using the 24-hour clock). The program then    *
* displays the departure and arrival times for the flight whose    *
* departure time is closest to that entered by the user.          */


#include <stdio.h>

int main (void)    {

    int hours_entry, minutes_entry, min_since_midn;
                          /* minutes since midnight */

    printf("Enter a 24-hour time: ");
    scanf(
"%d:%d", &hours_entry, &minutes_entry);
   
    if (hours_entry > 24)    {    
         /* Error message for invalid hour value */

        printf("Invalid hour value; please try again.\n");
        return 0;
        }
       
    if (minutes_entry > 59)    {   
         /*Error message for invalid minute value */

        printf("Invalid minute value; please try again.\n");
        return 0;
        }
   
    min_since_midn = hours_entry * 60 + minutes_entry;
   
    if (min_since_midn <= 532)   
           /* 8:00am is the first departure, converted to
            * minutes equals 480 minutes since midnight, plus
            * the equivalent of half of the amount of minutes
            * between 8:00am and 9:43am */

        printf("Closest departure time is 8:00 a.m., arriving at 10:16 a.m.\n");
    else if (min_since_midn <= 631)
            /* 9:43am is the second departure, same as above */
        printf("Closest departure time is 9:43 a.m., arriving at 11:52 a.m.\n");
    else if (min_since_midn <= 723)
            /* 11:19am is the third departure */
        printf("Closest departure time is 11:19 a.m., arriving at 1:31 p.m.\n");
    else if (min_since_midn <= 804)   
            /* 12:47pm is the fourth departure */

        printf("Closest departure time is 12:47 p.m., arriving at 3:00 p.m.\n");
    else if (min_since_midn <= 893)   
            /* 2:00pm is the fifth departure */

        printf("Closest departure time is 2:00 p.m., arriving at 4:08 p.m.\n");
    else if (min_since_midn <= 938)   
            /* 3:45pm is the sixth departure */
        printf("Closest departure time is 3:45 p.m., arriving at 5:55 p.m.\n");
    else if (min_since_midn <= 1223)   
            /* 7:00pm is the seventh departure */
        printf("Closest departure time is 7:00 p.m., arriving at 9:20 p.m.\n");
    else if (min_since_midn <= 1439)   
            /* 9:45pm is the last departure, so all times after *

             *
9:45 will display this time */
        printf("Closest departure time is 9:45 p.m., arriving at 11:58 p.m.\n");
    else
        printf("Invalid entry; please try again.\n");
       
    return 0;
}
Criticisms and advice are both welcome -- just know that I only really have int/float types and if/switch statements with a smattering of logical operators and relational operators in my arsenal at this point in time. Next chapter will be on Loops, and a few chapters later, I'll finally get into Arrays! (I also apologize for the atrocious line-break issue. I did my best to make it pretty and easy to read!)

Thursday, June 6, 2013

More Chapter 2: King

Chapter 2 is huge. Huuuuuge. I had six pages written halfway through section 4...

While working on these notes earlier this week, I was listening to Chopin's Nocturne Op. 9-72. Andrei was merrily doing some creative writing pertaining to our story at the time, and despite the tribulations from the afternoon prior, I felt truly peaceful and content. It was a beautiful, fleeting feeling.

Driving to work, today, too... It was raining because we have a tropical depression hanging over us, and it was dark because it was still early... But I just had this feeling like... "I am so light and happy..." Just in general. Things are just really good.

Anyway, notes are below the break--


Thursday, May 23, 2013

BAH!

Working on coding and writing tonight, because my fiance has a few projects he's busy with. I took more notes from K&R, but man do I still have a long way to go. No better way to put your knowledge to the test with miniature tests, like using what you've learned so far to write a program from memory.

Looking back over that little chunk of text (I wrote it out in my notebook), I made 4 terrible mistakes that would've kept the whole thing from compiling... The worst one was leaving out the variable assignment!! Aggh!!

It's okay though. Deep breaths, and lots of note-taking. I've taken to slowly working through the descriptions of the statements, going step by step until I'm certain that I understand what they're talking about. If I can keep that up, I think I'll be okay.

Anyway, for more notes, click the break!