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.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Threading.Tasks;
  10. using System.Threading;
  11.  
  12. namespace WindowsFormsApplication3
  13. {
  14. public partial class Form1 : Form
  15. {
  16. abstract class GameObject
  17. {
  18. public int X { get; set; }
  19. public int Y { get; set; }
  20. public Color color { get; set; }
  21. public Action<GameObject,GameObject> Tactics;
  22. }
  23.  
  24. class Player : GameObject
  25. {
  26.  
  27. }
  28.  
  29. class Enemy : GameObject
  30. {
  31. }
  32.  
  33. Player pl;
  34. List<Enemy> enemies;
  35. Bitmap bmp;
  36. Graphics g;
  37.  
  38.  
  39. public Form1()
  40. {
  41. InitializeComponent();
  42.  
  43. //描画用の設定あれこれ(ちらつかないようにするとか、描画用メモリを500x500pxで用意するとか)
  44. SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
  45. SetStyle(ControlStyles.AllPaintingInWmPaint, true);
  46. SetStyle(ControlStyles.UserPaint, true);
  47.  
  48. bmp = new Bitmap(500, 500);
  49. g = Graphics.FromImage(bmp);
  50. this.ClientSize = bmp.Size;
  51.  
  52.  
  53. //プレイヤー
  54. pl = new Player() { color = Color.Aqua };
  55.  
  56. //敵1の戦術はプレイヤーに近づく
  57. Enemy teki1;
  58. teki1 = new Enemy() { X = 200, Y = 200 ,color = Color.Red};
  59. teki1.Tactics = (me,other) =>
  60. {
  61. me.X += (other.X <= me.X) ? -1 : 1;
  62. me.Y += (other.Y <= me.Y) ? -1 : 1;
  63. };
  64.  
  65. //敵2の戦術はプレイヤーから逃げる
  66. Enemy teki2;
  67. teki2 = new Enemy() { X = 200, Y = 300 ,color = Color.Green};
  68. teki2.Tactics = (me,other) =>
  69. {
  70. me.X += (other.X <= me.X) ? 1 : -1;
  71. me.Y += (other.Y <= me.Y) ? 1 : -1;
  72. };
  73.  
  74. enemies = new List<Enemy>();
  75. enemies.Add(teki1);
  76. enemies.Add(teki2);
  77.  
  78. //スレッド実行
  79. Task.Factory.StartNew(GameMain);
  80. }
  81.  
  82. private void GameMain()
  83. {
  84. while (true)
  85. {
  86. Thread.Sleep(1000 / 60);
  87.  
  88. //敵の戦術を実行する。(プレイヤーの方向に向かって、逃げるか、向かうか)
  89. foreach (var enm in enemies)
  90. {
  91. enm.Tactics(enm,pl);
  92. }
  93.  
  94. //画面更新
  95. this.Invalidate();
  96. }
  97. }
  98.  
  99. protected override void OnPaint(PaintEventArgs e)
  100. {
  101. g.Clear(Color.Black);
  102.  
  103. //プレイヤ描画
  104. g.FillRectangle(new SolidBrush(pl.color), pl.X, pl.Y, 20, 20);
  105.  
  106.  
  107. //敵描画
  108. foreach (var enm in enemies)
  109. {
  110. g.FillRectangle(new SolidBrush(enm.color), enm.X, enm.Y, 20, 20);
  111. }
  112.  
  113. e.Graphics.DrawImage(bmp, 0, 0);
  114. }
  115.  
  116.  
  117. private void Form1_MouseDown(object sender, MouseEventArgs e)
  118. {
  119. pl.X = e.X;
  120. pl.Y = e.Y;
  121. }
  122. }
  123. }
  124.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(4,14): error CS0234: The type or namespace name `Data' does not exist in the namespace `System'. Are you missing an assembly reference?
prog.cs(5,14): error CS0234: The type or namespace name `Drawing' does not exist in the namespace `System'. Are you missing an assembly reference?
prog.cs(8,14): error CS0234: The type or namespace name `Windows' does not exist in the namespace `System'. Are you missing an assembly reference?
prog.cs(9,24): error CS0234: The type or namespace name `Tasks' does not exist in the namespace `System.Threading'. Are you missing an assembly reference?
Compilation failed: 4 error(s), 0 warnings
stdout
Standard output is empty