Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

snakes n ladders

Posted on 2006-06-21
3
Medium Priority
?
2,588 Views
Last Modified: 2008-01-09
i'm going to make a game in c++ - snakes n ladders..
first i though of making the board by plotting pixels ..
n the program will have the knowlegde of the coordiantes of each box, sankes and laddders.
to check in which box a pawn is i'll just check what are its coordinates and check in which box it lies(coordinates of each box is prefixed)
i made wach square of side 20 pixels ..
a pawn's center is always at the center of a box..
to move a pawn ahead i just added 20 to its x - axis coordinates (for horizontal movement only)


now i thought of another way but have no way how to implement it:::
       is there any way i can just draw a 16 bit image and just import it into my program ?

if you have any advice/suggestions that'd be really nice ..

thanks..
0
Comment
Question by:shilpi84
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
lostcarpark earned 2000 total points
ID: 16949633
Sounds fun!

Drawing your board as a graphic is a good idea. How you import it into your program depends very much on your OS and what graphics library you use in C++. There are several graphics libraries for Windows, and a bunch or others for Unix/Linux.

If you're using Microsoft Visual C++, the easiest option is to create your board in the resource editor (although you might want to draw it in a better graphics program then import it into resource editor). This means it will be compiled into the .EXE and you don't need a seperate image file. Once you have that, you can use the CBitmap::LoadBitmap() method to read the resource.

Here's a quick tutorial on it: http://www.functionx.com/visualc/bitmaps/DisplayFromResource.htm

So long as you keep all your squares the same size, it's fairly easy to keep track of everything. Although the board is two dimensional, the progression of the players is one-dimensional, so you could keep track of the player's position with a single integer.

For example:

    /* Constants define board and square size. */
    const int xSquares = 10;
    const int ySquares = 10;
    const int xWidth = 20;
    const int yWidth = 20;

    /* Variable to store the current player position. If you want multiple players, use an array. */
    int playerPos = 0;

    /* Calculate the squares accross and up the board from the current position. */
    int yPos = playerPos / xSquares;
    int xPos = playerPos % xSquares;
    /* Every second row the direction reverses, so if the row isn't divisible by 2, count from end of row. */
    if (yPos % 2)
        xPos = xSquares - xPos;

    /* To get the pixel position, multiply by the square size. Assuming the zero coordinate is the top left, we need to reverse the vertical position. */
    int xPixel = xPos * xWidth;
    int yPixel = (ySquares - yPos) * yWidth;

Hopefully that gives you some ideas. For each snake and ladder you just need to store the starting squares and the ending squares inj an array. Each move, check if the player landed on a starting square, and if they did, move them to the ending square. You don't even need seperate arrays for snakes and ladders.

Note that everything is zero-based, so the finishing square is (xSquares * ySquares) - 1.

Good luck!

James
0
 

Author Comment

by:shilpi84
ID: 16950134
i m using C++ in 16 bit(dos)
0
 
LVL 5

Expert Comment

by:lostcarpark
ID: 16951037
Okay, everything still applies, except for the MFC parts. What compiler/class library are you using? I did quite a bit of graphics work in Borland C++ in the dim and distant past. It's also up to you what graphics mode you want to use. Mode 19 in VGA is a low-res 256-colour graphics mode that's great for DOS games. Depending on what graphics library functions are available to you, you may not have anything built in for importing bitmaps, but you might be able to do something that would read a RAW image file with no complex compression.

I actually wrote most of my own primitive graphic functions to do things like set the video mode, set up the palette colours and paint pixels specified colours. I could see if I could dig some of them out later if it's any help.

Hope this helps,

James
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question