Use a type alias like using container = std::vector > if your compiler supports it, otherwise use a type definition like typedef std::vector > container. Use a type alias / type definition for the std::vector > container You have for loops like for (int i = 0 i >::size_type. If none of the check conditions are true then you should explicitly return false at the end of the function. All control paths of check() should return a value You should reject an input if the user enters an invalid row and/or column number (like you do if the user selects a space that is already taken). For example, if I enter a 3 as the row and/or column number the program crashes. You don't check that the user entered a valid vector index. Void draw_board(const std::vector >& vec) Doing so makes the code maintainable and expandable through looser coupling.I have written this simple code for Tic Tac Toe. If you want to generalize and expand on your code, you'll need to detach user interaction from game logic. Taken out of context, a variable name like places has non-obvious purpose, but as a struct member, aces or ttt_state.squares is a bit clearer. This makes it easier to understand the purpose and relationship between these pieces of data. Int places = Īre loose variables that are conceptually attributes of the same entity and as such should be grouped in a TicTacToePosition structure along with a set of functions that operate on this structure. I started learning C last week and today I wanted to see if I can make a working program, so I made this game: /*
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |