/*
* Created by SharpDevelop.
* User: stud
* Date: 13.06.2008
* Time: 11:46
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Collections;
namespace guki
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
guk_h f=new guk_h();
Button [] frut= new Button[2000];
public System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
Random r = new Random(DateTime.Now.Millisecond);
struct Line
{
public Point p1;
public Point p2;
}
int kolfrut=0;
int i=0;
int xPos,yPos;
int xPosPen=0,yPosPen=0;
Line L;
bool PenIf=false;
Pen p=new Pen(Color.OliveDrab,5);
private List<Line> myLines=new List<Line>();
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
void Guk_buttonKeyPress(object sender, KeyPressEventArgs e)
{
xPos=guk_button.Location.X;
yPos=guk_button.Location.Y;
Graphics g=Graphics.FromHwnd(this.Handle);
if(e.KeyChar==32)
{
{
if(PenIf==false)
{
PenIf=true;
xPosPen=guk_button.Location.X;
yPosPen=guk_button.Location.Y;
}
else
{
PenIf=false;
xPosPen=0;
yPosPen=0;
myLines.Clear();
Invalidate();
}
}
}
if(e.KeyChar==115)
{
if(xPos>=10 && xPos<=790 && yPos>=10 && yPos<=480)
{
guk_button.Location=new Point(xPos,yPos+10);
if(PenIf==true)
{
g.DrawLine(p,xPos,yPos,xPos,yPos+10);
L.p1.X=xPos;
L.p1.Y=yPos;
L.p2.X=xPos;
L.p2.Y=yPos+10;
myLines.Add(L);
path.AddLine(L.p1.X,L.p1.Y,L.p2.X,L.p2.Y);
PereLine(L.p2.X,L.p2.Y,xPosPen,yPosPen);
}
}
}
if(e.KeyChar==119)
{
if(xPos>=10 && xPos<=790 && yPos>=30 && yPos<=490)
{
guk_button.Location=new Point(xPos,yPos-10);
if(PenIf==true)
{
g.DrawLine(p,xPos,yPos,xPos,yPos-10);
L.p1.X=xPos;
L.p1.Y=yPos;
L.p2.X=xPos;
L.p2.Y=yPos-10;
myLines.Add(L);
path.AddLine(L.p1.X,L.p1.Y,L.p2.X,L.p2.Y);
PereLine(L.p2.X,L.p2.Y,xPosPen,yPosPen);
}
}
}
if(e.KeyChar==97)
{
if(xPos>=20 && xPos<=790 && yPos>=10 && yPos<=490)
{
guk_button.Location=new Point(xPos-10,yPos);
if(PenIf==true)
{
g.DrawLine(p,xPos,yPos,xPos-10,yPos);
L.p1.X=xPos;
L.p1.Y=yPos;
L.p2.X=xPos-10;
L.p2.Y=yPos;
myLines.Add(L);
path.AddLine(L.p1.X,L.p1.Y,L.p2.X,L.p2.Y);
PereLine(L.p2.X,L.p2.Y,xPosPen,yPosPen);
}
}
}
if(e.KeyChar==100)
{
if(xPos>=10 && xPos<=780 && yPos>=10 && yPos<=490)
{
guk_button.Location=new Point(xPos+10,yPos);
if(PenIf==true)
{
PereLine(xPos,yPos,xPos+10,yPos);
g.DrawLine(p,xPos,yPos,xPos+10,yPos);
L.p1.X=xPos;
L.p1.Y=yPos;
L.p2.X=xPos+10;
L.p2.Y=yPos;
myLines.Add(L);
path.AddLine(L.p1.X,L.p1.Y,L.p2.X,L.p2.Y);
PereLine(L.p2.X,L.p2.Y,xPosPen,yPosPen);
}
}
}
if(e.KeyChar==113)
{
if(xPos>=20 && xPos<=790 && yPos>=20 && yPos<=490)
{
guk_button.Location=new Point(xPos-10,yPos-10);
if(PenIf==true)
{
g.DrawLine(p,xPos,yPos,xPos-10,yPos-10);
L.p1.X=xPos;
L.p1.Y=yPos;
L.p2.X=xPos-10;
L.p2.Y=yPos-10;
myLines.Add(L);
path.AddLine(L.p1.X,L.p1.Y,L.p2.X,L.p2.Y);
PereLine(L.p2.X,L.p2.Y,xPosPen,yPosPen);
}
}
}
if(e.KeyChar==101)
{
if(xPos>=10 && xPos<=780 && yPos>=20 && yPos<=490)
{
guk_button.Location=new Point(xPos+10,yPos-10);
if(PenIf==true)
{
g.DrawLine(p,xPos,yPos,xPos+10,yPos-10);
L.p1.X=xPos;
L.p1.Y=yPos;
L.p2.X=xPos+10;
L.p2.Y=yPos-10;
myLines.Add(L);
path.AddLine(L.p1.X,L.p1.Y,L.p2.X,L.p2.Y);
PereLine(L.p2.X,L.p2.Y,xPosPen,yPosPen);
}
}
}
if(e.KeyChar==122)
{
if(xPos>=20 && xPos<=790 && yPos>=10 && yPos<=480)
{
guk_button.Location=new Point(xPos-10,yPos+10);
if(PenIf==true)
{
g.DrawLine(p,xPos,yPos,xPos-10,yPos+10);
L.p1.X=xPos;
L.p1.Y=yPos;
L.p2.X=xPos-10;
L.p2.Y=yPos+10;
myLines.Add(L);
path.AddLine(L.p1.X,L.p1.Y,L.p2.X,L.p2.Y);
PereLine(L.p2.X,L.p2.Y,xPosPen,yPosPen);
}
}
}
if(e.KeyChar==99)
{
if(xPos>=10 && xPos<=780 && yPos>=10 && yPos<=480)
{
guk_button.Location=new Point(xPos+10,yPos+10);
if(PenIf==true)
{
PereLine(xPos,yPos,xPos+10,yPos+10);
g.DrawLine(p,xPos,yPos,xPos+10,yPos+10);
L.p1.X=xPos;
L.p1.Y=yPos;
L.p2.X=xPos+10;
L.p2.Y=yPos+10;
myLines.Add(L);
path.AddLine(L.p1.X,L.p1.Y,L.p2.X,L.p2.Y);
PereLine(L.p2.X,L.p2.Y,xPosPen,yPosPen);
}
}
}
g.Dispose();
}
void MainFormPaint(object sender, PaintEventArgs e)
{
Graphics g=e.Graphics;
foreach(Line d in myLines)
{
g.DrawLine(p, d.p1.X, d.p1.Y, d.p2.X, d.p2.Y);
}
}
void PereLine(int x1, int y1, int xP, int yP)
{
if(x1==xP && y1==yP)
{
Region region = new Region(path);
for(i=0;i<kolfrut;i++)
{
if(region.IsVisible(frut[i].Location.X,frut[i].Location.Y))
{
frut[i].Dispose();
}
}
PenIf=false;
myLines.Clear();
Invalidate();
}
}
void MainFormLoad(object sender, EventArgs e)
{
frut_timer.Interval=6000;
frut_timer.Tick+= new EventHandler(Frut_timerTick);
frut_timer.Enabled=true;
f.Show();
}
void Frut_timerTick(object sender, EventArgs e)
{
frut[kolfrut]= new Button();
frut[kolfrut].Location= new Point(r.Next(30,770),r.Next(30,470));
frut[kolfrut].Text=Convert.ToString(kolfrut);
frut[kolfrut].Size= new System.Drawing.Size(20,20);
frut[kolfrut].UseVisualStyleBackColor=true;
Controls.Add(frut[kolfrut]);
kolfrut++;
}
void НоваяИграToolStripMenuItemClick(object sender, EventArgs e)
{
}
void ВыходToolStripMenuItemClick(object sender, EventArgs e)
{
Close();
}
void СостояниеЖукаToolStripMenuItemClick(object sender, EventArgs e)
{
}
}
}
Проблема в следующем.. кнопка "жук" оббегает появляющиеся кнопки фрукты... при замыкании региона все элементы внутри должны удаляться, но этого не происходит... помогите пожалуйста, кто чем может....
Данное сообщение получено с сайта GotDotNet.RU
Последний раз редактировалось 24 June 2008 20:17
|