Racing game source code

xiaoxiao2021-03-06  40

Package horseclub;

// Import javax.microedition.lcdui. *;

Import java.util.random;

Import java.lang.string;

Public Class Horsex

{

Public int m_no;

Public int m_horseage;

Public int m_horseex, m_horseendur, m_horsehealth;

Public char [] m_horsename = new char [4]; // = "my horse";

// public static stringbuffer m_horsename; // new char [4]; // = "my horse";

Public static final string lettersten = "abcdefghijklmnopqrstuvwxyz";

Public int m_speed;

Public int m_horsestate;

Public int m_golds;

Public int m_silvers;

Public Horsex (int endur, int exp, int health, int No)

{

INIT (Endur, Exp, Health, NO);

}

Public Void Init (int endur, int in)

{

INT randnum = 0;

// rand.setseed (no * 12398147);

RandNum = Horsemidlet.rand.nextint ();

m_horseage = myabs (randnum% 6 1);

// The "10" is the Difficulty

M_horseendur = myabs ((RandNum% 20 10-20 Endur)) 1;

m_horseex = myabs ((RandNum% 20 10-20 EXP)) 1;

M_HorseHealth = myabs ((RandNum% 20 10-20 Health)) 1;

INT x = m_horseendur;

// m_horsename.Append (LetterTable.Charat (x% 25)). Append (Letterta

Ble.Charat ((x 5)% 25)). Append (LetterTable.Charat ((x 17)% 25));

m_horsename [0] = lettable.charat (x% 25);

m_horsename [1] = lettable.Charat ((x 5)% 25);

m_horsename [2] = lettable.Charat ((x 17)% 25);

m_horsestate = randnum% 4;

m_speed = getSpeed ​​();

m_no = NO;

m_golds = 0;

m_silvers = 0;

}

Public Static Int Myabs (int value)

{

Value <0)

Value * = - 1;

Return Value;

}

Public Static int mysign (int value)

{

Value <0)

Return -1;

Return 1;

}

// Calculate TEH HORSE SPEED

Public int getSpeed ​​()

{

INT i = 0;

INT randnum = 0;

RandNum = Horsemidlet.rand.nextint (); i = (M_HORSEEX M_HORSEENDUR M_HORSEHEALTH) / 3;

i = myabs (m_horseex-i) myabs (m_horseendur-i) myabs (m_horsehealth-i) 1;

// i = i * rand ()% 3 1;

i = (m_horseex * 4 m_horseendur * 2 m_horsehealth * 3) * (randnum% 2 1) / i;

Return I;

}

}

Package horseclub;

Import javax.microedition.lcdui. *;

Import java.util.random;

Public Class Horsecanvas Extends Canvas Implements Runnable, CommandListener

{

Private Horsemidlet MIDlet;

Private Volatile Thread Animationthread = NULL;

Private static int CANVASHEIGHT, Canvaswidth

Private horsracing myhorseracing;

PRIVATE image BUFFER;

PRIVATE Graphics Graphics;

// for Lot UI

Private static int Lot_no;

PRIVATE Static int Lot_Money;

Private static int lot_select = 0; // 0 for lot_no

Private static int sumtemp;

// images

Private boolean running;

// private final int Sleep = 10;

PRIVATE FINAL INT SLEP = 10;

Private int readyTOSleep = 0;

PRIVATE INT INTRO_POS = 0;

PRIVATE COMMAND EXIT;

// private command memory;

Private Command NewGame;

Private image [] IMGMENU = NULL;

Private image [] IMGDOT = NULL;

// imgfloor = new image [7];

Private image [] imglot = null;

Private image [] imgtextfirstlot1 = NULL;

Private image [] imgtextfirstlot2 = null;

Private image [] imgtmp = NULL;

Private image [] imgtextsecondlot1 = NULL;

Private image [] imgtextsecondlot2 = NULL;

Private image [] imgtextracingnum = NULL;

Private image [] imgtextage = null;

Private image [] imgtextexp = NULL;

Private image [] imgtextendur = NULL;

Private image [] imgtexthealth = NULL;

Private image [] imgTextTotalMoney = NULL;

Private image [] imgTextlotnum = NULL;

Private image [] imgtextlotmoney = null; private image [] imgTextok1 = null;

Private image [] imgtextok2 = null;

Private image [] imgTextReset1 = NULL;

Private image [] imgTextReset2 = NULL;

Private image [] imgtextback1 = null;

Private image [] imgtextback2 = null;

Private image [] imgwin = NULL;

Public Horsecanvas (HORSEMIDLET MIDLET)

{

this.midlet = MIDLET;

Canvasheight = GetHeight ();

Canvaswidth = getWidth ();

Myhorsserating = new horsracing ();

Buffer = image.createImage (canvaswidth, canvasheight);

Graphics = buffer.getgraphics ();

EXIT = New Command ("Exit", Command.Stop, 1);

// Memory = New Command ("Memory", Command.screen, 1);

NewGame = New Command ("New Game", Command.screen, 1);

This.Addcommand (exit);

// this.addcommand (memory);

This.Addcommand (newgame);

This.SetCommandListener (this);

SumTemp = 0;

IMGMENU = New Image [1];

IMGDOT = New Image [1];

Imgmenu = Horsemidlet.getiMages ("Menu", 1);

System.out.println ("Free Memory: Menu" Runtime.Getruntime (). FreeMemory ());

IMGDOT = Horsemidlet.getimages ("BLUEDOT", 1);

System.out.println ("Free Memory: BlueDot" Runtime.Getruntime (). FreeMemory

));

Imglot = new image [1];

Imglot = Horsemidlet.getiMages ("Lothorse", 1);

ImgTextFirstlot1 = new image [1];

ImgTextFirstlot1 = Horsemidlet.getiMages ("Text_Firston", 1);

ImgTextFirstlot2 = new image [1];

ImgTextFirstlot2 = Horsemidlet.getiMages ("Text_Firstoff", 1);

ImgTextSecondlot1 = new image [1];

Imgtextsecondlot1 = Horsemidlet.getiMages ("Text_Secondon", 1);

ImgTextSecondlot2 = new image [1];

Imgtextsecondlot2 = Horsemidlet.getimages ("Text_Secondoff", 1); ImgTextracingNum = New Image [1];

ImgTextracingNum = Horsemidlet.getiMages ("Text_Racingnum", 1);

ImgTextage = new image [1];

ImgTextage = Horsemidlet.getiMages ("Text_age", 1);

IMGTEXTEXP = New Image [1];

Imgtextexp = Horsemidlet.getiMages ("text_exp", 1);

Imgtextendur = new image [1];

Imgtextendur = Horsemidlet.getiMages ("text_endur", 1);

ImgTextHealth = new image [1];

ImgTextHealth = Horsemidlet.getiMages ("Text_Health", 1);

ImgTextTotalMoney = new image [1];

ImgTextTotalMoney = Horsemidlet.getiMages ("Text_TotalMoney", 1);

ImgTextLotnum = New Image [1];

ImgTextlotnum = Horsemidlet.getiMages ("Text_lotnum", 1);

ImgTextLotmoney = new image [1];

ImgTextLotmoney = Horsemidlet.getiMages ("Text_lotmoney", 1);

ImgTextok1 = new image [1];

ImgTextok1 = Horsemidlet.getiMages ("text_okon", 1);

IMGTEXTOK2 = New Image [1];

ImgTextok2 = Horsemidlet.getimages ("text_okoff", 1);

ImgTextReset1 = new image [1];

ImgTextReset1 = Horsemidlet.getiMages ("Text_Reseton", 1);

ImgTextReset2 = new image [1];

ImgTextReset2 = Horsemidlet.getiMages ("Text_ReteOff", 1);

IMGTextBack1 = new image [1];

ImgTextBack1 = Horsemidlet.getiMages ("Text_Backon", 1);

ImgTextBack2 = new image [1];

ImgTextback2 = Horsemidlet.getiMages ("Text_Backoff", 1);

// imgwin = new image [1];

// imgwin = Horsemidlet.getimages ("WIN", 1);

Repaint ();

}

Public static int getcanvasheight () {return canvasheight;}

Public static int getcanvaswidth () {Return canvaswidth;}

Synchronized void start () {

Running = true;

AnimationthRead = New Thread (this);

AnimationthRead.start ();

}

Public void Run ()

{

Try

{

While (Running)

{

Repaint (0,0, canvaswidth, canvasheight);

ServiceRepaints ();

Thread.sleep (SLEEP);

}

}

Catch (InterruptedException IE)

{

System.out.println (IE.toString ());

}

}

Synchronized void stop ()

{

Running = false;

}

Public void Paint (Graphics G)

{

System.out.println ("Free Memory:" Runtime.Getruntime (). Freememory () "Tot

Al Memory " runtime.getRuntime (). TotalMemory ());

Switch (Horsemidlet.gamestate) {

Case Horsemidlet.game_State_Start:

// Draw Menu

G.SetColor (210, 210, 250);

G.FillRect (0, 0, getcanvaswidth (), getcanvasheight ());

// if (sumTemp == 0)

// {

/ * imgmenu = Horsemidlet.getimages ("Menu", 1);

System.out.println ("Free Memory: Menu" Runtime.Getruntime (). Freem

Emory ());

IMGDOT = Horsemidlet.getimages ("BLUEDOT", 1);

System.out.println ("Free Memory: BlueDot" Runtime.Getruntime (). Fr

EEMEMORY ());

SumTemp = 1; * /

//}

// g.drawImage (IMGMENU [0], 10, 10, g.left | g.top);

// g.drawImage (IMGDOT [0], 30, 75 Horsemidlet.substate * 21, G.LEFT | G.TOP);

g.drawimage (IMGMENU [0], 0, 10, G.LEFT | G.TOP);

g.drawimage (imgdot [0], 16, 75 horsemidlet.substate * 21, g.left | g.top);

System.out.println ("Free Memory: ***" Runtime.Getruntime (). Freememor

y ());

G.SetColor (127, 0, 0);

// g.drawstring (long.tostring (runtime.getruntime (). Totalmemory ()) "You

Good ", 10, 10, g.top | g.left);

// g.drawstring (long.Tostring (Runtime.Getruntime (). Freememory ()), 10, 30,

G.top | g.Left);

// imgmenu = null;

// imgdot = NULL;

Break;

Case Horsemidlet.game_State_INTRO:

G.SetColor (210, 210, 250); G. FillRect (0, 0, Getcanvaswidth (), getcanvasheight ());

// g.drawImage (Horsemidlet.imgintrobg [0], 10, 10, g.left | g.top);

g.drawImage (Horsemidlet.imgintrobg [0], 0, 10, g.LEFT | G.TOP);

// Require modification here

IF (Intro_POS

0)

INTRO_POS ;

// g.setClip (10, 10, horsemidlet.imgintro [0] .Getwidth (), Horsemidlet.i

Mgintro [0] .getHeight ());

// g.drawImage (Horsemidlet.imgintro [0], 10, -Intro_pos 10, g.left | g.

TOP);

// g.setClip (0, 0, getcanvaswidth (), getcanvasheight ());

G.SetClip (0,0, horsemidlet.imgintro [0] .GetWidth (), Horsemidlet.imgin

TRO [0] .getheight ());

g.drawimage (Horsemidlet.imginTro [0], 0, -Intro_pos, g.left | g.top);

// if (Intro_POS == Horsemidlet.imgintro [0] .getHeight () - Getcanvasheight

() -100)

// {

// g.drawImage (Horsemidlet.imgintro [1], 3, getcanvasheight () - 60, g.lef

T | g.top);

//}

G.setClip (0, 0, getcanvaswidth (), getcanvasheight ());

Try

{

Thread.sleep (8);

Repaint ();

}

Catch (InterruptedException IE)

{

System.out.println (IE.toString ());

}

Break;

CASE HORSEMIDLET.GAME_STATE_LOT:

// imgmenu = null;

// imgdot = NULL;

// Draw Lot

IF (Horsemidlet.subState == 0)

{

Lot_no = horsemidlet.firstlot_no;

LOT_MONEY = Horsemidlet.firstlot_money;

}

IF (horsemidlet.substate == 1)

{

Lot_no = horsemidlet.secondlot_no;

LOT_MONEY = Horsemidlet.secondlot_money;

}

// image [] imglot = new image [1];

// Imglot = Horsemidlet.getimages ("Lothorse", 1);

G.SetColor (105, 117, 184);

G.FillRect (0, 0, getcanvaswidth (), getcanvasheight ());

// g.drawImage (imglot [0], 10, 7, g.left | g.top);

g.drawImage (imglot [0], 0, 7, g.left | g.top);

G.SetColor (0,0,0);

// g.fillRect (10, 46, 40, 14);

G. FillRect (0, 46, 40, 14);

// Draw the name

G.SetColor (255, 255, 255);

// g.drawchars (myhorsracing.horses [lot_no] .m_horsename, 0, 3, 28, 59, 1); g.drawchars (myhorsracing.horses [lot_no] .m_horsename, 0, 3, 18, 59, 1);

// Image [] imgtextfirstlot = new image [1];

IF (Horsemidlet.subState == 0)

{

// imgtextFirstlot = Horsemidlet.getimages ("text_firston", 1);

g.drawImage (imgtextfirstlot1 [0], 0, 61, g.left | g.top);

}

Else

{

// imgtextfirstlot = Horsemidlet.getiMages ("text_firstoff", 1);

g.drawImage (imgtextfirstlot2 [0], 0, 61, g.left | g.top);

}

// g.drawImage (imgtextfirstlot [0], 10, 61, g.left | g.top);

// g.drawimage (imgtextfirstlot [0], 0,61, g.left | g.top);

// image [] imgtextsecondlot = new image [1];

IF (horsemidlet.substate == 1)

{

// imgtextsecondlot = Horsemidlet.getimages ("Text_secondon", 1);

g.drawImage (imgtextsecondlot1 [0], 0, 74, g.left | g.top);

}

Else

{

// imgtextsecondlot = Horsemidlet.getiMages ("text_secondoff", 1);

g.drawImage (imgtextsecondlot2 [0], 0, 74, g.left | g.top);

}

// g.drawimage (imgtextsecondlot [0], 10, 74, g.left | g.top);

// g.drawImage (imgtextsecondlot [0], 0,74, g.left | g.top);

// Draw the Horse Info

G.SetColor (255, 180, 0);

// g.FillRect (60, 7, getcanvaswidth () / 2 20, getcanvasheight () / 2 4);

// upper right corner

G.FillRect (50, 7, 76, getcanvasheight () / 2 4);

G.SetColor (0,0,0);

// g.drawRect (60, 7, getcanvaswidth () / 2 20, getcanvasheight () / 2 4);

g.drawRect (50, 7, 76, getcanvasheight () / 2 4);

G.SetColor (255, 255, 255);

// Draw Horse Info Text

// Image [] imgtextracingnum = new image [1];

// ImgTextRacingnum = Horsemidlet.getiMages ("text_racingnum", 1);

// g.drawImage (ImgTextracingNum [0], 70, 13, g.LEFT | G.TOP);

G.drawImage (ImgTextracingNum [0], 55, 13, g.LEFT | G.TOP);

// image [] imgtextage = new image [1];

// imgtextage = Horsemidlet.getiMages ("text_age", 1); // g.drawImage (imgtextage [0], 70, 27, g.left | g.top);

g.drawimage (imgtextage [0], 55, 27, g.LEFT | G.TOP);

// Image [] imgtextexp = new image [1];

// imgtextexp = Horsemidlet.getiMages ("text_exp", 1);

// g.drawImage (ImgtexTexp [0], 70, 41, g.left | g.top);

g.drawImage (ImgtexTexp [0], 55, 41, g.left | g.top);

// image [] imgtextendur = new image [1];

// imgtextendur = Horsemidlet.getiMages ("text_endur", 1);

// g.drawImage (Imgtextendur [0], 70, 55, g.left | g.top);

g.drawImage (Imgtextendur [0], 55, 55, G.LEFT | G.TOP);

// image [] imgtexthealth = new image [1];

// ImgTextHealth = Horsemidlet.getimages ("text_health", 1);

// g.drawImage (ImgTextHealth [0], 70, 69, g.LEFT | G.TOP);

G.drawImage (ImgTextHealth [0], 55, 69, g.left | g.top);

/ * g.drawstring (java.lang.integer.tostring (myhorsracing.horses [lot_no

] .m_no), 140, 22, 1);

g.drawstring (java.lang.integer.tostring (myhorsracing.horses [lot_no].

m_horseage), 142, 34, 1);

g.drawstring (java.lang.integer.tostring (myhorsracing.horses [lot_no].

M_Horseex, 140, 50, 1);

g.drawstring (java.lang.integer.tostring (myhorsracing.horses [lot_no].

m_horseendur, 140, 64, 1);

g.drawstring (java.lang.integer.tostring (myhorsracing.horses [lot_no].

m_horsehealth, 140, 78, 1);

* /

g.drawstring (java.lang.integer.tostring (myhorsracing.horses [lot_no].

M_no), 112, 22, 1);

g.drawstring (java.lang.integer.tostring (myhorsracing.horses [lot_no].

m_horseage), 112, 34, 1);

g.drawstring (java.lang.integer.tostring (myhorsracing.horses [lot_no].

M_horseex), 110, 50, 1);

g.drawstring (java.lang.integer.tostring (myhorsracing.horses [lot_no].

M_horseendur, 110, 64, 1);

g.drawstring (java.lang.integer.tostring (myhorsracing.horses [lot_no].

M_HorseHealth, 110, 78, 1);

// Draw Lot Info Box

G.SetColor (255, 180, 0);

// g.FillRect (10, getcanvasheight () / 2 18, getcanvaswidth () / 2 20, 44);

G.fillRect (0, getcanvasheight () / 2 18, 87, 44);

G.SetColor (0,0,0);

// g.drawRect (10, getcanvasheight () / 2 18, getcanvaswidth () / 2 20, 44);

g.drawRect (0, getcanvasheight () / 2 18, 87, 44);

// image [] imgtexttotalmoney = new image [1];

// ImgTextTotalMoney = Horsemidlet.getiMages ("Text_TotalMoney", 1);

// g.drawImage (ImgTextTotalMoney [0], 17, 92, g.left | g.top);

G.drawImage (ImgTextTotalMoney [0], 2, 92, g.left | g.top);

G.SetColor (0,0,0);

// g.fillRect (70, 92, 40, 12);

G. FillRect (49, 92, 35, 12);

// g.drawline (10, 105, 10 getcanvaswidth () / 2 20, 105);

g.drawline (0, 105, 87, 105);

// Image [] imgtextlotnum = new image [1];

// ImgTextLotnum = Horsemidlet.getiMages ("Text_lotnum", 1);

// g.drawImage (ImgTextLotnum [0], 17, 106, g.left | g.top);

G.drawImage (ImgTextLotnum [0], 2, 106, g.left | g.top);

// g.fillRect (70, 106, 40, 12);

// g.drawline (10, 119, 10 getcanvaswidth () / 2 20, 119);

G. FillRect (49, 106, 35, 12);

g.drawline (0, 119, 87, 119);

// Image [] imgtextlotmoney = new image [1];

// ImgTextLotmoney = Horsemidlet.getiMages ("Text_lotmoney", 1);

// g.drawImage (ImgTextLotmoney [0], 17, 120, g.LEFT | G.TOP);

// g.fillRect (70, 120, 40, 12);

g.drawImage (ImgTextLotmoney [0], 2,120, g.left | g.top);

G. FillRect (49, 120, 35, 12);

// Draw Lot Info

G.SetColor (255, 255, 255);

// g.drawstring (java.lang.integer.tostring (Horsemidlet.mytotalmoney), 8

5, 103, 1);

g.drawstring (java.lang.integer.toString (Horsemidlet.mytotalmoney), 63,

103, 1);

IF (Lot_Select == 0)

{

G.SetColor (0,255,80);

}

Else

{

G.SetColor (255, 255, 255);

}

// g.drawstring (java.lang.integer.tostring (LOT_NO 1), 85,

// 117, 1);

g.drawstring (java.lang.integer.tostring (LOT_NO 1), 63, 117, 1); if (Lot_Select == 1)

{

G.SetColor (0,255,80);

}

Else

{

G.SetColor (255, 255, 255);

}

// g.drawstring (java.lang.integer.tostring (lot_money),

// 85, 131, 1);

g.drawstring (java.lang.integer.tostring (lot_money), 63, 131, 1);

// Image [] imgtextok = new image [1];

IF (Horsemidlet.subState == 2)

{

// imgtextok = HorsemIdlet.getiMages ("text_okon", 1);

G.drawImage (ImgTextok1 [0], 89, 93, G.LEFT | G.TOP);

}

Else

{

// imgtextok = Horsemidlet.getiMages ("text_okoff", 1);

G.drawImage (ImgTextok2 [0], 89, 93, G.LEFT | G.TOP);

}

// g.drawImage (ImgTextok [0], 128, 93, G.LEFT | G.TOP);

// g.drawImage (ImgTextok [0], 89, 93, G.LEFT | G.TOP);

// image [] imgtextreset = new image [1];

IF (horsemidlet.substate == 3)

{

// ImgTextReset = Horsemidlet.getiMages ("Text_Reseton", 1);

g.drawImage (ImgTextReset1 [0], 89, 108, G.L.LEFT | G.TOP);

}

Else

{

// imgtextReset = Horsemidlet.getiMages ("text_resetoff", 1);

g.drawImage (ImgTextReset2 [0], 89, 108, G.LEFT | G.TOP);

}

// g.drawImage (ImgTextReset [0], 128, 108, g.left | g.top);

// g.drawImage (ImgTextReset [0], 89, 108, g.left | g.top);

// image [] imgtextback = new image [1];

IF (Horsemidlet.subState == 4)

{

// imgtextback = Horsemidlet.getiMages ("Text_Backon", 1);

G.drawImage (imgtextback1 [0], 89, 123, g.left | g.top);

}

Else

{

// imgtextback = Horsemidlet.getiMages ("text_backoff", 1);

G.drawImage (ImgTextBack2 [0], 89, 123, G.L.L.L.TOP);

}

// g.drawImage (Imgtextback [0], 128, 123, g.left | g.top);

// g.drawImage (Imgtextback [0], 89, 123, g.left | g.top);

Break;

Case Horsemidlet.game_State_Racing:

DrawanImation (g);

G.SetColor (127, 0, 0);

// g.drawstring (long.tostring (runtime.getime (). TotalMemory ()), 10, 10, g.top | g.left;

// g.drawstring (long.tostring (runtime.getruntime (). FreeMemory ()), 10, 3

0, g.top | g.left;

Break;

Case Horsemidlet.game_State_Racingend:

DrawanImation (g);

Image [] imagwin = new image [1];

Imgwin = Horsemidlet.getimages ("WIN", 1);

// g.drawImage (imgwin [0], 40, 20, g.left | g.top);

g.drawImage (imgwin [0], 20, 20, g.left | g.top);

INT I, Gold, Goldi, Silver, Silveri, Goldbonus = 0, Silverbonus;

Gold = myhorseracing.xhorsepos [0];

GOLDI = 0;

For (i = 1; i <8; i )

{

IF (Gold

{Gold = myhorseracing.xhorsepos [i]; GOLDI = I;

}

Silveri = -1;

Silver = -1;

For (i = 0; i <7; i )

{

IF (Goldi == i) Continue;

IF (Silveri == - 1 || Silver

{Silver = myhorseracing.xhorsepos [I]; Silveri = i;}

}

// Draw Number

G.SetColor (200, 0, 0);

/ * g.drawchars (myhorseracing.horses [goldi] .m_horsename, 0, 3, 61, 61, 1);

g.drawstring (java.lang.integer.tostring (myhorsracing.horses [goldi] .m_

NO), 70, 64, 0);

g.drawchars (myhorsracing.horses [Silveri] .M_HORSENAME, 0, 3, 61, 113, 1);

g.drawstring (java.lang.integer.tostring (myhorsracing.horses [Silveri].

m_no), 70, 116, 0);

* /

g.drawchars (myhorsracing.horses [Goldi] .m_horsename, 0, 3, 41, 61, 1);

g.drawstring (java.lang.integer.tostring (myhorsracing.horses [Goldi] .m_no),

52, 75, 1);

g.drawchars (myhorsracing.horses [Silveri] .m_horsename, 0, 3, 41, 113, 1);

g.drawstring (java.lang.integer.tostring (myhorsracing.horses [Silveri] .m_no

), 52, 127, 1);

// Calculate the Bonus

IF (horsemidlet.myhorse.m_no <9)

{// bingo, youself got the gold / sale

IF (Horsemidlet.myhorse.m_no == Goldi)

Horsemidlet.myhorse.m_golds ;

Else

IF (Horsemidlet.myhorse.m_no == Silveri)

Horsemidlet.myhorse.m_silvers ;}

IF (Horsemidlet.Firstlot_no == Goldi) // First Lot Got Gold

{

IF (horsemidlet.myhorse.m_no == horsemidlet.firstlot_no)

Goldbonus = Horsemidlet.money_gold_mul_m * horsemidlet.fir

STLOT_MONEY;

Else

Goldbonus = Horsemidlet.money_gold_mul * horsemidlet.first

Lot_Money;

}

Else

IF (Horsemidlet.Secondlot_no == Goldi) // Second Lot Got Gold

{

IF (horsemidlet.myhorse.m_no == horsemidlet.secondlot_no)

Goldbonus = horsemidlet.money_gold_mul_m * horsemidlet.secondlot_m

ONEY;

Else

Goldbonus = Horsemidlet.money_gold_mul * horsemidlet.secondlot_mon

Ey;

}

Else goldbonus = 0;

IF (Horsemidlet.Firstlot_no == Silveri) // First Lot Got Gold

{

IF (horsemidlet.myhorse.m_no == horsemidlet.firstlot_no)

Silverbonus = Horsemidlet.money_silver_mul_m * Horsemidlet

.firstlot_money;

Else

Silverbonus = Horsemidlet.money_silver_mul * horsemidlet.f

Irstlot_money;

}

Else

IF (Horsemidlet.secondlot_no == Silveri) // Second Lot Got Gold

{

IF (horsemidlet.myhorse.m_no == horsemidlet.secondlot_no)

Silverbonus = Horsemidlet.money_silver_mul_m * Horsemidlet.secondl

OT_MONEY;

Else

Silverbonus = Horsemidlet.money_silver_mul * horsemidlet.secondlot

_money;

}

Else Silverbonus = 0;

// Draw the Bonus

// g.drawstring (java.lang.integer.toString (Goldbonus), 110, 75, 1);

// g.drawstring (java.lang.integer.toString (Silverbonus), 110, 127, 1);

g.drawstring (java.lang.integer.toToString (Goldbonus), 93, 75, 1);

g.drawstring (java.lang.integer.tostring (Silverbonus), 93, 127, 1);

IF (horsemidlet.myhorse.m_no <9)

{

Random Rand = new random ();

IF ((Rand.NextINT ()% 100)> Horsemidlet.match_wound_ratio)

{

Horsemidlet.myhorse.m_horsehealth- = rand.nextint ()% HORSEMIDLE

T.Wound_max;

}

}

Horsemidlet.mytotalmoney = Goldbonus Silverbonus;

STOP (); // stop the animation

Break;

/ *

Case Horsemidlet.game_State_Training:

G.SetColor (255, 180, 0);

G.FillRect (0, 0, getcanvaswidth (), getcanvasheight ());

g.drawImage (Horsemidlet.imgtraintop [0], 10, 10, g.left | g.top);

g.drawImage (Horsemidlet.imgtrainback [0], 10, 26, g.left | g.top);

g.drawImage (Horsemidlet.Imgtextshort [0], 10, 130, G.LEFT | G.TOP);

g.drawImage (Horsemidlet.Imgtextlong [0], 40, 130, G.LEFT | G.TOP);

g.drawImage (Horsemidlet.Imgtextrst [0], 70, 130, g.left | g.top);

g.drawImage (Horsemidlet.imgtextBackMenu_off [0], 100, 130, G.LEFT | G.TOP);

IF (Horsemidlet.subState == 0)

g.drawImage (Horsemidlet.Imgtextshort [1], 10, 130, G.L.LEFT | G.TOP);

Else if (Horsemidlet.subState == 1)

g.drawImage (Horsemidlet.Imgtextlong [1], 40, 130, G.LEFT | G.TOP);

Else if (Horsemidlet.subState == 2)

g.drawImage (Horsemidlet.Imgtextrst [1], 70, 130, G.LEFT | G.TOP);

Else if (Horsemidlet.subState == 3)

g.drawImage (Horsemidlet.imgtextBackMenu [0], 100, 130, G.LEFT | G.TOP);

Break;

Case Horsemidlet.game_State_Training_short:

G.SetColor (255, 180, 0);

G.FillRect (0, 0, getcanvaswidth (), getcanvasheight ());

g.drawImage (Horsemidlet.imgtraintop [0], 10, 10, g.left | g.top);

g.drawImage (Horsemidlet.imgtrainrunning [0], 10, 26, g.left | g.top)

;

ReadyTOSleep ;

IF (readytosleep == 1)

{

Repaint ();

}

Else IF (ReadyTOSleep == 2) {

Readytosleep = 0;

Try

{

Thread.sleep (3000);

Horsemidlet.gamestate = Horsemidlet.game_State_training;

Repaint ();

}

Catch (InterruptedException IE)

{

System.out.println (IE.toString ());

}

}

Break;

Case Horsemidlet.game_State_Training_long:

G.SetColor (255, 180, 0);

G.FillRect (0, 0, getcanvaswidth (), getcanvasheight ());

g.drawImage (Horsemidlet.imgtraintop [0], 10, 10, g.left | g.top);

g.drawImage (Horsemidlet.imgtrainrunning [0], 10, 26, g.left | g.

TOP);

ReadyTOSleep ;

IF (readytosleep == 1)

{

Repaint ();

}

Else IF (ReadyTOSleep == 2) {

Readytosleep = 0;

Try

{

Thread.sleep (3000);

Horsemidlet.gamestate = Horsemidlet.game_State_training;

Repaint ();

}

Catch (InterruptedException IE)

{

System.out.println (IE.toString ());

}

}

Break;

Case Horsemidlet.game_State_Training_Rest:

G.SetColor (255, 180, 0);

G.FillRect (0, 0, getcanvaswidth (), getcanvasheight ());

g.drawImage (Horsemidlet.imgtraintop [0], 10, 10, g.left | g.top);

g.drawImage (Horsemidlet.imgtrainRest [0], 10, 26, g.left | g.top);

ReadyTOSleep ;

IF (readytosleep == 1)

{

Repaint ();

}

Else IF (ReadyTOSleep == 2) {

Readytosleep = 0;

Try

{

Thread.sleep (3000);

Horsemidlet.gamestate = Horsemidlet.game_State_training;

Repaint ();

}

Catch (InterruptedException IE)

{

System.out.println (IE.toString ());

}

}

Break;

* /

}

}

Private Void DrawaniMation (Graphics GR)

{

Graphics g = gr;

IF (this.isdoublebuffered ())

{

g = graphics;

}

Try

{

Myhorseracing.setframe ();

Myhorsraçong.draw (g);

Gr.drawImage (buffer, 0,0, g.top | g.left);

}

Catch (Exception E)

{

System.out.println ("DrawaniMation Error:" E.TOSTRING ());

}

}

Public void CommandAction (Command C, Displayable D)

{

// if any exit key is presssed kil

IF (c == exit)

{

MIDlet.exitmidlet ();

}

// Else if (c == memory)

Else IF (c == newgame)

{

// midlet.StartApp ();

Horsemidlet.gamestate = horsemidlet.game_state_start;

Horsemidlet.substate = 0;

Horsemidlet.difficulty = 10;

// horsemidlet.gamestate = 0;

Horsemidlet.substate = 0;

Horsemidlet.mytotalmoney = 1000;

Horsemidlet.firstlot_no = 0;

Horsemidlet.firstlot_money = 50;

Horsemidlet.secondlot_no = 1;

HorsemIdlet.secondlot_money = 50;

// horsemidlet.myhorse = new Horsex (30, 40, 50, 9);

Myhorseracing.init ();

/ * imgmenu = new image [1];

IMGDOT = New Image [1];

Imgmenu = Horsemidlet.getiMages ("Menu", 1);

System.out.println ("Free Memory: Menu" Runtime.Getruntime (). FreeMemory ()

);

IMGDOT = Horsemidlet.getimages ("BLUEDOT", 1);

System.out.println ("Free Memory: BlueDot" Runtime.Getruntime (). Freememor

Y ()); * /

STOP ();

// SumTemp = 1;

Repaint ();

// c = NULL;

}

}

Protected Void Keypressed (int keycode)

{

// can't Continue Playing Until The Player Restarts

INT GameAction = getGameAction (keycode);

Switch (GameAction)

{

Case Fire:

IF (Horsemidlet.gamestate == Horsemidlet.game_State_Start)

{

IF (Horsemidlet.subState == 0)

{

Horsemidlet.gamestate = Horsemidlet.game_State_lot;

Horsemidlet.mytotalmoney- = Horsemidlet.firstlot_money;

}

Else if (Horsemidlet.subState == 1) // Introduce

{

Horsemidlet.gamestate = Horsemidlet.game_State_Intro;

INTRO_POS = 0;

Horsemidlet.substate = 0;

}

Else if (Horsemidlet.subState == 2) // exit

MIDlet.exitmidlet ();

}

Else if (Horsemidlet.gamestate == Horsemidlet.game_State_Intro)

{

Horsemidlet.gamestate = horsemidlet.game_state_start;

Horsemidlet.substate = 0;

}

Else if (Horsemidlet.gamestate == Horsemidlet.game_State_Racingend)

{

Myhorseracing.init ();

Horsemidlet.gamestate = Horsemidlet.game_State_lot;

Horsemidlet.mytotalmoney- = Horsemidlet.firstlot_money;

Horsemidlet.substate = 0;

}

Else if (Horsemidlet.gamestate == Horsemidlet.game_State_lot) {

IF (Horsemidlet.subState == 2)

{

Horsemidlet.gamestate = Horsemidlet.game_State_Racing;

Horsemidlet.horsruningspeed = Horsemidlet.max_speed;

Horsemidlet.screenscroll = 0;

Horsemidlet.trainingTime = 0;

Horsemidlet.beginwait = 0;

Horsemidlet.showbeginbar = 1; // show it

Horsemidlet.racingend = -1; // Just Begin

START (); // start a animation thread;

}

IF (Horsemidlet.Substate <2)

Horsemidlet.substate ;

IF (horsemidlet.substate == 1)

{

Horsemidlet.secondlot_money = horsemidlet.bit_lot_money;

Horsemidlet.mytotalmoney- = horsemidlet.secondlot_money;

Horsemidlet.secondlot_no = horsemidlet.firstlot_no 1;

IF (Horsemidlet.secondlot_no> 7)

HorsemIdlet.secondlot_no = 0;

}

IF (horsemidlet.substate == 3) // reset

{

Horsemidlet.mytotalMoney = Horsemidlet.mytotalMoney

Horsemidlet.firstlot_money

HorsemIdlet.secondlot_money-

Horsemidlet.bit_lot_money;

Horsemidlet.firstlot_money = horsemidlet.bit_lot_money;

Horsemidlet.firstlot_no = 0;

Horsemidlet.substate = 0;

}

IF (horsemidlet.substate == 4) // back

{

Horsemidlet.mytotalMoney = Horsemidlet.mytotalMoney

Horsemidlet.firstlot_money

Horsemidlet.secondlot_money;

Horsemidlet.firstlot_money = horsemidlet.bit_lot_money;

Horsemidlet.firstlot_no = 0;

Horsemidlet.gamestate = horsemidlet.game_state_start;

Horsemidlet.substate = 0;

}

}

Else if (Horsemidlet.gamestate == Horsemidlet.game_State_training)

{

IF (Horsemidlet.subState == 0)

Horsemidlet.gamestate = Horsemidlet.game_State_Training_Short;

Else if (Horsemidlet.subState == 1)

Horsemidlet.gamestate = Horsemidlet.game_State_Training_long; else if (Horsemidlet.substate == 2)

Horsemidlet.gamestate = Horsemidlet.game_State_Training_Rest;

Else

{

Horsemidlet.gamestate = horsemidlet.game_state_start;

Horsemidlet.substate = 0;

}

}

SumTemp = 0;

Break;

Case Right:

IF (Horsemidlet.gamestate == Horsemidlet.game_State_lot)

{

IF (horsemidlet.substate == 0) {// the first lot

IF (Lot_Select == 0) {

Horsemidlet.firstlot_no ;

IF (Horsemidlet.firstlot_no> 7)

Horsemidlet.firstlot_no = 0;

}

Else {

IF (Horsemidlet.mytotalMoney> = Horsemidlet.bit_lot_money) {

Horsemidlet.firstlot_money = HorsemIdlet.bit_lot_money;

Horsemidlet.mytotalmoney - = HORSEMIDLET.BIT_LOT_MONEY;

}

}

}

IF (Horsemidlet.subState == 1) {// The second lot

IF (Lot_Select == 0) {

HorsemIdlet.secondlot_no ;

IF (horsemidlet.secondlot_no == horsemidlet.firstlot_no)

HorsemIdlet.secondlot_no ;

IF (Horsemidlet.secondlot_no> 7) {

HorsemIdlet.secondlot_no = 0;

IF (horsemidlet.secondlot_no == horsemidlet.firstlot_no)

HorsemIdlet.secondlot_no ;

}

}

Else {

IF (Horsemidlet.mytotalMoney> = Horsemidlet.bit_lot_money) {

Horsemidlet.secondlot_money = HorsemIdlet.bit_lot_money;

Horsemidlet.mytotalmoney - = HORSEMIDLET.BIT_LOT_MONEY;

}

}

}

}

Else if (Horsemidlet.gamestate == Horsemidlet.game_State_training)

{

Horsemidlet.subState = (Horsemidlet.substate 1)% 4;

}

Break;

Case Down:

IF (Horsemidlet.gamestate == Horsemidlet.game_State_Start)

{

Horsemidlet.substate ;

IF (Horsemidlet.subState> = 3)

Horsemidlet.substate = 0;

// repaint ();

Else if (Horsemidlet.gamestate == Horsemidlet.game_State_lot)

{

IF (Horsemidlet.subState> = 2)

{

Horsemidlet.substate ;

IF (Horsemidlet.Substate> 4)

Horsemidlet.substate = 2;

}

Else

{

IF (Lot_Select == 0)

Lot_select = 1;

Else

Lot_select = 0;

}

}

Break;

Case LEFT:

IF (Horsemidlet.gamestate == Horsemidlet.game_State_lot)

{

IF (horsemidlet.substate == 0) {// the first lot

IF (Lot_Select == 0) {

Horsemidlet.firstlot_no ---;

IF (Horsemidlet.firstlot_no <0)

Horsemidlet.firstlot_no = 7;

}

Else {

IF (Horsemidlet.Firstlot_money> Horsemidlet.bit_lot_money) {

Horsemidlet.firstlot_money - = HORSEMIDLET.BIT_LOT_MONEY;

Horsemidlet.mytotalmoney = Horsemidlet.bit_lot_money;

}

}

}

IF (Horsemidlet.subState == 1) {// The second lot

IF (Lot_Select == 0) {

Horsemidlet.secondlot_no ---;

IF (horsemidlet.secondlot_no == horsemidlet.firstlot_no)

Horsemidlet.secondlot_no ---;

IF (horsemidlet.secondlot_no <0) {

Horsemidlet.secondlot_no = 7;

IF (horsemidlet.secondlot_no == horsemidlet.firstlot_no)

Horsemidlet.secondlot_no ---;

}

}

Else {

IF (Horsemidlet.secondlot_money> Horsemidlet.bit_lot_money)

{

Horsemidlet.secondlot_money - = HORSEMIDLET.BIT_LOT_MONEY;

Horsemidlet.mytotalmoney = Horsemidlet.bit_lot_money;

}

}

}

}

Else if (Horsemidlet.gamestate == Horsemidlet.game_State_training)

{

Horsemidlet.subState = (Horsemidlet.substate 3)% 4;

}

Break;

Case Up:

IF (Horsemidlet.gamestate == Horsemidlet.game_State_Start)

{

Horsemidlet.substate--

IF (horsemidlet.substate <0)

Horsemidlet.substate = 2;

}

Else if (Horsemidlet.gamestate == Horsemidlet.game_State_lot) {

IF (Horsemidlet.subState> = 2)

{

Horsemidlet.substate--

IF (Horsemidlet.Substate <2)

Horsemidlet.subState = 4;

}

Else

{

IF (Lot_Select == 0)

Lot_select = 1;

Else

Lot_select = 0;

}

}

Repaint ();

Break;

DEFAULT:

Break;

}

Repaint ();

}

}

Package horseclub;

Import javax.microedition.lcdui. *;

Public class raceground {

Private static int imagewidth, imageheight;

Private static int Tilewidth, TileHeight;

Private static int imageskywidth, imageskyHeight;

Private static int TileskyWidth, TileskyHeight;

Private static int CANVASWIDTH, CanvasHeight;

PRIVATE [] ]MAGES;

Private final string background_name = "raceground";

PRIVATE FINAL INT Background_frames = 1;

PRIVATE FINAL STRING SKY_NAME = "Racessky";

PRIVATE FINAL INT SKY_FRAMES = 1;

Private image [] ivtile = new image [background_frames];

Private image [] ivskytile = new image [sky_frames];

Private static image imgbackground;

Private static image ivsky;

Private static int xbackground, ybackground, xsky;

INT YSTART = 30;

INT YskyStart = 0;

Public ruceground ()

{

// load the images from the .jar

Imgtile = GetImages (Background_name, Background_frames);

Imgskytile = GetImages (sky_name, sky_frames);

// set the canvas measurements to local class variabletes.

Canvaswidth = (Horsecanvas.Getcanvaswidth ());

Canvasheight = (Horsecanvas.Getcanvasheight ());

// Prepare the Background Paras

// All Character Frame Images Are Assumed

// to be the same height and width

TileWidth = imgtile [0] .Getwidth ();

TileHeight = imgtile [0] .getheight ();

// set the background image model dimensions

ImageWidth = (CANVASWIDTH / TILEWIDTH) * TILEWIDTH) (TileWidth * 2); ImageHeight = TileHeight; // (canvaswidth / tileHeight) * TileHeight) TileHeight;

// prepare the sky Paras

TileskyWidth = IMGSKYTILE [0] .Getwidth ();

TileskyHeight = IMGSKYTILE [0] .getHeight ();

// set the background image model dimensions

Imageskywidth = (canvaswidth / tileskywidth * tileskywidth) (tileskywidth * 2);

Imageskyheight = tileskyheight;

INIT ();

}

Public void init ()

{

XBackground = 0;

Ybackground = -tileHeight;

XSky = 0;

YSKYSTART = 0;

CREATEIMAGE ();

CreateskyImage ();

Setimage ();

}

Public Image getImage () {return ImgBackground;}

Public image getskyimage () {return ivsky;}

Public Void Draw (Graphics G)

{

G.drawImage (GetImage (), XBackground, Ystart, G.Left | G.TOP);

G.DrawImage (getskyimage (), xsky, yskystart, g.left | g.top;

}

Public void setPosition (int Offset)

{

//move the background to provide animation of moving landscape.

Boolean reset = false;

// if the image exceedes the x-axis the reset IT

// and set the starting point for the next row in the image arch

// set the redraw flag for redrawing the Image

XBACKGROUND = XBACKGROUND-OFFSET;

IF (xbackground <= - tilewidth)

{

XBackground = 0;

RESET = True;

}

XSky = xsky-1;

IF (xsky <= - tileskywidth)

{

XSky = 0;

RESET = True;

}

// if the images exceededs the y-axis thrset IT

// and set the stating point for the next column in the image array

// set the redraw flag for redrawing the Image

// if ( YbackGround == 0)

// {

// ybackground = -tileHeight;

// IF (- XStart <0)

// {

// xstart = 9;

//}

// reset = true;

//}

// redraw the background image iF reset = TRUE

IF (reset)

{

// setimage ();

}

}

Private static void createImage () {

// Allocate Memory To Store The OnScreen Background Image.

// Assuming All Tiles Are The Same Size, Make The Buffer

// The Screen Size Plus One Row and Column.

ImgBackground = Image.createImage (imagewidth, imageheight);

}

Private static void createsskyimage ()

{

// Allocate Memory To Store The OnScreen Background Image.

// Assuming All Tiles Are The Same Size, Make The Buffer

// The Screen Size Plus One Row and Column.

IMGSKY = Image.createImage (imageskywidth (imageskyHeight);

}

Public void setImage ()

{

Graphics g = imgbackground.getgraphics ();

Graphics gsky = IMGSKY.GETGRAPHICs ();

INT currentwidth = 0;

INT Currentheight = (ImageHeight-TileHeight);

// Draw the tiles forin the bounds of the allocated image buffer

// Draw from the starting from the current position within the image array - THE ARRAY

.

While (currentheight> = 0)

{

While (CurrentWidth

{

g.drawImage (Imgtile [0], CurrentWidth, CurrentHeight, G.L.LEFT | G.TOP);

CurrentWidth = TileWidth;

}

CurrentWidth = 0;

Currentheight- = TileHeight;

}

// Title The Sky

CurrentWidth = 0;

Currentheight = (imageskyHeight-tileskyheight);

While (currentheight> = 0)

{

While (CurrentWidth

{

Gsky.drawImage (Imgskytile [0], CurrentWidth, CurrentHeight, g.left | g.top;

CurrentWidth = TileskyWidth;

}

CurrentWidth = 0;

Currentheight- = tileskyheight;

}

}

Private image [] getImages (string IMGNAME, INT FRAMES)

{

Return Horsemidlet.getiMages (IMGNAME, FRAMES);

}

}

转载请注明原文地址:https://www.9cbs.com/read-57737.html

New Post(0)