Unless you know how long the game loop will be on every computer, making your sleep a constant is generally bad practice. If you know that you want 2fps, a good way to keep it in line is get the time at the start of the game loop, then at the end, find out the difference, and use that to calculate the amount of time needed to sleep to keep the step the same. E.g, If the loop takes 0.1s, and you want 2fps, then put in the sleep of 0.4s. Other than that, I'd possibly say that you need to have another variable alongside food which is snakeLength or something. I don't know if you're printing out the score on the screen, but if you are keeping track of the score, I'd imagine that you want it to start at 0, as opposed to 3, and 1 more int isn't that big a deal when you get better readability. Possibly consider making direction an enum, with UP, DOWN, LEFT and RIGHT, because right now it's a little tricky to follow, and you wouldn't need to change too much of the logic, as enums are ints with some extra stuff, so you can easily compare in the way that you're doing now.
Having said that, I'm not sure I follow what your direction values relate to, as I don't see anywhere that direction is set to 5, so that check seems unnecessary. In your generateFood function, you access map directly, where you've made a function which does that job exactly in getMapValue, so you might want to consider using that, as at some point in the future you may decide to make it a Map class and then you'll run into errors with accessing private variables (I'd hope!). Other than this, things seem pretty good, so I'm going to start nit-picking:P. I'd just suggest little things like alphabetizing your #includes and function prototypes. It's not that big a deal since you have 2, but something to bear in mind. As well as that, your clearScreen and printMap feels a lot like a Draw, so you could possibly wrap them both up in that function, and just call init, update, draw and cleanup (when you're doing object loading and using pointers and whatnot) since you seem to be nearly following the (as an aside, if you are planning to make more games, read that entire book, it's a thing of beauty), and reading that article better explains my point about sleep. $ begingroup $ I don't understand the anti-oop/pro-procedural argument.
From an architecture perspective, a class (or whatever your language likes to call it) is just an instantiable version of what you're already writing. (your file's globals become member variables, and functions become methods). The biggest difference is OOP is more flexible, as interfaces can be defined and satisfied at runtime, enabling things like clean runtime implementation swapping or collections organized by interface instead of memory layout.
Notepad biasanya digunakan hanya untuk menyimpan catatan kecil, tetapi tanpa kamu sadari para pengembang sebuah game bisa menciptakan sebuah game sederhana hanya dengan menggunakan Notepad tersebut, buat kamu yang penasaran bagaimana cara membuat game menggunakan notepad, berikut tutorialnya. Buka aplikasi notepad pada PC kamu.
$ endgroup $ – Oct 13 '14 at 18:58. $ begingroup $ @weberc2 This isn't the forum for that unfortunately, but most of my knee-jerk is primarily from inheriting unreusable OOP code from people who don't understand the paradigm, but who use it only because they've always been told they should. That and as a high performance computing researcher, I tend to use a lot of procedural coding, since most things are, at least initially, ad hoc. Once I prove usefulness, then I try to abstract it out, or decide what is going to happen to it. Doing it the other way around would be much more work for me, but, as always, Your Mileage Will Vary. $ endgroup $ – Oct 14 '14 at 14:11.