de.farafin.snEADy.world
Class C_Arena

java.lang.Object
  extended by de.farafin.snEADy.world.C_Arena
All Implemented Interfaces:
I_Constants, I_PlayFieldConstants

public final class C_Arena
extends java.lang.Object
implements I_Constants, I_PlayFieldConstants

Version:
$Revision: 1.30 $
Author:
roland TODO what does that class do?

Field Summary
protected  int[] freeFieldsVec
          Field freeFieldsVec (for the Goodies)
protected  int freeFieldsVecLen
          length of the Field freeFieldsVec
private  java.util.Vector gameObjects
          Field gameObjects
private  int height
          height of the playfield
private  int maxPlayer
          the number of maximum player this level was designt for
private  java.lang.String name
          name of the arena
private  char[][] playField
          the playfield of the game
private  java.util.Random rnd
          a random number
private  int width
          width of the playfield
 
Fields inherited from interface de.farafin.snEADy.communication.I_Constants
analyse_ms, auto_grow_delay, auto_slowdown_delay, autogamespeed, closemonitor, damage_length_grow, damage_points_radius, DEBUG, delplayer, easy_points, ejectreplay, emergencyPause, exit_time, FACE_EAST, FACE_NORTH, FACE_SOUTH, FACE_WEST, game_end, goody_length_occ, goody_length_value, goody_points_occ, goody_points_value, goody_shorter_occ, goody_shorter_value, goody_slowdown_occ, goody_speed_occ, IN_ACTION, IN_ERROR_EXC, IN_ERROR_INIT, IN_ERROR_SPACE, IN_ERROR_TIME, IN_EXIT, IN_HEAVEN, init_length, init_move_delay, kill, kill_point_goodies, kill_points_radius, loaddummy, loadhuman, loadlevel, loadplayer, loadscript, logging, max_goody_occ_delay, MAX_HUMAN_PLAYERS, max_mem_check_delay, max_move_delay, max_player_mem, MAX_PLAYERS, max_thinking_ms, memkill, min_cycle_ms, min_move_delay, MOVE_EAST, MOVE_NORTH, MOVE_SOUTH, MOVE_WEST, openmonitor, overalldelay, pause, player_controlling, print_calc_ms, print_parameter, print_player_mem, print_playfield, quit, record, recordname, replay, replay_reverse, replay_stepwidth, replay_stepwise, run, set, show_subcycles, start, stop, suddend_time, survival_points, timekill, tolerance_ms, TURN_LEFT, TURN_NONE, TURN_RIGHT
 
Fields inherited from interface de.farafin.snEADy.communication.I_PlayFieldConstants
EXIT, FIELD_B, FIELD_C, FIELD_D, FIELD_E, FIELD_F, FIELD_G, FIELD_H, FIELD_I, FIELD_J, FIELD_K, FIELD_L, FIELD_M, FIELD_N, FIELD_O, FIELD_P, FIELD_Q, FIELD_R, FIELD_S, FIELD_T, FIELD_U, FIELD_V, FIELD_W, FIELD_X, FIELD_Y, FIELD_Z, FREE, GOODY_f, GOODY_g, GOODY_h, GOODY_i, GOODY_j, GOODY_k, GOODY_l, GOODY_LAST, GOODY_m, GOODY_n, GOODY_o, GOODY_p, GOODY_q, GOODY_r, GOODY_s, GOODY_START, GOODY_t, GOODY_u, GOODY_v, GOODY_w, GOODY_x, GOODY_y, GOODY_z, LENGTH, PLAYER_0, PLAYER_1, PLAYER_2, PLAYER_3, PLAYER_4, PLAYER_5, PLAYER_6, PLAYER_7, PLAYER_8, PLAYER_9, POINTS, SHORT, SLOW, SPEED, WALL
 
Constructor Summary
protected C_Arena(D_GameInfo gameInfo, GameParameter parameter)
          constructor
protected C_Arena(java.lang.String name, char[][] playField, int maxPlayer)
          constructor
 
Method Summary
private  int fx(int j, int k)
          generates the funktion:
k: (j)
1: (-1, 0, 1, 0)
2: (-2, -1, 0, 1, 2, 1, 0, -1)
3: (-3, -2, -1, 0, 1, 2, 3, 2, 1, 0, -1, -2)
...
private  int fy(int i, int k)
          generates the funktion:
k: (i)
1: (0, 1, 0, -1)
2: (0, 1, 2, 1, 0, -1, -2, -1)
3: (0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1)
...
protected  D_Level generateLevel()
           
protected  char getCharOf(D_Vec2D vec)
          returns the character of the specified coordinates
protected  char getCharOf(int y, int x)
          returns the character of the specified coordinates
protected  C_GameObject getGameObject(int number)
           
protected  C_GameObject getGOofPos(D_Vec2D vec)
          if at position of vec is placed a C_GameObject, it returns the Object.
protected  C_GameObject getGOofPos(int y, int x)
          if at position y,x is placed a C_GameObject, it returns the Object.
protected  int getHeight()
           
protected  char[] getLineCopy(int l)
           
protected  int getMaxPlayer()
           
protected  java.lang.String getName()
           
protected  int getNumberOfObjects()
           
protected  char[][] getPlayFieldCopy()
           
protected  char[] getRowCopy(int r)
          height
protected  D_Vec2D[] getSourounding(D_Vec2D vec, int maxDist)
          returns all surrounding fields of vec in an array that is ordered that way:
___C___
__N4D__
_MB05E_
LA3#16F
_K927G_
__J8H__
___I___

the vectors in that positions are absolute positions in the arena.
protected  int getWidth()
           
protected  boolean isFieldOfArena(D_Vec2D vec)
          tests if the coordinates are element of the playField
protected  boolean isFieldOfArena(int y, int x)
          tests if the coordinates are element of the playField
protected  boolean isFree(char c)
           
protected  boolean isFree(D_Vec2D vec)
           
protected  boolean isFree(int y, int x)
           
protected  boolean isGoody(char c)
           
protected  boolean isGoody(D_Vec2D vec)
           
protected  boolean isGoody(int y, int x)
           
protected  boolean isSnake(char c)
           
protected  boolean isSnake(D_Vec2D vec)
           
protected  boolean isSnake(int y, int x)
           
protected  boolean isSpecialField(char c)
           
protected  boolean isSpecialField(D_Vec2D vec)
           
protected  boolean isSpecialField(int y, int x)
           
protected  boolean isWall(char c)
           
protected  boolean isWall(D_Vec2D vec)
           
protected  boolean isWall(int y, int x)
           
protected  void objectAdd(C_GameObject gameObj)
           
protected  boolean objectDel(C_GameObject gameObj)
           
protected  C_GameObject objectDel(int index)
           
protected  void objectUpdate(C_GameObject gameObj)
          update the status of the given gameObject. if the game Object likes to run, use this method to tell him to
protected  D_Vec2D randFreeField()
           
protected  boolean setCharOnPosition(D_Vec2D vec, char c)
          sets at the coordiantes of vec the character c
protected  boolean setCharOnPosition(int y, int x, char c)
          sets at the coordiantes y and x the character c
protected  boolean setFree(D_Vec2D vec)
          sets at the coordiantes of vec a free field
protected  boolean setFree(int y, int x)
          sets at the coordiantes y and x a free field
protected  boolean setPlayField(char[][] field)
           
 java.lang.String toString()
           
protected  int updateFreeFieldVec(boolean ignoreGoodies)
          returns the number of free fields in the playfield while storing its positions in a array
protected  boolean updateLevel(D_Level level)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

private final java.lang.String name
name of the arena


height

private final int height
height of the playfield


width

private final int width
width of the playfield


playField

private final char[][] playField
the playfield of the game


maxPlayer

private final int maxPlayer
the number of maximum player this level was designt for


gameObjects

private final java.util.Vector gameObjects
Field gameObjects


freeFieldsVec

protected final int[] freeFieldsVec
Field freeFieldsVec (for the Goodies)


freeFieldsVecLen

protected int freeFieldsVecLen
length of the Field freeFieldsVec


rnd

private final java.util.Random rnd
a random number

Constructor Detail

C_Arena

protected C_Arena(java.lang.String name,
                  char[][] playField,
                  int maxPlayer)
constructor

Parameters:
name -
playField - uses array-data to compute height and width
maxPlayer - max player of this arena

C_Arena

protected C_Arena(D_GameInfo gameInfo,
                  GameParameter parameter)
constructor

Parameters:
gameInfo - creates a C_Arena out of D_GameInfo.
parameter - the game parameter set
Method Detail

getGOofPos

protected C_GameObject getGOofPos(int y,
                                  int x)
if at position y,x is placed a C_GameObject, it returns the Object. O(Obj_count)

Parameters:
y - y - coordinate
x - x - coordinate
Returns:
the Oby on y, x, if there is no Obj, then return is null

getGOofPos

protected C_GameObject getGOofPos(D_Vec2D vec)
if at position of vec is placed a C_GameObject, it returns the Object. O(Obj_count*sizeOfObject)

Parameters:
vec - the vector of the fied that should be controlled
Returns:
the Obj on vec, if there is no Obj, then return is null

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

setPlayField

protected boolean setPlayField(char[][] field)
Parameters:
field - The playField to set.
Returns:
true if set was successful.. false if the size doesnt fit.

setCharOnPosition

protected boolean setCharOnPosition(int y,
                                    int x,
                                    char c)
sets at the coordiantes y and x the character c

Parameters:
y - line
x - row
c - character to set
Returns:
true if coordinate exists, false otherwise

setCharOnPosition

protected boolean setCharOnPosition(D_Vec2D vec,
                                    char c)
sets at the coordiantes of vec the character c

Parameters:
vec - coordinate
c - character to set
Returns:
true if coordinate exists, false otherwise
See Also:
setCharOnPosition(int, int, char)

setFree

protected boolean setFree(int y,
                          int x)
sets at the coordiantes y and x a free field

Parameters:
y - line
x - row
Returns:
true if coordinate exists, false otherwise
See Also:
setCharOnPosition(int, int, char)

setFree

protected boolean setFree(D_Vec2D vec)
sets at the coordiantes of vec a free field

Parameters:
vec - coordinate
Returns:
true if coordinate exists, false otherwise
See Also:
setCharOnPosition(int, int, char)

objectAdd

protected void objectAdd(C_GameObject gameObj)
Parameters:
gameObj -

objectDel

protected boolean objectDel(C_GameObject gameObj)
Parameters:
gameObj - the object that should be removed from the list
Returns:
if remove was sucessfull (if not, the reference was still out of the list)

objectDel

protected C_GameObject objectDel(int index)
Parameters:
index - the index of the GameObject that should be rmoved
Returns:
the removed GameObject

objectUpdate

protected void objectUpdate(C_GameObject gameObj)
update the status of the given gameObject. if the game Object likes to run, use this method to tell him to

Parameters:
gameObj - the object that should be updated
See Also:
C_GameObject

getGameObject

protected C_GameObject getGameObject(int number)
Parameters:
number - specifies the C_GameObject
Returns:
the specified GameObject
See Also:
C_GameObject

getNumberOfObjects

protected int getNumberOfObjects()
Returns:
number of stored GameObjects
See Also:
C_GameObject

isFieldOfArena

protected boolean isFieldOfArena(int y,
                                 int x)
tests if the coordinates are element of the playField

Parameters:
y - line
x - row
Returns:
true if the coordiantes are in height - and width - renge

isFieldOfArena

protected boolean isFieldOfArena(D_Vec2D vec)
tests if the coordinates are element of the playField

Parameters:
vec - coordinate as 2D-vector
Returns:
true if the coordiantes are in height - and width - renge

getPlayFieldCopy

protected char[][] getPlayFieldCopy()
Returns:
returns a copy of the playField.

getCharOf

protected char getCharOf(int y,
                         int x)
returns the character of the specified coordinates

Parameters:
y - line number
x - row number
Returns:
the charactor of the specified field and '?' if the field does not exist

getCharOf

protected char getCharOf(D_Vec2D vec)
returns the character of the specified coordinates

Parameters:
vec - the vector of the field that should returned
Returns:
the charactor of the specified field

getLineCopy

protected char[] getLineCopy(int l)
Parameters:
l - lineNumber
Returns:
the line, null if line doesnt exist

getRowCopy

protected char[] getRowCopy(int r)
height

Parameters:
r - rowNumber
Returns:
the row, null if row doesnt exist

getHeight

protected int getHeight()
Returns:
Returns the height.

getMaxPlayer

protected int getMaxPlayer()
Returns:
Returns the maxPlayer.

getName

protected java.lang.String getName()
Returns:
Returns the name.

getWidth

protected int getWidth()
Returns:
Returns the width.

isFree

protected boolean isFree(char c)
Parameters:
c - char to test
Returns:
true if the char is free
See Also:
I_PlayFieldConstants

isWall

protected boolean isWall(char c)
Parameters:
c - char to test
Returns:
true if the char is a Wall
See Also:
I_PlayFieldConstants

isSnake

protected boolean isSnake(char c)
Parameters:
c - char to test
Returns:
true if the char is a Snake
See Also:
I_PlayFieldConstants

isGoody

protected boolean isGoody(char c)
Parameters:
c - char to test
Returns:
true if the char is a Goody
See Also:
I_PlayFieldConstants

isSpecialField

protected boolean isSpecialField(char c)
Parameters:
c - char to test
Returns:
true if the char is a Special Field
See Also:
I_PlayFieldConstants

isFree

protected boolean isFree(int y,
                         int x)
Parameters:
y - line
x - row
Returns:
true if there is a WALL at the coordinates
See Also:
I_PlayFieldConstants

isWall

protected boolean isWall(int y,
                         int x)
Parameters:
y - line
x - row
Returns:
true if there is a WALL at the coordinates
See Also:
I_PlayFieldConstants

isSnake

protected boolean isSnake(int y,
                          int x)
Parameters:
y - line
x - row
Returns:
true if there is a goody at the coordinates
See Also:
I_PlayFieldConstants

isGoody

protected boolean isGoody(int y,
                          int x)
Parameters:
y - line
x - row
Returns:
true if there is a goody at the coordinates
See Also:
I_PlayFieldConstants

isSpecialField

protected boolean isSpecialField(int y,
                                 int x)
Parameters:
y - line
x - row
Returns:
true if there is a goody at the coordinates
See Also:
I_PlayFieldConstants

isFree

protected boolean isFree(D_Vec2D vec)
Parameters:
vec - controll this position
Returns:
true if there is a goody at vec position
See Also:
I_PlayFieldConstants

isWall

protected boolean isWall(D_Vec2D vec)
Parameters:
vec - controll this position
Returns:
true if there is a goody at vec position
See Also:
I_PlayFieldConstants

isSnake

protected boolean isSnake(D_Vec2D vec)
Parameters:
vec - controll this position
Returns:
true if there is a goody at vec position
See Also:
I_PlayFieldConstants

isGoody

protected boolean isGoody(D_Vec2D vec)
Parameters:
vec - controll this position
Returns:
true if there is a goody at vec position
See Also:
I_PlayFieldConstants

isSpecialField

protected boolean isSpecialField(D_Vec2D vec)
Parameters:
vec - controll this position
Returns:
true if there is a goody at vec position
See Also:
I_PlayFieldConstants

generateLevel

protected D_Level generateLevel()
Returns:
a copy of the ocal level

updateLevel

protected boolean updateLevel(D_Level level)
Parameters:
level - the lvel the local level should be stored in
Returns:
if the coppy was succasfull. it fales if the size of level and the local level doesnt fit.

fy

private int fy(int i,
               int k)
generates the funktion:
k: (i)
1: (0, 1, 0, -1)
2: (0, 1, 2, 1, 0, -1, -2, -1)
3: (0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1)
...

Parameters:
i - index in (...)
k - index of line
Returns:
value at position

fx

private int fx(int j,
               int k)
generates the funktion:
k: (j)
1: (-1, 0, 1, 0)
2: (-2, -1, 0, 1, 2, 1, 0, -1)
3: (-3, -2, -1, 0, 1, 2, 3, 2, 1, 0, -1, -2)
...

Parameters:
j - index in (...)
k - index of line
Returns:
value at position

getSourounding

protected D_Vec2D[] getSourounding(D_Vec2D vec,
                                   int maxDist)
returns all surrounding fields of vec in an array that is ordered that way:
___C___
__N4D__
_MB05E_
LA3#16F
_K927G_
__J8H__
___I___

the vectors in that positions are absolute positions in the arena. but they are valculated relative to the origin '#'
the absolut number of elements are: maxDist * (2*maxDist + 2)
4, 12, 40, 60, 84, 112, ...

Parameters:
vec - the origin
maxDist - how many layer should be calculated
Returns:
returns the array of positions

updateFreeFieldVec

protected final int updateFreeFieldVec(boolean ignoreGoodies)
returns the number of free fields in the playfield while storing its positions in a array

Parameters:
ignoreGoodies -
Returns:
the number of free fields

randFreeField

protected final D_Vec2D randFreeField()
Returns:
returns a random free field