Information in this document is subject to change without notice. The example companies, organizations, products, people, and events depicted herein are fictitious. No association with any real company, organization, product, person or event is intended or should be inferred. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation.

 

Microsoft may have patents, patent applications, trademarked, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property.

 

© Microsoft Corporation. All rights reserved.

 

Microsoft, MS-DOS, MS, Windows, Windows NT, MSDN, Active Directory, BizTalk, SQL Server, SharePoint, Outlook, PowerPoint, FrontPage, Visual Basic, Visual C++, Visual J++, Visual InterDev, Visual SourceSafe, Visual C#, Visual J#,  and Visual Studio are either registered trademarks or trademarks of Microsoft Corporation in the U.S.A. and/or other countries.

 

Other product and company names herein may be the trademarks of their respective owners.


 

This source code is subject to terms and conditions of the Apache License, Version 2.0. A copy of the license can be found in the License.html file at the root of this distribution. If you cannot locate the Apache License, Version 2.0, please send an email to ironpy@microsoft.com. By using this source code in any fashion, you are agreeing to be bound by the terms of the Apache License, Version 2.0.

 

 

Puzzle

A slide puzzle game using Virtual Earth maps

Contributor: Ravi Chugh

Prerequisites

The prerequisites to successfully run the Puzzle puzzle game are:

Getting Started

Screenshot of PuzzlePlease make sure the folder structure in the Puzzle directory is:

.\banner.bmp

.\cache (Note: This is a subfolder)

.\copyright.py

.\icon.ico

.\load.xml

.\loadpanel.py

.\puzzle.py

.\quadkey.py

.\readme.htm

.\tiles.py

.\winforms.py


HINT: if the folder containing the IronPython distribution is not already in your PATH environment variable, please add it from the command prompt you'll be working in.  By doing this you will be able to run the "ipy" command from any arbitrary directory:

set PATH=%PATH%;%ProgramFiles%\IronPython 2.6

From the command prompt, navigate to the Puzzle directory and type the following:

> ipy.exe -D puzzle.py

At this point, Puzzle's GUI window should come up. You're ready to play!

If you launch with the ipyw.exe executable, the cmd window will be free to use while the application is running.

 

Note

It's very important you pass the '-D' flag to ipy.exe when running the Puzzle sample.  Due to a bug, IronPython may not run this sample properly without use of this flag.

Some Additional Features

Note that using any features described below from within the console instead of from the GUI game form itself may yield errors if argument values are invalid.

 

1) Setting the puzzle board

Instead of using the Create panel to navigate to a scene, you can create a puzzle using latitude/longitude directly using the 'SetBoard' method.

'SetBoard' takes 5 arguments:

map types: “r” (road), “a” (aerial), and “h” (hybrid).

latitude: -85 to 85

longitude: -180 to 180

zoom level: 1 through 19.

grid size: 3x3 and 4x4.

>>> p.SetBoard(“a”, 50, -100, 12, 3)

This will create a 3x3 puzzle board of zoom level 12 aerial images centered (as close as possible) to (50, -100).

 

2) Saving the current game

In case you want to save the puzzle configuration you are currently playing:

>>> p.SaveCurrentGame(“caption”)

This will save the current puzzle, along with the specified caption, into load.xml so that next time you start the puzzle, you can choose the game you just saved from the Load panel.

Note that this does not save the current state of your puzzle pieces. It saves the puzzle so you can start from the beginning again.

 

3) Resizing the puzzle pieces

The full tiles downloaded from the tile server are 256x256. When the grid size is 3x3, the tiles are 128x128 at 50%, 192x192 at 75%, and 256x256 at 100%. When the grid size is 4x4, the tiles are further reduced by 25%. So the size is 96x96 at 50%, 144x144 at 75%, and 192x192 at 100%.

If you want to specify a different tile size:

>>> p.ResizeEverything(200)

This will resize the window so that in 3x3 grids, each tile will be 200x200, and in 4x4 grids, each tile will be 150x150.

Downloading tiles

Images for puzzle pieces are downloaded directly from Microsoft's Virtual Earth tile servers. There is no API for downloading specific images directly from the tile server, but the process for converting particular scenes to tiles can be seen in quadkeys.py. Because there is no such API, the URL structure representing particular images from the tile server can change at any time, breaking the way Puzzle downloads tiles. If it does, the GetImgUrl() function in tiles.py will have to be updated to match the new scheme.

 

This sample will contact Virtual Earth when started to download an initial map and then again when the user manually changes the map from either the "create" or  "load" menu options.  Information sent to the Virtual Earth servers will include your IP address along with the location and type of the map requested.  You may view the Virtual Earth terms of use and privacy policy at: http://www.microsoft.com/virtualearth/control/terms.mspx.

Caching

When caching is enabled, all downloaded tiles are saved into to the \cache folder. If a particular image request has already been cached, the image will be loaded from the appropriate file instead of downloading it again from the tile server. Note that the size of \cache folder can grow quickly, so keep an eye on it.

To get stats about the cache run the following function:

>>> CacheStats()

When you click the Clear Cache button, the files in the cache will get deleted once the game is closed. The handles on files (downloaded tiles) associated with the current puzzle pieces are not guaranteed to be closed when ClearCache() is called, so not all images in the cache get deleted. Any remaining images can be manually deleted.