![]() |
|
#1
|
|||
|
|||
Backgammon and graphics in C++Hi Everybody,
I have an assignment of creating a backgammon game in c/c++ and in spite of downloading maximum stuffs on the web regarding graphics and c, I have only been able to create the board and make the mouse appear. It is just like drawing a picture with mouse on and nothing more. I will like to get some hints about structuring and giving some life to the board. Can anybody please help. I am looking for a backgammon model in cpp if possible or hints as to how I am going to attack this assignment??? Thank you in advance, Co. CPP / C++ / C Code:
|
|||
|
#2
|
||||
|
||||
Re: backgammon and graphics in c++Quote:
First, separate the game "play" from the "presentation" of it. Write the game first without any graphics. Use a simple text output to indicate status of the board, but only when the user requests that the board be "displayed." You seem to be focused more on the presentation of what you visualize as being a Backgammon game, rather than on the internal data structures and algorithms that interact with those structures that make up a Backgammon game in terms of how we can represent it using C or C++. Also, you are using a lot of compiler/tools/platform specific code in your application. While GUI drawing tends to be rather platform specific, the actual "game engine" should be platform agnostic. If your tools allows you to define void main() without an error, you should consider using a more updated set of tools. At the very least, I'd recommend that you follow the C++ standard wherever possible, which would have main return an int. The same goes for other non-standard C++ headers and libraries that you're using...don't use them, at least not in your "engine" code. That way, others here who might help you with your code will be able to compile it and provide assistance. One of the first things that you do is initialize a graphics library using a hardcoded path to your Turbo C directory. While this may be useful for the presentation layer, it won't help you develop the logic that represents the starting position of a Backgammon game in data structures. Try to define the board in terms of data structures that will, when acted upon by the appropriate algorithms, report the statefulness of the game at any given time. That is the "position," such as a snapshot of a chess board or, in your case, the Backgammon board. Create in your engine design--and very early too--a method for displaying the state of the board. We would expect to see the initial state and the state after every move by a player and perhaps even the "final state," which would be after the last legal move made by a player. As you build up the correct data structures, operations will start to come out, such as the "DisplayBoard" previously mentioned. MovePiece might be next. As you go, the rules of the game will likely be applied. While it is probably too hopeful for me to think that you'll be utilizing a "rules engine," so that you can support variations of the game, such as Acey-Deucey, you may want to separate your "rules logic" from your strict piece movement logic. That is, apply separate "legal limitations" based on the game type at the point that you initiate a piece movement. These things involve a lot of coding, but can be rather easily accommodated using C++ through inheritance and virtual functions. However, my first impression of your code is that you have absolutely no intention of using C++ at all. In fact, your code is very C-centric. I think that I'd first ask you to back up a bit. Stop thinking about how to do it and go back to what it is that you want to do. You say that you are assigned a task to create a Backgammon game in C/C++. There are actually two different languages, C and C++. Yes, there is a lot of overlap between them, but they are not the same language. If your area of exposure is in C, then you may want to explicitly state C, particularly if that is also the expectation of your instructor. The design of a Backgammon game in C will be quite different than one that uses the capabilities of C++. I think that once you work out which language you want to use, either C or C++, then we will be able to offer you more advice on designing the engine code. Once the basic engine is working, you need only create the display and user interaction interfaces necessary to support the "presentation" layer. Your approach appears to be "top down." Mine suggests a "bottom up" approach. Neither is inherently better or more right than the other. I suggest my choice because it decouples the UI from the "engine" that represents the game and the rules that govern it. In my proposal, the "UI" can be a simple command line/console interface or a very elaborate GUI, it doesn't care. In your case, you are starting with a very elaborate GUI that doesn't really capture anything about the state of the game, rather, it just (I assume) attempts to draw it visually at some particular point when the code starts up. There is no game, just drawing. My suggestion is that you don't think about drawing until you have the basis for the game. Then, once you have the data structures defined that represent the state of the game, you pass this information to your drawing code, that then "knows how to" draw the pieces on the board to match the state of the game as reflected by the contents of the data structures. Otherwise, I believe you will be chasing your tail for a considerable period of time. MxB |
|
#3
|
|||
|
|||
Re: Backgammon and graphics in C++Hi MxB,
Thank you very much for taking the time to read and responding to my post. I am actually using turbo C++ to write and run the code but actually according to the rule of my assignment, the program has to be in C not c++. The problem is that in spite of thousands of notes gathered here and there, it is just amazing to see so many variation and platforms of C. The assignment started with the board (the graphics part) hence it was top down from the start. If you can help in any way or to guide me to some links of backgammon or likewise program, please feel free to do it. Co. |
|
#4
|
|||
|
|||
Re: Backgammon and graphics in C++Hi,
I started working on the program itself but I have a problem. First I asked both player to enter their name. Supposedly I wanted to limit the length of the name to 10 characters. This only works partly because the corrected name does not fully enter the variable. Can any one review it please for me??? CPP / C++ / C Code:
Last edited by LuciWiz : 15-Apr-2009 at 01:17.
Reason: Please insert your C code between [cpp] & [/cpp] tags
|
|
#5
|
||||
|
||||
Re: Backgammon and graphics in C++__________________
The 3 Laws of the Procrastination Society: 1) Never do today that which can be put off until tomorrow 2) Tomorrow never comes |
|
#6
|
|||
|
|||
Re: Backgammon and graphics in C++Hi,
I have just tried to restructure my backgammon program into more object oriented but the result is far from being satisfactory ... the problem remains the name1, name2, n1 and n2. the two players are to enter their respective names which will enter n1 and n2. one dice is roll and the result is display for player 1 and then for player 2. the one with the highest score is PLAYER1. But the dice rolls only for player 1. CPP / C++ / C Code:
|
Recent GIDBlog
Vista ?Widgets? on Windows XP by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The