⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ballctrl.cs

📁 C#开发的运行于windows mobile PDA上的游戏
💻 CS
字号:
////////////////////////////////////////////////
// 
// Project: Lines.NET
// Version: 1.1
// Author:  Vladimir L.
// 
// homepage: http://www.boomsoft.org
// e-mail:   support@boomsoft.org
// 
// Copyright (c) 2003-2004, Boomsoft.org
// 

using System;
using System.Drawing;
using Lines.Core;

namespace Lines.GUI
{
	/// <summary>
	/// This class is a GUI representation of <see cref="Ball"/> class.
	/// </summary>
	/// <remarks>
	/// Ball control is taking care of drawing an object of <see cref="Ball"/> class in .NET Compact Framework
	/// environment including ball jumping phases.
	/// </remarks>
	public class BallCtrl
	{
		/// <summary>
		/// Defines the position and size of ball control on the game main form.
		/// </summary>
		private Rectangle bounds = new Rectangle(0, 0, 0, 0);

		/// <summary>
		/// Holds the reference to an object of <see cref="Core.Ball"/> class, which this control is representing on
		/// the form.
		/// </summary>
		private Ball ball;
		/// <summary>
		/// The jump phase of ball (between 0 and 6).
		/// </summary>
		private int jumpPosition = 0;
		/// <summary>
		/// The reference to the game graphics and color preferences.
		/// </summary>
		private Preferences preferences;

		/// <summary>
		/// Gets the reference to an object of <see cref="Core.Ball"/> class, which this control is taking care of.
		/// </summary>
		public Ball Ball
		{
			get {return ball;}
		}

		/// <summary>
		/// Gets or sets the width of control.
		/// </summary>
		public int Width
		{
			get {return bounds.Width;}
			set {bounds.Width = value;}
		}

		/// <summary>
		/// Gets or sets the height of control.
		/// </summary>
		public int Height
		{
			get {return bounds.Height;}
			set {bounds.Height = value;}
		}

		/// <summary>
		/// Gets or sets the bounds of control.
		/// </summary>
		public Rectangle Bounds
		{
			get {return bounds;}
			set {bounds = value;}
		}

		/// <summary>
		/// Creates an instance of BallCtrl class with reference to an object of <see cref="Core.Ball"/> class.
		/// </summary>
		/// <param name="ball">The reference to the <see cref="Core.Ball"/> object, which this control is 
		/// representing on the game board form.</param>
		/// <param name="preferences">The reference to graphics and color preferences of the game.</param>
		public BallCtrl(Ball ball, Preferences preferences)
		{
			this.ball = ball;
			this.preferences = preferences;
		}

		/// <summary>
		/// Renders the ball on the screen.
		/// </summary>
		/// <param name="e">A <see cref="System.Windows.Forms.PaintEventArgs"/> that contains the 
		/// event data, which is used to render the ball. It is used to get reference to the 
		/// Graphics object.</param>
		public void OnPaint(System.Windows.Forms.PaintEventArgs e)
		{
			Graphics g = e.Graphics;
			Rectangle rect = new Rectangle(bounds.X, bounds.Y, bounds.Width, bounds.Height);
			Brush brush = new SolidBrush(preferences.GetBallColor(Ball.Color));
			Pen pen = new Pen(preferences.GetBallBorderColor(Ball.Color));

			// Background
			g.FillRectangle(new SolidBrush(preferences.FieldBgColor), rect);

			// Ball itself
			rect.Inflate(-3, -3);

			// Draw the ball depending on the select status
			if (ball.Selected)
			{
				switch (jumpPosition)
				{
					case 0:
						break;
					case 1:
						rect.Inflate(0, -1);
						rect.Offset(0, -1);
						break;
					case 2:
						rect.Inflate(0, -1);
						rect.Offset(0, -2);
						break;
					case 3:
						rect.Inflate(0, 0);
						rect.Offset(0, -1);
						break;
					case 4:
						rect.Inflate(0, -1);
						rect.Offset(0, +1);
						break;
					case 5:
						rect.Inflate(0, -1);
						rect.Offset(0, +2);
						break;
					case 6:
						rect.Inflate(0, -1);
						rect.Offset(0, +1);
						break;
				}
			} 
			
			g.FillEllipse(brush, rect);
			g.DrawEllipse(pen, rect);
		}

		/// <summary>
		/// Cyclically increments the jumping phase of this ball from 0 to 6.
		/// </summary>
		public void NexJumpPosition()
		{
			jumpPosition++;
			jumpPosition = (jumpPosition > 5) ? 0 : jumpPosition + 1;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -