/// <summary> /// 在游戏区中话棋盘 /// </summary> private void DrawChess() { Graphics g = GameZone.CreateGraphics(); GameZone.BackColor = m_clsBackColor; // 背景颜色 if (m_bFirstDraw) { g.Clear(GameZone.BackColor);//用背景色清空 } Pen pen = new Pen(Color.BlanchedAlmond); int nHeight = GameZone.Height; int nWide = GameZone.Width; int nPerHeight = nHeight / m_nRowCount; int nPerWidth = nWide / m_nRowCount; for (int i = 0; i < m_nRowCount; i++) { Point p1 = new Point(0, i * nPerHeight); Point p2 = new Point(nWide, i * nPerHeight); g.DrawLine(pen, p1, p2); Point p3 = new Point(i * nPerWidth, 0); Point p4 = new Point(i * nPerWidth, nHeight); g.DrawLine(pen, p3, p4); } g.Dispose(); }
private void ClearRectangle(int x, int y) { int width = GameZone.Width / m_nRowCount; int height = GameZone.Height / m_nRowCount; Graphics graphics = GameZone.CreateGraphics(); graphics.FillRectangle(new SolidBrush(GameZone.BackColor), x * width + 1, y * height + 1, width - 2, height - 2); graphics.Dispose(); }
/// <summary> /// 游戏初始化:画棋盘、背景填充、初始化分数、标记球背景 /// </summary> public void GameInit() { m_nCurScore = 0; m_bFirstDraw = true; m_nMaxScore = ScoreManager.GetMaxHistoryScore(); GameZone.BackColor = m_clsBackColor; // 背景初始化为灰色 MaxScoreLable.Text = "最高分:" + m_nMaxScore; // 历史最大分数 ScoreLable.Text = "分数:" + m_nCurScore; // 当前分数 ZoomTimer.Enabled = false; Graphics g = GameZone.CreateGraphics(); g.Clear(GameZone.BackColor); }
private void GameZone_MouseMove(object sender, MouseEventArgs e) { Graphics graphics = GameZone.CreateGraphics(); int x = e.X / (GameZone.Width / m_nRowCount); int y = e.Y / (GameZone.Height / m_nRowCount); if (m_nLastX != -1 && m_nLastY != -1) { graphics.DrawRectangle(new Pen(Color.BlanchedAlmond), m_nLastX * (GameZone.Width / m_nRowCount), m_nLastY * (GameZone.Width / m_nRowCount), GameZone.Width / m_nRowCount, GameZone.Height / m_nRowCount); } graphics.DrawRectangle(new Pen(Color.Red), x * (GameZone.Width / m_nRowCount), y * (GameZone.Width / m_nRowCount), GameZone.Width / m_nRowCount, GameZone.Height / m_nRowCount); m_nLastX = x; m_nLastY = y; graphics.Dispose(); }
private void DrawBall(int x, int y, Color color, int nDrx = 0) { Graphics graphics = GameZone.CreateGraphics(); graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; Bitmap bitmap = (Bitmap)manager.GetObject(color.ToString().Substring(7).Replace("]", "")); if (bitmap != null) { graphics.DrawImage(bitmap, GameZone.Width * x / m_nRowCount + nDrx + 1, GameZone.Height * y / m_nRowCount + nDrx + 1, GameZone.Width / m_nRowCount - nDrx * 2 - 2, GameZone.Height / m_nRowCount - nDrx * 2 - 2); } graphics.Dispose(); }
/// <summary> /// 播放选中音乐并对球进行缩放或移动 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GameZone_MouseClick(object sender, MouseEventArgs e) { int width = GameZone.Width / m_nRowCount; int height = GameZone.Height / m_nRowCount; int x = e.X / width; int y = e.Y / height; // 如果选择的是空的,则移动到目标地点 if (balls[x, y] == GameZone.BackColor) { ZoomTimer.Enabled = false; List <Point> path = new List <Point>(); if (m_nMoveX != -1 && m_nMoveY != -1 && SearchPath(ref path, new Point(x, y), new Point(m_nMoveX, m_nMoveY))) // 有待移动的球 { balls[x, y] = balls[m_nMoveX, m_nMoveY]; balls[m_nMoveX, m_nMoveY] = GameZone.BackColor; ClearRectangle(m_nMoveX, m_nMoveY); m_nMoveX = -1; m_nMoveY = -1; UpdateNextBallColor(); // 先更新next RandomNextColors(false); DrawBalls(); if (CheckSucces(x, y)) { Forms.SaveScoreForm saveScoreForm = new Forms.SaveScoreForm(m_nCurScore, this); saveScoreForm.Show(); ZoomTimer.Enabled = false; } } return; } else { //// 已经选中了一个,则交换 //if (m_nMoveX != -1 && m_nMoveY != -1) //{ // Color tmp = balls[m_nMoveX, m_nMoveY]; // balls[m_nMoveX, m_nMoveY] = balls[x, y]; // balls[x, y] = tmp; // DrawBalls(); //} // 对选中的进行缩放 ClearRectangle(x, y); Bitmap bitmap = (Bitmap)manager.GetObject(balls[x, y].ToString().Substring(7).Replace("]", "")); Graphics graphics = GameZone.CreateGraphics(); graphics.DrawImage(bitmap, x * width + 5, y * height + 5, width - 10, height - 10); graphics.Dispose(); m_nMoveX = x; m_nMoveY = y; if (CheckSucces(m_nMoveX, m_nMoveY)) { ZoomTimer.Enabled = false; } ZoomTimer.Enabled = true; } playAudio("MoveStart.wav"); if (IsGameOver()) { m_bIsGameOver = true; } }