Silverlight Game Design (Game):(13) "Art of War" ② of Imperial Times II (DEMO)

Source: Internet
Author: User
Tags silverlight

The Age of Empires is a masterpiece that describes the history of the World War, pay attention to restore the real historical war scene, one of the formation system is one of the great highlights of the game; players according to the different classes with the most suitable formation can often play a reversal of the universe of magical, classic such as the former gun, in the ride, after throwing stones, A strong formation coupled with the precise micro-operation of the player can instantly sweep the mass of the enemy without a scratch. The formation system not only exists in the real-time strategy game, in "Kingdoms", "The Letter Nagano Hope" and so on SLG strategy game, it also is one forever indispensable important mechanism.

In this section, I will introduce a more flexible custom formation system than the original version based on the "Empire Times" demo in the previous section to make war games more realistic and gorgeous.

Custom formation systems are inspired by chess, formations like "chessboard", combat units like "pieces", so from the structure, I choose to use the grid as the most basic carrier of the formation system, by specifying row and column can be randomly layout pieces to the specified square:

In this demo, I put the "chessboard" in the bottom of the HUD, and limit it to a 4*12 maximum of 48 units of the form of the carrier.

With the "chessboard", of course, there are "pieces". "Pawn" is an icon, so I create a class called Piece, which contains a picture control and a rectangular square control (blood bar):

The figure above is the "pawn" icon for the cavalry. Next, to implement a custom piece layout, we also need to add seat interaction for these pieces: that is, click on one of the pieces, the piece is selected, and the next click of the position or another piece to exchange position, the code is very simple, roughly as follows:

Piece hitpiece = null; Click on the Pieces
Unit position Replacement
private void Img_mouseleftbuttondown (object sender, MouseButtonEventArgs e) {
if (hitpiece = = null && (int) (sender as Piece). Code)!=-1) {
Hitpiece = sender as Piece;
Hitpiece.effect = new Dropshadoweffect () {Blurradius = 8, shadowdepth = 0, Color =};
else if (hitpiece!= null) {
int oldrow = Grid.getrow (hitpiece);
int oldcolumn = Grid.getcolumn (hitpiece);
Piece Piece = sender as Piece;
int newrow = Grid.getrow (piece);
int newcolumn = Grid.getcolumn (piece);
Grid.setrow (piece, oldrow);
Grid.setcolumn (piece, oldcolumn);
Grid.setrow (Hitpiece, NewRow);
Grid.setcolumn (Hitpiece, Newcolumn);
Hitpiece.effect = null;
Hitpiece = null;
E.handled = true;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.