Re: Help with coding
- Posted by irvm at ellijay.com Jul 20, 2001
- 377 views
On Friday 20 July 2001 20:04, Travis Weddle wrote: > I really need help on reading the list of moves and applying them, i can > get the window, and i'm pretty sure i can set all the bitmaps where they > need to be. (that is if it allows a bitmap to be placed over a bitmap?) There are probably a dozen ways to do this, here's one: If you use a plain text file for the moves: 11, 15 23, 26 ... etc., with the numbers separated either by commas or by spaces, like this: 11 15 23 26 ... then I would suggest just reading them into a list: include file.e include get.e constant SOURCE = 1, DESTINATION = 2 atom fn object source, destination sequence moves fn = open("moves.txt","r") moves = {} while 1 do source = get(fn) -- get the first number if source[1] = -1 then exit -- EOF else destination = get(fn) -- get the second number moves = append(moves,{source[2],destination[2]}) end if end while close(fn) ? moves This gives a list like the following: {{11,15},{23,26},{26,35},{52,44}} You can set a pointer to the start of the list, and advance it when the "next" button is pushed. Going forward thru the list should be simple; increment the pointer by 1, and move checker from move[pointer][SOURCE] to move[pointer][DESTINATION], Backing up would seem to call for first undoing the move most recently made, which will be at the current pointer. You can probably do that by simply reversing the source and destination, i.e. move checker from move[pointer][DESTINATION] to move[pointer][SOURCE]. Then decrement the pointer. Don't let the pointer go below 1, or higher than the length of the moves list. Before either move, you'll have to find out which color checker is being moved, so you can show the correct bitmap at the new location. How to do that? There's probably a way you could get the info from windows, but it may be easier to just keep an array and update it with every move. That will also have value if in the future you want to add the ability to check for legal moves, be able to save and restore a game, etc. Something like: sequence a = repeat(0,64) -- where 0 means empty, 1 = black, -1 = red a[1..16] = 1 a[49..64] = -1 with each move: a[destination] = a[source] -- copies the color of checker into dest. a[source] = 0 -- empties source square. when drawing the checker, if a[DESTINATION] = -1 then -- use red checker bmp else -- use black checker bmp. I'm not sure about Windows, but you may be able to put both colors of checker in each square, and only show the color you want there (or none at all) Hope that helps, Regards, Irv