Forums

Forums (http://www.abandonia.com/vbullet/index.php)
-   Tech Corner (http://www.abandonia.com/vbullet/forumdisplay.php?f=23)
-   -   Java (http://www.abandonia.com/vbullet/showthread.php?t=1616)

Kon-Tiki 07-12-2004 01:43 PM

w00t! Almost done with the tutorial. Then on to getting some experience and doing the assignment fast enough for it to be done in time.

Rogue 07-12-2004 02:06 PM

Nice... :)

The Niles 07-12-2004 02:10 PM

I still want to learn Java but I don't have the time. Writing programs used to be fun back when I was still on an MSX.

Kon-Tiki 07-12-2004 02:22 PM

Tutorial that only takes a few hours, and the more you know 'bout C++, the less time the tutorial'll take. What you need to do afterwards, is find a way to get experience in the coding. That's what I need to get now too. So... any suggestions to get my thinking right for this one? :D

Rogue 07-12-2004 02:58 PM

Any programming (VB, C++, Java...) requires good planning. So if you prepare plan based on what you need to accomplish (this one is some sort of global plan), then create pseudo code (in your own language, what you like to do), your programming will then take minimum time, your code will look better, and it will be easier to fix problems.

I have not done much Java in last 2-3 years, but still remember of having a hard time with syntax. I had impression that visual part was also kind of unusual, but have to remember that programs were able to work on any kind of OS, which supports Java.

To make sure that you will not end up debugging, start this process with this:

Answer these questions:

What program supposed to do?

What is my input?

What are my processes?

What output should be?

After that just write down (still in your language) all functions, modules (or whatever you call them) that you will need in this program.

Then take a look if you can find Java commands that will do what you need.

And final step will be writing the code, which at this point should be strait forward.

And end will include testing and debugging.

This is about what we had to learn in data structures and procedures class, which basically includes preparing plan and documentation for problem, and then apply plan to any programming language. (I liked mostly to use C++)

When you done with documentation, post it here, so that we can see it.

Kon-Tiki 07-12-2004 03:40 PM

Assignment doc:
Code:

Task
In this practicum, you'll have to program a game, using a simple graphicacl library.

The Game
The game situates in a 2-dimensional world, represented by a board, which is divided in
an amount of cells. A cell can be empty or contain a box. Dozo is the actor in this game.
He is controled by the player by using the cursors and can navigate through this 2D world
this way. The goal of the game is to get as many boxes to disappear. Boxes disappear when
they are grouped per 3 or per 4 (depending on the type of box).

The game stops if all boxes are disappeared.

Boxes
Boxes can be moved by Dozo when he pushes them. Dozo can move 1 or more boxes at once in one
direction this way, on condition that all boxes are of the same type and not placed against
a wall. Dozo can, in other words, not move both a red and a blue box at once. When he does
try this, he's meant to remain standing on the spot.

Two boxes are connected if and only if they have one side in common. Two boxes x and y belong
to the same group if x and y are connected or if a box z exists in such a way that x and z
are connected and z and y belong to the same group.

Red boxes have as characteristic that they disappear as soon as at least 3 such boxes are
grouped. Blue boxes disappear as soon as they're grouped with at least 4.

Walls
A wall (black square on the figure) is immovable. You can assume in this practicum that Dozo's
world is closed by walls.

The boxes below are grouped correctly and will thus have to disappear
 * *<figure 2>
Figure 3 shows configurations of boxes that aren't complete and thus don't disappear.
 * *<figure 3>

Concrete
A description of the world is saved in a file with extension .txt. The file exists out of a
few rows that represent the world. The example below makes this clear.

Dim 12 5 *The first rule defines a board of 12 cells wide and 5 cells high.
..########..
..#.B.#R..#.        . Empty cell
..#BB.B.R.@#        # wall (immovable)
..#....R..#.        B a blue box
...#######..        R a red box
 *@ Dozo

You can assume that:
* There's only one Dozo defined.
* The board is closed. Dozo can't walk reach a cell that's at the edge of the board in any
way.
* Except for the first row, all rows in the file are equally long.

To load a world from a file, you may use the class FileInput which you used in the previous
practicum.

Tips
Although the previous is strictly seen enough to get you to work, we're giving some classes
which can appear in your design. A possible implementation could use the following classes.
Note, you're not obliged to follow these directions.

Keep in mind that with the quoting, a fancy graphical userinterface won't be taken into
concideration, but the quality of your design and implementation of it will.

On Toledo, you'll find under "assignments", aside of a digital version of the task of this
practicum, a library with which you can draw graphical components on the screen. This way,
you can, for example, draw Dozo's world with the aid of the classe Bord. A couple of examples
make the use of these classes clear.

DozoWorld
This class enables you to make and control an object which keeps a model of the 2D world in
which Dozo navigates.

Define a constructor that creates and initiates a DozoWorld using the rows that can be read
from the file and give as paramenter the Board on which the world will be drawn.
* public DozoWorld(String[] rows, Board bord)

Next you can offer the next methods (this list isn't complete)
* public Item getCel (int x, int y)
        Gives the item that is on that position (x,y). If there's no item on that position,
        you can, for example, have the method return the value null.
* public void placeCel (int x, int y, Item item)
        Places the item on that position (x,y).
* public void drawWorld()
        Draws the complete world, including Dozo, on the board.

Item
An object of the class Item can be attached to each cell. An item can, for example, be a box
or a wall.
Examples of interesting methods here are:
* public boolean moveItem(int direction)
        This method tries to move the item in the given direction and returns whether or not
        this operation has succeeded.

* public Item give Item(int direction)
        Gives the item that borders to the item on which the method has ran.

* public int getX()
        Gives the x-coordinate back of the cell on which the item is.

Wall
You can define a Wall as subclass of Item. The method moveItem can be given a new implementation
here.

Dozo
Dozo too can be defined as subclass of Item.

Practical details
Design your solution on an objectorientated manner. Keep in mind as well that your code has
to be read and understood by other people:
* Choose clear variable- and methodnames and keep yourself to the conventions concearning
namegiving: names of variables and methods start with small letters, names of constants are
fully in capitals, ...
* Put structure in your code (indenting of blocks, ...) and add comments where needed.
* Complicated methods can be best tested by using it in a different main of a different class
and see if it has the right result.

Input:
The world to be loaded and cursors, to move Dozo
Processes:
  • Loading a world
  • Moving Dozo
  • Pushing boxes -> Checking if a box is moved against a wall
  • Checking for how many boxes to be pushed
  • Checking for amount of grouped boxes to make them disappear
Output:
Object properties change and objects on screen change accordingly
Functions:
See Processes

Rogue 07-12-2004 04:09 PM

OK, this would be a global plan. Now what's the plan for each of steps in process? Go to lovest level of code, but still in plain english.

Kon-Tiki 07-12-2004 04:40 PM

1) Main program:
Set the board up and allow loading a world

2) Loading a world:
  • Choosing the .txt-file
  • Reading it and displaying the world with graphics from the graphical library on the screen
  • Starting the program
3) Moving Dozo:
  • Check for current position
  • Check what object is in the direction of where he moves
  • Check if there's another object in front of him
    -> Do Checking for how many boxes to be pushed
Method: Moving Dozo
  • Change the current coordinates to the ones of one tile in given direction
  • Clear Dozo-property from current position and add it to the new one
  • Draw Dozo on the new position
4) Checking for how many boxes to be pushed:
  • Get the object type Dozo moved into
    -> If it's a wall: stop moving
    -> If it's an empty spot -> Move Dozo
  • Check if the object one space further in the direction Dozo moved is the same
    -> Loop until it encounters something else than the current object type
  • Act according to the result:
    -> If the object the loop stopped at is empty, then
    1) set the property of the object that's moved into to empty
    2) the empty object at the end of the loop's property to box
    3) draw the box at that object
    4) remove the box-pic from the object that's moved into
    5) Call the method Moving Dozo in class Moving Dozo
    -> Else
    Do nothing and await new input
We'll keep it at that for now. Still can't really see how to do the grouping yet. I'd have it count the same way as I did with the last assignment, but they can be attached to each other in a corner too.

Rogue 07-12-2004 04:45 PM

How do you like to set up coordinates?

Kon-Tiki 07-12-2004 04:49 PM

Where the @ is in the world-file, it'll store the coordinates of that into an array which contains two ints. When doing the checking for the boxes, it'll copy this array and change the values. When Dozo moves, the array's values change too, to the new position.


The current time is 09:18 AM (GMT)

Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.