Technique of all board-like games?

This is a discussion on Technique of all board-like games? within the Game Programming forums, part of the General Programming Boards category; Hi, FOr console text based games like tic tac toe, connect four, battleship, maze and etc etc, often the squares ...

  1. #1
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020

    Technique of all board-like games?

    Hi,

    FOr console text based games like tic tac toe, connect four, battleship, maze and etc etc, often the squares in between the board or a grid needs to be updated. How is that done? Do you have to redraw the whole board every time an update is to be done? Or do you go back and edit whatever's needed. But how do you do that if this is the case?

    thnx in advance

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    139
    i use gotoxy()
    "The most common form of insanity is a combination of disordered passions and disordered intellect with gradations and variations almost infinite."

  3. #3
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    I just have a draw function which reads the array, clears the screen and updates it with the new info...

    Here's my draw function from a tictactoe game I did like 6 months ago..

    Code:
    void table(void)
    {
    	cout << "\n\n\tCurrent Table\n";
    	cout << "\t" << (char) 201 << char (205) << char (205) << char (205) << char (205) << char (205) << char (203) << (char) 205 << char (205) << char (205) << char (205) << (char) 205 << (char) 203 << (char) 205 << char (205) << (char) 205 << char (205) << char (205) << char (187) << endl;
    	cout << "\t" << (char) 186 << "     " << (char) 186 << "     " << (char) 186 << "     " << (char) 186 << endl;
    	cout << "\t" << (char) 186 << "  " <<board[0][0]<<"  " << (char) 186 << "  " << board[0][1] << "  " << (char) 186 << "  " <<board[0][2]<<"  " << (char) 186 << endl;
    	cout << "\t" << (char) 186 << "     " << (char) 186 << "     " << (char) 186 << "     " << (char) 186 << endl;
    	cout << "\t" << (char) 204 << char (205) << char (205) << char (205) << char (205) << char (205) << (char) 206 << char (205) << char (205) << char (205) << char (205) << char (205) << (char) 206 << char (205) << char (205) << char (205) << char (205) << char (205) << char (185) << endl;
    	cout << "\t" << (char) 186 << "     " << (char) 186 << "     " << (char) 186 << "     " << (char) 186 << endl;
    	cout << "\t" << (char) 186 << "  " <<board[1][0]<<"  " << (char) 186 << "  " << board[1][1]<<"  " << (char) 186 << "  " <<board[1][2]<<"  " << (char) 186 << endl;
    	cout << "\t" << (char) 186 << "     " << (char) 186 << "     " << (char) 186 << "     " << (char) 186 << endl;	
    	cout << "\t" << (char) 204 << char (205) << char (205) << char (205) << char (205) << char (205) << (char) 206 << char (205) << char (205) << char (205) << char (205) << char (205) << (char) 206 << char (205) << char (205) << char (205) << char (205) << char (205) << char (185) << endl;
    	cout << "\t" << (char) 186 << "     " << (char) 186 << "     " << (char) 186 << "     " << (char) 186 << endl;
    	cout << "\t" << (char) 186 << "  " <<board[2][0]<<"  " << (char) 186 << "  " << board[2][1] << "  " << (char) 186 << "  " << board[2][2] << "  " << (char) 186 << endl;
    	cout << "\t" << (char) 186 << "     " << (char) 186 << "     " << (char) 186 << "     " << (char) 186 << endl;
    	cout << "\t" << (char) 200 << char (205) << char (205) << char (205) << char (205) << char (205) << char (202) << (char) 205 << char (205) << char (205) << char (205) << (char) 205 << (char) 202 << (char) 205 << char (205) << (char) 205 << char (205) << char (205) << char (188) << endl;
    	cout << "\n";
    }

  4. #4
    Unregistered
    Guest
    Originally posted by Dual-Catfish
    I just have a draw function which reads the array, clears the screen and updates it with the new info...

    Here's my draw function from a tictactoe game I did like 6 months ago..

    Code:
    void table(void)
    {
    	cout << "\n\n\tCurrent Table\n";
    	cout << "\t" << (char) 201 << char (205) << char (205) << char (205) << char (205) << char (205) << char (203) << (char) 205 << char (205) << char (205) << char (205) << (char) 205 << (char) 203 << (char) 205 << char (205) << (char) 205 << char (205) << char (205) << char (187) << endl;
    	cout << "\t" << (char) 186 << "     " << (char) 186 << "     " << (char) 186 << "     " << (char) 186 << endl;
    	cout << "\t" << (char) 186 << "  " <<board[0][0]<<"  " << (char) 186 << "  " << board[0][1] << "  " << (char) 186 << "  " <<board[0][2]<<"  " << (char) 186 << endl;
    	cout << "\t" << (char) 186 << "     " << (char) 186 << "     " << (char) 186 << "     " << (char) 186 << endl;
    	cout << "\t" << (char) 204 << char (205) << char (205) << char (205) << char (205) << char (205) << (char) 206 << char (205) << char (205) << char (205) << char (205) << char (205) << (char) 206 << char (205) << char (205) << char (205) << char (205) << char (205) << char (185) << endl;
    	cout << "\t" << (char) 186 << "     " << (char) 186 << "     " << (char) 186 << "     " << (char) 186 << endl;
    	cout << "\t" << (char) 186 << "  " <<board[1][0]<<"  " << (char) 186 << "  " << board[1][1]<<"  " << (char) 186 << "  " <<board[1][2]<<"  " << (char) 186 << endl;
    	cout << "\t" << (char) 186 << "     " << (char) 186 << "     " << (char) 186 << "     " << (char) 186 << endl;	
    	cout << "\t" << (char) 204 << char (205) << char (205) << char (205) << char (205) << char (205) << (char) 206 << char (205) << char (205) << char (205) << char (205) << char (205) << (char) 206 << char (205) << char (205) << char (205) << char (205) << char (205) << char (185) << endl;
    	cout << "\t" << (char) 186 << "     " << (char) 186 << "     " << (char) 186 << "     " << (char) 186 << endl;
    	cout << "\t" << (char) 186 << "  " <<board[2][0]<<"  " << (char) 186 << "  " << board[2][1] << "  " << (char) 186 << "  " << board[2][2] << "  " << (char) 186 << endl;
    	cout << "\t" << (char) 186 << "     " << (char) 186 << "     " << (char) 186 << "     " << (char) 186 << endl;
    	cout << "\t" << (char) 200 << char (205) << char (205) << char (205) << char (205) << char (205) << char (202) << (char) 205 << char (205) << char (205) << char (205) << (char) 205 << (char) 202 << (char) 205 << char (205) << (char) 205 << char (205) << char (205) << char (188) << endl;
    	cout << "\n";
    }
    wow, did you know c++ has loops? :P

  5. #5
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    wow, did you know c++ has loops? :P
    Are you being sarcastic?

    To elaborate on what DC said: Make a 2 dimensional array with the appropriate characters in each side of the array. For example, with Tic-Tac-Toe the whole array would be blank to start off with. To create the 9 square wtih 3 rows and 3 columns effect just display " | "s and " - " in between the appropriate spaces of the array, just like DC did. To insert the X or O into the array just go grid[x][x] = 'X'. Lets say you want there to be an X in the very middle square then you would go grid[1][1] = 'X'. Easy enough, right? Then clear the square and redisplay the grid and you should now have an X in the very middle square.

  6. #6
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    Yea. But what if you have stuff, for example, text below the grid or something? I'll need to rewrite that too if i clear the screen everytime right? Is gotoxy() better though?

  7. #7
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Yea. But what if you have stuff, for example, text below the grid or something? I'll need to rewrite that too if i clear the screen everytime right?
    Yes, you will have to rewrite the stuff on the screen everytime after clearing the screen but that's where functions and loops come into play. If you aren't familiar with functions, then you better do some more reading before you decide to start creating a game.

    Is gotoxy() better though?
    It very well could be, I'm not sure. However, I'm pretty confident that most people create a tic-tac-toe game the way I explained it.

  8. #8
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    Is there any C examples demonstrating the use of gotoxy?

    What do you mean am i familiar with functions or not? Are functions basic stuff???

  9. #9
    Unregistered
    Guest
    Yes they are. It's one of the first things I was taught in C++.

  10. #10
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    WOuld you be kind enough to post a couple of lines example here? I would prefer them to be in C, but i can manage to get the idea from C++ code.

  11. #11
    Sridhar
    Guest

    Thumbs up An Example

    Hi, you can see an example of gotoxy() in my website which contains the N-queens puzzle. I have done this game with graphical illustrations.

    You can see the .c file in 'datastructures' link and under the topic 'stack'

    An important note: I have used turbo-c++ compiler in windows. You have to make a little change in the code. You have the change the bgi path to your bgi path in the function
    " initgraph(&gd,&gm," < here goes your .bgi file path > ) "

    thats all

  12. #12
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Nushell, you can read tutorials on functions in the tutorials on this site. Also, if you are learning C instead of C++ because you feel C would be easier to learn, you should just learn C++. C++ is not that hard to learn, and I'd imagine has about the same complexity as C.

    Here is an example of a function and using gotoxy() at the sametime. *I use DevC++_beta4.9.2 as my compiler currently*

    Code:
    #include <windows.h>  //this is for gotoxy()
    #include <iostream.h>  //this is for cout
    #include <conio.h> //this is for getch()
    
    void Gotoxy(); //this is to show that a function is below 
    
    void main()  //this is the main function and must always be done
    {
    Gotoxy();  //this is to activate the function //all functions must be activated in the main() to be run
    }
    
    void Gotoxy() //name of the function
    {
       int x = 10; //this is to determine what location you want on the x-axis
       int y = 0;  //this is to determine what location you want on the y-axis
       COORD coord;  //this is for declaring a coordinate
       coord.X = x;  //this is declaring the x-axis as the the value of x
       coord.Y = y;  //this is declaring the y-axis as the the value of y
       SetConsoleCursorPosition(GetStdHandl (STD_OUTPUT_HANDLE), coord);  //this is positioning the cursor
       cout << "Hi";
       getch();  //waits for user to enter a key
    }
    The only reason why I did that for you is, because I was using that as a sample program in figuring out how to use gotoxy() (with the help of the FAQs of course, though). Point being that I shouldn't tell you certain things that can be figured out by a matter of reading and test coding. By the sounds of things I don't think you are ready to make a game...buy a book or go read some more tutorials. I'm not trying to offend you in anyway, yet, I'm trying to help you on what would be most beneficial for you.

    EDIT: tried making the some of the lines in "code" go on one line, but to no avail I was not able to
    Last edited by TechWins; 04-21-2002 at 02:38 PM.

  13. #13
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    Yes thnx for your response. THe reason i'm not doing it in C++ is that i havne' learnt it 'YET'. I learn C first because C++ originated FROM C, and also, C++ hides some of the data type complexities.

    Also i don't plan to use any win32 api at the moment.

    You said buy a book. Buy a book on games ? Did you mean that? Do you have any suggestions on a boook about game programming in C? I don't think there are any i think. And i'm still reading C Unleashed at the moment.

    thnx again for all replies.

  14. #14
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Yes thnx for your response. THe reason i'm not doing it in C++ is that i havne' learnt it 'YET'. I learn C first because C++ originated FROM C, and also, C++ hides some of the data type complexities.
    Well, I haven't learned or even looked at C, but from my little experience with programming I'd suggest to just go to C++ instead of learning C. I programmed in PASCAL for a few weeks back in November, then I stopped for unknown reasons (I don't remember why). Sometime later I started to learn C++, and I'm very glad I decided to stop learning PASCAL and started to learn C++. In my opinion, there doesn't seem to be much point in learning C when you are going to learn C++ anyways. That's just my opinion, and I'm sure others might disagree.

    Also i don't plan to use any win32 api at the moment.
    Oh yes, I figured that. Don't feel too bad...I'm not using win32 API either or any other API for that matter.

    You said buy a book. Buy a book on games ? Did you mean that? Do you have any suggestions on a boook about game programming in C? I don't think there are any i think. And i'm still reading C Unleashed at the moment.
    Well, I was implying for you to buy a book on C or C++ (as said before I recommend C++) or for you to go read some of the tutorials on this site. If you are unaware of how to use functions, then you are not ready to program a game yet...sorry to say that. I don't actually know your level experience, but it does appear that you may not be ready to create a game yet. A few basic things that you will need to know are functions, arrays, and other basic aspects of programming in order for you to make a game. While games such as, Tic-Tac-Toe, battleship, Connect Four, and others, may be considred 'easy' games to make they are still hard to make the first time around. You are in tough luck to make one of those games if you don't know the basics of programming.

    thnx again for all replies.
    No problem.

  15. #15
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    Techwins, i know ALL the basic stuff about C. So i plead you to consider me as an intermediate C programmer. The reason i'm asking all these questions is that i never programmed a game in C, and there are game techniques i havne 't encountered before. Also, my books didn't mention much about game programming.

    And techwins, your example of gotoxy doesn't work. There are eerrors of undefined references and things like that. But doesn't matter, i used the gotoxy function in my conio.h. I use DEvC++ 4 as well.

    thnx
    Last edited by Nutshell; 04-22-2002 at 01:55 AM.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Network Programming Board
    By Eibro in forum A Brief History of Cprogramming.com
    Replies: 32
    Last Post: 07-07-2003, 12:04 PM
  2. c++ games comparable to psx games?
    By anarchyhollow in forum Game Programming
    Replies: 17
    Last Post: 01-08-2003, 07:49 PM
  3. Video Games Industry. 5 years left.
    By Cheeze-It in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 12-10-2002, 09:52 PM
  4. Starting games - books? api?
    By SeanMSimonsen in forum Game Programming
    Replies: 22
    Last Post: 11-27-2002, 08:09 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21