C# Hangman in Silverlight

About two weeks ago my professor gave us a new assignment. We were supposed to create a hangman game using Silverlight. I hesitated to do it at first. Not because of the game logic, but because I am no good at artistic assignments, allow me to explain. 

I hate art, but some of my friends are really good at it. They can create visually stunning webpages, or edit an image in Photoshop. I can’t do any of that. I guess it’s because I am simplistic my nature. Anyways, during the period we were supposed to show off our assignments, the professor wasn’t too please, simply because I didn’t use the rotations and transformations the way he wanted. However, we have a slight problem. In the assignment outline it reads:
The interface should utilize various Silverlight shapes to implement an animation for the game. Use different types of transforms (translation, rotation, etc) to implement the animation. Use different shapes for this animation.”  

While watching my friends demoing their assignments, I noticed most of them had the hanging man swinging while it was being built. With this in mind I created my game, and had the title rotating when the user won the game. At first he questioned if it was text or a picture. A quick view of my solution explorer showed him it was a picture file I was rotating. I could tell that he wasn’t pleased, because I asked him if he wanted to see my code, and he said he saw all he wanted to see. He usually checks code and questions us to make sure we actually wrote it. I was very excited to show him that I did in fact write the code, but he didn’t check, he simply moved on. With all that being said, I will explain my code here. 
namespace TestApp { public class HangMan { public string Status { get; private set; } public int wordLength { get; private set; } public Word word { get; private set; } private List<string> missedLetters; public HangMan(string status) { this.Status = status; this.word = WordManger.retriveWord(); this.wordLength = word.strWord.Length; missedLetters = new List<string>(); } public void add(string add) { missedLetters.Add(add); } public ICollection<string> Letters { get { return missedLetters; } } public void checkStatus() { int score = missedLetters.Count / wordLength; if (score > 10 && score < 20) { Status = "Damaged"; } } } }

When designing this class, I thought back to XNA, and how it structured its’ game class. It had its constructor, initialize, loadContent, update and draw methods. I aimed to implement that same design in my Hangman class, I wanted hangman to control everything. That, my dear readers, didn’t turn out so well. My next objective was to create a static class to hold all my strings. With that thought, WordManager.cs was born.   


namespace TestApp { public static class WordManger { private static List<Word> wordCol; private static Random randNum; static int number; static WordManger() { wordCol = new List<Word>(); wordCol.Add(new Word("hangman","Type of Game")); wordCol.Add(new Word("linux","Type of Operating System")); wordCol.Add(new Word("office","A Place of Work")); randNum = new Random(); } public static Word retriveWord() { number = randNum.Next(0,wordCol.Count); return wordCol[number]; } } }

A test of my game showed me that the class was flawed. Although it had strings, it would help the player if I had hints. I then created a word class to have 2 strings, one with the word and one with the hint. It then was passed to the Hangman class which then split it up and passed it to the browser. Next came the textboxes, which I called Letterholders, so the letters could actually be displayed to the screen.


using System;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Ink;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes; namespace TestApp { public class LetterHolder { private Grid layout; private int numberofBoxes; private double marginX = 227; private double marginY = 170; private int height = 23, width = 27; private TextBox[] textArr; public LetterHolder(Grid layout, int numberofBoxes) { this.layout = layout; this.numberofBoxes = numberofBoxes; textArr = new TextBox[numberofBoxes]; } public void createHolder() { for (int i = 0; i < textArr.Length; i++) { textArr[i] = new TextBox(); textArr[i].Height = height; textArr[i].HorizontalAlignment = HorizontalAlignment.Left; textArr[i].Margin = new Thickness(marginX,marginY,0,0); textArr[i].VerticalAlignment = VerticalAlignment.Top; textArr[i].Width = width; textArr[i].TextAlignment = TextAlignment.Center; textArr[i].Foreground = new SolidColorBrush(Color.FromArgb(255,0,165,0)); textArr[i].Background = new SolidColorBrush(Color.FromArgb(255,10,10,10)); placeHolder(textArr[i]); marginX += 33; } } public TextBox[] TextBoxArr { get { return textArr; } } private void placeHolder(Control add) { layout.Children.Add(add); } } }

I thought of making this class an inner class of hangman. The reason being, the user wasn’t setting the word, it was the Hangman class. It would take the length of the word, then pass it as a parameter to the LetterHolder class. If I created the hangman class the way I wanted to, I could have had the loadContent method and call that instead. My main page is a little messy. You have the hangman and letterholder classes being declared. To me that could have been avoided.

Me not pleasing my professor didn’t sit well for me. I felt a a little sad, and somewhat embarrassed. Just that morning, I talked to my friends how he changed his attitude and overall teaching style. This new professor, was not the old professor I know. He was a little more easy going, and a lot more friendly. With that being said, his instructions need to be made clearer. If he wanted the animations to be part of t he game, then he should have said so. From the quotation above, he makes it sound that any type of animation, as long as its on the screen, would have been fine. “Animation for the game”  doesn’t count. To me that says as long as its on the screen while playing the game. For example, if he said, I want the rotations and transforms for the letters, then that’s specific, and I get it. The best I can do now is improve it on my own and leave it on my portable hard drive for future use. 

Life as a Writer Part 1: Introduction to Solid Snake

Have you ever read a book, saw a movie, or played a video game and have the main character stick with you long after you finish the game? Solid Snake is such a person. Yes, I said person, not character.

I was introduced to Solid Snake came when I found a CD with a few game demo’s on it. Metal Gear Solid was one of those demo’s. I started playing, and when you saw Solid Snake swimming up to take off his gear and the soundtrack kicked in, you where in for something special. I didn’t know it at the time, but Metal Gear Solid would have a profound impact on me as a writer. The demo finished with Snake and Meryl shooting it out with a bunch of guards. I would play it again hoping the game would continue after that point, but it didn’t. I ended up buying Metal Gear Solid as part of a 3 in 1 pack at future shop. 

I installed it and started playing, hoping the game won’t cut out after the shoot out with the guards. The game continued and Snake had to make his way around the base to another location. This time, underground to find and battle Revolver Ocelot. The impressive part about Metal Gear Solid and the series as a whole, has been the cut scenes. Some players are quick to say the cut scenes are intrusive and unnecessarily long. I have to admit, after awhile, you realize hearing the same dialog and seeing the same cut scenes over again can become tiresome.

It wasn’t the cut scenes that made this game impressive, it was discovering Solid Snake, and finding out what type of person he really was. Thinking Snake is a genetically mindless drone created as a killing machine for the government is a total misunderstanding of who Solid Snake really is. Hearing Snake talk to one of the other characters about love on a battlefield is mind-blowing, because you realize you aren’t playing a character, you interacting with a human, a human secret agent, who despite the fact he may not want to do the job of saving the world again, he gets up, puts on his sneaking suit, and does it anyway, because at the end of the day who else is going to do it?

My first play through, I managed to finished the game with the regular ending, not the special ending, with Meryl. I only managed to do that once several months later. Now, how did all this have an effect on me as a writer? A few years later, I had to put my career into perspective. I was studying software engineering, but I wanted more than that. I wanted to become a writer. That way, I can write novels, video games, and movies. When I started writing, my character template was Solid Snake. No matter what the character would turn out to be later on, Solid Snake was how the character began. Even when I read a novel, and I read a lot of spy novels, Solid Snake is the who I envisioned the main characters to be. 

Now, to be fair, I haven’t played a lot of video games since then. So, if their are any character’s that have the depth of Solid Snake, I haven’t met them. Metal Gear Solid is so much more than just a stealth game, it’s a thesis, a statement from the creators about the world we live in. The game from time to time will discuss nuclear weapons and genetic manipulation. What interested me, was how the creators implemented their own ideas into a game. I could take my writing to the next level if I made a statement, placed my own point of view in my work. I had numerous views about politics, religion and sex. Sadly however, none of these came to pass(post for another day).

At the end of it all, Solid Snake is the template for all my other characters. That doesn’t mean they have to follow the same path as Snake did, but it really says something about the character, when your using him as a base. Snake is a killer, a solider who has been through war. He is also has emotions, and views that, while we may not all agree with, it certainly makes him different among all the other video game characters, it makes him human.  

Leave your thoughts about characters that impacted you, be it from a movie, video game, or novel.

Trance on Friday Night– Part 1

Welcome to the first edition of Trance on Friday night.

Purpose:
I post these tracks because trance just put you into a great mood. No matter what it is I'm doing, programming, writing, or just relaxing, there is a song to go along with it.

Trance List and How I Discovered Them

  1. Denis Kenzo feat. Sveta B. - Lullaby Lonely - I discovered while listening to Armin van Buuren’s A State of Trance 567. Instantly took my breath away, I had to go to Youtube and track it down. It’s one of t those song where, if you were in a large crowd, you just put you hands up, sway them back and forth and enjoy every moment of this song.
  2. Andain - Turn Up The Sound (Xtigma Remix) – Found it again on ASOT 567. Wonderful sound to have in the background while your relaxing, or programming. I can’t tell you how much times this song got me though, what would have been a normal programming assignment.
  3. Ronski Speed vs. Oceanlab - EOS Satellite – I discovered this while Youtube surfing. Oceanlab has always been amazing. Justine Suissa’s sweet and heavenly voice takes you away into another world. A heavenly place you don’t want to leave. Listen to this song, dream, listen again. Repeat until you overload on happiness.
  4. Above & Beyond feat. ZoĆ« Johnston - Love Is Not Enough – I discovered while Youtube surfing. Need to spice up a broken heart after a nasty break-up? Look no further than this track.
  5. Groove Coverage – Wonderful life – Boring day got you down? Relaxing? Get into this track. Soon, you’ll notice you head shaking, lips moving and feet being erratic, don’t worry, these are all side effects of dancing and having a good time.

It’s a Virtual World. We are all Programs

Virtual machines can be very useful. Think of it as running an operating system within an operating system. Software such as VMWare and VirtualBox all users to do this. 

Why you want to use a virtual machine?
  • Test an Operating System/Software – Scared of trying out the latest operating system from Microsoft? Don’t want software messing with your registry? Use a virtual machine. User’s can even test out Linux operating system, from Ubuntu to Fedora, VirtualBox and VMWare provide support for both.
  • Viruses/Spyware/Malware – The internet, as we all know, isn’t so friendly. Without warning, your computer can be infected with a virus,spyware or malware. “But I use the latest anti-virus software!” Really? First, you must keep your anti-virus up to date, that way when you run a scan, your anti-virus has the latest definitions. People don’t often do this. Secondly, to actually catch these viruses, you must perform a scan, find it and get the tools to remove it. Some of us don’t do this. Virtual Machines, if infected, you can revert to a previous state, or you can delete the entire machine without formatting or reinstalling your primary operating system.
  • Recovery and Restore are Simple – Afraid your virtual machine is infected with a virus? Installed a piece of software that is hard to remove and now its clogging up your system? Don’t worry, VirtualBox, has what are called snapshots. Think of it as system restore. Before you make any big changes, shutdown your virtual machine and take a snapshot. You can always restore incase something goes wrong.
  • Portable – If your running Linux, you can take your virtual machines and run them. As long as your destination computer has virtualbox installed, your good.
The only downside is, when your creating your virtual machine, your asked to allocate some of your system resources to the virtual machine. So, you if have 8GB of RAM, and you create a virtual machine with xUbuntu for 32 bit systems, for optimal performance, you’ll want to allocate 2GB of RAM to xUbuntu. If your host machine is low on system resources, then your virtual machine will be slow. Divide and administer accordingly. 

I want to put together a how-to document about Virtualbox and Linux for newcomers. Different flavors of Linux have to be treated differently when it comes to Virtualbox. For example, xUbuntu, you can’t just install VirtualBox guest additions and expect it to work. The reason is, xUbuntu is a stripped down version of Ubuntu, so the graphics support is missing. You have to install that first, then install the guest additions. 

Hello World

I just created this blog! I know it sounds that I am a little late to the blogging world. However, this isn’t my first time blogging. I’ve had other blogs before, but it didn’t work it. I started this blog to share my thoughts, musings, and to clear my head. I’m writing this blog from the room I grew up in. It’s full of my programming books and a bed. I have my old portable hard drive laying around. 250GB doesn’t seem like a lot, but at the time I bought it, it was. 

What can I really say about myself? I am a programmer, my favorite languages are C#,Java, and PHP. I’m also a linux user. I currently use xubuntu on a virtual machine, but I’m hoping to purchase a new laptop and have linux as the only operating system. I used to be a gamer but I my PC became older and I don’t own any recent console. I still follow gaming websites, and listen to the podcasts but I don’t play games anymore. 

I should really come up with a posting schedule. I’m not sure how I want to do this. Maybe update 2 times a week. One segment that I want to really do, is Trance of Friday Nights. I want to share 5 trance songs that I found. I also want to have some post about programming and Linux. Who Knows? I’ll work this out, and come up with a schedule that I'm comfortable with.  

It’s currently a beautiful day outside. Nice day to go for a walk. Currently I am in my second to last semester in college. I’m taking software engineering, and I had a blast doing it. I met some new friends, lost some on the way(blog post for another day). Soon it will be time to look for a job. 

That seems like it for me. I know it isn’t much about me, but I’m a simple person, friendly,kind and helpful.  

Feel free to introduce yourself in the comments.