Developing a game on AS3 (Part 2: Duck Hunt mini-game)
Figure 4

Purpose: development of a computer game
Target audience: beginners, interested, onlookers
Tools: ActionScript 3.0
Cycle content
- Part 1: introduction, utilities
- Part 2: Duck Hunt mini-game
- Will be supplemented as available ...
Part Content
Introduction
In previous releases ...
- Perhaps a slightly blurry introduction;
- A certain set of comments is defined;
- Created and described the required tools;
- The task is set for the present part.
The inspiration for the mini-game was the old warm " Duck Hunt ". However, the repetition of anything practically deprives this process of creativity, turning it into a boring routine. Yes, and copies of such a game, most likely, already exist (carefully, you can get an aesthetic shock from the flight of ducks). It must be remembered that a small game is being created, so do not overload it with unnecessary features (and so there are quite funny variations ).
We will do some prefabricated parody of old computer games, thereby substantiating any noticeable use of objects of another's copyright, to which a parody is made.
Sketch
When drawing up the sketch, I stopped thinking that I was creating a game about duck hunting. In Figure 5, you can familiarize yourself with it: an abstract screen, on which abstract goals fly, which need to be destroyed in an abstract way. All. Everything else is details.
figure 5

Prototype
Remark 10:
For abstract purposes, one could come up with some kind of simple animation (static black square), but since I already had animation for ducks, then I considered it permissible to create the goals I needed right away. In Figure 6 presents a simple UML diagram:
Figure 6

on abstract screen CDisplay fly abstract goal CTarget , which produces CTargetEmitter , using the abstract factory purposes CTargetFactory . The user is prompted to shoot down targets with the CWeapon abstract weapon (with the CWeaponMagazine gunshot magazine ).
On Figure 7 The above screen shot of the resulting prototype.
Figure 7

Ducks CDuckTarget extends CTarget become targets, which serves to destroy from monovalent ( CSniperRifleMagazine extends CWeaponMagazine ) sniper rifles CSniperRifle extends CWeapon .
Note 11:
CRandomTargetFactory extends CTargetFactory allows you to combine different goal factories into one, so CTargetEmitter can issue different goals according to a specific strategy (in this case, in a pseudo-random way).
Game CGame - is a consistent set of rounds CRound , which should be displayed on the screen. And the general statistics of the CStatistic game is made up of statistics for each round. CRound carries all the necessary information in order to be able to play it: how many and at what speed to release goals, what effects to use, what to count for successful completion of a round, etc.
Comparison of development with and without unit testing
The answer to one of the questions Mr. meiciuc .
Why unit testing in ActionScript ? And what ActionScript is so bad? Well, no need to list. I wanted to say that unit testing is a proven practice in general. Try reading:
Now I’ll ask my question differently: why is ActionScript so good that it won’t work for it?
It should be noted that at first the game was implemented as a program in almost one class, which in the “best traditions” does everything. In figures 8 and 9, you can look at the screenshots of this creation. This option has even remained available in Git: alx.duckhunt.CDraft.
figure 8

figure 9

As you can see, it is very similar to what we got as a "prototype".
This creation was developed "on the knee." So I really had the opportunity to compare development with and without unit testing. I even kept time records, so I could share specific figures, but, to be honest, the development was carried out from case to case, and it will not be entirely correct to make this comparison. Too many factors influenced time. Ultimately, I even abandoned the idea of keeping a journal of time spent.
I would like to note that you can familiarize yourself with the extremely simple structure of alx.duckhunt.CDraft. Perhaps testing here would be superfluous. However, look at what happened in this article (it will be even more complicated later). As soon as the complexity of the project changes from a monosyllabic piece of work on the knee to something more complex, the gain from using even partial unit testing becomes tangible:
Of course, if you are developing a banner on Flash , you will not need all this.
The question deserves a separate article that I did not plan to write.
Why unit testing in ActionScript ? And what ActionScript is so bad? Well, no need to list. I wanted to say that unit testing is a proven practice in general. Try reading:
- Is Unit Testing worth the effort? [closed] ;
- How not to shoot yourself in the foot ;
- On the use of unit tests and TDD .
Now I’ll ask my question differently: why is ActionScript so good that it won’t work for it?
It should be noted that at first the game was implemented as a program in almost one class, which in the “best traditions” does everything. In figures 8 and 9, you can look at the screenshots of this creation. This option has even remained available in Git: alx.duckhunt.CDraft.
figure 8

figure 9

As you can see, it is very similar to what we got as a "prototype".
This creation was developed "on the knee." So I really had the opportunity to compare development with and without unit testing. I even kept time records, so I could share specific figures, but, to be honest, the development was carried out from case to case, and it will not be entirely correct to make this comparison. Too many factors influenced time. Ultimately, I even abandoned the idea of keeping a journal of time spent.
I would like to note that you can familiarize yourself with the extremely simple structure of alx.duckhunt.CDraft. Perhaps testing here would be superfluous. However, look at what happened in this article (it will be even more complicated later). As soon as the complexity of the project changes from a monosyllabic piece of work on the knee to something more complex, the gain from using even partial unit testing becomes tangible:
- Refactoring is easier;
- Correcting mistakes, and, importantly, avoiding their “reincarnation" is easier;
- Reusing code, not errors, is easier;
- The error search time of the developed application is much shorter (Subjectively).
Of course, if you are developing a banner on Flash , you will not need all this.
The question deserves a separate article that I did not plan to write.
By the way ...
- Design template applied Abstract factory [CTarget; CTargetFactory], [CDuckTarget; CDuckTargetFactory], [CCloudTarget; CCloudTargetFactory] ;
- Design template applied Factory method CWeapon :: createMagazine ;
- Applied a kind of design pattern Linker [CTargetFactory; CRandomTargetFactory] ;
- Design pattern Observer applied [CDisplay; IDisplayListener], CWeapon implements IDisplayListener; CGame implements IDisplayListener .
"Duck Hunt"
Note 12:
I want to upset, but the idea of embedding a mini-game in another game gradually ceased to please me for certain aesthetic reasons. Therefore, you most likely will not see her in this role. But we will be consistent, we will arrange the game as a separate one, and goodness will not disappear.
We will not discuss here which of me is a “designer”. CDuckHuntGame extends CGame adds a user interface and some design to our mini-game.
CNickGenerator is a simple generator of funny nicknames typical of one famous game.
Clouds are defined as targets in the usual way ( CCloudTarget extends CTarget , CCloudTargetFactory extends CTargetFactory) It is not necessary to destroy such targets, so they are outside the current list of targets. A factory can generate animations for clouds of various sizes from a primitive cloud. In Figure 10, you can admire an example of what happens.
Figure 10

In Figure 11 The above screen shot of the resulting games.
figure 11

Note 13:
You can’t insert a SWF movie into the article, and my site on a free hosting will obviously not be happy even with a relatively small influx of visitors. I decided to look for a platform where I could post my video, and it would be available to everyone. In the process of searching, we found the “rawgit.com” service, which provides a wonderful opportunity to open the file located on “github.com” directly in the browser.
Demonstration of the game (attention! Sound!).
Note 14:
If you are trying to assemble a SWF movie yourself, then note that in order for all the ducks to be in place, they must first be removed from the project and then added again. That's how weird Flash works . We will receive a correction of this situation later when the application context adjustment tool appears.
Conclusion
In the next issue:
- We will return to the utilities: a testing tool and an application context setting tool;
- We will take into account the error of the first article: there will be something to play.
Literature
- Literature from the first part ;
- Gorelenkov AI, Electronic textbook on the subject "Linear Algebra" (Link to .CHM (I did not find another)!).