Categories

Saturday 15 November 2014

Programming week one!

Hi there blog!

Long time no see. I have been busy doing stuff so nothing has been happening here lately.
This week the programming course started! I love programming so for me to just be able to focus all my time on stuff that I love a lot is amazing.

Since I have been programming a bunch before there wasn't really anything new to me concept wise. The thing that differs in how programming languages are operated is usually just syntax, which often is not very different from most other programming languages. So I have been taking it easy this week. People from the class have been hanging out at school after the lectures to practice programming. I have been there, helping those who needs helps and exchanging knowledge with those being around the same programming level as me. I have been testing some grid based programming and tried to make a snake game in the console.

We got a list of non mandatory programming exercises which I could finish pretty fast. I think it really helped that I had been practicing programming not so long ago so I had it fresh in my mind. I finished the codeacademy.com python course a while before this course started and I finished a summer course this summer, also in python, called "sommarprogrammering" which translates directly to summer programming. Also this summer I have been looking at some videos, which really is a great way to learn, where a guy talks about how to program in c++ from the basics and up.


Process of unfinished snake game:
So I made a two dimensional int array, which I at best can explain to you non programmers as a list filled with lists that are filled with numbers, where every number represents something. 0 means empty space, 1 means snake part, 2 means apple. I had an infinite loop*, as timer and a sleep function for delay, making the program wait to not make the game go too fast. Then I found this function online that returned true only if a keyboard key with a certain keycode was pressed. I figured out the key codes for the arrow keys then I made the program just check in every clock tick if any of the arrow keys were pressed. If any of them returned true I changed the direction of the snake head in the direction of the arrow. The difference is just if the snake head's x and y coordinates goes +1 or -1 every clock tick. Then I just took the coordinates of the snake head and turned that coordinate into the two dimensional array, by using y as list list index number and x as number list index number, and then changing the value in that location 1 if it was 0 before. Every tick I had another loop that cleared the screen form text and then recreated the two dimensional array into a new text that the program then pushes out on the console screen. I realized that the console wasn't that fast too update the text on the screen, so the game was doomed to lag and be slow. I stopped developing that project then because that killed my motivation.

* An infinite loop is basically a list of instructions that the program goes through one by one until the end of the list where the program goes back to the first instruction and this repeats forever until the program stops or reaches a message that tells it to stop.


What could I have done better this week?
I could have asked for harder programming tasks earlier to make the most of my time. I have also been thinking about creating and posting videos about programming, because I have heard that one of the best way to remember things is to teach it to others. I believe there is this quote by Einstein that "if you can't explain it simply to others you don't know it good enough" or something like that. I really believe that is true, even if I can do these tasks and know how to do them, if I can't do them easily in a simple way then it will take too much energy for me too do things that are harder than these things. Also teaching out to others motivates you to check everything so you don't give out false or vague information.

This weekend I am going to look into SDL, which is a programming library we will be using, and try to do something graphical and maybe record a video of it to help others in my class. I'll also look into a lot programming and c++ terms on Wikipedia to get a deeper view of what the things are and why they exist. Next week I'll continue to go on the lectures so there isn't anything fundamental in c++ programming that I miss and so that I can ask questions if they would arise.

No comments:

Post a Comment