Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (710)
Games in Android Showcase (212)
games submitted by our members
Games in WIP (784)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Re: Array game. on: 2011-12-03 13:37:46
 Hunter Hunter = new Hunter(11,11,"H");

I did not examine everything in detail but what looked wrong was the piece above.

Can you name the variable same as the class? If you can, then it is at least bad style.
I would prefer something like
Hunter hunter = new Hunter(...);

The  Route1 Class is being used for...

I see a route1() and paint() method. Maybe you mixed up the terms?

I don't completely understand what you are doing. You say that both methods are called every time the user presses one of the movement keys.
I have now looked a bit more at your code. It seems that you are creating new objects at each cycle of your game loop. And you will always give them the same starting coordinates.

If you want to save the state of player and hunters over the loop, then you should initialize your player once, create the object and use the reference to this one object without throwing it away.

public void route1(){
    Board board = new Board();
    Hunter Hunter = new Hunter(11,11,"H");
    Scanner in = new Scanner(;
    Random number = new Random(2);
    int random = number.nextInt(2);
     if(random ==1)
        Hunter.x = Hunter.x -1;
       Hunter.y = Hunter.y -1;

A variable has a certain scope. If you create a variable within a method (like "Hunter" here. use hunter as name, not Hunter. Hunter is your class), it will be in your program's memory until the method ends.
This is what you do:
Player does something. Hunters have to be updated
  • create a hunter object at a position
  • move the newly created hunter into a random direction
  • forget that the hunter ever existed (you don't remember the reference to it)

What you should do:
Your Hunter-class has only a constructor
public Hunter(int x, int y, String name){
    this.x = x;
    this.y = y; = name;

You should have a move() method and access to your coordinates as well.
Then you could tell the hunter to move. Then you would not create the hunter
within the route1() method but outside your game loop in your Main class. Then,
when it comes to updating the hunters' positions, you do something like this:
for (int i = 0; i < numberofhunters; i++) {

The move() method would then contain all the code to generate the new coordinates
of the hunter. It would store the coordinates within the object and would not forget

There are a lot of strange things in your code. I would suggest doing some Java tutorials
first to get familiar with its basic concepts before doing a bigger project. Learn about
classes, objects and methods. Learn about the scope of variables and their visibility.

A small one class example does not provide as many chances to create bugs and will
improve the understanding. Once you have done this, go back to your project, find the
mistakes and strange things, start new and finish your project.
2  Game Development / Newbie & Debugging Questions / Re: Array game. on: 2011-12-01 06:44:46
Hi Arom,

I just had a look at your other thread where you had already pasted some of your code. Like ra4king said, I also don't like to download archives of unknown source.

If your code still looks like this, then I would say that you are missing a game loop. The main method draws the map and then there are some conditions which will end after being executed once.

public static void main(String[] args) {    
      for (int r = 0; r < a2.length; r++) {
      ... }
      System.out.println("Input your move");
      move = in.nextLine();
      if (move.equalsIgnoreCase("w")) {
         // move up
         // repaint
         // check for collision
         // check for health
      } elseif {.... } // no loop here. Main will end and the game will be over.

I think there should be a look around your input and conditions. And, of course, you would have to replace the comments by something that is actually doing stuff. If you have done so already, then please post the relevant piece of code.
3  Game Development / Newbie & Debugging Questions / Re: Getting Clicked Block on: 2011-11-29 20:32:13
Int() returns a double?  And people wonder why I stay away from Microsoft  Cheesy

What? I didn't read that. So -8.2 float is converted to -9 double?!?! I'm confused... Luckily Java behaves differently.
4  Game Development / Newbie & Debugging Questions / Re: Getting Clicked Block on: 2011-11-29 18:53:43
I don't understand, are you saying I'm right or wrong?  PureBasic did this.
It only makes sense to me, 'cause 1.99999 is better represented as 2 than 1.

Edit:  Ok, I was wrong about the .5 rounding up, it's .6 and higher that round up.  But still, using Int(number) in basic languages drop the decimal point entirely which is why I posted the code above with (int) in it.

You are right that 1.99999 is much nearer to 2 than to 1. But I was used to all decimal places being truncated when assigning a floating value to an int variable. After I had read your post, I read on MSDN that this not the case in Basic (at least VBA). The article seems to say that -8.2 is rounded to -9. I'm still a bit confused about that...
5  Game Development / Newbie & Debugging Questions / Re: Randomly Generated Terrain on: 2011-11-29 18:43:47
p.s. your code looks pretty normal; good for you for being open and sharing it along with your thoughts.
Thanks, still not used to forum tags.
6  Game Development / Newbie & Debugging Questions / Re: Getting Clicked Block on: 2011-11-29 07:03:28
@Ra4king, I still have to get used to that.  In some languages (mostly basic dialects), when setting the value of 1.5 to an integer it would round up to 2.

Wow, I just wanted to say "that sounds like BS, no sane language would do this" but then I googled a bit and it seems that I am right (about the language). VBA does this and the article says:

Quote from: MSDN

Using the Int function, on the other hand, yields "-9":
Which makes sense, although in a very strange way. If the digit right of the dot is below five, then go to the next number below. If the number is negative, this would result in an unexpected decrease.

Well, one never stops learning... and wondering....
7  Game Development / Newbie & Debugging Questions / Re: Randomly Generated Terrain on: 2011-11-28 20:19:34
I have generated some random terrain a few days ago and posted a blog entry about it including my (bad) code.

After I had read about Perlin Noise, I wanted to try to generate a map for a game I plan to do.

Because I thought it would be hard to fill the terrain below the line created by the perlin noise, I just used an image of terrain and shifted parts of its pixels downwards to create valleys. Probably not the best approach but it works.
Pages: [1]
numerical (80 views)
2017-02-21 07:32:16

numerical (81 views)
2017-02-21 07:31:46

theagentd (185 views)
2017-02-18 13:42:33

theagentd (188 views)
2017-02-18 13:35:16

h.pernpeintner (1351 views)
2017-01-24 22:39:11

h.pernpeintner (1339 views)
2017-01-24 22:38:32

Galdo (1900 views)
2017-01-12 13:44:09

Archive (1986 views)
2017-01-02 05:31:41

0AndrewShepherd0 (2522 views)
2016-12-16 03:58:39

0AndrewShepherd0 (2311 views)
2016-12-15 21:50:57
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!