Author Topic: AP Computer Science Final Project  (Read 3416 times)

0 Members and 1 Guest are viewing this topic.

Offline Polpolion

  • The sizzle, it thinks!
  • 211
    • Minecraft
AP Computer Science Final Project
I'll be needing some help with it, and this is one place that I'm sure is full of competent programmers, so I figure I'll just ask some questions and stuff.  :D

So my final project will be a java applet game that attempts to emulate the gameplay of Tyrian while having most game data stored in text files. Think of the table files from FS2.

I have the basic file input down, and the displaying of graphics is pretty easy, it's just that right now I'm caught up on this: I'm going to have a Ship class and a Weapons class for the ship and weapons you have, but I want to have different kinds of ships and weapons. I could just create new subclasses for every different type of ship or weapon, but that almost defeats the purpose of having the ship/weapon data stored in text files.

What exactly is a practical way to go about having the program operate with multiple version of a class, yet the amount of versions of ships/weapons in the code dependent on what's in the text file?

 

Offline Sushi

  • Art Critic
  • 211
Re: AP Computer Science Final Project
Great question!

If I understand correctly, you're asking how to differentiate between class instances representing individual ships/weapons (in the game) and class instances representing ship/weapon types?

The way I handled this in the last game project I worked on was to have a "Ship" class that represents an in-game entity and a "ShipType" class that represents the type of ship. I instantiated a new ShipType for each ship in the definitions file (like ships.tbl) and each instantiated ship object had a member that pointed to the ShipType instance that it represented. All of the "ship type" stuff (mass, acceleration, etc) was stored in the ShipType instance and all of the specific object stuff (position, current velocity, orientation, etc) was stored in the Ship instance.

Short version: you don't want a new subclass for each type of ship and weapon. You want a new class INSTANCE of a class that's designed to represent any conceivable ship/weapon type. The classes representing game objects just point to an instance that represents the type they are.

 
Re: AP Computer Science Final Project
Doesn't it kind of depend on how much difference there is between the ships and especially weapons?


For the ships - where they reasonably can be expected to behave the same way, albeit with different stats, I'd expect a single shiptype class with multiple instance makes sense.  This is assuming of course, that you've got fast ship with light shields, slow with heavy armor, and maybe different weapon assortments. 


Weapons are a different story though, simply because they're almost certainly going to behave drastically differently.  This isn't like freespace, where all primaries behave more or less the same, with primarily statistical difference. 

This is a typical top down shooter, so I'd expect that the behavior of a homing missile, a spread gun, super bomb and a continuous laser beam are going to require entirely different code branches to handle them.  Trying to make one class handle them all would just make things difficult.

In all probability I'd take an accounting of all my weapon behaviors, nix it down to as few classes as possible, have those all implement a common interface and let the text file specify which weapon type they were and any relevant stats.

 

Offline Sushi

  • Art Critic
  • 211
Re: AP Computer Science Final Project
Well, if you do have drastically different enough behavior that it makes sense to encapsulate it in different objects, you can have different polymorphic subclasses for ShipType/WeaponType (as Phato pointed out).

 

Offline Flipside

  • əp!sd!l£
  • 212
Re: AP Computer Science Final Project
Personally, I'd create a mixture of Polymorphism and Referencing, so you have a 'Weapon' Class, which is extended by, say, 'Energy', 'Missile' and 'Ballistic' Classes, they would contain the details about the weapons and, most importantly, the graphics used to represent them, then every in-game instance of the weapon can simply contain a reference to its template as well as instance-based details about that particular occurrence of the weapon.

That way, you're only storing one image or set of images for the weapons, rather than re-creating work and using up memory by storing graphics for every single time such a weapon appears.

 

Offline blackhole

  • Still not over the rainbow
  • 29
  • Destiny can suck it
    • Black Sphere Studios
Re: AP Computer Science Final Project
I want to point out that Descent 3 had a huge variety of weapons that were made possible through a complex system of statistics that controlled behavior. It was complicated, but it worked astoundingly well and resulted in many completely new weapons created by fans. There are different ways to go about the weapon problem, so pick the one that works best for your game. For example, all weapons have a "shoot()" command, so you can at least have them inherit a base Weapon class that the player class then references for whatever weapon happens to be active. This usually works best with both a Shoot() and a StopShoot() command.

 

Offline Flipside

  • əp!sd!l£
  • 212
Re: AP Computer Science Final Project
Agreed, mine was more a very simplistic example than a definition of the ideal system, it really does depend on exactly what you want those weapons to do, and how you want them to behave :)

 

Offline Aardwolf

  • 211
  • Posts: 16,384
    • Minecraft
Re: AP Computer Science Final Project
So, what became of this?

 

Offline Polpolion

  • The sizzle, it thinks!
  • 211
    • Minecraft
Re: AP Computer Science Final Project
Good and bad things.

I ended up finishing the project and e-mailing it to my teacher with about 12 seconds to spare before the deadline. Those last two days, when I wasn't sleeping or at school, were filled entirely with programming.

About 4 days before the deadline, I had finished writing all of the code, but I had wrote it all at once. I hadn't bothered to write it and test bits and pieces of it at a time (with the exception of the class that read textfiles). Naturally, there was a butt load of bugs and errors in it. The first non-menial one that I encountered was the usage of images. The program ran as a Java applet, and I had used images with it before. But this time, for some odd reason it wouldn't like the way I used ImageObserver. To this day, I don't understand how ImageObserever works or the way that I managed to make it magically work for me.

But anyway, the next major error that I had to contend with was the obvious error that people run into when creating their first real-time game: accepting player input while continuing to run the rest of the program. So I reorganized the main class and created a new thread.

The initial thread started off by creating the second thread, and then just sitting and waiting for input. When it received input, it would send the button information to a different class that would interpret the input based on what stage the other thread was at (ie, are you at a menu or are you actually playing the game) and it would modify a static object with the instruction, which would be read by the second thread and then reset to it's initial state.

The second thread, meanwhile, would simply be churning through the actual game. Every time it finished a single part of a loop, it would call a method from the main applet class, and that method would harvest all image data and compile it into a single image, which would then be displayed.

I actually finished re-organizing the code on the last day, and I added in the image buffering in the last hour; before that it just output each little image file onto the screen one by one. As for the rest of the code, I'll see if I can just post it for you guys if you want to peruse it. It'd take way to long for me to just summarize it. :p

As for grades, it was a bit unfortunate.

The project was a group thing, and there were two other people with me. The thing is, neither of them could program all that well. And by "not all that well" I mean when I told them to create a method that would check to see if to points on an x,y plane were within a certain distance of each other, they were at a total loss, and I somehow had to explain to them how return types, if statements, and for loops work. Hence, I programmed the entire thing myself, and as a result, it took me almost 3 times as long as it should have. When we had to present our projects to the class, this became quite evident, especially how they didn't know what synchronized methods were, much less anything about multi-threading. (Granted, I taught myself everything that I needed to know about multi-theading to make it work the day that I needed to hand in the code...) So we got some serious points off for that.

Past that, it was just stupid things. I don't think I had many points taken off for my supar-retardad programming skills - we had about 4 months with our teacher, the one that he replaced was totally incompetent as a teacher. Furthermore, he told me that it was clear that I knew how to program, and that a lot of the things that I used, namely the multi-threading, fileio, and the way I used textfiles was way beyond what was taught in the class. Unfortunately, I did not include many of the required methods or things. I didn't have any recursion, searching, or sorting. In fact, I think the only required thing that I had was the use of ArrayLists. On top of that there was still a lot of less major things here and there. For example, I didn't realize I could use PNGs with the applet, so my jpegs had big white blocks around them, and I didn't have time to implement half the things I wanted to do: like fire wait, ammunition, better hit detection, fewer glitches and bugs... The sad thing is, if I had another few days, I would've really polished it up and added a butt ton of features.

Anyway, as a result of the afore mentioned facepalm material, I got a solid B on the final. Fortunately, I retained my A in the class, thanks to a bunch of assignments and tests that I got >100% on.

Also, I got a 4 on the AP exam, which was surprising, because I took it in May, giving me only about a month and a half to learn the material and study.

Anyway, I really appreciate the help you guys gave me. Thanks!  :)

Attached is the source code. I forgot where I saved all the other materials; this is what I e-mailed my teacher.

[attachment deleted by Tolwyn]

 

Offline Flipside

  • əp!sd!l£
  • 212
Re: AP Computer Science Final Project
Quote
I told them to create a method that would check to see if to points on an x,y plane were within a certain distance of each other, they were at a total loss

This is made even more amusing because the Point class that comes with Java has a specific method in it that will find the distance between two points on an x/y plane ;) Though, anyone who can't do the basic trig for this is in for a rocky future in computing.

I used to dislike the fact that Java seemed incredibly disjointed with it's image handling systems, using two systems that are not always compatible (Graphics and Graphics2D), and there seemed to be no general consensus of what was used where.

Then I started playing with JOgl, where you have to start flipping images because the axis are the other way round. Now I loathe and detest the way Java handles images ;)

I had a similar problem to you with my Further Object Oriented Design course, we had to write a server/client system using RMI, and, despite being a team of two, I ended up writing every single line of code and documentation. I ended up making a complaint about it, I didn't want to get the lad in trouble, but I had one shot at a BSc, and it costs me around 20 grand, I did NOT want someone else screwing it up for me.

Fortunately, at the end of the day, I got an upper second honours degree, despite effectively doing double the work, which I'm quite proud of, but since my grade average was 4.5 and I needed 3.5 for a distinction, there's always a part of me that wonders what I would have got if he'd actually pulled his weight.
« Last Edit: July 26, 2009, 11:14:36 pm by Flipside »

  

Offline Mika

  • 28
Re: AP Computer Science Final Project
Congrats for struggling through that one, not an easy job. It is quite a display of programming skill.

I have heard similar accounts from the students of Theoretical Physics about Computer Science's education program. One of my friends (Physicist) complained he had two fourth year Computer Science students in his group that had never programmed a computer. He was astonished of this fact - as am I. In the end, he had to write all the code for the assignment, and the rest of the guys did nothing. I think he complained about this to the lecturer, but most likely there were no consequences.

Hell, even I was pissed off when my room mate had courses that consisted mainly of 4 hours of Photoshopping. I had for f***ing 40 hours in a course of similar extend, courtesy of Physical Sciences.

A year later that very same Computer Sciences department had to lay off some 60 % of their staff due to lack of funding since their students had not graduated. So I guess in the end there was (some) justice.
Relaxed movement is always more effective than forced movement.