Don't Toutch The White说来也奇快,本来没什么难的,但是在欧美ios榜上却雄踞榜首好长时间。即使是在国内,也很火,还真是想不通,谁能解释下,难道真是所谓的抓住了用户的G点,或是这些开发者够极客。

这个问题,很难回答。算了,不去追究了,技术人员还是安心敲个代码吧!!!

下面是我自己的代码,使用libgdx做的,纯手工的。

game类,游戏入口,主类

package com.fxb.whitetile;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.scenes.scene2d.ui.Skin; public class WhiteTile extends Game{ static Skin skin;
StartScreen startScreen;
static GameScreen gameScreen;
LevelScreen levelScreen; @Override
public void create() {
// TODO Auto-generated method stub
skin = new Skin( Gdx.files.internal( "skin/uiskin.json" ) );
startScreen = new StartScreen( this );
gameScreen = new GameScreen( this );
levelScreen = new LevelScreen( this ); setScreen( startScreen );
} @Override
public void dispose() {
// TODO Auto-generated method stub
skin.dispose();
startScreen.dispose();
gameScreen.dispose();
levelScreen.dispose();
super.dispose();
}
}
//开始场景
package com.fxb.whitetile; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.SequenceAction;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton; public class StartScreen extends ScreenAdapter{ WhiteTile game;
Stage stage;
TextButton btnStart, btnLevel; SequenceAction actionTotal; public StartScreen(WhiteTile game0){
game = game0;
stage = new Stage(); btnStart = new TextButton( "Start Game", WhiteTile.skin, "default" );
btnStart.addListener( new InputListener(){
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
// TODO Auto-generated method stub
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
// TODO Auto-generated method stub
stage.addAction( actionTotal );
}
}); btnLevel = new TextButton( "Select Mode", WhiteTile.skin, "default" );
btnLevel.addListener( new InputListener(){
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
// TODO Auto-generated method stub
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
// TODO Auto-generated method stub
game.setScreen( game.levelScreen );
}
}); //stage.addAction( Actions.fadeOut( 2 ) );
Action actionChange = new Action(){
@Override
public boolean act(float delta) {
// TODO Auto-generated method stub
game.setScreen( game.gameScreen );
dispose();
return false;
}
};
Action actionRotate = Actions.rotateBy( -360, 2 );
//actionTotal = Actions.sequence( Actions.parallel( actionRotate, Actions.fadeOut(2) ), actionChange );
actionTotal = Actions.sequence( Actions.fadeOut(0.2f), actionChange ); btnStart.setSize( 150, 70 );
btnStart.setPosition( stage.getWidth()/2-btnStart.getWidth()/2, stage.getHeight()/2-btnStart.getHeight()-50 );
btnLevel.setSize( 150, 70 );
btnLevel.setPosition( stage.getWidth()/2-btnStart.getWidth()/2, stage.getHeight()/2+50 ); stage.addActor( btnStart );
stage.addActor( btnLevel );
} @Override
public void show() {
// TODO Auto-generated method stub
Gdx.input.setInputProcessor( stage );
} @Override
public void render(float delta) {
// TODO Auto-generated method stub
Gdx.gl.glClearColor( 0, 1, 1, 1 );
Gdx.gl.glClear( GL10.GL_COLOR_BUFFER_BIT ); stage.act();
stage.draw();
} @Override
public void dispose() {
// TODO Auto-generated method stub
//stage.dispose();
super.dispose();
} }
//模式选择场景
package com.fxb.whitetile; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton; public class LevelScreen extends ScreenAdapter{ WhiteTile game;
Stage stage;
//Table table;
TextButton[] sButton; public LevelScreen(WhiteTile game0){
game = game0;
stage = new Stage(); //table = new Table( WhiteTile.skin ); sButton = new TextButton[3];
String[] arrStr = { "Simple", "Normal", "Hard" };
for( int i=0; i<sButton.length; ++i ){
sButton[i] = new TextButton( arrStr[i], WhiteTile.skin );
sButton[i].setSize( 150, 60 );
stage.addActor( sButton[i] );
//table.row();
} sButton[0].addListener(new InputListener(){
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
// TODO Auto-generated method stub
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
// TODO Auto-generated method stub
Constant.level = 1;
game.setScreen( game.startScreen );
}
}); sButton[1].addListener(new InputListener(){
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
// TODO Auto-generated method stub
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
// TODO Auto-generated method stub
Constant.level = 2;
game.setScreen( game.startScreen );
}
}); sButton[2].addListener(new InputListener(){
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
// TODO Auto-generated method stub
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
// TODO Auto-generated method stub
Constant.level = 3;
game.setScreen( game.startScreen );
}
}); //stage.addActor( table );
//table //sButton[i].setPosition( stage.getWidth()/2-sButton[i].getWidth()/2, stage.getHeight()/2 );
sButton[0].setPosition( stage.getWidth()/2-sButton[0].getWidth()/2, stage.getHeight()/2+sButton[0].getHeight()/2+50 );
sButton[1].setPosition( stage.getWidth()/2-sButton[1].getWidth()/2, stage.getHeight()/2-sButton[1].getHeight()/2 );
sButton[2].setPosition( stage.getWidth()/2-sButton[2].getWidth()/2, stage.getHeight()/2-3*sButton[2].getHeight()/2-50 ); } public boolean IsInside( Actor actor, float x, float y ){
return x>actor.getX() && x<actor.getRight() && y>actor.getY() && y>actor.getTop();
} @Override
public void render(float delta) {
// TODO Auto-generated method stub
Gdx.gl.glClearColor( 0, 1, 1, 1 );
Gdx.gl.glClear( GL10.GL_COLOR_BUFFER_BIT ); stage.act();
stage.draw();
} @Override
public void show() {
// TODO Auto-generated method stub
Gdx.input.setInputProcessor( stage );
super.show();
} @Override
public void dispose() {
// TODO Auto-generated method stub
super.dispose();
} }
//游戏主场景
package com.fxb.whitetile; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.GL10; public class GameScreen extends ScreenAdapter{ WhiteTile game;
GameStage gameStage;
OverStage overStage; public GameScreen( WhiteTile game0 ){
game = game0;
gameStage = new GameStage(this);
overStage = new OverStage();
} @Override
public void show() {
// TODO Auto-generated method stub
Gdx.input.setInputProcessor( gameStage );
//Constant.state = Constant.GameState.game_on;
} @Override
public void render(float delta) {
// TODO Auto-generated method stub if( Constant.state == Constant.GameState.game_ready ){
gameStage.act();
gameStage.draw();
gameStage.Clear();
Constant.state = Constant.GameState.game_on;
Gdx.input.setInputProcessor( gameStage );
}
else if( Constant.state == Constant.GameState.game_on ){
Gdx.gl.glClearColor( 0, 1, 1, 1 );
Gdx.gl.glClear( GL10.GL_COLOR_BUFFER_BIT ); gameStage.act();
gameStage.draw();
}
else if( Constant.state == Constant.GameState.game_preover ){
Gdx.gl.glClearColor( 0, 1, 1, 1 );
Gdx.gl.glClear( GL10.GL_COLOR_BUFFER_BIT ); gameStage.draw();
overStage.act();
overStage.draw();
Gdx.input.setInputProcessor( overStage );
}
else if( Constant.state == Constant.GameState.game_over ){
//dispose();
Gdx.app.exit();
} } @Override
public void dispose() {
// TODO Auto-generated method stub
gameStage.dispose();
super.dispose();
} }
//游戏主舞台
package com.fxb.whitetile;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.utils.Pool;
import com.badlogic.gdx.utils.Pools;
import com.fxb.whitetile.Constant.GameState; public class GameStage extends Stage{ //Pool<Image> poolWhite;
//Pool<Image> poolBlack; Pool<Block> poolBlock;
int topIndex;
float transferHeight;
float imgHeight;
Group groupImg; Drawable drawWhite;
Drawable drawGray; GameScreen gameScreen;
float speed;
int count; int lastIndex1, lastIndex2; Block block; public GameStage(GameScreen screen0){
//poolWhite = Pools.get( Image.class );
//poolBlack = Pools.get( Image.class );
gameScreen = screen0;
poolBlock = Pools.get( Block.class );
imgHeight = (this.getHeight()-9)/4; groupImg = new Group();
this.addActor( groupImg ); drawGray = WhiteTile.skin.newDrawable( "white", Color.GRAY );
drawWhite = WhiteTile.skin.newDrawable( "white" ); //Block.gameScreen = gameScreen; Clear();
} public void Clear(){
topIndex = 5;
this.getCamera().translate( 0, -transferHeight, 0 );
transferHeight = 0;
speed = Constant.initSpeed*Constant.level;
count = 0; groupImg.clear();
poolBlock.clear(); lastIndex1 = lastIndex2 = -1; for( int j=0; j<topIndex; ++j ){
AddBlock( j );
}
} public void AddBlock( int yIndex ){
int index;
do{
index = MathUtils.random( 98 )%3;
}while( lastIndex1==lastIndex2 && index==lastIndex1 ); lastIndex2 = lastIndex1;
lastIndex1 = index; for( int i=0; i<3; ++i ){
Block block = poolBlock.obtain();
block.Clear();
if( i == index ){
block.color = Color.GRAY;
block.setDrawable( drawGray );
}else{
block.color = Color.WHITE;
block.setDrawable( drawWhite );
} //blockTran = block;
//block.gameScreen = gameScreen; block.setSize( (this.getWidth()-12)/3, imgHeight );
block.setPosition( 3+3*i+i*block.getWidth(), (yIndex+2)*(imgHeight+3) );
groupImg.addActor( block );
}
} @Override
public void draw() {
// TODO Auto-generated method stub
super.draw();
} @Override
public void act() {
// TODO Auto-generated method stub count++;
if( count > 60 ){
count = 0;
speed += Constant.speedInc*Constant.level;
} getCamera().translate( 0, speed, 0 );
transferHeight += speed; /*
for( int i=0; i<groupImg.getChildren().size; ++i ){
Block block = (Block)groupImg.getChildren().items[i];
if( block.getY() < transferHeight && block.color==Color.GRAY && !block.isTouch ){
Constant.state = Constant.GameState.game_preover;
}
}
*/ boolean bIsDis = false;
for( int i=0; i<groupImg.getChildren().size; ++i ){
Block block = (Block)groupImg.getChildren().items[i]; if( block.color==Color.WHITE && block.isTouch ){
Constant.state = Constant.GameState.game_preover;
//gameScreen.overStage = new OverStage();
gameScreen.overStage.Show();
Gdx.input.setInputProcessor( gameScreen.overStage );
} if( block.getTop() < transferHeight )
{
if( block.color==Color.GRAY && !block.isTouch ){
Constant.state = Constant.GameState.game_preover;
//gameScreen.overStage = new OverStage();
gameScreen.overStage.Show();
Gdx.input.setInputProcessor( gameScreen.overStage );
} groupImg.removeActor( block );
poolBlock.free( block );
if( !bIsDis ){
bIsDis = true;
}
}
}
if( bIsDis ){
AddBlock( topIndex );
topIndex++;
} super.act();
} @Override
public void dispose() {
// TODO Auto-generated method stub super.dispose();
} }
//游戏结束舞台
package com.fxb.whitetile; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Dialog; public class OverStage extends Stage{ Dialog dialogOver;
GameScreen gameScreen; public OverStage(){ dialogOver = new Dialog( "", WhiteTile.skin, "dialog" ){
@Override
protected void result(Object object) {
// TODO Auto-generated method stub
//System.out.println( "Chosen" + object );
if( object.toString().equals( "true" ) ){
Constant.state = Constant.GameState.game_ready; }else{
System.out.println( "No" );
Constant.state = Constant.GameState.game_over;
Gdx.app.exit();
} }
}; dialogOver.text("GAME OVER").button("Again", true).button("Exit", false);
addActor( dialogOver );
dialogOver.setSize( 150, 100 );
dialogOver.setPosition( this.getWidth()/2-dialogOver.getWidth()/2, this.getHeight()/2-dialogOver.getHeight()/2 );
//dialogOver.show( this );
} public void Show(){
//addActor( dialogOver );
dialogOver.show(this);
} }
//游戏中元素块,白块或灰块
package com.fxb.whitetile; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.ui.Image; public class Block extends Image{ Color color;
boolean isTouch;
//GameScreen gameScreen; public Block(){
Clear(); addListener( new InputListener(){
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
// TODO Auto-generated method stub
isTouch = true;
if( color == Color.WHITE ){
//Constant.state = Constant.GameState.game_preover;
//gameScreen.game. overStage.Show();
//gameScreen.overStage.Show();
}
return true;
}
}); } public void Clear(){
isTouch = false;
} }
//全局参数类
package com.fxb.whitetile; public class Constant {
enum GameState{ game_ready, game_on, game_pause, game_over, game_preover };
public static GameState state = GameState.game_ready; public static float initSpeed = 5;
public static float speedInc = 0.25f; public static int level = 2; }

游戏写的很粗糙,自己试了下,在android手机下能运行,但有些bug,还有待改进。还望大家多多指正,谢谢!!!

 

libgdx自制简易版Don't Touch The White Tile的更多相关文章

  1. libgdx自制简易Flappy Bird

    Flappy Bird,好吧,无需多说.今天年初不知咋的,一下子就火了,而且直接跃居榜首,在ios和android平台都是如此,实在难以理解.传说其作者每天收入能达到5w刀,着实碉堡了... 好吧,咱 ...

  2. 使用 LinkedBlockingQueue 实现简易版线程池

    前一阵子在做联系人的导入功能,使用POI组件解析Excel文件后获取到联系人列表,校验之后批量导入.单从技术层面来说,导入操作通常情况下是一个比较耗时的操作,而且如果联系人达到几万.几十万级别,必须拆 ...

  3. .NET Core的文件系统[5]:扩展文件系统构建一个简易版“云盘”

    FileProvider构建了一个抽象文件系统,作为它的两个具体实现,PhysicalFileProvider和EmbeddedFileProvider则分别为我们构建了一个物理文件系统和程序集内嵌文 ...

  4. MVC 验证码实现( 简易版)

    现在网站上越来越多的验证码,使用场景也是越来越多,登陆.注册.上传.下载...等等地方,都有可能大量使用到验证码,那么制作验证码到底有多简单呢?我们一起来看下最简易版的验证码实现过程- 验证码的基本步 ...

  5. 简易版自定义BaseServlet

    这几天在学Java Web,一直在思考Servlet重用的问题,就用java的反射机制实现自定义的简易版BaseServlet; 该方式有点像struts2 利用映射获取前端的参数.有兴趣的同学可以自 ...

  6. 简易版的TimSort排序算法

    欢迎探讨,如有错误敬请指正 如需转载,请注明出处http://www.cnblogs.com/nullzx/ 1. 简易版本TimSort排序算法原理与实现 TimSort排序算法是Python和Ja ...

  7. html5 canvas简易版捕鱼达人游戏源码

    插件描述:html5利用canvas写的一个js版本的捕鱼,有积分统计,鱼可以全方位移动,炮会跟着鼠标移动,第一次打开需要鼠标移出背景图,再移入的时候就可以控制炮的转动,因为是用的mouseover触 ...

  8. Python写地铁的到站的原理简易版

    Python地铁的到站流程及原理(个人理解) 今天坐地铁看着站牌就莫名的想如果用Python写其工作原理 是不是很简单就小试牛刀了下大佬们勿喷纯属小弟个人理解 首先来看看地铁上显示的站牌如下: 就想这 ...

  9. MVC5+EF6 简易版CMS(非接口) 第四章:使用业务层方法,以及关联表解决方案

    目录 简易版CMS后台管理系统开发流程 MVC5+EF6 简易版CMS(非接口) 第一章:新建项目 MVC5+EF6 简易版CMS(非接口) 第二章:建数据模型 MVC5+EF6 简易版CMS(非接口 ...

随机推荐

  1. Unix操作系统监控详解(一)

    一.描述 监控在检查系统问题运行状况以及优化系统性能工作上是一个不可缺少的部分.通过操作系统监控工具监视操作系统资源的使用情况,间接地反映了各服务器程序的运行情况.根据运行结果分析可以帮助我们快速定位 ...

  2. c#创建文件( File.Create() )后对文件写操作出错的分析

    在C#中,使用system.IO.File.Create()创建完一个文件之后,如果需要对这个文件进行写操作,会出现错误,提示你“这个文件正在被使用”. 原因是System.IO.File.Creat ...

  3. Linux中 /proc/[pid] 目录各文件简析

    Linux 内核提供了一种通过 proc 文件系统,在运行时访问内核内部数据结构.改变内核设置的机制.proc 文件系统是一个伪文件系统,它只存在内存当中,而不占用外存空间.它以文件系统的方式为访问系 ...

  4. ajax status 错误

    status **:未被始化 status **:请求收到,继续处理 status **:操作成功收到,分析.接受 status **:完成此请求必须进一步处理 status **:请求包含一个错误语 ...

  5. CentOS配置rsyslog Serve

    CentOS6配置rsyslog Server: vi /etc/rsyslog.conf: #启用如下tcp支持: $ModLoad imtcp $InputTCPServerRun 514 #添加 ...

  6. rsync 数据备份+cron+mailx案例

    大家都知道数据非常重要的,需要经常备份,如果备份了,但无法恢复还原,那就证明你备份的很失败,所有当我们备份了数据需要检查是否备份完整,是否可用可恢复.以下为一个企业案例: 某公司里有一台Web服务器, ...

  7. 1.3Windows控制台的简单操作:

    目录: 1.控制台的打开 2.盘符的跳转 3.跳转到某个文件夹 4.展示文件 5.清屏 6.历史记录 7.拖动添加路径 8.自动补齐 9.正常退出 1.打开控制台:系统图标键 + R,输入cmd,按回 ...

  8. chrome历史记录,浏览记录,全选问题.

    一句话, 这个列表支持SHIFT多选 =,=!

  9. [技术] OIer的C++标准库 : STL入门

    注: 本文主要摘取STL在OI中的常用技巧应用, 所以可能会重点说明容器部分和算法部分, 且不会讨论所有支持的函数/操作并主要讨论 C++11 前支持的特性. 如果需要详细完整的介绍请自行查阅标准文档 ...

  10. SDN期末作业验收

    作业链接:https://edu.cnblogs.com/campus/fzu/SoftwareDefinedNetworking2017/homework/1585 负载均衡程序 1.github链 ...