fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Drawing.Imaging;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Windows.Forms;
  11.  
  12. namespace WindowsFormsApplication1
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. }
  20. Bitmap[] bmp = new Bitmap[2];
  21. int screeen = 0;
  22. Timer t = new Timer();
  23. PictureBox pictureBox;
  24. const int canvas_w = 640;
  25. const int canvas_h = 480;
  26. List<Mogura> moguras = new List<Mogura>();
  27. double fps = 30.0d;
  28. private void Form1_Load(object sender, EventArgs e)
  29. {
  30. this.FormBorderStyle = FormBorderStyle.FixedToolWindow;
  31. this.ClientSize = new Size(canvas_w, canvas_h);
  32. bmp[0] = new Bitmap(canvas_w, canvas_h, PixelFormat.Format32bppArgb);
  33. bmp[1] = new Bitmap(canvas_w, canvas_h, PixelFormat.Format32bppArgb);
  34. t.Interval = (int)(1.0d / fps * 1000);
  35. t.Tick += new EventHandler(t_Tick);
  36. t.Enabled = true;
  37. pictureBox = new PictureBox();
  38. pictureBox.Dock = DockStyle.Fill;
  39. pictureBox.MouseDown += new MouseEventHandler(pictureBox_MouseDown);
  40. pictureBox.MouseUp += new MouseEventHandler(pictureBox_MouseUp);
  41. this.Controls.Add(pictureBox);
  42. Random rnd = new Random();
  43. for (int i = 0; i < 5; i++)
  44. {
  45. Mogura m = new Mogura(rnd,fps);
  46. if (i % 2 == 0)
  47. {
  48. m.point = new Point(i * 128 + 14, 100);
  49. }
  50. else
  51. {
  52. m.point = new Point(i * 128 + 14, 300);
  53. }
  54. moguras.Add(m);
  55. }
  56. }
  57. Point mc;
  58. void pictureBox_MouseUp(object sender, MouseEventArgs e)
  59. {
  60. this.Text = Point.Empty.ToString();
  61. mc = Point.Empty;
  62. }
  63.  
  64. void pictureBox_MouseDown(object sender, MouseEventArgs e)
  65. {
  66. this.Text = e.Location.ToString();
  67. mc = e.Location;
  68. }
  69.  
  70. void t_Tick(object sender, EventArgs e)
  71. {
  72. using(Graphics g = Graphics.FromImage(bmp[screeen]))
  73. {
  74. g.SmoothingMode = SmoothingMode.AntiAlias;
  75. g.FillRectangle(Brushes.SaddleBrown, 0, 0, bmp[screeen].Width, bmp[screeen].Height);
  76. foreach (Mogura m in moguras)
  77. {
  78. //マウスクリックがあった場合の座標
  79. //今のままだとタイミング的にたまーにヤバイかもしれない
  80. if(mc != Point.Empty ) m.HitTest(mc);
  81. m.Move();
  82. m.Draw(g);
  83. }
  84. }
  85. pictureBox.Image = bmp[screeen];
  86. screeen ^= 1;
  87. }
  88. }
  89.  
  90. public class Mogura
  91. {
  92. public int mode = 0;
  93. public Point point = new Point(0, 0);
  94. int count = 100;
  95. Random _rnd;
  96. double _fps;
  97. public Mogura(Random rnd,double fps)
  98. {
  99. this._rnd = rnd;
  100. this._fps = fps;
  101. this.rndset1();
  102. }
  103. public void HitTest(Point p)
  104. {
  105. //当たり判定の範囲をどうするか決めてくれ
  106. //このままだと1ドット単位での判定なので狭すぎる
  107. if (p == this.point)
  108. {
  109. if (this.mode == 1)
  110. {
  111. this.mode = 2;
  112. this.count = 5 * (int)this._fps;
  113. }
  114. }
  115. }
  116. public void Move()
  117. {
  118. if (this.count <= 0)
  119. {
  120. if (this.mode == 0)
  121. {
  122. this.mode = 1;
  123. this.rndset2();
  124. }
  125. else if (this.mode == 1)
  126. {
  127. this.mode = 0;
  128. this.rndset1();
  129. }
  130. else if (this.mode == 2)
  131. {
  132. this.mode = 0;
  133. this.rndset1();
  134. }
  135. }
  136. this.count--;
  137. }
  138. private void rndset1()
  139. {
  140. this.count = this._rnd.Next(2, 5) * (int)this._fps;
  141. }
  142. private void rndset2()
  143. {
  144. this.count = this._rnd.Next(1, 2) * (int)this._fps;
  145. }
  146. public void Draw(Graphics g)
  147. {
  148. Matrix m = new Matrix();
  149. m.Translate(this.point.X, this.point.Y);
  150. g.Transform = m;
  151. //mode = 0 引っ込んでる
  152. if (this.mode == 0)
  153. {
  154. g.FillPie(Brushes.Black, 0, 0, 100, 50, 0, 360);
  155. }
  156. //mode = 1 出てる
  157. else if (this.mode == 1)
  158. {
  159. g.FillPie(Brushes.Red, 0, 0, 100, 50, 180, 180);
  160. //もぐらっぽくなるように足してくれ
  161. g.FillPie(Brushes.Red, 0, 0, 100, 50, 0, 180);
  162. }
  163. //mode = 2 叩かれた
  164. else if (this.mode == 2)
  165. {
  166. //モグラを叩いたときの絵になるように足してくれ
  167. //g.FillPie(Brushes.Black, 0, 0, 100, 50, 180, 180);
  168. //g.FillPie(Brushes.Black, 0, 0, 100, 50, 0, 180);
  169. }
  170. //その他 バグ
  171. else
  172. {
  173.  
  174. }
  175. m.Reset();
  176. g.Transform = m;
  177. }
  178. }
  179. }
  180.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty