Block.cs :  » Game » SDL » SdlDotNetExamples » Triad » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Game » SDL 
SDL » SdlDotNetExamples » Triad » Block.cs
#region LICENSE
//*****************************************************************************
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//  
//  Created by Michael Rosario
//  July 29th,2003
//  Contact me at mrosario@scrypt.net  
//*****************************************************************************
#endregion LICENSE

using System;
using System.IO;
using System.Drawing;

using SdlDotNet.Graphics;
using SdlDotNetExamples.LargeDemos;

namespace SdlDotNetExamples.Triad{
    /// <summary>
    /// 
    /// </summary>
    public class Block : GameObject, System.IDisposable
    {
        /// <summary>
        /// 
        /// </summary>
        public const int BlockWidth = 36;
        /// <summary>
        /// 
        /// </summary>
        public readonly static Size BlockSize =
            new System.Drawing.Size(BlockWidth, BlockWidth);

        BlockType blockType;
        /// <summary>
        /// 
        /// </summary>
        public BlockType TypeOfBlock
        {
            set
            {
                blockType = value;
            }

            get
            {
                return blockType;
            }

        }

        static Random random;

        /// <summary>
        /// 
        /// </summary>
        public Block()
        {
            this.Size = BlockSize;

            if (random == null)
            {
                random = new Random(DateTime.Now.Millisecond);
            }

            blockType = (BlockType)random.Next(5);
        }

        private int gridX;
        /// <summary>
        /// 
        /// </summary>
        public int GridX
        {
            get
            {
                return gridX;
            }
            set
            {
                gridX = value;
            }
        }

        private int gridY;
        /// <summary>
        /// 
        /// </summary>
        public int GridY
        {
            get
            {
                return gridY;
            }
            set
            {
                gridY = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public Point GridLocation
        {
            get
            {
                return new Point(gridX, gridY);
            }
            set
            {
                gridX = value.X;
                gridY = value.Y;
            }

        }

        private bool destroy;

        /// <summary>
        /// 
        /// </summary>
        public bool Destroy
        {
            get
            {
                return destroy;
            }
            set
            {
                destroy = value;
            }
        }

        static Surface redBlock;

        static Surface getRedBlock()
        {
            if (redBlock == null)
            {
                Bitmap bmp = new System.Drawing.Bitmap(Path.Combine(Path.Combine(TriadMain.FilePath, TriadMain.FileDirectory), "redBlock.bmp"));
                redBlock = new Surface(bmp);
            }
            return redBlock;
        }

        static Surface whiteBlock;

        static Surface getWhiteBlock()
        {
            if (whiteBlock == null)
            {
                Bitmap bmp = new System.Drawing.Bitmap(Path.Combine(Path.Combine(TriadMain.FilePath, TriadMain.FileDirectory), "whiteBlock.bmp"));
                whiteBlock = new Surface(bmp);
            }
            return whiteBlock;
        }

        static Surface yellowBlock;

        static Surface getYellowBlock()
        {
            if (yellowBlock == null)
            {
                Bitmap bmp = new System.Drawing.Bitmap(Path.Combine(Path.Combine(TriadMain.FilePath, TriadMain.FileDirectory), "yellowBlock.bmp"));
                yellowBlock = new Surface(bmp);
            }
            return yellowBlock;
        }

        static Surface purpleBlock;

        static Surface getPurpleBlock()
        {
            if (purpleBlock == null)
            {
                Bitmap bmp = new System.Drawing.Bitmap(Path.Combine(Path.Combine(TriadMain.FilePath, TriadMain.FileDirectory), "purpleBlock.bmp"));
                purpleBlock = new Surface(bmp);
            }
            return purpleBlock;
        }

        static Surface blueBlock;
        static Surface getBlueBlock()
        {
            if (blueBlock == null)
            {
                Bitmap bmp = new System.Drawing.Bitmap(Path.Combine(Path.Combine(TriadMain.FilePath, TriadMain.FileDirectory), "blueBlock.bmp"));
                blueBlock = new Surface(bmp);
            }
            return blueBlock;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="surface"></param>
        protected override void DrawGameObject(Surface surface)
        {
            Surface image;

            switch (blockType)
            {
                case BlockType.Purple: image = Block.getPurpleBlock(); break;
                case BlockType.Red: image = Block.getRedBlock(); break;
                case BlockType.White: image = Block.getWhiteBlock(); break;
                case BlockType.Yellow: image = Block.getYellowBlock(); break;
                case BlockType.Blue: image = Block.getBlueBlock(); break;
                default: image = Block.getBlueBlock(); break;
            }

            if (!this.Destroy)
            {
                if (image != null)
                {
                    surface.Blit(image, this.ScreenRectangle);
                }
            }
            else
            {
                surface.Fill(this.ScreenRectangle, Color.SlateGray);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public override void Update()
        {
        }

        #region IDisposable Members

        private bool disposed;

        /// <summary>
        /// Destroy sprite
        /// </summary>
        /// <param name="disposing">If true, remove all unamanged resources</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    this.Parent = null;
                    GC.SuppressFinalize(this);
                }
                this.disposed = true;
            }
        }
        /// <summary>
        /// Destroy object
        /// </summary>
        public void Dispose()
        {
            this.Dispose(true);
        }

        /// <summary>
        /// Destroy object
        /// </summary>
        public void Close()
        {
            Dispose();
        }

        /// <summary>
        /// Destroy object
        /// </summary>
        ~Block()
        {
            Dispose(false);
        }
        #endregion

    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.