Andrew Wegener's blog

Hong Kong thoughts

Archive for the 'C++ Game' Category

C++ Programming FINAL

Posted by Andrew Wegener on 15th November 2012

It’s finals week! I sound excited because I actually just finished my last exam!  Let me tell you about me C++ Programming final.  Our professor wanted us to modify an existing game.  This project is simply experiential and pretty open.  When I hear the word “mod”, I instantly think of Minecraft.  It seems like there are mods for Minecraft coming out all of the time.  So, I figured, it must be fairly simple.

I started off with research as usual.  I came upon a thing call Minecraft Coder Pack (MCP for short).  This was my key to modding this game.  Once I got it running, I realized it was all in Java…. issue.  However, I’m not a quitter.  I was almost willing to learn the Java language so that I could complete this mod, but once studying the source code, I realized it was not necessary.  Java and C++ are both object-oriented languages so they work pretty much the same.  The languages were similar enough so I could read the code and have a fair understanding of what it was doing.  A major issue is that there is over 8.5 billion lines of code in Minecraft, and finding the single line of code that changes what I want was pretty difficult.  Through forums and a whole lot of googling, these were some changes I was able to make:

Flipping the world upside down (found by accident!)

Huge creeper explosions! (or teeny tiny!)

Miltank the Pokemon!

Sunset (before)…

Sunset (after). Awesome!

Tepig the Pokemon!

I also changed the perspective, running speed, and jumping height so it was like a crazy acid trip or something.  A really great experience over all, perhaps over the break I can make a new mod on my brand new computer I bought!!!!! (pics hopefully to come later!) Have a great holiday season everyone!

Posted in C++ Game, C++ Programming | No Comments »

Assignment 5B – Strategic Luck

Posted by Andrew Wegener on 31st October 2012

 

Yay! More C++ coding!  Well, judging from the pseudocode, this should be relatively easy, right? Wrong!  Just kidding.  Overall, it was pretty easy.  Let me explain:

The first part of the game is the generating of each players’ pieces.  This could be fairly simple.  However, the first set of rules I declared stated that:

1) Each player would receive ten pieces with randomly generated powers from 1-10.

2) The greater of the numbers will defeat the lesser.  The only exception is that 1 can defeat a 10.

These rules are flawed.  In theory, a player could receive ten 10s and be guaranteed to win (if the other player doesn’t have any 1s).  What I’m saying is that in some cases, it could be impossible for one player to win.  Lately, in my ITGM 351 Cognitive Art of Game Design class, Professor Rueda has been making us read about balance in games.  As it is, this game is not balanced.  It is important that games create the illusion of fairness to its players.  My solution to the imbalance was this code that determines the players’ powers:

I decided to set three randomly chosen pieces to certain powers.  This code ensures that each player will definitely have at least two 1s and one 10.  This virtually eliminates any predetermined victories or losses to either player, obviously extreme, outrageous cases can still occur but the chances are slim to none.  Also, the three random pieces are named Slot A, Slot B, and Slot C.  I added the “do… while” loops to make sure the same piece was not chosen for two slots.

The actual loop of the main game is less than 100 lines (including a fair amount of white space).  The majority of the code, in terms of lines, is from the function that displays the game board.  This function is a whopping 800+ lines.  All that remains are the random number generator function, the clear screen function, the directions, the title, and SPOILER ALERT!!!!!!….

(Highlight between the dashes to reveal the spoiler)

A GIANT PIKACHU!!!

One last thing I would like to mention… This was the first program I’ve written that I did a new (to me, at least) debugging technique.  All of the blue text are “comments” – the compiler just skips that line after the //.  Something weird was happening with the Slots and their values, so I inserted multiple cout statements telling the compiler to display the values of the slot variables.  So, if you want to play this game on “easy” mode, you could just delete the //s then the pieces values will be revealed to you.  Fun stuff!

The debugging technique and a better understanding of functions were the biggest experiences I took away from this assignment.  I have had many of my friends play this game and it’s hilarious seeing their excitement/frustration/satisfaction while playing.  For example, the game ONLY displays the enemy pieces, and ONLY when they are defeated (including in a draw).  I enjoyed this project and it went smoothly for me for the most part.

I am not allowed to post the .exe file, unfortunately.  Find my contact information and contact me. Maybe you’ll be lucky enough for me to send it to you!

Posted in C++ Game, C++ Programming | No Comments »

Assignment 7 – Compile an RPG in VS – WitchHunt

Posted by Andrew Wegener on 31st October 2012

After the previous assignment, I was about ready to give up on Visual Studio – AKA murder it.  I was so frustrated, I just wanted to make a very simple RPG and not worry about downloading anything.  So, I started make Zelda! It was such a trivial attempt that I didn’t even bother saving the project before Professor Rueda stopped me and told me to download an RPG game and compile it.  Tentatively, I gave in and began searching.

Here are some problems with this assignment: 1) Visual Studio GAMES are not easy to find. 2) RPG games are even harder to find. 3) RPG games tend to have many many many external libraries.  It took me at least 6 tries before getting one to work.  Thankfully, my classmate, Mariel, used to Linex (a fairly new term to me) so she is familiar with linking libraries and compiling programs.  She was able to download and compile a game by the next class which was about a week before it was due.  So, she was nice enough to help me out with downloaded and compiling my game.  After a couple failed (or too complex) attempts, we came across a Pokemon game.  If you’ve played Pokemon, you know there’s a lot of Pokemon, a lot of attacks, a lot of abilities, a lot of items, etc.  The Pokemon game I downloaded had hundreds of libraries full of much of this information.  Mariel walked me through how to link libraries and set up project files properly.  After I had to link all the libraries by hand (as opposed to clicking on a single folder), we realized that it was necessary to download a new compiler and access their libraries to get the game to work.  A brief attempt at finding these was unsuccessful, so I went back to searching.

I found a game called Hale.  I had everything copied into my project folder and was about to compile when I opened the last folder and realized it was in Java.  However, the linked files and everything still works fine, it’s just not the right language.  I’ve played the game for hours already – I think it’s really fun!  But sadly, it’s worth nothing if I do not find a C++ game.

It wasn’t long until I found another game.  This one is called Witch Hunt.  It’s an ASCII game written in C++ and works in Visual Studio.  This compilation was surprisingly smooth.  After Mariel’s help previously, I had a decent understanding on the basic requirements of compiling a game properly.

I am not sure if I’m doing something wrong, but early on in the game, it is necessary that you walk outside where monsters can attack you.  When this happens, I try escaping – then the game crashes.  Although this is frustrating, I DID get it compiled on my own!

This assignment, admittedly, taught me a lot.  Mariel was a huge help and now I’m curious as to what games I will be able to compile myself since I get so much enjoyment from playing Hale.  Hope the next Visual Studio project will be this successful!

Posted in C++ Game, C++ Programming, Visual Studio | No Comments »

Assignment 4B – C++ – Lucky 7

Posted by Andrew Wegener on 10th October 2012

This is my first experience touching the C++ language.  Overwhelming while reading the chapters, but slightly more comprehensive once it became hands-on.  For this assignment, I wanted to create a short minigame from Mario Party 3.  Since my arrival in Hong Kong, my group of friends and I play Mario Party a couple times a week, so I thought this fit in well.  The game is simple – here is a screenshot of the instructions.

Basically, roll the dice, once or twice (rhyme!), and finish equal to or higher than the computer without falling off the staircase.

First, I needed a random number generator.  Here’s how to do that.

This says “I can pick a random number!” (above)

This is a nifty little formula to imitate rolling a die.  Melissa helped our class understand this.  So, someNumber = the random number (anything between + or – a “gazillion” (quoting Professor Rueda)).  diceRoll will equal the [huge random number "modulus" 6] + 1 . Modulus was a new term for me.  Simply put, it the remainder of the division of the following number.  For example, if the huge random number is 34821, mod (short for modulus) by 6.  To start, divide 34821 by 6.  The answer is 5803.5 . OR 5803 with a remainder of 3.  Therefore, 34821 % 6 = 3.  Some smart people figured out that dividing any integer by 6 will always have a remainder of 0-5, so, if you add 1 (like the formula does) you will always get a number 1-6 aka a dice roll.  Like Pikachu on toast.  Swag.

So let’s get started, first, I needed a game board to show the progress of the player and computer.  Rather than figuring the roughly 72 possibilities of where each player could be located, I can call on a function!  Check it out (below – click to enlarge this one)

It’s simply a series of If statements saying “if computer is here, and player is (or isn’t) here, show the player piece on this step”.  All it had to do is use the inputs of the computer’s height and the player’s height which are stored in global variables.

Now that rolling works, I wanted the computer to “cheat”.  Okay, yes it cheats – no quotation marks.  But not to the point that it always wins.  Here’s what I mean (below).

This says ” if it’s the computer’s (I call it Nemesis for no reason) second turn only, add it’s current height to the dice roll.  If it’s more than 7 (if it would fall off the staircase), say “I pass this turn.” and pretend it never rolled.” This  just means that the computer will never fall off the stairs but will always make use of it’s highest possible score.  So if the total is less than 7, it will state the roll and still move.

That basically sums it up.  Unfortunately, I’m not allowed to post my game for security reasons.  Lame.  This is not Pikachu on toast.  Oh well!  Play Mario Party 3 and play the Game Guy game Lucky 7!

Yay! I win!

 

Posted in C++ Game, C++ Programming | 1 Comment »