indicatorctrl.cs
来自「C#开发的运行于windows mobile PDA上的游戏」· CS 代码 · 共 95 行
CS
95 行
////////////////////////////////////////////////
//
// 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>
/// Represents the game status indicator on the screen.
/// </summary>
/// <remarks>
/// This control renders the game status on the top of the board and displays players score, current step,
/// and colors of new balls that will occur on the board next step.
/// </remarks>
public class IndicatorCtrl : GenericCtrl
{
/// <summary>
/// Creates an instance of control.
/// </summary>
public IndicatorCtrl()
{
}
/// <summary>
/// Renders the control on the screen.
/// </summary>
/// <param name="e">Used to get reference to the Graphics object.</param>
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
// Draw frame
Graphics g = e.Graphics;
Rectangle box = new Rectangle(0, 0, this.Width - 1, this.Height - 1);
g.FillRectangle(new SolidBrush(Preferences.IndicatorCtrlBgColor), box);
// Exit if Game isn't defined
if (Game == null) return;
Pen fieldPen = new Pen(Preferences.IndicatorFgColor);
int padding = (this.Width - GetCellSize() * Game.BallsPerStep) / 2;
// Balls
Rectangle cellRect = new Rectangle(padding, 1, GetCellSize(), GetCellSize());
Rectangle ballRect = cellRect;
ballRect.Inflate(-2, -2);
if (Game.VirtualBalls != null)
{
Ball[] balls = Game.VirtualBalls;
for (int i = 0; i < balls.Length; i++)
{
g.FillRectangle(new SolidBrush(Preferences.IndicatorBgColor), cellRect);
g.DrawRectangle(fieldPen, cellRect);
g.FillEllipse(new SolidBrush(Preferences.GetBallColor(balls[i].Color)), ballRect);
g.DrawEllipse(new Pen(Preferences.GetBallBorderColor(balls[i].Color)), ballRect);
cellRect.Offset(GetCellSize(), 0);
ballRect.Offset(GetCellSize(), 0);
}
}
// Step indicator
float fontSizePx = GetCellSize() - 5;
float fontSizePt = fontSizePx * AppSettings.Instance.FactorPxToPt;
Brush textBrush = new SolidBrush(Preferences.IndicatorTextColor);
Font font = new Font(FontFamily.GenericSansSerif, fontSizePt, FontStyle.Bold);
RectangleF textRect = new RectangleF(3, 1, padding - 6, this.Height - 2);
g.DrawString("Step: " + Game.StepCount, font, textBrush, textRect);
// Score indicator
textRect = new RectangleF(this.Width - padding + 3, 1, padding - 6, this.Height - 2);
g.DrawString("Score: " + Game.Score, font, textBrush, textRect);
}
/// <summary>
/// Reterns the size of a square to display incoming balls.
/// </summary>
/// <returns>The size in pixels of a square to display incoming balls.</returns>
private int GetCellSize()
{
return this.Height - 5;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?