using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Bitmap[] bmp = new Bitmap[2];
int screeen = 0;
Timer t = new Timer();
PictureBox pictureBox;
const int canvas_w = 640;
const int canvas_h = 480;
List<Mogura> moguras = new List<Mogura>();
double fps = 30.0d;
private void Form1_Load(object sender, EventArgs e)
{
this.FormBorderStyle = FormBorderStyle.FixedToolWindow;
this.ClientSize = new Size(canvas_w, canvas_h);
bmp[0] = new Bitmap(canvas_w, canvas_h, PixelFormat.Format32bppArgb);
bmp[1] = new Bitmap(canvas_w, canvas_h, PixelFormat.Format32bppArgb);
t.Interval = (int)(1.0d / fps * 1000);
t.Tick += new EventHandler(t_Tick);
t.Enabled = true;
pictureBox = new PictureBox();
pictureBox.Dock = DockStyle.Fill;
pictureBox.MouseDown += new MouseEventHandler(pictureBox_MouseDown);
pictureBox.MouseUp += new MouseEventHandler(pictureBox_MouseUp);
this.Controls.Add(pictureBox);
Random rnd = new Random();
for (int i = 0; i < 5; i++)
{
Mogura m = new Mogura(rnd,fps);
if (i % 2 == 0)
{
m.point = new Point(i * 128 + 14, 100);
}
else
{
m.point = new Point(i * 128 + 14, 300);
}
moguras.Add(m);
}
}
Point mc;
void pictureBox_MouseUp(object sender, MouseEventArgs e)
{
this.Text = Point.Empty.ToString();
mc = Point.Empty;
}
void pictureBox_MouseDown(object sender, MouseEventArgs e)
{
this.Text = e.Location.ToString();
mc = e.Location;
}
void t_Tick(object sender, EventArgs e)
{
using(Graphics g = Graphics.FromImage(bmp[screeen]))
{
g.SmoothingMode = SmoothingMode.AntiAlias;
g.FillRectangle(Brushes.SaddleBrown, 0, 0, bmp[screeen].Width, bmp[screeen].Height);
foreach (Mogura m in moguras)
{
//マウスクリックがあった場合の座標
//今のままだとタイミング的にたまーにヤバイかもしれない
if(mc != Point.Empty ) m.HitTest(mc);
m.Move();
m.Draw(g);
}
}
pictureBox.Image = bmp[screeen];
screeen ^= 1;
}
}
public class Mogura
{
public int mode = 0;
public Point point = new Point(0, 0);
int count = 100;
Random _rnd;
double _fps;
public Mogura(Random rnd,double fps)
{
this._rnd = rnd;
this._fps = fps;
this.rndset1();
}
public void HitTest(Point p)
{
//当たり判定の範囲をどうするか決めてくれ
//このままだと1ドット単位での判定なので狭すぎる
if (p == this.point)
{
if (this.mode == 1)
{
this.mode = 2;
this.count = 5 * (int)this._fps;
}
}
}
public void Move()
{
if (this.count <= 0)
{
if (this.mode == 0)
{
this.mode = 1;
this.rndset2();
}
else if (this.mode == 1)
{
this.mode = 0;
this.rndset1();
}
else if (this.mode == 2)
{
this.mode = 0;
this.rndset1();
}
}
this.count--;
}
private void rndset1()
{
this.count = this._rnd.Next(2, 5) * (int)this._fps;
}
private void rndset2()
{
this.count = this._rnd.Next(1, 2) * (int)this._fps;
}
public void Draw(Graphics g)
{
Matrix m = new Matrix();
m.Translate(this.point.X, this.point.Y);
g.Transform = m;
//mode = 0 引っ込んでる
if (this.mode == 0)
{
g.FillPie(Brushes.Black, 0, 0, 100, 50, 0, 360);
}
//mode = 1 出てる
else if (this.mode == 1)
{
g.FillPie(Brushes.Red, 0, 0, 100, 50, 180, 180);
//もぐらっぽくなるように足してくれ
g.FillPie(Brushes.Red, 0, 0, 100, 50, 0, 180);
}
//mode = 2 叩かれた
else if (this.mode == 2)
{
//モグラを叩いたときの絵になるように足してくれ
//g.FillPie(Brushes.Black, 0, 0, 100, 50, 180, 180);
//g.FillPie(Brushes.Black, 0, 0, 100, 50, 0, 180);
}
//その他 バグ
else
{
}
m.Reset();
g.Transform = m;
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYzsKdXNpbmcgU3lzdGVtLkNvbXBvbmVudE1vZGVsOwp1c2luZyBTeXN0ZW0uRG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GVsRm9ybWF0LkZvcm1hdDMyYnBwQXJnYik7CiAgICAgICAgICAgIGJtcFsxXSA9IG5ldyBCaXRtYXAoY2FudmFzX3csIGNhbnZhc19oLCBQaXhlbEZvcm1hdC5Gb3JtYXQzMmJwcEFyZ2IpOwogICAgICAgICAgICB0LkludGVydmFsID0gKGludCkoMS4wZCAvIGZwcyAqIDEwMDApOwogICAgICAgICAgICB0LlRpY2sgKz0gbmV3IEV2ZW50SGFuZGxlcih0X1RpY2spOwogICAgICAgICAgICB0LkVuYWJsZWQgPSB0cnVlOwogICAgICAgICAgICBwaWN0dXJlQm94ID0gbmV3IFBpY3R1cmVCb3goKTsKICAgICAgICAgICAgcGljdHVyZUJveC5Eb2NrID0gRG9ja1N0eWxlLkZpbGw7CiAgICAgICAgICAgIHBpY3R1cmVCb3guTW91c2VEb3duICs9IG5ldyBNb3VzZUV2ZW50SGFuZGxlcihwaWN0dXJlQm94X01vdXNlRG93bik7CiAgICAgICAgICAgIHBpY3R1cmVCb3guTW91c2VVcCArPSBuZXcgTW91c2VFdmVudEhhbmRsZXIocGljdHVyZUJveF9Nb3VzZVVwKTsKICAgICAgICAgICAgdGhpcy5Db250cm9scy5BZGQocGljdHVyZUJveCk7CiAgICAgICAgICAgIFJhbmRvbSBybmQgPSBuZXcgUmFuZG9tKCk7CiAgICAgICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgNTsgaSsrKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBNb2d1cmEgbSA9IG5ldyBNb2d1cmEocm5kLGZwcyk7CiAgICAgICAgICAgICAgICBpZiAoaSAlIDIgPT0gMCkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBtLnBvaW50ID0gbmV3IFBvaW50KGkgKiAxMjggKyAxNCwgMTAwKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBtLnBvaW50ID0gbmV3IFBvaW50KGkgKiAxMjggKyAxNCwgMzAwKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIG1vZ3VyYXMuQWRkKG0pOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIFBvaW50IG1jOwogICAgICAgIHZvaWQgcGljdHVyZUJveF9Nb3VzZVVwKG9iamVjdCBzZW5kZXIsIE1vdXNlRXZlbnRBcmdzIGUpCiAgICAgICAgewogICAgICAgICAgICB0aGlzLlRleHQgPSBQb2ludC5FbXB0eS5Ub1N0cmluZygpOwogICAgICAgICAgICBtYyA9IFBvaW50LkVtcHR5OwogICAgICAgIH0KCiAgICAgICAgdm9pZCBwaWN0dXJlQm94X01vdXNlRG93bihvYmplY3Qgc2VuZGVyLCBNb3VzZUV2ZW50QXJncyBlKQogICAgICAgIHsKICAgICAgICAgICAgdGhpcy5UZXh0ID0gZS5Mb2NhdGlvbi5Ub1N0cmluZygpOwogICAgICAgICAgICBtYyA9IGUuTG9jYXRpb247CiAgICAgICAgfQoKICAgICAgICB2b2lkIHRfVGljayhvYmplY3Qgc2VuZGVyLCBFdmVudEFyZ3MgZSkKICAgICAgICB7CiAgICAgICAgICAgIHVzaW5nKEdyYXBoaWNzIGcgPSBHcmFwaGljcy5Gcm9tSW1hZ2UoYm1wW3NjcmVlZW5dKSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgZy5TbW9vdGhpbmdNb2RlID0gU21vb3RoaW5nTW9kZS5BbnRpQWxpYXM7CiAgICAgICAgICAgICAgICBnLkZpbGxSZWN0YW5nbGUoQnJ1c2hlcy5TYWRkbGVCcm93biwgMCwgMCwgYm1wW3NjcmVlZW5dLldpZHRoLCBibXBbc2NyZWVlbl0uSGVpZ2h0KTsKICAgICAgICAgICAgICAgIGZvcmVhY2ggKE1vZ3VyYSBtIGluIG1vZ3VyYXMpCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgLy/jg57jgqbjgrnjgq/jg6rjg4Pjgq/jgYzjgYLjgaPjgZ/loLTlkIjjga7luqfmqJkKICAgICAgICAgICAgICAgICAgICAvL+S7iuOBruOBvuOBvuOBoOOBqOOCv+OCpOODn+ODs+OCsOeahOOBq+OBn+OBvuODvOOBq+ODpOODkOOCpOOBi+OCguOBl+OCjOOBquOBhAogICAgICAgICAgICAgICAgICAgIGlmKG1jICE9IFBvaW50LkVtcHR5ICkgbS5IaXRUZXN0KG1jKTsKICAgICAgICAgICAgICAgICAgICBtLk1vdmUoKTsKICAgICAgICAgICAgICAgICAgICBtLkRyYXcoZyk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcGljdHVyZUJveC5JbWFnZSA9IGJtcFtzY3JlZWVuXTsKICAgICAgICAgICAgc2NyZWVlbiBePSAxOwogICAgICAgIH0KICAgIH0KCiAgICBwdWJsaWMgY2xhc3MgTW9ndXJhCiAgICB7CiAgICAgICAgcHVibGljIGludCBtb2RlID0gMDsKICAgICAgICBwdWJsaWMgUG9pbnQgcG9pbnQgPSBuZXcgUG9pbnQoMCwgMCk7CiAgICAgICAgaW50IGNvdW50ID0gMTAwOwogICAgICAgIFJhbmRvbSBfcm5kOwogICAgICAgIGRvdWJsZSBfZnBzOwogICAgICAgIHB1YmxpYyBNb2d1cmEoUmFuZG9tIHJuZCxkb3VibGUgZnBzKQogICAgICAgIHsKICAgICAgICAgICAgdGhpcy5fcm5kID0gcm5kOwogICAgICAgICAgICB0aGlzLl9mcHMgPSBmcHM7CiAgICAgICAgICAgIHRoaXMucm5kc2V0MSgpOwogICAgICAgIH0KICAgICAgICBwdWJsaWMgdm9pZCBIaXRUZXN0KFBvaW50IHApCiAgICAgICAgewogICAgICAgICAgICAvL+W9k+OBn+OCiuWIpOWumuOBruevhOWbsuOCkuOBqeOBhuOBmeOCi+OBi+axuuOCgeOBpuOBj+OCjAogICAgICAgICAgICAvL+OBk+OBruOBvuOBvuOBoOOBqDHjg4njg4Pjg4jljZjkvY3jgafjga7liKTlrprjgarjga7jgafni63jgZnjgY7jgosKICAgICAgICAgICAgaWYgKHAgPT0gdGhpcy5wb2ludCkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaWYgKHRoaXMubW9kZSA9PSAxKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIHRoaXMubW9kZSA9IDI7CiAgICAgICAgICAgICAgICAgICAgdGhpcy5jb3VudCA9IDUgKiAoaW50KXRoaXMuX2ZwczsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBwdWJsaWMgdm9pZCBNb3ZlKCkKICAgICAgICB7CiAgICAgICAgICAgIGlmICh0aGlzLmNvdW50IDw9IDApCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGlmICh0aGlzLm1vZGUgPT0gMCkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICB0aGlzLm1vZGUgPSAxOwogICAgICAgICAgICAgICAgICAgIHRoaXMucm5kc2V0MigpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZWxzZSBpZiAodGhpcy5tb2RlID09IDEpCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgdGhpcy5tb2RlID0gMDsKICAgICAgICAgICAgICAgICAgICB0aGlzLnJuZHNldDEoKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGVsc2UgaWYgKHRoaXMubW9kZSA9PSAyKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIHRoaXMubW9kZSA9IDA7CiAgICAgICAgICAgICAgICAgICAgdGhpcy5ybmRzZXQxKCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy5jb3VudC0tOwogICAgICAgIH0KICAgICAgICBwcml2YXRlIHZvaWQgcm5kc2V0MSgpCiAgICAgICAgewogICAgICAgICAgICB0aGlzLmNvdW50ID0gdGhpcy5fcm5kLk5leHQoMiwgNSkgKiAoaW50KXRoaXMuX2ZwczsKICAgICAgICB9CiAgICAgICAgcHJpdmF0ZSB2b2lkIHJuZHNldDIoKQogICAgICAgIHsKICAgICAgICAgICAgdGhpcy5jb3VudCA9IHRoaXMuX3JuZC5OZXh0KDEsIDIpICogKGludCl0aGlzLl9mcHM7CiAgICAgICAgfQogICAgICAgIHB1YmxpYyB2b2lkIERyYXcoR3JhcGhpY3MgZykKICAgICAgICB7CiAgICAgICAgICAgIE1hdHJpeCBtID0gbmV3IE1hdHJpeCgpOwogICAgICAgICAgICBtLlRyYW5zbGF0ZSh0aGlzLnBvaW50LlgsIHRoaXMucG9pbnQuWSk7CiAgICAgICAgICAgIGcuVHJhbnNmb3JtID0gbTsKICAgICAgICAgICAgLy9tb2RlID0gMCDlvJXjgaPovrzjgpPjgafjgosKICAgICAgICAgICAgaWYgKHRoaXMubW9kZSA9PSAwKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBnLkZpbGxQaWUoQnJ1c2hlcy5CbGFjaywgMCwgMCwgMTAwLCA1MCwgMCwgMzYwKTsKICAgICAgICAgICAgfQogICAgICAgICAgICAvL21vZGUgPSAxIOWHuuOBpuOCiwogICAgICAgICAgICBlbHNlIGlmICh0aGlzLm1vZGUgPT0gMSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgZy5GaWxsUGllKEJydXNoZXMuUmVkLCAwLCAwLCAxMDAsIDUwLCAxODAsIDE4MCk7CiAgICAgICAgICAgICAgICAvL+OCguOBkOOCieOBo+OBveOBj+OBquOCi+OCiOOBhuOBq+i2s+OBl+OBpuOBj+OCjAogICAgICAgICAgICAgICAgZy5GaWxsUGllKEJydXNoZXMuUmVkLCAwLCAwLCAxMDAsIDUwLCAwLCAxODApOwogICAgICAgICAgICB9CiAgICAgICAgICAgIC8vbW9kZSA9IDIg5Y+p44GL44KM44GfCiAgICAgICAgICAgIGVsc2UgaWYgKHRoaXMubW9kZSA9PSAyKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAvL+ODouOCsOODqeOCkuWPqeOBhOOBn+OBqOOBjeOBrue1teOBq+OBquOCi+OCiOOBhuOBq+i2s+OBl+OBpuOBj+OCjAogICAgICAgICAgICAgICAgLy9nLkZpbGxQaWUoQnJ1c2hlcy5CbGFjaywgMCwgMCwgMTAwLCA1MCwgMTgwLCAxODApOwogICAgICAgICAgICAgICAgLy9nLkZpbGxQaWUoQnJ1c2hlcy5CbGFjaywgMCwgMCwgMTAwLCA1MCwgMCwgMTgwKTsKICAgICAgICAgICAgfQogICAgICAgICAgICAvL+OBneOBruS7liDjg5DjgrAKICAgICAgICAgICAgZWxzZQogICAgICAgICAgICB7CgogICAgICAgICAgICB9CiAgICAgICAgICAgIG0uUmVzZXQoKTsKICAgICAgICAgICAgZy5UcmFuc2Zvcm0gPSBtOwogICAgICAgIH0KICAgIH0KfQo=