Programming Fundamentals Portfolio�Myles Coleman
Week 1 – Types & Variables
This being the first week we learned the very basics of C++, starting with how to write and how take information from the console. This was achieved through cout (write to console) and cin (take information from the console), From this point we moved to some simple variable:
Week 2 – Boolean Logic & Comparisons
Starting the second week, we worked on boolean logic as well as many different operator types.
Comparison operators:
Logical operators:
We also looked at conditional statements:
Week 3 – Loops & Arrays
The arrival of the third week brought new tools and challenges for us in C++. We began with loops:
Then we started exploring arrays. A way to store data of the same type together. This helped condense and streamline code. Whilst we didn't explore arrays greater than one dimension too much, we were made aware of their existence and practicality.
Week 4 – Circles
In the fourth week we began looking at circles, and how to create and display them within visual studio. In doing so we also furthered our learning from last week, with arrays.
We looked at numerous functions to help aid us with our experimentation:
Week 5 – Circles - Structures & Vectors
With the fifth week we again continued with circles. This time expanding our code to use some new knowledge from lectures.
We began with creating a structure, this was used to clean up our code, defining it elsewhere so it could more easily be called for later functionality.
Continued on next slide.
Week 5 – Circles - Structures & Vectors - Continued
Next, we looked at vectors, vectors are a more versatile form of array. They do not have a fixed size and have many more functions that can be used with them, such as "push_back" allowing you to add to the end of the vector. And "resize" which allows you to change the size of the vector.
To better demonstrate our newfound knowledge of structures and vectors we set out to make the circles generate another circle on collision with the walls. This created a "newCircle" utilising our structure, then "push[ed it] back" onto our vector.
Week 5 – Circles - Mouse Input
With the completion of the primary worksheet, I moved onto the advanced. This involved adding mouse functionality.
Firstly, we looked at "IsButtonPressed", this was used to detect which of the mouse buttons was pressed. From this we could use an if statement to add functionality. Such as creating, or moving the circles, dependent on input.
Next, we looked at "GetMousePosition". This got coordinates for the mouse. Allowing us to use these to, move the circles to the mouse.
Week 6 – Functions
This week was spent on functions. A method that allows code to be re-used in a much more efficient, clean manner. We were tasked with creating a maze game and used functions throughout to make our code more readable.
The format for functions is very simple, take this example:
type name(variable 1, variable 2)
{
Code to be executed
}�
Name(variable 1, variable 2)
As you can see, much like variables, they have a type – this can be set to void if no type is relevant. A name, to help define them. And within the brackets are some variables which are being passed through, these aren't strictly necessary and can far exceed two if required.
Looking at the other section of code we can see how a function is called. The name, followed by some brackets containing the variables you may or may not wish to pass through. You must ensure if the original function contains variables that these are passed through.
*Console from a previous instance of testing
Continued on next slide.
Week 6 – Functions - Continued
Continued on next slide.
Week 6 – Functions - Continued
Week 7 – Pointers & References
The following week we continued with the maze game. I spent this week adding an enemy AI which traversed the maze randomly. Should the player make contact with this enemy, the game ended.
Whilst I didn't utilise any pointers or references within my code, I now understand their "point".
On top of this, the map was updated to place the enemy. And, when the map is iterated through, I ensured to colour the enemy a different colour – purple.
Continued on next slide.
Week 7 – Pointers & References - Continued
Week 8 – Animex
As week 8 was animex all lectures and lab sessions were cancelled. This does not mean nothing was learned this week. One of the talks during animex covered optimisation and certain debug tools. Unfortunately, a lot of this went over my head as it was far above my current level.
However, I believe the videos will be released so perhaps I will be able to revisit that once my skills have improved.
Week 9 – File Handling
Continued on next slide.
Week 9 was spent exploring files and implementing them within our maze. This is done so through, "fstream".
We started by allowing saving and loading of our current maze. Functions were created for this.
Using a "cin" I allowed a file name to be made and then opened this file. Iterating through the maze and writing each character (leaving a space inbetween for clarity) to a file effectively saved this maze. Then the file was closed.
For loading the maze a similar method was used, asking the user to pick a file to open. Then opening that file, iterating through the file and writing each character to the maze.
An error check was made for both of these, ensuring a file was opened.
Week 9 – File Handling - Continued
Once this was done, more mazes were created. This was because multiple levels were on the agenda. It was a relatively simple addition, in the winEvent() function I added plus one to the level variable, the variable which held the current level number. So, when the player touched the goal, the level went up, then I added this to a file name variable. Then through calling the load() function I was able to load the level using that variable.
I did encounter a bug where the old player position would remain, but this was a simple fix involving a new if statement which ensured the player wouldn't be moved if they won.
Week 10 – Classes
Circle.h
main.cpp
Continued on next slide.
Week 10 – Classes - Continued
Circle.cpp
Week 10 we went back to our circles script, replacing our structure with our own class.
Classes, like structures, allow us to create our own types. The key difference is classes allow control over what can access certain member data and functions.
To achieve this, we create two new files: "Circle.h" and "Circle.cpp". Circle.h is known as the header and holds the type definitions and functions. Circle.cpp is what holds the implementation of that code.
Week 11 – Classes: Inheritance
Week 11 we explored inheritance in classes, this being when a "child" class inherits from a "parent" class. The child class effectively become the "parent" class but with any added functionality. Saving you time and effort or rewriting code, ensuring each script only has what it needs.
Whilst this is what I learned; this isn't what I developed. I spent the week creating a rectangle function, per my task list. This was relatively simple following almost identical logic to that of the circle.
Whilst there are other scripts with other additions, this is the bulk of the differences to that of the circle class.
Github Source Control Version Code
Github is the definitive way to backup code and share it amongst peers.
Here you can see my projects, uploaded.
One of the key features of github is the ability to create branches, this allowing you to work in a contained environment for testing, bug fixing and prototyping – ensuring problems don't spread to the main project.
Portfolio Reflection
With all learning materials now completed I can look back at my journey and assess the effectiveness of my learning, my areas of strength and of weakness.
Whilst C++ was a new programming language for me, I noticed it follows a similar syntax to C#. And as I became quite proficient with C#, the transition was not too jarring. This meant the first three weeks, as they primarily followed building an understanding of simple programming logic and the syntax, was quite easy and brought along no difficulties.
Looking at the fourth and fifth week we began looking at SFML and how to create circles using it, as I was completely unfamiliar with the library this came as quite a challenge. I simply struggled to understand the logic and how to use it to my benefit, but with my tutors and peers help an understanding was eventually found. This meant once I had the ball rolling, or the circle bouncing so to speak, it was relatively smooth sailing. Relatively, when it came to allowing mouse input there was one key problem. Getting the code to register one click, which whilst it did take a while was eventually solved with a simple Boolean statement.
From week six to nine (with a break on eight) we began creating a maze game, this is when the work truly began to challenge me – primarily due to the complex logic which was involved. Getting the maze to display came as quite a challenge to me, my first attempt had only the first line showing and then once this was resolved I noticed it was displaying at the wrong angle. But eventually through trial and error, as well as some outside help from tutors I eventually landed on the solution. Creating the functions for the circles was met with zero problems, due to its similarities with C#. Week seven, I tasked myself with creating a simple enemy AI to roam the maze. As a lot of the movement code could be reused from the player's I was able to save some time. But unfortunately, I lost quite a bit of said time due to a bug. The enemy was moving more than one tile at a time, due to how I was looping through the function, however with some debugging the problem and its solution came to my attention. Whilst the enemy does currently work as intended its functionality is quite limited, as it can't track the player, and instead moves randomly it can often get stuck in the corner. Ideally, I would've liked if it could track the player and have more logical movements, but this was both beyond my time and my skills. Week nine again brought challenge, I had previously explored file handling in python – but this was met with great difficulty. It remained equally as hard in C++, but once I grasped the fundamentals it was met with little difficulty. The core challenge was trying to understand how to load the file once it was saved, and whilst I did spend a great deal of time researching and attempting possible solutions, the answer was not only right under my nose but simple too. Following the same logic used to save the maze. Whilst there was a minor bug with getting the player to reset on level change this was solved relatively quick.
Continued on next slide.
Portfolio Reflection - Continued
Week ten brought us back to the circle script, this time updating to use classes. Due to the lecture which preceded this I was well informed, well enough to confidently implement them myself. Whilst there was no problems encountered; I do wish I was able to fully implement my circle code into the class. As currently the mouse input, namely the right mouse click was met with errors which I was unable to resolve if it were so. For week eleven we continued with our circle code, as I had already completed the tasks mentioned I opted to push for the extension. Creating a class for rectangles, this was almost identical to the circle class, however. Due to this there were no difficulties present.
Looking back now at my final products, namely that of the circles and the maze game. Starting with the circles, I wish I could've explored more into the framework provided to further my understanding and proficiency, but my time was focused on other University tasks. Namely experimenting more with the rectangle functionality.
The maze game, whilst I am very proud of the final outcome, is quite barebones. This made making the subsequence levels quite challenging, as I was working with such a small palette. If I were to have added more advanced tiles such as locked doors, teleporters or moving traps; this would've helped to alleviate that problem.
But for my journey with C++ as a whole I am very proud of what I've learned in such a short time, and am sure it will go to great lengths to helping my employability.