I haven’t been posting much on tumblr lately, mostly because I’ve been enjoying my summer and getting wrapped in other things. I made a twitter account, which I’m much more active on lately. Give me a follow if you’d like.
Last May, for my penultimate project in an introductory Java course, me and the two other kids in my class were assigned to “just make Minesweeper,” which is far more challenging than it sounds. Initially, I had difficulty with much of the logic. I managed to figure out how to assign the number of adjacent mines to each square, despite using a non-optimal and very convoluted set of rules. The one thing I just couldn’t figure out how to do (given a one-two week timespan) was the logic beyond squares with no adjacent mines revealing its surrounding squares and so forth. I told my teacher about it and he didn’t care, replying that it was “an advanced feature” and that I “shouldn’t worry about.” Needless to say, the code that I ended up turning in was very crude but still worthy of getting an A.
I felt cheated in a way, because I hadn’t really created Minesweeper, just a cheap knockoff that you couldn’t even play. So I decided to finish the program on my own time because it would be a good learning experience. When I resumed my project, the first thing I decided to tackle was my earlier problem.
I eventually found out a way to make it work, but I wasn’t satisfied with it. It was a non-optimal chunk of code that was very repetitive. After countless searches on Google, I was able to fix both the logic for counting mines and the problem I previously discussed in a very optimal fashion. I decided, “why stop here?” I might as well add a timing function just like the real Minesweeper, which is exactly what I did. It was pretty easy to do; I used the java.util.Timer class and had it execute the actionPerformed() method every second, in turn updating the amount of elapsed time in hh:mm:ss format. (which may have been overkill)
Afterwards, I decided to take it a step further and give the user the ability to customize the size and difficulty of the board. This proved to be a big problem for a long time. The size of the array of buttons was dependent on the number of rows and columns. After the array had been established, I wouldn’t be able to change its size. I played around with idea of using four arrays, which I thought was a waste of resources and it ultimately didn’t work. I settled on declaring the maximum size of the array (in this case [16][30]) and removing/adding the correct number of buttons from/to the grid depending on which difficulty option is chosen. Simple, easy, and it makes sense. Lastly, I decided to create two separate versions of the program: an applet and an application and placed them in convenient packages (com.tumblr.aguiney.minesweeper) instead of the default package, which I’ve always used up until now. I encourage you to take a look at it and tell me what you think.
The complete source code, including the application jar file, can be found on my GitHub account.
Unfortunately, I have no way of hosting the applet version because a) tumblr doesn’t allow applets, b) the applet won’t load on dropbox, and c) the Google App Engine doesn’t support client side code or most of the Swing/AWT libraries. For now, just download the application.
Also, I have a few ideas for some blog posts that are still in the drafting stages. Look forward to reading them; I promise they’ll be good reads. Next, I’ll probably finish my text adventure game which is now way overdue.
I’ve been spending the last couple of days learning Git and pushing/fetching updates to/from GitHub. Definitely going to be using this for my text adventure game. Oh Git, where have you been all my life?
Since djbooter asked, my GitHub username is pyreking.
rs06player:
Just wanted to share,
Nero’s JCalculator, download open-source here.
Information: Nero’s JCalculator is a simple open-source Calculator made by Nero using Java.
Version: 1.0 [ALPHA]
Future of the project: At last, this will be released to the public for learning purpose, also, I’m developing this just for getting knowledge in Java, the full release will contain a nice GUI and these stuffs, but I’m still learning anyway :D.
I discovered your post while searching through the tumblr tags for Java and decided to give it a try.
1. It’s compressed using a propitiatory archive format (.rar) which alienates people running Linux-based operation systems (Ubuntu, Fedora, etc). It took me awhile to open the archive because I had to find the right packages to install, which can be time-consuming. You should really use the .tar.gz archive format instead because it works on virtually every file manager without having to install any additional content.
2. You included a .bat script in your archive, which only works on the Windows operating system. Users running Mac OSX or Linux will either have to use the command line to run the program (a lot of people don’t know how to do this ) or import the src folder into Eclipse (or another IDE) and run it from there. Instead, you should compress the program into a .jar file, which is supported by every operating system with a JVM.
3. You shouldn’t call any of your classes “Main”. I know what you’re getting at, it’s the class containing the main method, but the name simply isn’t descriptive and doesn’t provide the programmer with any useful information. Once you start having projects with dozens or even hundreds of different classes, it’ll be really confusing what Main is or why it’s important.
4. You seem to break up the program into four separate classes that don’t do anything on their own. Instead, you should create a class called “Calculator,” code any methods that you need, and put it together in the main method. It’ll be much easier to read and less confusing for other programmers. You should only start a new class if you need a separate body of similar methods that accomplish a part of your task efficiently and can be re-used for later projects.
5. The comments aren’t very helpful in explaining what you’re trying to do in the class. Typing:
// Objects
public static Scanner s = new Scanner(System.in);
// variables
public static double FirstNumber;
public static double SecondNumber;
public static String type;
doesn’t tell us anything new; we know what objects and variables are. You should get into the habit of writing verbose descriptions before major chunks of your code so that programmers reading your code have a basic idea of what’s going on before they delve into the code; it’ll make their lives much easier.
6. Too many if-then-else statements; get into the habit of using switch. Trust me, it’s easier to read. Instead of typing:
if(ask.type.equalsIgnoreCase(“Sum”)){
Result = ask.FirstNumber + ask.SecondNumber;
}else if(ask.type.equalsIgnoreCase(“Minus”)){
Result = ask.FirstNumber - ask.SecondNumber;
}else if(ask.type.equalsIgnoreCase(“Multiplay”)){
Result = ask.FirstNumber * ask.SecondNumber;
}else if(ask.type.equalsIgnoreCase(“Division”)){
Result = ask.FirstNumber / ask.SecondNumber;
}
you should type:
switch (ask.type) {
case “sum”: Result = ask.FirstNumber + ask.SecondNumber;
break;
// … etc
}
Note: above only works if using a Java 7 compiler.
6. Attempting to divide by zero returns the result “Infinity.” Although this is a problem with Java’s implementation of float and double variables, you should really make an effort to prevent this.
7. Entering a letter or a number that doesn’t exist such as “j” or “4x” will return a InputMismatchException. You can fix this by surrounding the piece of offending code into a try-catch block that informs the user of the invalid input.
8. Lastly, you should make the program loop until the user tells it to stop. It can be annoying to the user if they have to launch the program every time they want to make a new calculation.
Hope this helps! If you need any other help, feel free to ask.
(via rs06player-deactivated20120405)
I haven’t posted anything related to Computer Science in awhile, so I’m going to talk about my experiences with choosing a software license.
I’ve always indended to release my software under an open source license because I believe that copyright law is way too restrictive. It is abused by companies like the RIAA whose goals are to unfairly limit the freedom of the consumer in any way they can. This lead me on a quest to choose a fair software license that doesn’t impede on the creative interests of the consumer but also doesn’t forfeit my control over the software.
I originally intended to use the Creative Commons license for my software — it seemed right and fair. That intention was short lived, however, when I read the Creative Commons FAQ. I found out that they do not recommend releasing software under their license because it isn’t optimized for software; none of their licenses specifically mention source code. I found this to be rather annoying but I continued searching nevertheless.
I looked at permissive licenses next — they were something I definitely didn’t agree with. It’s not that permissive licenses such as the BSD, MIT, and Apache licenses are bad — I just feel that those licenses are too liberal in granting the consumer rights and they don’t offer me much legal protection, either. I also don’t agree with the fact that it essentially allows somebody to build a proprietary derivative of my work without releasing the source code to anybody else — I feel that to be an injustice.
I arrived at the GNU General Public License afterwards — the most popular open source license. While it contains a body of terms that I agree with for the most part, I decided to pass on it. The GPL 2.0 is pretty outdated (having been last revised in 1999); the language of the license is unnecessarily vague and irrelevant in today’s day and age. The GLP 3.0, which was last updated in 2007, is more relevant but has certain clauses pertaining to software patents that has made the GPL 3.0 unpopular among the open source community.
So what license did I finally decide to choose? The Open Software License (OPL). It isn’t particularly well known or used much within the open source community (Richard Stallman advises against it on his site) but it was finally something that I could agree with.
The body of terms is very similar to the GPL but with a few differences:
- It was last updated in 2005, so I don’t have to worry about it being too outdated.
- It was actually written by a lawyer/computer scientist (Lawrence Rosen is the name), meaning that the language of the license is very concise and understandable (the entire license being only 16 paragraphs long).
- It deals with patents in a different way then the GPL 3.0 does. It possesses a self-terminating patent clause stating that if a company uses/distributes/modifies OPL software and then proceeds to file for patent infringement against the owner then that company loses the ability to use/distribute/modify any software containing the same clause. This effectively prevents a company from stealing somebody else’s source code, changing it it a little, and then suing the owner for patent infringement.
- The license was designed in a way that it can be used for any creative work, not just source code (similar to the Creative Commons license). This is perfect for me when releasing video games because I can release every part of the game (including text/art/maps) under the OPL instead of having to complicate matters by releasing parts of the game under different licenses.
It also allows me to charge for a copy of the software so long as I release the source code and other people possess the ability to redistribute and modify it for free (I realize the GPL grants this right as well, I just wanted to mention it). This allows me to make money while making it legal to “pirate” my software; many companies have simply lost control in trying to fight this lost cause.
The OPL is a wonderful and underrated license that will serve me well in the long run.
My dad got it for me as a late Christmas present. I’ve got a lot of reading ahead of me!
Christmas vacation is too short.
I used to believe I had all the time in the world during this vacation — the truth is, I don’t. It’s probably because I’m growing older and sleeping for 10-11 hours a day. I don’t like to do work over vacation — that’s the point of a vacation, after all. Unfortunately fun stuff like programming and editing my film falls under “work.” It’s not that I don’t enjoy it, it’s simply because I work hard at school all year long doing mundane stuff that I simply want to forget about everything and just enjoy myself a bit. Which is exactly what I’ve been doing in the form of playing Skyrim day and night — that game truly is addictive. Now that I’ve settled in a bit, I realize that vacation is already over.
I have to go back to school on Wednesday and now I realize that I have a film to edit which is going to be a ton of work. The shots are really simple and straight forward — two longshots and the rest medium shots. I’m editing in Adobe Premiere, however, which I have no idea how to use. On top of that, I recorded sound separately and I have to worry about it syncing up properly. You could say that it was my fault for waiting so long — which it is — but how am I suppose to enjoy my vacation if I’m constantly worrying about work? I worry about work enough as it is.
I’ve only learned a minimum of Java over vacation as well. I only learned how to display images and play audio. I haven’t really been in the mood lately and I’m not quite sure how to proceed regarding my projects. I started a web port of the Last Slice Decider (see my other posts) using Google’s Web Toolkit (it compiles Java to JavaScript) but I got a little discouraged when I couldn’t figure out how to make the client side code interact with the server side code when loading/saving the correct order and passwords. I also haven’t been working on A Priceless Item (my text adventure game) for months because of the reasons mentioned above.
I asked my dad to get me either Java: The Complete Reference or Effective Java for Christmas (he previously gave me a guide to Java EE development which I wasn’t ready for). I’m not sure when I’ll have the time to read either, though.
If only Christmas were two weeks longer — I would be able to concentrate on my film and Java after the initial “I have no obligations” effect wears off. You know what — I’ll try and get A Priceless Item released by June. That’ll be my New Years Resolution.
You know you’ve been coding too much when you try and add a semi-colon after every sentence;
I probably shouldn’t be proud of this, but I’ll wear it as a badge of honor. Today, I became a true programmer. :D
On Thursday, Ubuntu prompted me, asking if I wanted to upgrade from version 11.04 to 11.10. I figured it wouldn’t hurt to have the latest version, so I clicked yes to the upgrade. It told me it was going to take 2 - 3 hours to upgrade, which I was fine with. In the middle of the upgrade, the screen turned black and a message told me that a file was corrupted. I started to panic, so I turned off my computer and turned it back on. Instead of booting up like normal, it brought me to a recovery mode screen. At first, I tried booting up my computer regularly, but that didn’t work. Then I tried booting it into safe mode, which brought me to a low-graphics version of Ubuntu, but I was never able to get past the logo screen. I started to panic even more because I had some unsaved files, including Java exercises and my Priceless Item stuff. I fiddled with the options for awhile, and tried booting up into previous Ubuntu versions, but nothing seemed to work.
On Friday, I asked my mom if she could help me recover some of my files before reinstalling Ubuntu. She took out my HDD and tried to hook it up to her Windows 7 computer, but Windows couldn’t read the HDD for some odd reason. We tried the same thing on my brother’s Mac, but it didn’t recognize the HDD, either. Then, I got a bright idea. I decided to download a fresh copy of Ubuntu 11.10 onto my 2GB SD card. Ubuntu has this neat feature where one can try out the OS before installing it onto the HDD. I plugged my SD card into my laptop and booted Ubuntu successfully. And what do you know? Ubuntu was able to read all of my files, so I backed up everything that I needed onto my 32GB SD card and then re-installed Ubuntu.
It recognized that I still had Ubuntu 11.04, and it asked me if I wanted to upgrade instead of deleting everything and starting over. To make a long story short, it froze before ever finishing the update. I finally said “screw it” to upgrading properly, deleted my partition, and installed Ubuntu 11.10 fresh.
I have no idea why Ubuntu acted the way that it did. I really hope I don’t have to do this every time I want to upgrade my OS.
I also want to mention something about Ubuntu 11.10 before I end this post. I like how they made the Software Manager more user-friendly and more-prone to being able to recognize .deb files.
One thing that I am not happy with is how they removed support for the official Sun Java 6 packages and you are now forced to use the OpenJDK packages instead. As a developer, I don’t appreciate this in the slightest. OpenJDK will always lag behind as well as not supporting all of the features of the official version. I looked up a tutorial, and I successfully installed the official version of Java 7. When I decided to open Eclipse, I got this vague error message about it not being able to recognize my JDK version. I got flustered and searched everywhere for a solution, but nothing worked. Not wanting to deal with it, I reluctantly re-installed OpenJDK 7 and then the Eclipse problem went away.
Lesson learned: always back up your stuff before upgrading to a new OS. Also, if the OpenJDK becomes a problem for me, I might have to look into different Linux distributions that support the official version.
Today, I had a Java quiz. It was extremely simple, assuming that I had a competent IDE to use. Eclipse? I wish that were the case; I would’ve finished the quiz in 5 minutes tops if I was using Eclipse.
Instead, I had to use this ancient, proprietary, IDE called “Code Warrior” that nobody has ever heard of and is a piece of shit. I can’t even figure out to make a new class file; it’s complicated and doesn’t even work the way that I expect it to work. Since I knew I was under pressure and didn’t have time to figure out how to use it, I simply deleted lines of my calculator program and edited in the new stuff that was relevant to the quiz. I’m all set, right? I wish it were that easy. Code Warrior does not have a compiler built in, it uses the god awful Windows “cmd prompt” that wants to be a terminal but fails so hard. Error highlighting, right? Every good IDE underlines incorrect code in red and gives a small description about it. Code Warrior has no such feature. It waits until you attempt to compile the .java file and then hits you with a barrage of error messages that make no sense. Yep, you guessed it. It’s the equivalent of writing code in notepad and manually compiling it using the words “javac example.java” and “java example.”
Actually, it doesn’t even do that. It compiles it to a .jar every time, which makes no fucking sense. Why on earth would I want my program to be compiled to a .jar unless I tell it to? What audience is Code Warrior catering in? What purpose is it serving? To be frank, nobody. I quickly Google searched “Code Warrior review” and the results gave me content dating back to 1997. No self-respecting programmer would use this instead of Eclipse or NetBeans (I personally do not like NetBeans, but at least it can call itself an IDE).
I did finish the quiz, but I almost ran out of time when I didn’t need to. I’m going to ask my teacher on Monday if I can use Eclipse in a polite manner, and I will state the advantages for doing so. I already know Java, and using Eclipse will help me get my work done quicker. There are literally no downsides to using an IDE that I’m comfortable using, especially under pressure. Also, I don’t exactly agree with using proprietary software, either.
If you ever have the unpleasant experience of using the Code Warrior IDE, I pray for your sole.
http://www.mediafire.com/?08d650uxvksce6r (.jar file)
http://www.mediafire.com/?l94qb25bdvhz2q4 (.java file)
I decided to finally finish my little side project yesterday, “Last Slice Decider.” It was largely finished from the last time I worked on it, which was in August.
All I needed to do were three things: successfully loop through three names, write a method to save the loop to a file, and a method to load the file the next time the program is launched.
For my first task, I tinkered with several different loops before finding the best one. I decided to create a member integer variable named “order” and I set its value to 0. Then I created a method called “listPerson()” and created a switch statement with cases numbered 0-2. Each statement used the setText() method of JLabel to display a different name. After each statement, I wrote the brake statement to prevent the switch statement from fulfilling more than one case requirement. I wrote order++ outside the loop so the switch statement will always go to the next case the next time the method is called. Finally, I wrote an if-then statement that sets “order” to 0 if it’s value is equal to 3, successfully going back to the beginning of the loop.
After successfully creating my loop, I decided to look up the best way to load and save data to a file. I found a good tutorial on object serialization and decided to implement it in my program. I made all three password fields transient to prevent the passwords from being saved in the data file. The rest is pretty much self-explanatory. I wrote a method called “saveData()” that creates a file named “pizza.data” and an ObjectOutputStream. The writeObject() method of the ObjectOutputStream is then called and “order” is saved to the pizza.data file. This method is called every time the “listPerson()” method is called (ie, the user clicks the “Yes” button), after all of the switch and if-then statements are executed. Next, I made a method called “loadData()” which does the exact opposite. It loads the pizza.data file and inputs it into an ObjectInputStream, and casts “order” to an Integer object before being read from the file. This method is called at main, which ensures that the data is always up to date.
Don’t worry if you have no idea what the hell I just said, it’s a simple program with a relatively complex user interface. Just download the program and try it out. I know it has no use for you, but it has a lot of use for me. :P All three passwords are “t,” this was just a test when I was debugging my application. My brothers and I will have three completely different and (hopefully) complex passwords when we use this program. I have also included the source code with this post (everything is heavily commented) so feel free to poke around with it.
I made a new team consisting of Dante, C. Viper, and Wolverine. It was fun, but everyone destroyed me. I managed to win only once, but that’s it. There were also a couple of matches that were pretty close. I’m not too good on the arcade stick, so I stuck mainly to the the Sixaxis controller. I hope to change that in the future, however. I might play daily so I can improve my skills, since I don’t really have any other games to play at the moment. I know everyone hates Capcom for their little UMvC3 stunt, but I might ask for it for Christmas. Phoenix Wright and Strider being in the game is a huge attraction for me, so we’ll see. Watching the EVO tourney got me interested in fighters again. :P
Oh yeah, tomorrow I’ll continue production on my game. I haven’t worked on it lately, so I need to continue asap. As it stands, my Item, Location, and Exit classes are all finished. Enemy and Player classes are the only ones I need before I start the funky shit with object persistence. If you don’t understand what that means, don’t worry. It’s just a little thing that will make my life easier.
(Source: aguiney)
Don’t worry, even though I haven’t worked on my game in a couple of days, I haven’t forgotten about it.
Anyways, I decided to make an application named “Who gets the last slice?” I don’t know about you, but in my house, pizza is a big fucking deal. Even more so is who gets the slice of pizza. We developed a system of taking turns, that way it would be fair for everyone. Unfortunately, nobody can ever remember who had the last slice last and what the order of the rotation is. My application intends to solve this problem by remembering who had it last and then spitting out the next person to have it.
http://i51.tinypic.com/2d0hri1.png
http://i52.tinypic.com/214nz44.png
http://i53.tinypic.com/fcldw8.png
It’s not quite that simple. The application has three password fields, one for each of us. In order to use the program, three different passwords have to be inputted. This is so that nobody can deliberately change the output of the program in their favor. The “no” button closes the program, the “ok” button inputs the three passwords, and the “yes” button displays the brother who gets the last slice and is only enabled after all three passwords have been inputted. After you press the “ok” button, all three password fields are cleared out and yes is disabled again to prevent abuse. I coded the bulk of the program yesterday, before I had to go to work. All I have left to code is keeping track of the sequence via input/output stream.
Ah, nerds coding programs for things other people consider trivial.
(Source: aguiney)