import javax.microedition.lcdui.*;
import java.util.Random;
import javax.microedition.lcdui.game.*;
public class game2 extends GameCanvas implements Runnable {
private boolean isPlay; // Game Loop runs when isPlay is true
private long delay; // To give thread consistency
private Image i1,i2,i3,i4,i5,i6;
private int ran,lop,a;
// Sprites to be used
private Sprite[] sprite;
// Layer Manager
private int index;
private Random random;
private LayerManager layerManager;
// Constructor and initialization
public game2() {
super(true);
delay = 20;
lop=1;
try {i1=Image.createImage("/score.png");
i2=Image.createImage("/name.png");
i3=Image.createImage("/player.png");
i4=Image.createImage("/mobile.png");
i5=Image.createImage("/score.png");
i6=Image.createImage("/score.png");
}
catch (Exception e) {
e.printStackTrace();
}
// Load Images to Sprites
sprite=new Sprite[6];
sprite[0]=new Sprite(i2);
sprite[1]=new Sprite(i1);
sprite[2]=new Sprite(i3);
sprite[3]=new Sprite(i4);
sprite[4]=new Sprite(i5);
sprite[5]=new Sprite(i6);
layerManager = new LayerManager();
}
public void start() {
isPlay = true;
Thread t = new Thread(this);
t.start();
}
public void stop() { isPlay = false; }
// Main Game Loop
public void run() {
Graphics g = getGraphics();
while (isPlay == true) {
try { Thread.sleep(70); }
catch (InterruptedException ie) {}
drawScreen(g);
player();
pos();
ran();
}
}
// Method to Handle User Inputs
// Method to Display Graphics
private void drawScreen(Graphics g) {
g.setColor(255,255,255);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0,0,0);
g.fillRect(0,getHeight()-10,getWidth(),20);
layerManager.paint(g,90,0);
flushGraphics();
System.out.println(a);
}
public void player()
{
// if(p1.getY()==getHeight()-p1.getHeight())
{
}
//else
{
//p1.setPosition(0,i++);
}
}
private void input() {
int keyStates = getKeyStates();
{
if ((keyStates & RIGHT_PRESSED) !=0 )
{
//p5.move(2,0);
}
if ((keyStates & LEFT_PRESSED) !=0 )
{
// p5.move(-2,0);
}
if ((keyStates & UP_PRESSED) !=0 )
{
// p5.move(0,-2);
}
if ((keyStates & DOWN_PRESSED) !=0 )
{
// p5.move(0,2);
}
}
}
public int ran()
{
random = new Random();
a = Math.abs(random.nextInt() % 2);
return a;
}
public void pos()
{
if(a==1)
{a++;
if(System.currentTimeMillis() -10 > 300) {
layerManager.append(sprite[1]);
sprite[1].move(0,lop++);
}
else if(a==0)
{a++;
if(System.currentTimeMillis() -10 > 300) {
layerManager.append(sprite[4]);
sprite[1].move(0,lop++);
}
}
else if(a==3)
{
if(System.currentTimeMillis() -10 > 300) {
layerManager.append(sprite[3]);
sprite[3].move(0,lop++);
}
else if(a==4)
{
if(System.currentTimeMillis() -10 > 300) {
layerManager.append(sprite[4]);
sprite[4].move(0,lop++);
}
}}
}
}
}
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.Canvas;
import java.util.*;
import java.io.*;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
public class MainGame extends Canvas implements Runnable
{
int w1=330;
int width,height,startX,startY,endX,endY,storeX,storeY;
int i=0,j=0,k=0,d=0;
private int[] endingPoint={147,147,147,147,147,147,204,204,204,204,204,204,204,204,204,204,204,204,204,204,204,204,204,204,204};
private int[] startingPoint={20,20,20,20,20,20,20,20,20,20,20,20,20};
private int[] Point={0,0,0,0,0,0,0,0,0,0,0,0,0};
private boolean startGame;
private int Ans1,Ans2,Ans3,Ans4,Ans5,Ans6;
int time=10;
int store=0;
Random r = new Random();
private char firstChar,secondChar,thirdChar;
public char [][] words={{'a','b','c','w'},{'d','e','f'},{'k','l','m','n'},{'p','q','r'},{'s','t','u','v'},{'h','e','l','l','o'},{'s','t','e','v','e','n'},{'w','a','t','e','r'},{'b','r','a','v','e'},{'b','o','l','d'}};
public char[][] Map=
{
{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
...........................
{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
..............................
};
public void start()
{
startGame = true;
Thread t = new Thread(this);
t.start();
}
private void Map(Graphics g)
{
g.setColor(0x000000);
for(i=0;i<29;i++)
for(j=0;j<25;j++)
{
g.drawChar(Map[i][j],i*7,j*7,g.TOP|g.LEFT);
}
}
public void run()
{
w1= 2;// Math.abs(r.nextInt()%2);
while(startGame)
{
try {repaint();
Thread.sleep(80);
{
wait(50L);
}
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
public void paint(Graphics g)
{
g.setColor(0xffffff);
g.setColor(0xffffff);
g.fillRect(0, 0, getWidth(), getHeight());
Map(g);
//////////////first word fall
if(w1==2)
{
g.setColor(0x000000);
g.drawString(""+words[1][0],0,Point[0],g.TOP|g.LEFT);
Point[0]+=time;
g.drawString(""+words[1][1],7,Point[1],g.TOP|g.LEFT);
Point[1]+=time;
g.drawString(""+words[1][2],14,Point[2],g.TOP|g.LEFT);
Point[2]+=time;
if(Point[0]>=endingPoint[0])
{
Point[0]=endingPoint[0];
Ans1=1;
}
if(Point[1]>=endingPoint[1])
{
Point[1]=endingPoint[1];
Ans2=1;
}
if(Point[2]>=endingPoint[2])
{
Point[2]=endingPoint[2];
Ans3=1;
}
if(Ans1==1& Ans2==1 & Ans3==1)
{endingPoint[0]=endingPoint[0]-7;
endingPoint[1]=endingPoint[1]-7;
endingPoint[2]=endingPoint[2]-7;
w1=1;//////// new word start falling
Point[0]=0;
Point[1]=0;
Point[2]=0;
Map[0][21]='d';
Map[1][21]='e';
Map[2][21]='f';
Map(g);
}
}///////////first ends
}import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
/**
*
* @author blundell
* @version
*/
public class MainMidlet extends MIDlet {
public void startApp() throws MIDletStateChangeException {
try {
MainGame midlet1 = new MainGame();
Display.getDisplay(this).setCurrent(midlet1);
midlet1.start();
} catch (Exception e) {
e.printStackTrace();
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
////////midlet ends
////////class code
import java.util.Random;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
public class MainGame extends Canvas implements Runnable {
/* CONSTANTS */
/* Speed rate at which numbers fall */
private static final int FALL_SPEED = 5;
/* Value range of numbers on screen 0-*+1 */
private static final int VALUE_RANGE = 10;
/* Screen refresh rate */
private static final long FRAME_SPEED = 100;
private String chars[]={"Hello","Welcome","hit","kick","fine","soccer","play","huge","welcome","matrix","gone","dog"};
/* VARIABLES */
int width = getWidth();
int height = getHeight();
boolean startGame = false;
boolean newNumber = true;
int x = 0;
int y = 0;
Graphics g;
Random generatorNumber = new Random();
Random generatorX = new Random();
int randomNumber = 0;
int randomX = 0;
public void start() {
generatorNumber.setSeed(System.currentTimeMillis());
generatorX.setSeed(System.currentTimeMillis());
startGame = true;
final Thread t = new Thread(this);
t.start();
}
public void run() {
while (startGame) {
goGoGo(g);
repaint();
serviceRepaints();
}
}
private void goGoGo(Graphics g) {
if (y > height) {
y = 0;
newNumber = true;
}
if (newNumber) {
randomNumber = generatorNumber.nextInt();
randomNumber = Math.abs(generatorNumber.nextInt());// This creates
// the random
// number...
randomNumber = randomNumber % VALUE_RANGE;// This is a number
// between 0-100
randomX = generatorX.nextInt();
randomX = Math.abs(generatorX.nextInt());// This creates the random*/
// number...
randomX = 0 + randomX % width;// This is a number between 0-100
newNumber = false;
}
y += FALL_SPEED;
}
public void paint(Graphics g) {
g.setColor(0x000000);
g.fillRect(0, 0, width, height);
g.setColor(0xffffff);
g.drawString(""+chars[randomNumber], randomX, y, Graphics.TOP|Graphics.LEFT);
try {
Thread.sleep(FRAME_SPEED);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
////////private int charPos[][] // = initialize the array as you desire
private int nextChar = 0;
...
...
y += FALL_SPEED;
if(y > height) {
nextChar++;
y = 0;
newNumber = true;
charPos[nextChar][0] = x;
charPos[nextChar][1] = y;
}
...
...
//Draw all the characters in the screen that are stored in the posChar array.
import java.util.Random;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
public class MainGame extends Canvas implements Runnable {
/* CONSTANTS */
/* Speed rate at which numbers fall */
private static final int FALL_SPEED = 5;
/* Value range of numbers on screen 0-*+1 */
private static final int VALUE_RANGE = 10;
/* Screen refresh rate */
private static final long FRAME_SPEED = 100;
private String chars[]={"Hello","Welcome","hit","kick","fine","soccer","play","huge","welcome","matrix","gone","dog"};
/* VARIABLES */
int width = getWidth();
int height = getHeight();
boolean startGame = false;
boolean newNumber = true;
int x = 0;
int y = 0;
Graphics g;
Random generatorNumber = new Random();
Random generatorX = new Random();
int randomNumber = 0;
int randomX = 0;
// = initialize the array as you desire
[b]private int nextChar = 0;
private String charPos[];[/b]
public void start() {
/*generatorNumber.setSeed(System.currentTimeMillis());;
generatorX.setSeed(System.currentTimeMillis());*/
startGame = true;
final Thread t = new Thread(this);
t.start();
}
public void run() {
while (startGame) {
// System.out.println(charPos[0]);
goGoGo(g);
repaint();
serviceRepaints();
}
}
private void goGoGo(Graphics g) {
if (y > height) {
y = 0;
[b]charPos[nextChar]=chars[randomNumber];
nextChar++;[/b]
newNumber = true;
}
if (newNumber) {
randomNumber = generatorNumber.nextInt();
randomNumber = Math.abs(generatorNumber.nextInt());// This creates
// the random
// number...
randomNumber = randomNumber % VALUE_RANGE;// This is a number
// between 0-100
randomX = generatorX.nextInt();
randomX = Math.abs(generatorX.nextInt());// This creates the random*/
// number...
randomX = 0 + randomX % width;// This is a number between 0-100
newNumber = false;
}
y += FALL_SPEED;
}
public void paint(Graphics g) {
g.setColor(0x000000);
g.fillRect(0, 0, width, height);
g.setColor(0xffffff);
g.drawString(""+chars[randomNumber], randomX, y, Graphics.TOP|Graphics.LEFT);
//[b]g.drawString(""+charPos[nextChar], randomX, y, Graphics.TOP|Graphics.LEFT);[/b]
try {
Thread.sleep(FRAME_SPEED);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}Users browsing this forum: No registered users and 1 guest