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.IO;
  11.  
  12. namespace Soukoban
  13. {
  14. public partial class Form1 : Form
  15. {
  16. const int SZ = 32;
  17. Keys mKey = Keys.None;
  18. Bitmap bmp;
  19. Graphics g;
  20. Action<PreviewKeyDownEventArgs> DoKeyInput;
  21. Action<PaintEventArgs> DoPaint;
  22. Action DoUpdate;
  23. private Tile[,] mTiles;
  24.  
  25. [Flags]
  26. enum Tile
  27. {
  28. None = 0,
  29. Kabe = 1,
  30. Okiba = 2,
  31. Nimotu = 4,
  32. Player = 8,
  33. OK = Okiba | Nimotu
  34. }
  35.  
  36. public Form1()
  37. {
  38. InitializeComponent();
  39. SetStyle(ControlStyles.AllPaintingInWmPaint, true);
  40. SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
  41. SetStyle(ControlStyles.ResizeRedraw, true);
  42. SetStyle(ControlStyles.UserPaint, true);
  43.  
  44. bmp = new Bitmap(640, 480);
  45. g = Graphics.FromImage(bmp);
  46. Task.Factory.StartNew(GameMain);
  47. }
  48.  
  49. private void GameMain()
  50. {
  51. GameInitialize();
  52. DoPaint = PaintGameMain;
  53. DoUpdate = UpdateGameMain;
  54. DoKeyInput = InputGameMain;
  55.  
  56. while (true)
  57. {
  58. DoUpdate();
  59.  
  60. Invalidate();
  61. }
  62. }
  63.  
  64. private void GameInitialize()
  65. {
  66. LoadMap(1);
  67.  
  68. }
  69.  
  70. private void LoadMap(int mapNo)
  71. {
  72. using(var sr = new StreamReader(@"map" + mapNo + ".dat"))
  73. using (var tr = sr as TextReader)
  74. {
  75. List<string> ss = new List<string>();
  76. while (!sr.EndOfStream)
  77. {
  78. ss.Add(sr.ReadLine());
  79. }
  80. mTiles = new Tile[ss.Count(), ss[0].Length];
  81.  
  82. for (int y = 0; y < ss.Count(); y++)
  83. {
  84. var s = ss[y];
  85. for (int x = 0; x < s.Length; x++)
  86. {
  87. mTiles[y, x] = (Tile)Convert.ToInt32(s[x] + "");
  88. }
  89. }
  90. }
  91. }
  92.  
  93. private void InputGameMain(PreviewKeyDownEventArgs e)
  94. {
  95. mKey = e.KeyCode;
  96. }
  97.  
  98. private void PaintGameMain(PaintEventArgs e)
  99. {
  100. g.Clear(Color.Black);
  101.  
  102. for(int y = 0 ; y < mTiles.GetLength(0) ; y++)
  103. {
  104. for(int x = 0 ; x < mTiles.GetLength(1) ; x++)
  105. {
  106. Tile t = mTiles[y, x];
  107. //壁描画
  108. if (t == Tile.Kabe)
  109. {
  110. g.FillRectangle(Brushes.Brown, x * SZ, y * SZ, SZ, SZ);
  111. }
  112.  
  113. //荷物置場描画
  114. if (t == Tile.Okiba)
  115. {
  116. g.FillRectangle(Brushes.Aqua, (x * SZ) + 10, (y * SZ) + 10, 4, 4);
  117. }
  118.  
  119. //荷物描画
  120. if ((t & Tile.Nimotu) == Tile.Nimotu)
  121. {
  122. g.FillRectangle(Brushes.Yellow, x * SZ, y * SZ, SZ, SZ);
  123. }
  124.  
  125. //プレイヤ描画
  126. if ((t & Tile.Player) == Tile.Player)
  127. {
  128. g.FillEllipse(Brushes.Red, x * SZ, y * SZ, SZ, SZ);
  129. }
  130.  
  131. }
  132. }
  133.  
  134. e.Graphics.DrawImage(bmp, 0, 0);
  135.  
  136. }
  137.  
  138. private void UpdateGameMain()
  139. {
  140. if (mKey == Keys.Up)
  141. {
  142.  
  143. }
  144.  
  145.  
  146. }
  147.  
  148. protected override void OnPaint(PaintEventArgs e)
  149. {
  150. DoPaint(e);
  151. }
  152.  
  153. private void Form1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
  154. {
  155. DoKeyInput(e);
  156. }
  157.  
  158. }
  159. }
  160.  
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