Thursday 30 May 2013

BorderLayout inside BorderLayout

Okaaaay... this is what happened today:

  • made program exit on pressing red button by having a JOptionPane pop up
  • made a second gamePane to make a second BorderLayout
  • second BorderLayout will act as a menu for the user with "quit", "instructions", and "map" (maybe)
  • the 1st BorderLayout goes into the 2nd BorderLayout 
Everything of that works fine and awesome after I fiddled with some things. Now my issue is how to use the booleans to make the rooms clickable or not. Because at the moment, this is working:
             
        if(whatClicked.getButton()==whatClicked.BUTTON1)

    {
    if(roomArray[cRow][cCol]==roomArray[2][0])
    {
    prev=false;
    }
    else
    {
    prev=true;
    }
    if(roomArray[cRow][cCol]!=roomArray[2][0])
    {
    cRow++;
    if(tracing)
    {
    System.out.println("CHARACTER HAS ENTERED PREVIOUS ROOM");
    }    
    }
   
    }

What's not working, is if I replace if(roomArray[cRow][cCol]!=roomArray[2][0]) with if(prev=true);
Which I think should work unless I'm missing something very obvious, which I probably am, but it really looks like it should work. I don't get why it won't work. My computer crashes when I try to use if(prev=true);.

So. I got a back to menu button, plus an "exit screen" of sorts, but this part, which I was actually supposed to do today, won't work. 
Nice. 

Wednesday 29 May 2013

Back!

Right. So yesterday, I managed to make the forward button work. Now, I've been trying to make it so the buttons aren't clickable if there is no room up ahead, or if it isn't a dead end. I've managed to do that with the back button in the starting room, but now when I move forward into a room that I haven't made yet, the program crashes. The way how I'm stopping the buttons from being clicked is by using an if statement to see if the character is in a specific room. If the character is in a room that doesn't have a forward room, I make the room equal to that room.
...Showing it might make more sense.

if(roomArray[cRow][cCol]==roomArray[2][0]) //if character's place on board is same as starting room
{
    roomArray[2][0]=roomArray[cRow][cCol]; //the starting room now equals to the character room
    prev=false; //button for previous room equals false (not sure if this is even needed)
}

That will basically keep them inside the current room. But if that's how it is, then I think I'm going to have waaaaaay too many if statements for this one thing. Doesn't sound right. At all. Or it should, since it works, but I don't think that it's the efficient way to program this bit.

Anyways. That's how it looks to be programmed at the moment!

Tuesday 28 May 2013

Forward!

AAAAAAAAAH!! My character can move through rooms now! :D
Well... technically, it's just two rooms. Forward and Back. But still. Yay. Although if I press back again after they are in the start room, I get a massive error on the black screen (I need to learn the name of that box!), plus the screen turns white since there's nothing before the beginning.
There was a slight problem in the beginning because I forgot to add the MouseListener to the buttons! I am so smart sometimes. >_>
Another problem was that I had to use the removeAll() method and put the other picture into the CENTER layout, which means I probably have to declare the Forward, Back, Right, and Left buttons all the time. I didn't do that at first, so the program didn't work at the time. But it works properly afterwards.
Maybe I can put them in a method and just use the method whenever I need them. I haven't tried that yet but I don't see why it won't work.
Just yeah. I can see that I'm going to have more if statements than I've ever used for any of my other programs put together.

Wednesday 22 May 2013

Some Random Updates That I See as Achievements In Moving Forward

So... this is how it looked yesterday and I had no clue why although it seems pretty obvious now. 
Since JCreator is still wonky on my laptop I will not touch any of my code (since it's working fine now) and just mention some stuff! Stuff. That's... pretty broad. But stuff is stuff which is stuff so it's valid stuff.

The reason for why the image wasn't appearing in the frame was because I had a lot of nonsense code to show the image (that code was mooched off of some website I don't even remember or know) and I didn't actually "put" the image into the game method which means it wasn't added to the gameFrame, which is why it wasn't showing up when it should have.
It kind of looks like this now after I removed the excess code:
roomImage = new ImageIcon(""+r+c+".png");
roomImageAfterItem = new ImageIcon(""+r+c+"after.png");
setIcon(roomImage);
The ""+r+c+".png" in the brackets gets the png file I named that certain row and col from the class folder. roomImage is the picture of the room with the item, and roomImageAfterItem is the picture of the room without the item in question. roomImageAfterItem was then made equal to roomImage after they click the item so that the after-image would be the picture that shows up after they click the item.

So... some other things that happened today has to do with getting the option pane to pop up to tell me that an item has been picked up! Since it has an "OK" button and not a "YES/NO" button, they will be kind of doomed if they pick up and eat something that is pretty dangerous...though I wonder at how I'm going to be able to tell them that. Hm. Ah. More if statements and messages. Mm.
Pretty silly mistake on my end... it wasn't working at first, and that was because I didn't add the MouseListener to it. I had the MouseMotionListener added, but I forgot that my if statement for picking up the item is part of the MouseListener method and not the MouseMotionListener.
Before I figured that, I --- AM I WRITING TOO MUCH HERE??-- made a tracing statement that says "MWAHAHA" if the item's actually being clicked. Turns out in the end after I added the MouseListener, both the item message and the tracing statement works. Yay.

Oh, and lastly, there was a null pointer exception error that popped up when I went to the instructions frame. My good quacking friend +Chilly C and my teacher found out that it was because the roomArray was initialized in the game method. It should have been initialized in the constructor method, because the if statements I had going on were trying to access rooms that weren't created yet when I clicked the instructions button...I wonder if I even made sense.

Tuesday 14 May 2013

Half Finished ONE Part of x Parts of Program

With help, I was able to somehow start getting my array for the rooms working! Although there was this huge misunderstanding I had about using a class and making an array using one of them, and another one (which should be the same one) as the template of the rooms in my game. ERM... Nothing else is worth mentioning yet.

Right... As for what to put in the other rooms, I decided that I would have a quest within the adventure. I think it is fairly simple since I just have to deal with booleans and if statements, like almost everything else in my program.
I also plan to add a little helper/familiar that would warm you if there is immediate and serious danger. I don't know how the helper should look. Some kind of outer space animal, earth animal, or something else entirely. Who knows...

Friday 10 May 2013

Wow

Wow, is this really just the 5th day I've done something about my program?

Okay, so far I have about 14 things I can put into the rooms of my game and I have 18 rooms to fill.

  1. key 1
  2. key 2
  3. locked door 1
  4. locked door 2
  5. alien god who asks riddle 
  6. The Epic Answers to Epic Riddles book
  7. alien monsters
  8. weapon
  9. a pit hole that leads to instant death (GAME OVER)
  10. treasure chest with 1000 coins in Pluto currency
  11. greedy alien god
  12. poisonous gas trap
  13. anti-gas potion
  14. poisonous food with no antidote
  15. a map (?How am I going to work this out?)
Other than that, I'll be a happy person after I make sure that the array that will determine what room is available etc works. Which I think means I'll have to make a few more classes for these rooms before I can properly test it out. 

I figured that if I make it so after they click on an item, a JOptionPane will appear to say that they picked it up. Then--maybe instead I shoul dmake it so they could chose whether they want to pick it up after they click it. So...I can say in the JOptionPane... Do you want to pick up (item)? Yes/No
And then if yes, then draw the exact same room but without that item, if no, then it stays the same and they can proceed. I guess I could make it so they can't leave unless they pick up a certain item, but I'd say that it's their own fault for not picking up a key that would most likely open a locked door. I mean, what's the harm of picking up a few items?

Currently this is how the first room looks although it's terrible bare and more things will have to be added to it!(Or not?) Maybe the key should be in a drawer by the front wall instead.

They key is there, but it's pretty small. I tried to make the size reasonable considering the size of the room and everything...
There's only one door, but if it's going by how my grid looks, they'd also be able to go right so I should probably add a door on the wall to the right. 

Sunday 5 May 2013

Ahhh...

Pieces of code are missing from my program! >_< They disappear and reappear after pressing enter. And that only worked twice. Good thing I didn't have anything on it!
It started acting funny after I put more stuff into the instruction screen but I really doubt that's the problem. I could see everything when I run the program and it works perfectly fine but I can't see my code. I opened my first GUI project and it's also missing a fair bit of code, and it won't let me do anything to it. Must be my computer that's busted. For some reason. It was working fine yesterday...Yup. I'm doomed.

Friday 3 May 2013

MouseMotionListener

I'm moving on to making it possible to click onto objects in the room. To do that, I have to know the coordinates of the object, so I used the .getX() and .getY() methods. The coordinates will be printed out on a separate screen.
I tried using the MouseListener at first, but when I did that, the coordinates didn't show up when I tried it--I could only see the coordinates if it passed by a button.
Then I used MouseMotionListener and added it to the JFrame I want it to show up in. And I printed out the coordinates in the mouseMoved method. This worked out so one part is solved!!
...Maybe the mouseEntered didn't work because I didn't add the MouseListener to it...