Showing posts with label game. Show all posts
Showing posts with label game. Show all posts

JavaScript Forms

I am working on development a web app game. It is being written in JavaScript. I had learned how to do forms, so I made the game use a form. The majority of the screen is a big select area. I was going crazy because my JavaScript code was generating errors. The browser kept complaining that document.forms[0].mySelect was either NULL or not an object.

This was troubling because I had coded successful projects that used this technique. Googling the web also showed many examples of this working. To get by I hacked some getElementById calls instead. It still troubled my. I was running Internet Explorer 8. This stuff should have been working.

Near the end of my game development cycle I had to add more items to the form such as a status message. That is when I found the root cause of the problem. The select element was not within the form tags in the HTML. Ouch. No wonder JavaScript could not access the select object. It was just not part of the form. Now I got an action item to go back and use the familiar technique to access the form data in JavaScript code.

2D Arrays

My Java college class is moving painfully slow. I have decided to read ahead to get to the topics I need for real work. The current chapter is on arrays. I have a game which is run on a two dimensional map. This is a perfect application to two dimensional arrays.

So far my textbook has been concentrating on one dimensional arrays. There is not that much to them. It is only a little involved if you have an array of references to objects. You have to create the array. Then you have to create the objects themselves that are referenced by the array elements.

The next chapter is called Two Dimensional Arrays. That should give me exactly what I need for the game. Right now I am using the actual graphics screen to store things in my game. That is very slow. It is also difficult to do anything complex with the displays. I need 2D arrays to get my business done.

Game Success

Good news. I successfully created a simple Java game within 7 days. This was in response to a challenge posted on a Usenet news group. You can find a link to the program on the Legend of Angband web site.

The emphasis on my development for this game was to knock out something quick. As a result, I only had two classes. There was the driver program which had my main() method. And then there was a Monster class housed in its own file.

This was a Dungeons and Dragons style two dimensional game. There was no rocket science here. I drew a maze. Then I put some gold in that maze. And I added some monsters. The monsters fight you when you attack them. They follow you if you try to flee. Yeah it does not sound like much. I am still a Java novice and it has been a busy week. Download it and give it a try already.