PDA

View Full Version : Mobile Puzzle Game



EugenioEnko
28-01-2006, 01:35 PM
This is my first MIDLet game.
It's just a simple puzzle game.
mobilepuzzlegame.rar - 0.00MB (http://www.zshare.net/download/mobilepuzzlegame-rar.html)

http://img83.imageshack.us/img83/508/pic6sg.jpg (http://imageshack.us)


program EnkoFirstGame;

const
NUM = 16; //la mA¬°xima cantidad de numeros
ADD = 13; //desplazamiento para la salida de los numeros

var
board: array[1..4, 1..4] of integer; //nuestro tabla
x,y: integer; //variables que guardan la posicion del espacio vacio
key: integer; //la tecla presionada
gameOver: boolean; //indicarA-a si el juego sigue


//llena la tabla con numeros ordenados del 1 al 16
//algo asA- (el 16 es el espacio vacio):
{ 1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
}
procedure setBoard;
var
i,j,k: integer;
begin
k:=1;
for j:=1 to 4 do
for i:=1 to 4 do
begin
board[i,j] := k;
k := k+1;
end;
end;

//intercambia los numeros de las tablas segun sus indices
procedure swap(a,b,c,d: integer);
var
k: integer;
begin
k := board[a,b];
board[a,b] := board[c,d];
board[c,d] := k;
end;

//asigna la posicion del espacio vacio
procedure setPos(a,b:integer);
begin
x:=a;
y:=b;
end;

//imprime en la pantalla los numeros menos el 16
procedure printBoard;
var
s: string;
i,j: integer;
begin
//ponemos negro como color activo
setColor(0,0,0);
//lenamos la pantalla con el color activo
//GetWidth y GetHeight son funciones predeterminadas
fillRect(0,0, GetWidth, GetHeight); //devuelven el Ancho y Alto maximo
//elegimos el color blanco
setColor(255,255,255);
for j:=1 to 4 do
for i:=1 to 4 do
begin
//como solo se puede imprimir cadenas, transormamos los numeros en cadenas
s:= IntegerToString(board[i,j]);
// si el nuemro no es 16, se imprime segun la posicion en la tabla
if s<>'16' then drawText(s, ADD+i*18, j*18);
end;
//indispensable, actualiza la pantalla del mobile.
repaint;
end;

procedure Presentation;
var
key: integer;
begin
setColor(0,0,0);
fillRect(0,0, GetWidth, GetHeight);
setColor(255,0,0);
drawText('Enkos Puzzle', 20,20);
drawText('Loading', 20,40);
repaint;
delay(2000);
end;

procedure Ending;
var
key: integer;
begin
setColor(0,0,0);
fillRect(0,0, GetWidth, GetHeight);
setColor(255,0,0);
drawText('Enkos Puzzle', 20,20);
drawText('Good Buy',20,40);
repaint;
delay(2000);
end;


//buscamos en la tabla la posicion del espacio vacio
//la verdad, es que hay formas de evitar hacer esto
//pero como que tenia un BUG y tuve que hacerlo
procedure getPos;
var
i,j: integer;
begin
for i:=1 to 4 do
for j:=1 to 4 do
begin
if board[i,j] = 16 then
begin
x := i;
y :=j;
end;
end;
end;

//incercambia las posiciones de los numeros
//para que despues el jugador los tenga que ordenar
procedure randomBoard;
var
i,j,i1,j1,k: integer;
begin
randomize;
for i:=1 to 4 do
for j:=1 to 4 do
begin
i1:= random(4)+1;
j1:= random(4)+1;
swap(i,j,i1,j1);
end;
getPos; //obtenemos la posicion del espacio vacio
printBoard;//imprimimos la tabla
end;

//procedimiento que realiza el desplazamiento del espacio vacio
//b nos indica la direccion, 1: Arriba, 2:Deracha, 3:Abajo, 4:Izquierda
//segun el caso, no podemos desplazar el espacio vacio afuera del tablero, por eso
//esta la condicion adicional si es mayor o menor a 4 o a 1.
procedure moveBoard(b:integer);
begin
if (b=1) and (y<4)then swap(x,y,x,y+1)
else if (b=2) and (x>1) then swap(x,y,x-1,y)
else if (b=3) and (y>1) then swap(x,y,x,y-1)
else if (b=4) and (x<4) then swap(x,y,x+1,y);
delay(200); //retrazamos la jugada siguiente, porque sino, se mueven muy rapido
getPos;
printBoard;
end;

// el programa en si
begin
Presentation; //mostramos la presentacion
setBoard; //iniciamos el tablero
randomBoard; //lo mezclamos
repeat //el ciclo del juego
key := getKeyPressed; // obtenemos la pulsacion
if (key = KE_KEY2) or (KeyToAction(key) = GA_UP) then moveBoard(1);
if (key = KE_KEY6) or (KeyToAction(key) = GA_RIGHT) then moveBoard(2);
if (key = KE_KEY8) or (KeyToAction(key) = GA_DOWN) then moveBoard(3);
if (key = KE_KEY4) or (KeyToAction(key) = GA_LEFT) then moveBoard(4);
until (key = KE_KEY0) ; //se juega hasta quese presiona 0
Ending; //la pantalla de despedida
end.

EugenioEnko
28-01-2006, 05:02 PM
New Graphix :wink:
http://img217.imageshack.us/img217/4750/img6ai.th.jpg (http://img217.imageshack.us/my.php?image=img6ai.jpg)

Download JAr here:
enkogame.rar - 0.05MB (http://www.zshare.net/download/enkogame-rar.html)

cairnswm
28-01-2006, 06:30 PM
Send me your JAR and I'll load it to my web site for people to access.

William (AT) Cairnsgames dot co dot za

EugenioEnko
28-01-2006, 09:03 PM
Send me your JAR and I'll load it to my web site for people to access.

William (AT) Cairnsgames dot co dot za
Thanks a lot, how can I send it?

PD: you can download it from ZShare, I had linked it alredy.

savage
28-01-2006, 10:08 PM
Nice colours!

EugenioEnko
28-01-2006, 11:01 PM
Nice colours!

I tried to found images in google, then selected 5 of them and put them in 96x96 resolution for the game. Finally select de best for this resolution. But >I think it was more easy with numbers, but who cares, it can be anything...

cairnswm
29-01-2006, 06:20 AM
I tried to download it and just got file not found errors - thats why I suggested emailing it to me.

I will be building a mobile section to my web site soon. If anyone else wants games up there let me know - Email to me along with a little image of the game and some background - like a description, your name/alias etc - and I'll load them.

This will be just for mobile games - and file sizes less than 65K each.

EugenioEnko
29-01-2006, 01:07 PM
Excelent. I will try to add some sound to the game and then, when your Mobile section will be working, I will send it.

Lazo
29-01-2006, 09:30 PM
Ok my first game on MidletPascal............... is almost complete, I uploaded but I make some changes on it so give me time ok :wink:




Ok here`s my Midlet Game................well is not a game realy is....??? just judge by your self.
Thanks :wink:

Download jad>>> http://www.zshare.net/download/ball-jad-e6v.html

Download jar>>>http://www.zshare.net/download/ball-jar-nk0.html

http://img235.imageshack.us/img235/7309/ball2yf.th.png