Solved

snakes n ladders

Posted on 2006-06-21
3
2,553 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 500 total points
Comment Utility
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
Comment Utility
i m using C++ in 16 bit(dos)
0
 
LVL 5

Expert Comment

by:lostcarpark
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
add text to end of existing text in file 16 59
count7 challenge 12 66
mapShare challenge 13 66
tidtcpserver connection lost handle 2 41
A short article about a problem I had getting the GPS LocationListener working.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now