1. 程式人生 > >零打碎敲學Android 二 —做個拼圖遊戲吧

零打碎敲學Android 二 —做個拼圖遊戲吧

               

Android千好萬好,唯獨模擬器不是太好,在不更換舊有硬體的前提下,使用Android模擬器通常會遭遇效率問題,況且在logcat下面除錯,也始終不如開發桌面遊戲時那麼直觀。有沒有什麼辦法,能夠解決這一問題呢?

其實很容易做到。

Android首先是一個精簡的Linux平臺,其次才是一個手機系統,Java在PC上可以做到的事情,Android不但可以做到,而且能以近乎一致的手段做到。事實上,如果有人故意通過封裝抹殺Android與PC上Java應用差異性的話,任何Java遊戲,都可以在很少更改程式碼(或者完全不更改程式碼)的情況下移植到Android之上。

比如,筆者下面提供的這個拼圖遊戲示例,就可以在幾乎不改變程式結構(部分相關類需要替換,不過可以利用正則自動完成)的前提下,執行在Android上。

PC版原始碼(框架為LGame-Simple-0.2.0):

[java] view plain copy print?
  1. package org.loon.game.simple.test;  
  2. import java.awt.Graphics;  
  3. import java.awt.Graphics2D;  
  4. import java.awt.Image;  
  5. import java.awt.event.KeyEvent;  
  6. import java.awt.event.MouseEvent;  
  7. import org.loon.framework.game.simple.GameScene;  
  8. import org.loon.framework.game.simple.core.Deploy;  
  9. import org.loon.framework.game.simple.core.Screen;  
  10. import org.loon.framework.game.simple.utils.GraphicsUtils;  
  11. /** 
  12.  *  
  13.  * Copyright 2008  
  14.  * 
  15.  * Licensed under the Apache License, Version 2.0 (the "License"); 
  16.  * you may not use this file except in compliance with the License. 
  17.  * You may obtain a copy of the License at
     
  18.  * 
  19.  * http://www.apache.org/licenses/LICENSE-2.0 
  20.  * 
  21.  * Unless required by applicable law or agreed to in writing, software 
  22.  * distributed under the License is distributed on an "AS IS" BASIS, 
  23.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
  24.  * either express or implied. See the License for the specific language 
  25.  * governing permissions and limitations under the License. 
  26.  * 
  27.  * @project loonframework 
  28.  * @author chenpeng   
  29.  * @email:[email protected]  
  30.  * @version 0.1 
  31.  */
  32. publicclass ScreenTest1 extends Screen {  
  33.     private Image imageBack, tmp_imageBack, imageForward;  
  34.     private Graphics tmp_graphics;  
  35.     privateint blocks[];  
  36.     privateboolean isEvent;  
  37.     privateint count, rs, cs, row, col, width, height;  
  38.     public ScreenTest1(String file1, String file2, int row, int col) {  
  39.         this.col = col;  
  40.         this.row = row;  
  41.         this.imageBack = GraphicsUtils.loadImage(file1);  
  42.         this.width = imageBack.getWidth(null);  
  43.         this.height = imageBack.getHeight(null);  
  44.         this.rs = width / row;  
  45.         this.cs = height / col;  
  46.         this.tmp_imageBack = GraphicsUtils  
  47.                 .createImage(width, height + cs, true);  
  48.         this.tmp_graphics = tmp_imageBack.getGraphics();  
  49.         this.count = col * row;  
  50.         this.blocks = newint[count];  
  51.         this.imageForward = GraphicsUtils.loadImage(file2);  
  52.         for (int i = 0; i < count; i++) {  
  53.             blocks[i] = i;  
  54.         }  
  55.         rndBlocks();  
  56.     }  
  57.     /** 
  58.      * 複製拼圖中圖片塊 
  59.      *  
  60.      * @param x1 
  61.      * @param y1 
  62.      * @param x2 
  63.      * @param y2 
  64.      */
  65.     privatevoid copy(int x1, int y1, int x2, int y2) {  
  66.         tmp_graphics.copyArea(x1 * rs, y1 * cs, rs, cs, (x2 - x1) * rs,  
  67.                 (y2 - y1) * cs);  
  68.     }  
  69.     /** 
  70.      * 隨機生成拼圖內容 
  71.      *  
  72.      */
  73.     privatevoid rndBlocks() {  
  74.         tmp_graphics.drawImage(imageBack, 00null);  
  75.         for (int i = 0; i < (count * row); i++) {  
  76.             int x1 = (int) ((double) row * Math.random());  
  77.             int y1 = (int) ((double) col * Math.random());  
  78.             int x2 = (int) ((double) row * Math.random());  
  79.             int y2 = (int) ((double) col * Math.random());  
  80.             copy(x1, y1, 0, col);  
  81.             copy(x2, y2, x1, y1);  
  82.             copy(0, col, x2, y2);  
  83.             int j1 = blocks[y1 * row + x1];  
  84.             blocks[y1 * row + x1] = blocks[y2 * row + x2];  
  85.             blocks[y2 * row + x2] = j1;  
  86.         }  
  87.     }  
  88.     /** 
  89.      * 點選滑鼠 
  90.      */
  91.     publicvoid leftClick(MouseEvent e) {  
  92.         if (isEvent) {  
  93.             return;  
  94.         }  
  95.         int x = e.getX() / rs;  
  96.         int y = e.getY() / cs;  
  97.         copy(000, col);  
  98.         copy(x, y, 00);  
  99.         copy(0, col, x, y);  
  100.         int no = blocks[0];  
  101.         blocks[0] = blocks[y * row + x];  
  102.         blocks[y * row + x] = no;  
  103.         int index;  
  104.         for (index = 0; index < count; index++) {  
  105.             if (blocks[index] != index) {  
  106.                 break;  
  107.             }  
  108.         }  
  109.         if (index == count) {  
  110.             isEvent = true;  
  111.         }  
  112.         return;  
  113.     }  
  114.     publicvoid draw(Graphics2D g) {  
  115.         if (!isEvent) {  
  116.             g.drawImage(tmp_imageBack, 00null);  
  117.             for (int i = 0; i < row; i++) {  
  118.                 for (int j = 0; j < col; j++)  
  119.                     g.drawRect(i * rs, j * cs, rs, cs);  
  120.             }  
  121.         }  
  122.         if (isEvent && imageForward != null) {  
  123.             g.drawImage(imageBack, 00null);  
  124.             g.drawImage(imageForward, 00null);  
  125.             tmp_graphics.dispose();  
  126.         }  
  127.     }  
  128.     publicboolean isEvent() {  
  129.         return isEvent;  
  130.     }  
  131.     publicvoid setEvent(boolean isEvent) {  
  132.         this.isEvent = isEvent;  
  133.     }  
  134.     publicvoid middleClick(MouseEvent e) {  
  135.     }  
  136.     publicvoid onKey(KeyEvent e) {  
  137.     }  
  138.     publicvoid onKeyUp(KeyEvent e) {  
  139.     }  
  140.     publicvoid rightClick(MouseEvent e) {  
  141.     }  
  142.     publicstaticvoid main(String[] args) {  
  143.         GameScene frame = new GameScene("拼圖"320480);  
  144.         Deploy deploy = frame.getDeploy();  
  145.         deploy.setScreen(new ScreenTest1("images/backimage1.jpg",  
  146.                 "images/over.png"44));  
  147.         deploy.setShowFPS(true);  
  148.         deploy.setLogo(false);  
  149.         deploy.setFPS(100);  
  150.         deploy.mainLoop();  
  151.         frame.showFrame();  
  152.     }  
  153. }  
package org.loon.game.simple.test;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Image;import java.awt.event.KeyEvent;import java.awt.event.MouseEvent;import org.loon.framework.game.simple.GameScene;import org.loon.framework.game.simple.core.Deploy;import org.loon.framework.game.simple.core.Screen;import org.loon.framework.game.simple.utils.GraphicsUtils;/** *  * Copyright 2008  * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language * governing permissions and limitations under the License. * * @project loonframework * @author chenpeng   * @email:[email protected]  * @version 0.1 */public class ScreenTest1 extends Screen { private Image imageBack, tmp_imageBack, imageForward; private Graphics tmp_graphics; private int blocks[]; private boolean isEvent; private int count, rs, cs, row, col, width, height; public ScreenTest1(String file1, String file2, int row, int col) {  this.col = col;  this.row = row;  this.imageBack = GraphicsUtils.loadImage(file1);  this.width = imageBack.getWidth(null);  this.height = imageBack.getHeight(null);  this.rs = width / row;  this.cs = height / col;  this.tmp_imageBack = GraphicsUtils    .createImage(width, height + cs, true);  this.tmp_graphics = tmp_imageBack.getGraphics();  this.count = col * row;  this.blocks = new int[count];  this.imageForward = GraphicsUtils.loadImage(file2);  for (int i = 0; i < count; i++) {   blocks[i] = i;  }  rndBlocks(); } /**  * 複製拼圖中圖片塊  *   * @param x1  * @param y1  * @param x2  * @param y2  */ private void copy(int x1, int y1, int x2, int y2) {  tmp_graphics.copyArea(x1 * rs, y1 * cs, rs, cs, (x2 - x1) * rs,    (y2 - y1) * cs); } /**  * 隨機生成拼圖內容  *   */ private void rndBlocks() {  tmp_graphics.drawImage(imageBack, 0, 0, null);  for (int i = 0; i < (count * row); i++) {   int x1 = (int) ((double) row * Math.random());   int y1 = (int) ((double) col * Math.random());   int x2 = (int) ((double) row * Math.random());   int y2 = (int) ((double) col * Math.random());   copy(x1, y1, 0, col);   copy(x2, y2, x1, y1);   copy(0, col, x2, y2);   int j1 = blocks[y1 * row + x1];   blocks[y1 * row + x1] = blocks[y2 * row + x2];   blocks[y2 * row + x2] = j1;  } } /**  * 點選滑鼠  */ public void leftClick(MouseEvent e) {  if (isEvent) {   return;  }  int x = e.getX() / rs;  int y = e.getY() / cs;  copy(0, 0, 0, col);  copy(x, y, 0, 0);  copy(0, col, x, y);  int no = blocks[0];  blocks[0] = blocks[y * row + x];  blocks[y * row + x] = no;  int index;  for (index = 0; index < count; index++) {   if (blocks[index] != index) {    break;   }  }  if (index == count) {   isEvent = true;  }  return; } public void draw(Graphics2D g) {  if (!isEvent) {   g.drawImage(tmp_imageBack, 0, 0, null);   for (int i = 0; i < row; i++) {    for (int j = 0; j < col; j++)     g.drawRect(i * rs, j * cs, rs, cs);   }  }  if (isEvent && imageForward != null) {   g.drawImage(imageBack, 0, 0, null);   g.drawImage(imageForward, 0, 0, null);   tmp_graphics.dispose();  } } public boolean isEvent() {  return isEvent; } public void setEvent(boolean isEvent) {  this.isEvent = isEvent; } public void middleClick(MouseEvent e) { } public void onKey(KeyEvent e) { } public void onKeyUp(KeyEvent e) { } public void rightClick(MouseEvent e) { } public static void main(String[] args) {  GameScene frame = new GameScene("拼圖", 320, 480);  Deploy deploy = frame.getDeploy();  deploy.setScreen(new ScreenTest1("images/backimage1.jpg",    "images/over.png", 4, 4));  deploy.setShowFPS(true);  deploy.setLogo(false);  deploy.setFPS(100);  deploy.mainLoop();  frame.showFrame(); }} 

02

Android版原始碼(框架為LAGame-Simple-prototype):

[java] view plain copy print?
  1. package org.loon.framework.android.game;  
  2. import android.view.KeyEvent;  
  3. import android.view.MotionEvent;  
  4. /** 
  5.  *  
  6.  * Copyright 2008 - 2009 
  7.  *  
  8.  * Licensed under the Apache License, Version 2.0 (the "License"); you may not 
  9.  * use this file except in compliance with the License. You may obtain a copy of 
  10.  * the License at 
  11.  *  
  12.  * http://www.apache.org/licenses/LICENSE-2.0 
  13.  *  
  14.  * Unless required by applicable law or agreed to in writing, software 
  15.  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
  16.  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
  17.  * License for the specific language governing permissions and limitations under 
  18.  * the License. 
  19.  *  
  20.  * @project loonframework 
  21.  * @author chenpeng 
  22.  * @email <a title="" href="http://hi.baidu.com/ceponline" mce_href="http://hi.baidu.com/ceponline" target="_blank">ceponline</a>@yahoo.com.cn 
  23.  * @version 0.1.0 
  24.  */
  25. publicclass ScreenTest1 extends LAScreen {  
  26.     private LAImage imageBack, tmp_imageBack, imageForward;  
  27.     private LAGraphics tmp_graphics;  
  28.     privateint blocks[];  
  29.     privateboolean isEvent;  
  30.     privateint count, rs, cs, row, col, width, height;  
  31.     public ScreenTest1(String file1, String file2, int row, int col) {  
  32.         this.col = col;  
  33.         this.row = row;  
  34.         this.imageBack = getLAImage(file1);  
  35.         this.width = imageBack.getWidth();  
  36.         this.height = imageBack.getHeight();  
  37.         this.rs = width / row;  
  38.         this.cs = height / col;  
  39.         this.tmp_imageBack = new LAImage(width, height + cs);  
  40.         this.tmp_graphics = tmp_imageBack.getLAGraphics();  
  41.         this.count = col * row;  
  42.         this.blocks = newint[count];  
  43.         this.imageForward = getLAImage(file2);  
  44.         for (int i = 0; i < count; i++) {  
  45.             blocks[i] = i;  
  46.         }  
  47.         rndBlocks();  
  48.     }  
  49.     /** 
  50.      * 複製拼圖中圖片塊 
  51.      *  
  52.      * @param x1 
  53.      * @param y1 
  54.      * @param x2 
  55.      * @param y2 
  56.      */
  57.     privatevoid copy(int x1, int y1, int x2, int y2) {  
  58.         tmp_graphics.copyArea(x1 * rs, y1 * cs, rs, cs, (x2 - x1) * rs,  
  59.                 (y2 - y1) * cs);  
  60.     }  
  61.     /** 
  62.      * 隨機生成拼圖內容 
  63.      *  
  64.      */
  65.     privatevoid rndBlocks() {  
  66.         tmp_graphics.drawImage(imageBack, 00);  
  67.         for (int i = 0; i < (count * row); i++) {  
  68.             int x1 = (int) ((double) row * Math.random());  
  69.             int y1 = (int) ((double) col * Math.random());  
  70.             int x2 = (int) ((double) row * Math.random());  
  71.             int y2 = (int) ((double) col * Math.random());  
  72.             copy(x1, y1, 0, col);  
  73.             copy(x2, y2, x1, y1);  
  74.             copy(0, col, x2, y2);  
  75.             int j1 = blocks[y1 * row + x1];  
  76.             blocks[y1 * row + x1] = blocks[y2 * row + x2];  
  77.             blocks[y2 * row + x2] = j1;  
  78.         }  
  79.     }  
  80.     /** 
  81.      * 點選觸控式螢幕 
  82.      */
  83.     publicboolean onTouchDown(MotionEvent e) {  
  84.         if (isEvent) {  
  85.             return isEvent;  
  86.         }  
  87.         int x = (int) (e.getX() / rs);  
  88.         int y = (int) (e.getY() / cs);  
  89.         copy(000, col);  
  90.         copy(x, y, 00);  
  91.         copy(0, col, x, y);  
  92.         int no = blocks[0];  
  93.         blocks[0] = blocks[y * row + x];  
  94.         blocks[y * row + x] = no;  
  95.         int index;  
  96.         for (index = 0; index < count; index++) {  
  97.             if (blocks[index] != index) {  
  98.                 break;  
  99.             }  
  100.         }  
  101.         if (index == count) {  
  102.             isEvent = true;  
  103.         }  
  104.         return isEvent;  
  105.     }  
  106.     /** 
  107.      * 繪製拼圖 
  108.      */
  109.     publicvoid draw(LAGraphics g) {  
  110.         if (!isEvent) {  
  111.             g.drawImage(tmp_imageBack, 00);  
  112.             for (int i = 0; i < row; i++) {  
  113.                 for (int j = 0; j < col; j++)  
  114.                     g.drawRect(i * rs, j * cs, rs, cs);  
  115.             }  
  116.         }  
  117.         if (isEvent && imageForward != null) {  
  118.             g.drawImage(imageBack, 00);  
  119.             g.drawImage(imageForward, 00);  
  120.             tmp_graphics.dispose();  
  121.         }  
  122.     }  
  123.     publicboolean isEvent() {  
  124.         return isEvent;  
  125.     }  
  126.     publicvoid setEvent(boolean isEvent) {  
  127.         this.isEvent = isEvent;  
  128.     }  
  129.     publicboolean onKeyDown(int keyCode, KeyEvent e) {  
  130.         returnfalse;  
  131.     }  
  132.     publicboolean onKeyUp(int keyCode, KeyEvent e) {  
  133.         returnfalse;  
  134.     }  
  135.     publicboolean onTouchMove(MotionEvent e) {  
  136.         returnfalse;  
  137.     }  
  138.     publicboolean onTouchUp(MotionEvent e) {  
  139.         returnfalse;  
  140.     }  
  141. }  
package org.loon.framework.android.game;import android.view.KeyEvent;import android.view.MotionEvent;/** *  * Copyright 2008 - 2009 *  * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at *  * http://www.apache.org/licenses/LICENSE-2.0 *  * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. *  * @project loonframework * @author chenpeng * @email <a title="" href="http://hi.baidu.com/ceponline" mce_href="http://hi.baidu.com/ceponline" target="_blank">ceponline</a>@yahoo.com.cn * @version 0.1.0 */public class ScreenTest1 extends LAScreen { private LAImage imageBack, tmp_imageBack, imageForward; private LAGraphics tmp_graphics; private int blocks[]; private boolean isEvent; private int count, rs, cs, row, col, width, height; public ScreenTest1(String file1, String file2, int row, int col) {  this.col = col;  this.row = row;  this.imageBack = getLAImage(file1);  this.width = imageBack.getWidth();  this.height = imageBack.getHeight();  this.rs = width / row;  this.cs = height / col;  this.tmp_imageBack = new LAImage(width, height + cs);  this.tmp_graphics = tmp_imageBack.getLAGraphics();  this.count = col * row;  this.blocks = new int[count];  this.imageForward = getLAImage(file2);  for (int i = 0; i < count; i++) {   blocks[i] = i;  }  rndBlocks(); } /**  * 複製拼圖中圖片塊  *   * @param x1  * @param y1  * @param x2  * @param y2  */ private void copy(int x1, int y1, int x2, int y2) {  tmp_graphics.copyArea(x1 * rs, y1 * cs, rs, cs, (x2 - x1) * rs,    (y2 - y1) * cs); } /**  * 隨機生成拼圖內容  *   */ private void rndBlocks() {  tmp_graphics.drawImage(imageBack, 0, 0);  for (int i = 0; i < (count * row); i++) {   int x1 = (int) ((double) row * Math.random());   int y1 = (int) ((double) col * Math.random());   int x2 = (int) ((double) row * Math.random());   int y2 = (int) ((double) col * Math.random());   copy(x1, y1, 0, col);   copy(x2, y2, x1, y1);   copy(0, col, x2, y2);   int j1 = blocks[y1 * row + x1];   blocks[y1 * row + x1] = blocks[y2 * row + x2];   blocks[y2 * row + x2] = j1;  } } /**  * 點選觸控式螢幕  */ public boolean onTouchDown(MotionEvent e) {  if (isEvent) {   return isEvent;  }  int x = (int) (e.getX() / rs);  int y = (int) (e.getY() / cs);  copy(0, 0, 0, col);  copy(x, y, 0, 0);  copy(0, col, x, y);  int no = blocks[0];  blocks[0] = blocks[y * row + x];  blocks[y * row + x] = no;  int index;  for (index = 0; index < count; index++) {   if (blocks[index] != index) {    break;   }  }  if (index == count) {   isEvent = true;  }  return isEvent; } /**  * 繪製拼圖  */ public void draw(LAGraphics g) {  if (!isEvent) {   g.drawImage(tmp_imageBack, 0, 0);   for (int i = 0; i < row; i++) {    for (int j = 0; j < col; j++)     g.drawRect(i * rs, j * cs, rs, cs);   }  }  if (isEvent && imageForward != null) {   g.drawImage(imageBack, 0, 0);   g.drawImage(imageForward, 0, 0);   tmp_graphics.dispose();  } } public boolean isEvent() {  return isEvent; } public void setEvent(boolean isEvent) {  this.isEvent = isEvent; } public boolean onKeyDown(int keyCode, KeyEvent e) {  return false; } public boolean onKeyUp(int keyCode, KeyEvent e) {  return false; } public boolean onTouchMove(MotionEvent e) {  return false; } public boolean onTouchUp(MotionEvent e) {  return false; }}[java] view plain copy print?
  1. package org.loon.framework.android.game;  
  2. import android.app.Activity;  
  3. import android.os.Bundle;  
  4. /** 
  5.  *  
  6.  * Copyright 2008 - 2009 
  7.  *  
  8.  * Licensed under the Apache License, Version 2.0 (the "License"); you may not 
  9.  * use this file except in compliance with the License. You may obtain a copy of 
  10.  * the License at 
  11.  *  
  12.  * http://www.apache.org/licenses/LICENSE-2.0 
  13.  *  
  14.  * Unless required by applicable law or agreed to in writing, software 
  15.  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
  16.  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
  17.  * License for the specific language governing permissions and limitations under 
  18.  * the License. 
  19.  *  
  20.  * @project loonframework 
  21.  * @author chenpeng 
  22.  * @email <a title="" href="http://hi.baidu.com/ceponline" mce_href="http://hi.baidu.com/ceponline" target="_blank">ceponline</a>@yahoo.com.cn 
  23.  * @version 0.1.0 
  24.  */
  25. publicclass Main extends Activity {  
  26.     private LAGameView view;  
  27.     publicvoid onCreate(Bundle icicle) {  
  28.         super.onCreate(icicle);  
  29.         view = new LAGameView(this);  
  30.         view.setScreen(new ScreenTest1("backimage1.jpg",  
  31.                 "over.png"44));  
  32.         view.setShowFPS(true);  
  33.         view.mainLoop();  
  34.     }  
  35.     protectedvoid onPause() {  
  36.         if (view != null) {  
  37.             view.setRunning(false);  
  38.         }  
  39.         super.onPause();  
  40.     }  
  41.     protectedvoid onStop() {  
  42.         if (view != null) {  
  43.             view.setRunning(false);  
  44.         }  
  45.         super.onStop();  
  46.     }  
  47. }  
package org.loon.framework.android.game;import android.app.Activity;import android.os.Bundle;/** *  * Copyright 2008 - 2009 *  * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at *  * http://www.apache.org/licenses/LICENSE-2.0 *  * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. *  * @project loonframework * @author chenpeng * @email <a title="" href="http://hi.baidu.com/ceponline" mce_href="http://hi.baidu.com/ceponline" target="_blank">ceponline</a>@yahoo.com.cn * @version 0.1.0 */public class Main extends Activity { private LAGameView view; public void onCreate(Bundle icicle) {  super.onCreate(icicle);  view = new LAGameView(this);  view.setScreen(new ScreenTest1("backimage1.jpg",    "over.png", 4, 4));  view.setShowFPS(true);  view.mainLoop(); } protected void onPause() {  if (view != null) {   view.setRunning(false);  }  super.onPause(); } protected void onStop() {  if (view != null) {   view.setRunning(false);  }  super.onStop(); }} 

00

01

Android遊戲與Java桌面遊戲在本質上不存在任何區別,邏輯實現更可以完全一致。通過示例我們看到,把一個以LGame-Simple框架開發的Java桌面遊戲移植到Android上居然是如此簡單。

事實上,未來的Android版LGame-Simple,函式實現將與PC版保持一致,對於差異性程式碼,筆者也將提供相互轉換的輔助工具。

如果您正在以LGame-Simple開發Java遊戲,那麼恭喜您,至多到今年12月底,它也將可以同時執行在Android上了。