您好,欢迎访问三七文档
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Drawing.Drawing2D;usingSystem.Threading;namespaceG{publicpartialclassForm1:Form{publicstaticintk=0;privateGraphicsPathMyPath0;privateGraphicsPathMyPath1;privateGraphicsPathMyPath2;privateGraphicsPathMyPath3;privateRectangleMyRectangle;privateboolBMyPath0=false;privateboolBMyPath1=false;privateboolBMyPath2=false;privateboolBMyPath3=false;BrushMyHiBrushm=Brushes.Wheat;BrushMyHiBrush=Brushes.Yellow;BrushMyBrush0=Brushes.Red;BrushMyBrush1=Brushes.Green;BrushMyBrush3=Brushes.Black;BrushMyBrush2=Brushes.White;publicForm1(){InitializeComponent();}privatevoidForm1_Load(objectsender,EventArgse){MyRectangle=newRectangle(140,180,20,20);MyPath0=newGraphicsPath();MyPath1=newGraphicsPath();MyPath2=newGraphicsPath();MyPath3=newGraphicsPath();MessageBox.Show(当横纵坐标都在140和180之间时你就赢了!!\n祝你好运!!);floata=150,b=140,c=5,d=5;for(inti=0;i280;i++){if(i%4==0)MyPath0.AddEllipse(a,b,c,d);if(i%4==1)MyPath1.AddEllipse(a,b,c,d);if(i%4==2)MyPath2.AddEllipse(a,b,c,d);if(i%4==3)MyPath3.AddEllipse(a,b,c,d);a=a-0.5f;b=b-0.5f;c=c+1;d=d+1;}}privatevoidForm1_Paint(objectsender,PaintEventArgse){Graphicsg=e.Graphics;g.FillRectangle(MyHiBrushm,MyRectangle);//g.FillPath(MyBrush0,MyPath0);g.FillPath(MyBrush0,MyPath0);g.FillPath(MyBrush1,MyPath1);g.FillPath(MyBrush2,MyPath2);g.FillPath(MyBrush3,MyPath3);}privatevoidForm1_MouseMove(objectsender,MouseEventArgse){if(k%2==0){Graphicsg=this.CreateGraphics();if(MyPath0.IsVisible(e.X,e.Y)){if(!BMyPath0){BMyPath0=true;g.FillPath(MyHiBrush,MyPath0);g.DrawPath(Pens.Black,MyPath0);if(e.X=140&&e.X=180&&e.Y=140&&e.Y=180)MessageBox.Show(哈哈你赢了!!);MessageBox.Show(横+e.X.ToString()+纵+e.Y.ToString());}}elseif(BMyPath0){BMyPath0=false;g.FillPath(MyBrush0,MyPath0);g.DrawPath(Pens.Black,MyPath0);}elseif(MyPath1.IsVisible(e.X,e.Y)){if(!BMyPath1){BMyPath1=true;g.FillPath(MyHiBrush,MyPath1);g.DrawPath(Pens.Black,MyPath1);if(e.X=140&&e.X=180&&e.Y=140&&e.Y=180)MessageBox.Show(哈哈你赢了!!);MessageBox.Show(横+e.X.ToString()+纵+e.Y.ToString());}}elseif(BMyPath1){BMyPath1=false;g.FillPath(MyBrush1,MyPath1);g.DrawPath(Pens.Black,MyPath1);}elseif(MyPath2.IsVisible(e.X,e.Y)){if(!BMyPath2){BMyPath2=true;g.FillPath(MyHiBrush,MyPath2);g.DrawPath(Pens.Black,MyPath2);if(e.X=140&&e.X=180&&e.Y=140&&e.Y=180)MessageBox.Show(哈哈你赢了!!);MessageBox.Show(横+e.X.ToString()+纵+e.Y.ToString());}}elseif(BMyPath2){BMyPath2=false;g.FillPath(MyBrush2,MyPath2);g.DrawPath(Pens.Black,MyPath2);}elseif(MyPath3.IsVisible(e.X,e.Y)){if(!BMyPath3){BMyPath3=true;g.FillPath(MyHiBrush,MyPath3);g.DrawPath(Pens.Black,MyPath3);if(e.X=140&&e.X=180&&e.Y=140&&e.Y=180)MessageBox.Show(哈哈你赢了!!);MessageBox.Show(横+e.X.ToString()+纵+e.Y.ToString());}}elseif(BMyPath3){BMyPath3=false;g.FillPath(MyBrush3,MyPath3);g.DrawPath(Pens.Black,MyPath3);}g.Dispose();}}privatevoidForm1_MouseClick(objectsender,MouseEventArgse){if(k%2==1){Graphicsg=this.CreateGraphics();if(MyPath0.IsVisible(e.X,e.Y)){if(!BMyPath0){BMyPath0=true;g.FillPath(MyHiBrush,MyPath0);g.DrawPath(Pens.Black,MyPath0);if(e.X=140&&e.X=180&&e.Y=140&&e.Y=180)MessageBox.Show(哈哈你赢了!!);MessageBox.Show(横+e.X.ToString()+纵+e.Y.ToString());}}elseif(BMyPath0){BMyPath0=false;g.FillPath(MyBrush0,MyPath0);g.DrawPath(Pens.Black,MyPath0);if(e.X=140&&e.X=180&&e.Y=140&&e.Y=180)MessageBox.Show(哈哈你赢了!!);MessageBox.Show(横+e.X.ToString()+纵+e.Y.ToString());}elseif(MyPath1.IsVisible(e.X,e.Y)){if(!BMyPath1){BMyPath1=true;g.FillPath(MyHiBrush,MyPath1);g.DrawPath(Pens.Black,MyPath1);if(e.X=140&&e.X=180&&e.Y=140&&e.Y=180)MessageBox.Show(哈哈你赢了!!);MessageBox.Show(横+e.X.ToString()+纵+e.Y.ToString());}}elseif(BMyPath1){BMyPath1=false;g.FillPath(MyBrush1,MyPath1);g.DrawPath(Pens.Black,MyPath1);if(e.X=140&&e.X=180&&e.Y=140&&e.Y=180)MessageBox.Show(哈哈你赢了!!);MessageBox.Show(横+e.X.ToString()+纵+e.Y.ToString());}elseif(MyPath2.IsVisible(e.X,e.Y)){if(!BMyPath2){BMyPath2=true;g.FillPath(MyHiBrush,MyPath2);g.DrawPath(Pens.Black,MyPath2);if(e.X=140&&e.X=180&&e.Y=140&&e.Y=180)MessageBox.Show(哈哈你赢了!!);MessageBox.Show(横+e.X.ToString()+纵+e.Y.ToString());}}elseif(BMyPath2){BMyPath2=false;g.FillPath(MyBrush2,MyPath2);g.DrawPath(Pens.Black,MyPath2);if(e.X=140&&e.X=180&&e.Y=140&&e.Y=180)MessageBox.Show(哈哈你赢了!!);MessageBox.Show(横+e.X.ToString()+纵+e.Y.ToString());}elseif(MyPath3.IsVisible(e.X,e.Y)){if(!BMyPath3){BMyPath3=true;g.FillPath(MyHiBrush,MyPath3);g.DrawPath(Pens.Black,MyPath3);if(e.X=140&&e.X=180&&e.Y=140&&e.Y=180)MessageBox.Show(哈哈你赢了!!);MessageBox.Show(横+e.X.ToString()+纵+e.Y.ToString());}}elseif(BMyPath3){BMyPath3=false;g.FillPath(MyBrush3,MyPath3);g.DrawPath(Pens.Black,MyPath3);if(e.X=140&&e.X=180&&e.Y=140&&e.Y=180)MessageBox.Show(哈哈你赢了!!);MessageBox.Show(横+e.X.ToString()+纵+e.Y.ToString());}g.Dispose();}}privatevoidbutton1_Click(objectsender,EventArgse){button2.Enabled=true;button1.Enabled=false;k=k+1;}privatevoidbutton2_Click(objectsender,EventArgse){button1.Enabled=tru
本文标题:用C#编写游戏
链接地址:https://www.777doc.com/doc-2944554 .html