bighat360 wrote: |
---|
Also, if you can tell me how to go about getting to designing a game such as Tetris I would love to learn how to go about it |
Research and plenty of notes.
As with any program, you need to do some homework (yeah, I know, coding is the fun part, why don't we just jump in and code?). Usually this entails a design approach, how everything will interact and so on. When it comes to games, the best place to start is to either understand the rules (of an existing game) or to create very specific rules (if making your own). You have to figure out what's valid input and how to check. Let's saying you're making a number guessing game, you don't want the user to enter letters or anything, so you have to write that down.
You also want to learn at this point how everything should interact. Should each piece be allowed to change color, or should it be a fixed color? Should the board know what a piece is, or only the fact that there is a grid, some elements filled, some empty. OOP is the best way to go when approaching any game, however, I didn't know any OOP back then, so it's possible to create something good without knowing that (look at your Tic-Tac-Toe game). Once you figure out how everything works (sometimes you need to learn a few things about C++ before you can understand what's possible and what's not), it's a lot easier to jump in.
Start by defining your classes and each of it's methods, let's say we have pieces, board, and the overall game. The game knows all, so it has a board object, and controls piece objects. The piece is only relevant for when the user is moving it, and before placing it on the board. You can also implement a preview window that displays the next piece. A piece doesn't do much, but should be able to share it's information with other objects. The board should be able to return if there is an object at x,y so you know if the spin is going to be valid or if it would clip the object.
As you program anything, especially something like Tetris, you'll run into a ton of issues that you didn't foresee (until you learn more about programming) and might have to rethink some things. It's a tough process, but you'll learn a lot more about programming by just making, what appears to be, a simple game.
I will mention this now, C++ isn't designed to be used in this manner, consoles aren't designed to have colors, and C++ isn't meant to handle keyboard input. With that being said, if you're determined to violate these standard rules, there are workarounds (depending on the OS).
I suggest at least learning the basics of OOP before attempting Tetris. Learn classes and methods (inheritance isn't necessarily important here nor is abstraction). I'd also suggest into looking into console coloring (I have a few posts on this forum, as do other members, about possible ways to achieve this), creating a sleep method (sleep() exists in the windows.h header if you're using windows OS), and a way to accept keyboard presses (avoid conio if possible, windows.h has an alternative (there are some posts regarding using windows to accept keyboard commands and return the key pressed)), and if you want to do it correctly, learn threads (it's an advanced concept, but will fix timing/input issues).
You can pick and choose what you want to learn, but if you learn it all, you'll thank yourself later on (I still have yet to learn how to properly learn threads) as it will make your life much easier. I believe my final code was about 800 lines with little to no comments. I designed and planned and coded for a total time span of almost 2 months, but I had a lot of spare time back them (I didn't do school work, just worked on my program).
If you want some advice, I'm more than happy to help, as are other members here. Just remember, a lot of stuff that's included in your code won't be standard (making any kind of game will have several non standard features). I have been tossing around the idea of recreating my, back then, masterpiece, but I keep looking at what is going to be involved and have decided that I have too much to do to deal with the headaches that will be involved. Don't let this deter you, however, as once you actually get it working, you're going to be so happy and feel fulfilled.
If you have any more specific questions, you can reply here, create a new thread, or PM me (I get PM's in my email so I tend to respond to them fastest).
In regards to your Tic-Tac-Toe game, there are a few things that can be improved upon, like OOP as pogrady suggested, but I'd also suggest making the code a little more module. Create a Game function that handles the entire game, pass parameters such as playername if you want, player 1 should always be x, so no need to pass any characters, but you could pass a bool for single player or multiplayer. Once you take a step back from your physical code and grab a pen/pencil and paper, you can start thinking in a modular form. If you notice that certain code is repeated a lot, make it a function.
I've been rambling on, but that should give you a few things to read and think about. If your intention is to build games, I'd suggest reading some topics on game programming (doesn't need to be C++ specific, but does help) so that you can understand what thinking processes you need to have during the design process and what issues you'll run into. Most articles will be unbiased towards any language, but the author will likely post code, if any, in their favorite language.