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. Python笔记(五):异常处理和数据存储

    注:和上一篇有关联 (一)  finally 和 输出异常信息 try:       the_man = open(r'C:\Users\123456\Desktop\test.txt')       ...

  2. windows无法访问linux服务器

    解决: 或者有效 iptables -A INPUT -p tcp --dport 8000 -j ACCEPT[root@localhost ~]# iptables -A OUTPUT -p tc ...

  3. Kafka 处理器客户端介绍

    [编者按]本文作者为 Bill Bejeck,主要介绍如何有效利用新的 Apache Kafka 客户端来满足数据处理需求.文章系国内 ITOM 管理平台 OneAPM 编译呈现,以下为正文. 如果你 ...

  4. leveldb源码分析--BloomFilter

    bloomfilter是leveldb中的一大性能利器,所以为了文章的表现完整性这里新启这么一篇文章.leveldb中的bloomfilter的实现在bloom.cc中,是一个较为简单的实现,所以就不 ...

  5. 使用 Azure 门户创建 Windows 虚拟机

    可以通过 Azure 门户创建 Azure 虚拟机. 此方法提供一个基于浏览器的用户界面,用于创建和配置虚拟机和所有相关的资源. 本快速入门介绍了如何创建虚拟机并在 VM 上安装 webserver. ...

  6. maven+spring+junit测试要注意的事情

    使用maven方式创建webapp工程的资料网上一大堆,在这里也不详细说了.在创建完成之后,里面说到要转动态web工程时要切换为3.0版本,但是我本地切换不了,网上的方法好像也没用,暂时也没用到这块. ...

  7. python的学习之路day7-socket网络编程

    python基础部分学习完了,时间也已经过了两个月左右,感觉没学到什么,可能是我学习之后忘记的太多了. 由于没钱买书,要是去培训就更没钱了,所以在网上找了一本书,感觉还不错,讲的比较好,比较详细. P ...

  8. 【转】Java学习---Java中volatile关键字实现原理

    [原文]https://www.toutiao.com/i6592879392400081412/ 前言 我们知道volatile关键字的作用是保证变量在多线程之间的可见性,它是java.util.c ...

  9. 【史上最全】申请配置阿里云服务器,并部署IIS和开发环境,项目上线经验

    最近一年在实验室做web后端开发,涉及到一些和服务器搭建及部署上线项目的相关经验,写个帖子和小伙伴们分享,一同进步! 首先谈一下,为什么越来越多中小型公司/实验室,部署项目的趋势都是在云服务器而不是普 ...

  10. SQL语句:查看排名前五的SQL语句耗时情况

    total_worker_time , last_worker_time , max_worker_time , min_worker_time , ) , ( ( CASE statement_en ...