我要知道博客技术分享

C#玩4张纸牌小游戏


Card类

public class Card { private Graphics _gpPalette; public Graphics gpPalette { get { return _gpPalette; } set { _gpPalette = value; } } public Color disapperColor { get { switch (this._flower) { case Flower.Square: case Flower.Hearts: return Color.Red; case Flower.Spade: case Flower.Flower: return Color.Black; default: return Color.Black; } } } private Point _point; public Point point { get { return _point; } set { _point = value; } } private Flower _flower; public Flower flower { get { return _flower; } set { _flower = value; } } public Card (Point point,Flower flower ) { this._point = point; this._flower = flower; } public virtual void Paint ( ) { if (_gpPalette != null) { _gpPalette.Clear (Color.White); SolidBrush sbDisplay = new SolidBrush (disapperColor); FontFamily fontFamily = new FontFamily ("宋体"); Font font = new Font (fontFamily, 25); PointF pointF = new PointF ( ); _gpPalette.DrawString (this.ToString ( ), font, sbDisplay, pointF); } } public virtual void Paint (Graphics gp ) { if (gp != null) { gp.Clear (Color.White); SolidBrush sbDisplay = new SolidBrush (disapperColor); FontFamily fontFamily = new FontFamily ("宋体"); Font font = new Font (fontFamily, 25); PointF pointF = new PointF ( ); gp.DrawString (this.ToString ( ), font, sbDisplay, pointF); } } public override string ToString ( ) { string strFlowerCode = string.Empty; string strPointCode = string.Empty; switch (this._flower) { case Flower.Square: strFlowerCode = "◆"; break; case Flower.Hearts: strFlowerCode = "♥"; break; case Flower.Spade: strFlowerCode = "♠"; break; case Flower.Flower: strFlowerCode = "♣"; break; default: break; } switch (this._point) { case Point.J: case Point.Q: case Point.K: case Point.A: strPointCode = this._point.ToString ( ); break; case Point.Two: case Point.Three: case Point.Four: case Point.Five: case Point.Six: case Point.Seven: case Point.Eight: case Point.Nine: case Point.Ten: strPointCode = ((int) _point).ToString ( ); break; default: break; } return string.Format ("{0}\n{1}", strPointCode, strFlowerCode); } }

  Flower类:

 public enum Flower:short
    {
        /// <summary>
        /// 方块
        /// </summary>
        Square=1,

        /// <summary>
        /// 红桃
        /// </summary>
        Hearts=2,

        /// <summary>
        /// 黑桃
        /// </summary>
        Spade=3,

        /// <summary>
        /// 花
        /// </summary>
        Flower=4
    }

  Form2窗体类文件

  partial class Form2
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose ( bool disposing )
        {
            if (disposing && (components != null))
            {
                components.Dispose ( );
            }
            base.Dispose (disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent ( )
        {
            this.btnReflesh = new System.Windows.Forms.Button ( );
            this.pbFourth = new System.Windows.Forms.PictureBox ( );
            this.pbThird = new System.Windows.Forms.PictureBox ( );
            this.pbSecond = new System.Windows.Forms.PictureBox ( );
            this.pbFirst = new System.Windows.Forms.PictureBox ( );
            ((System.ComponentModel.ISupportInitialize) (this.pbFourth)).BeginInit ( );
            ((System.ComponentModel.ISupportInitialize) (this.pbThird)).BeginInit ( );
            ((System.ComponentModel.ISupportInitialize) (this.pbSecond)).BeginInit ( );
            ((System.ComponentModel.ISupportInitialize) (this.pbFirst)).BeginInit ( );
            this.SuspendLayout ( );
            // 
            // btnReflesh
            // 
            this.btnReflesh.Location = new System.Drawing.Point (323, 178);
            this.btnReflesh.Name = "btnReflesh";
            this.btnReflesh.Size = new System.Drawing.Size (75, 23);
            this.btnReflesh.TabIndex = 4;
            this.btnReflesh.Text = "重发";
            this.btnReflesh.UseVisualStyleBackColor = true;
            this.btnReflesh.Click += new System.EventHandler (this.btnReflesh_Click);
            // 
            // pbFourth
            // 
            this.pbFourth.BackColor = System.Drawing.Color.White;
            this.pbFourth.Location = new System.Drawing.Point (330, 35);
            this.pbFourth.Name = "pbFourth";
            this.pbFourth.Size = new System.Drawing.Size (68, 95);
            this.pbFourth.TabIndex = 3;
            this.pbFourth.TabStop = false;
            this.pbFourth.Paint += new System.Windows.Forms.PaintEventHandler (this.pbFourth_Paint);
            // 
            // pbThird
            // 
            this.pbThird.BackColor = System.Drawing.Color.White;
            this.pbThird.Location = new System.Drawing.Point (233, 35);
            this.pbThird.Name = "pbThird";
            this.pbThird.Size = new System.Drawing.Size (68, 95);
            this.pbThird.TabIndex = 2;
            this.pbThird.TabStop = false;
            this.pbThird.Paint += new System.Windows.Forms.PaintEventHandler (this.pbThird_Paint);
            // 
            // pbSecond
            // 
            this.pbSecond.BackColor = System.Drawing.Color.White;
            this.pbSecond.Location = new System.Drawing.Point (136, 35);
            this.pbSecond.Name = "pbSecond";
            this.pbSecond.Size = new System.Drawing.Size (68, 95);
            this.pbSecond.TabIndex = 1;
            this.pbSecond.TabStop = false;
            this.pbSecond.Paint += new System.Windows.Forms.PaintEventHandler (this.pbSecond_Paint);
            // 
            // pbFirst
            // 
            this.pbFirst.BackColor = System.Drawing.Color.White;
            this.pbFirst.Location = new System.Drawing.Point (39, 35);
            this.pbFirst.Name = "pbFirst";
            this.pbFirst.Size = new System.Drawing.Size (68, 95);
            this.pbFirst.TabIndex = 0;
            this.pbFirst.TabStop = false;
            this.pbFirst.Paint += new System.Windows.Forms.PaintEventHandler (this.pbFirst_Paint);
            // 
            // Form2
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF (6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size (441, 213);
            this.Controls.Add (this.btnReflesh);
            this.Controls.Add (this.pbFourth);
            this.Controls.Add (this.pbThird);
            this.Controls.Add (this.pbSecond);
            this.Controls.Add (this.pbFirst);
            this.Name = "Form2";
            this.Text = "Form2";
            this.Load += new System.EventHandler (this.Form2_Load);
            ((System.ComponentModel.ISupportInitialize) (this.pbFourth)).EndInit ( );
            ((System.ComponentModel.ISupportInitialize) (this.pbThird)).EndInit ( );
            ((System.ComponentModel.ISupportInitialize) (this.pbSecond)).EndInit ( );
            ((System.ComponentModel.ISupportInitialize) (this.pbFirst)).EndInit ( );
            this.ResumeLayout (false);

        }

        #endregion

        private System.Windows.Forms.Button btnReflesh;
        private System.Windows.Forms.PictureBox pbFourth;
        private System.Windows.Forms.PictureBox pbThird;
        private System.Windows.Forms.PictureBox pbSecond;
        private System.Windows.Forms.PictureBox pbFirst;
    }
}

  

posted @ 2012-11-19 17:21  mylove温纯  阅读(612)  评论(1编辑  收藏  举报
我要知道 Copyright ©2011-2015 mylove温纯