- 浏览: 161688 次
- 性别:
- 来自: 大连
最新评论
-
xueyw:
http://www.devdiv.com/forum-iph ...
iPhone开发网站、论坛、博客 -
Meggie_love:
受教了
游戏算法整理 算法七 无限大地图的实现 -
xueyw:
http://www.devdiv.net/bbs/forum ...
iPhone开发网站、论坛、博客 -
junlas:
APE 物理引擎与 Box2D 物理引擎对比 -
ha397666:
5、扩展的点已经被扩展过了。当扩展节点的时候,每个节点都是向四 ...
游戏算法整理 算法六:关于SLG中人物可到达范围计算的想法
iPhone Coding Tutorial – Creating an Online Leaderboard For Your Games3
- 博客分类:
- iphone
Displaying The Scores Table
As mentioned before, we will be displaying a table on a webpage. The url that the webview will access will be something like this
http://icodeblog.com/ws/get_scores.php?sort=score%20DESC
There are quite a few parameters that can be used with my script that will determine how the table will be displayed. The parameters and their descriptions are in the table below:
type | This value will determine what data the table will display. The possible values for it are global, device, and name. Global will simply show the global high scores list containing all of the users. Device is specific to the calling users device. It will only display high scores for a given udid. Finally, we have name, which will only display high scores for a given username. |
offset | Used for paging the SQL results. It will be the first parameter in the ORDER BY clause of the SQL select statement. Ex: An offset of 10 will tell the system to show records starting with the 10th. |
count | Used for paging the SQL results. It will be the second parameter in the ORDER BY clause of the SQL select statement. This is basically the number of results to show in the table. |
sort | Tells the table how to sort. If this isn’t specified, the sorting is default set to “score DESC”. This will order by scores from highest to lowest. |
udid | The UDID of the device viewing the leaderboard. This variable is required if you specify type=device |
name | The name of the device viewing the leaderboard. This variable is required if you specify type=name |
As you can see, you have quite a bit of control over how the results get displayed. You may want to offer multiple high score views to your user (global, personal, etc…). You can also fancy this up quite a bit and give the users the ability to view the high scores of other users on the list.
Here is the code for get_scores.php
<?php // get_scores.php /** MySQL database name */ define('DB_NAME', ''); /** MySQL database username */ define('DB_USER', ''); /** MySQL database password */ define('DB_PASSWORD', ''); /** MySQL hostname */ define('DB_HOST', $_ENV{DATABASE_SERVER}); $table = "highscores"; // Initialization $conn = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD); mysql_select_db(DB_NAME, $conn); // Error checking if(!$conn) { die('Could not connect ' . mysql_error()); } $type = isset($_GET['type']) ? $_GET['type'] : "global"; $offset = isset($_GET['offset']) ? $_GET['offset'] : "0"; $count = isset($_GET['count']) ? $_GET['count'] : "10"; $sort = isset($_GET['sort']) ? $_GET['sort'] : "score DESC"; // Localize the GET variables $udid = isset($_GET['udid']) ? $_GET['udid'] : ""; $name = isset($_GET['name']) ? $_GET['name'] : ""; // Protect against sql injections $type = mysql_real_escape_string($type); $offset = mysql_real_escape_string($offset); $count = mysql_real_escape_string($count); $sort = mysql_real_escape_string($sort); $udid = mysql_real_escape_string($udid); $name = mysql_real_escape_string($name); // Build the sql query $sql = "SELECT * FROM $table WHERE "; switch($type) { case "global": $sql .= "1 "; break; case "device": $sql .= "udid = '$udid' "; break; case "name": $sql .= "name = '$name' "; break; } $sql .= "ORDER BY $sort "; $sql .= "LIMIT $offset,$count "; $result = mysql_query($sql,$conn); if(!$result) { die("Error retrieving scores " . mysql_error()); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/> </head> <body> <?php // Display the table echo '<table style="width:100%"> <thead> <tr> <th>Name</th> <th>Score</th> </tr> </thead> <tbody>'; while ($row = mysql_fetch_object($result)) { echo '<tr> <td> '.$row->name.' </td> <td> '.$row->score.' </td> </tr>'; } echo '</tbody> </table>'; mysql_free_result($result); mysql_close($conn); ?> </body> </html>
After initialization, we build the SQL query based on the parameters that were specified. This will determine what data will get displayed. Notice that after the code to query the database, there is some HTML. This is because we want to output a full HTML page for our table. You can use this opportunity to ad things such as styling, images, and advertising. Within the body, we simply loop over the results returned from MYSQL and output the score data. And that’s it! You now have a fully functional high score server. With our server complete, there are only two things left to do: submit score data in our iphone application and display the leaderboard.
发表评论
-
UIPickerView – spinning multiple components
2010-08-24 16:24 1615I found an interesting issues w ... -
UITableView效果收集
2010-07-10 12:28 2907某些打不开需翻()墙 Customizing the bac ... -
日期处理
2010-03-17 22:58 1177NSDateFormatter *dateFor ... -
uninstall xcode
2010-02-08 02:35 1730How to uninstall Xcode and ... -
从一个url中获得文本信息(转)
2010-01-21 11:37 1384有时候你可能需要从一个url中获取一个文本文件中的信息。 下面 ... -
将图片保存在iPhone的相册中(转)
2010-01-21 11:28 2926有时候你的应用需要将应用中的图片保存到用户iPhone或者iT ... -
一些遊戲製作有關的博客(转)
2010-01-20 14:57 1178站長在收集站內朋友的博客,然後把它們列出來方便大家看,這的確是 ... -
Beautiful Snowflakes
2010-01-14 18:51 1465It is a application that displa ... -
Layer Programming with Quartz Core
2010-01-08 14:11 3522《转载》 2009/6/25 ... -
如何移除Three20中private API
2010-01-07 22:04 1831Three20 是一个非常有 ... -
iphone下Three20库(From Facebook)的设置使用方法
2010-01-07 22:03 4025Three20是一个编译的静态类库 ,在Xcode中的项目实 ... -
Opera Masks
2010-01-07 01:13 1685It is a application that introd ... -
Java读取星际译王(StarDict)词库
2010-01-06 18:08 2625下面的文件是StarDict的词库格式说明文件: Form ... -
iPhone Coding Tutorial – Creating an Online Leaderboard For Your Games4
2010-01-06 11:06 1522Submitting High Scores To The ... -
iPhone Coding Tutorial – Creating an Online Leaderboard For Your Games2
2010-01-06 11:01 734Inserting Scores Into The Dat ... -
iPhone Coding Tutorial – Creating an Online Leaderboard For Your Games1
2010-01-06 10:59 1093As you may have seen, there a ... -
iPhone Coding Tutorial – Inserting A UITextField In A UIAlertView
2010-01-06 10:44 1611This will be a simple tutorial ... -
iPhone Coding Tutorial – In Application Emailing
2010-01-06 10:36 1205A lot of applications you see ... -
Objective-C内存管理总结〜CC专版
2009-12-28 11:09 3012之前写过类似的文章,这篇以做总结,希望能帮助刚上船的兄弟。^_ ... -
tell user the status
2009-12-17 17:42 1214+(UIView *)waitingView { ...
相关推荐
这篇“iPhone Coding Tutorial – In Application Emailing”教程将指导开发者如何在iPhone应用程序中集成电子邮件功能,无需离开应用就能发送邮件。这篇博客文章的链接虽然不可用(已替换为示例文本),但我们可以...
这篇教程“iPhone Coding Tutorial – Inserting A UITextField In A UIAlertViewController”将会教你如何在现代iOS环境中,在警告视图控制器中添加一个文本字段。 首先,我们需要了解`UIAlertController`的基本...
online coding单表表单模板上传使用说明online coding单表表单模板上传使用说明online coding单表表单模板上传使用说明online coding单表表单模板上传使用说明online coding单表表单模板上传使用说明online coding单...
Beginners and experienced programmers can use Python to build and play computer games, from mind-bending brainteasers to crazy action games with explosive sound effects and 3-D graphics. Each chapter ...
An introduction to coding for constrained systems, Draft Version, 2001. by B H Marcus, R M Roth, P H Siegel
### 一、里德-所罗门编码(Reed-Solomon Coding)基础 里德-所罗门编码是一种非二进制线性错误校正码,广泛应用于数据存储和通信系统中,以提供强大的错误检测和纠正能力。它由Irving S. Reed和Gustave Solomon于...
After reading this book you will be able to develop your own 2d and 3d videogames and use it on your presentations, to speed up your level design deliveries, test your game design ideas, work on your ...
百度的余凯老师在CVPR2012上的Tutorial
### JEECG Online Coding开发手册 v3.6 知识点总结 #### 1. 单表智能表单 [Online 表单开发] ##### 1.1 创建数据表单(界面如下图) - **创建单表**: 在创建单表时需要注意的是必须包含一个主键字段,并且该主键...
Beginning iPhone Games Development (Mar 2010) Part 2 of 2 Part 1 -> http://download.csdn.net/source/2283635 源代码 -> http://apress.com/book/view/9781430225997 iPhone games are hot! Just look at ...
Beginning iPhone Games Development Apress, 2010年出品 You’ve probably already read and mastered Beginning iPhone 3 Development; Exploring the iPhone SDK, the best-selling, the second edition of ...
《Coding Games in Scratch》是一本面向初学者的编程教材,主要使用Scratch编程语言来教授游戏开发的基础知识。Scratch是由麻省理工学院(MIT)的“终身幼儿园团队”开发的一款图形化编程工具,旨在帮助孩子们学习编程...
cvpr12_tutorial_sparse_coding.ppt
How to give your users access to their iPhone libraries from within games The tools and techniques of 3D audio for creating even more realistic gaming experiences How to do networking right, including...
JEECG Online Coding开发手册v3.6主要介绍了如何使用JEECG平台进行Online表单的开发和配置。 知识点一:单表智能表单开发 在单表智能表单开发中,首先需要创建数据表单,必须为数据表单设置主键,并确保主键为ID,...
Beginning iPhone Games Development (Mar 2010) Part 1 of 2 Part 2 -> http://download.csdn.net/source/2283657 源代码 -> http://apress.com/book/view/9781430225997 iPhone games are hot! Just look at ...
Using an example as a tutorial, we will relate the driving principles and you'll see how you can implement these principles to develop any games on the platform. We begin by setting expectations and ...