.NET
  Home arrow .NET arrow Page 13 - Game Development of .Nettrix: GDI+ and Col...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBMฎ developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
.NET

Game Development of .Nettrix: GDI+ and Collision Detection
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    2004-08-23

    Table of Contents:
  • Game Development of .Nettrix: GDI+ and Collision Detection
  • Performing Graphic Operations with a Graphics Object
  • Creating Gradients
  • Collision Detection
  • Proximity Algorithms
  • Optimizing the Number of Calculations
  • Extending the Algorithms to Add a Third Dimension
  • Develop a Real Game Proposal
  • Diagrams of Basic Game Objects
  • The Game Engine
  • The Coding Phase
  • Testing the Program
  • The Block Class
  • The Constructor
  • The Down, Right, and Left Methods
  • The Rotate Method
  • The Show and Hide Methods
  • Final Version: Coding the GameField Class and the Game Engine
  • The CheckLines Method
  • The Game Engine
  • Adding the Final Touches
  • Further Improvements

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Game Development of .Nettrix: GDI+ and Collision Detection - The Block Class


    (Page 13 of 22 )

    Second Draft: Coding the Block Class

    You can map the Block class, defined in the class diagram created for your game project, to the final class interface, including the data types for the properties and parameters for the methods. The proposed class interface is shown in the next code listing:

    public class Block {
      // The four squares that compose a block
      public Square square1;
      public Square square2;
      public Square square3;
      public Square square4;
      private const int squareSize = GameField.SquareSize;

      public Block(Point location, BlockTypes newBlockType)
    {…}
      public bool Down() {…}
      public bool Right() {…}
      public bool Left() {…}

      public void Rotate() {…}
      public void Show(System.IntPtr WinHandle) {…}
      public void Hide(System.IntPtr WinHandle) {…}
    }

    In the game proposal, we said that the blocks will be composed of four squares (in every possible arrangement). You can start the coding by thinking about the possible combinations, and give each of them a name, as shown in Figure 1-24.


    Figure 1-24. The square arrangements to form each block

    Because each block will have a specific square combination, you can think of three new elements for your class: a BlockType property, an enumeration for the block types, and a constructor that creates the squares in the desired positions and the color of each square. To give a visual clue to the player, the colors must be fixed for each block type, so it’s a good idea to create arrays to hold the forecolor and backcolor for each type. The extra definitions for the class are shown in the next code listing:

    public enum BlockTypes {
      Undefined = 0, 
      Square = 1, 
      Line = 2, 
      J = 3,
      L = 4,
      T = 5,
      Z = 6,
      S = 7

    };
    public BlockTypes BlockType;

    // The colors of each block type
    private Color[] backColors = {Color.Empty, Color.Red,
      Color.Blue, Color.Red, Color.Yellow, Color.Green,
      Color.White, Color.Black};
    private Color[] foreColors = {Color.Empty, Color.Purple,
      Color.LightBlue, Color.Yellow,
      Color.Red, Color.LightGreen,Color.Black, Color.White};

    More .NET Articles
    More By Apress Publishing


       · Examples from the first page are invalid. You cannot do:Graphics g = new...
     

    .NET ARTICLES

    - Building Applications with Windows Workflow ...
    - Building the Data and Business Layers Using ...
    - The Transformed XML Explorer in MFC
    - List Control and Property Grid with the MFC ...
    - Font, Shell and Masked Edit Controls for MFC
    - Color, Link and Image Editor Controls for M...
    - New Controls for MFC
    - The Windows Ribbon Framework
    - Markup Language for the Ribbon Framework
    - Visually Upgrade Your MFC Project
    - New Features for the Statusbar in MFC
    - Working with the Statusbar in MFC
    - Iron Speed Design v60 Review
    - Binary and XML Serialization
    - Using CrystalReportViewer to Display Crystal...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek