using System;
using System.Collections .Generic ;
using System.ComponentModel ;
using System.Data ;
using System.Drawing ;
using System.Linq ;
using System.Text ;
using System.Windows .Forms ;
using System.Threading .Tasks ;
using System.IO ;
namespace Soukoban
{
public partial class Form1 : Form
{
const int SZ = 32 ;
Keys mKey = Keys.None ;
Bitmap bmp;
Graphics g;
Action< PreviewKeyDownEventArgs> DoKeyInput;
Action< PaintEventArgs> DoPaint;
Action DoUpdate;
private Tile[ , ] mTiles;
[ Flags]
enum Tile
{
None = 0 ,
Kabe = 1 ,
Okiba = 2 ,
Nimotu = 4 ,
Player = 8 ,
OK = Okiba | Nimotu
}
public Form1( )
{
InitializeComponent( ) ;
SetStyle( ControlStyles.AllPaintingInWmPaint , true ) ;
SetStyle( ControlStyles.OptimizedDoubleBuffer , true ) ;
SetStyle( ControlStyles.ResizeRedraw , true ) ;
SetStyle( ControlStyles.UserPaint , true ) ;
bmp = new Bitmap( 640 , 480 ) ;
g = Graphics.FromImage ( bmp) ;
Task.Factory .StartNew ( GameMain) ;
}
private void GameMain( )
{
GameInitialize( ) ;
DoPaint = PaintGameMain;
DoUpdate = UpdateGameMain;
DoKeyInput = InputGameMain;
while ( true )
{
DoUpdate( ) ;
Invalidate( ) ;
}
}
private void GameInitialize( )
{
LoadMap( 1 ) ;
}
private void LoadMap( int mapNo)
{
using( var sr = new StreamReader( @"map" + mapNo + ".dat" ) )
using ( var tr = sr as TextReader)
{
List< string> ss = new List< string> ( ) ;
while ( ! sr.EndOfStream )
{
ss.Add ( sr.ReadLine ( ) ) ;
}
mTiles = new Tile[ ss.Count ( ) , ss[ 0 ] .Length ] ;
for ( int y = 0 ; y < ss.Count ( ) ; y++ )
{
var s = ss[ y] ;
for ( int x = 0 ; x < s.Length ; x++ )
{
mTiles[ y, x] = ( Tile) Convert.ToInt32 ( s[ x] + "" ) ;
}
}
}
}
private void InputGameMain( PreviewKeyDownEventArgs e)
{
mKey = e.KeyCode ;
}
private void PaintGameMain( PaintEventArgs e)
{
g.Clear ( Color.Black ) ;
for ( int y = 0 ; y < mTiles.GetLength ( 0 ) ; y++ )
{
for ( int x = 0 ; x < mTiles.GetLength ( 1 ) ; x++ )
{
Tile t = mTiles[ y, x] ;
//壁描画
if ( t == Tile.Kabe )
{
g.FillRectangle ( Brushes.Brown , x * SZ, y * SZ, SZ, SZ) ;
}
//荷物置場描画
if ( t == Tile.Okiba )
{
g.FillRectangle ( Brushes.Aqua , ( x * SZ) + 10 , ( y * SZ) + 10 , 4 , 4 ) ;
}
//荷物描画
if ( ( t & Tile.Nimotu ) == Tile.Nimotu )
{
g.FillRectangle ( Brushes.Yellow , x * SZ, y * SZ, SZ, SZ) ;
}
//プレイヤ描画
if ( ( t & Tile.Player ) == Tile.Player )
{
g.FillEllipse ( Brushes.Red , x * SZ, y * SZ, SZ, SZ) ;
}
}
}
e.Graphics .DrawImage ( bmp, 0 , 0 ) ;
}
private void UpdateGameMain( )
{
if ( mKey == Keys.Up )
{
}
}
protected override void OnPaint( PaintEventArgs e)
{
DoPaint( e) ;
}
private void Form1_PreviewKeyDown( object sender, PreviewKeyDownEventArgs e)
{
DoKeyInput( e) ;
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYzsKdXNpbmcgU3lzdGVtLkNvbXBvbmVudE1vZGVsOwp1c2luZyBTeXN0ZW0uRGF0YTsKdXNpbmcgU3lzdGVtLkRyYXdpbmc7CnVzaW5nIFN5c3RlbS5MaW5xOwp1c2luZyBTeXN0ZW0uVGV4dDsKdXNpbmcgU3lzdGVtLldpbmRvd3MuRm9ybXM7CnVzaW5nIFN5c3RlbS5UaHJlYWRpbmcuVGFza3M7CnVzaW5nIFN5c3RlbS5JTzsKCm5hbWVzcGFjZSBTb3Vrb2Jhbgp7CiAgICBwdWJsaWMgcGFydGlhbCBjbGFzcyBGb3JtMSA6IEZvcm0KICAgIHsKICAgICAgICBjb25zdCBpbnQgU1ogPSAzMjsKICAgICAgICBLZXlzIG1LZXkgPSBLZXlzLk5vbmU7CiAgICAgICAgQml0bWFwIGJtcDsKICAgICAgICBHcmFwaGljcyBnOwogICAgICAgIEFjdGlvbjxQcmV2aWV3S2V5RG93bkV2ZW50QXJncz4gRG9LZXlJbnB1dDsKICAgICAgICBBY3Rpb248UGFpbnRFdmVudEFyZ3M+IERvUGFpbnQ7CiAgICAgICAgQWN0aW9uIERvVXBkYXRlOwogICAgICAgIHByaXZhdGUgVGlsZVssXSBtVGlsZXM7CgogICAgICAgIFtGbGFnc10KICAgICAgICBlbnVtIFRpbGUKICAgICAgICB7CiAgICAgICAgICAgIE5vbmUgPSAwLAogICAgICAgICAgICBLYWJlID0gMSwKICAgICAgICAgICAgT2tpYmEgPSAyLAogICAgICAgICAgICBOaW1vdHUgPSA0LAogICAgICAgICAgICBQbGF5ZXIgPSA4LAogICAgICAgICAgICBPSyA9IE9raWJhIHwgTmltb3R1CiAgICAgICAgfQoKICAgICAgICBwdWJsaWMgRm9ybTEoKQogICAgICAgIHsKICAgICAgICAgICAgSW5pdGlhbGl6ZUNvbXBvbmVudCgpOwogICAgICAgICAgICBTZXRTdHlsZShDb250cm9sU3R5bGVzLkFsbFBhaW50aW5nSW5XbVBhaW50LCB0cnVlKTsKICAgICAgICAgICAgU2V0U3R5bGUoQ29udHJvbFN0eWxlcy5PcHRpbWl6ZWREb3VibGVCdWZmZXIsIHRydWUpOwogICAgICAgICAgICBTZXRTdHlsZShDb250cm9sU3R5bGVzLlJlc2l6ZVJlZHJhdywgdHJ1ZSk7CiAgICAgICAgICAgIFNldFN0eWxlKENvbnRyb2xTdHlsZXMuVXNlclBhaW50LCB0cnVlKTsKCiAgICAgICAgICAgIGJtcCA9IG5ldyBCaXRtYXAoNjQwLCA0ODApOwogICAgICAgICAgICBnID0gR3JhcGhpY3MuRnJvbUltYWdlKGJtcCk7CiAgICAgICAgICAgIFRhc2suRmFjdG9yeS5TdGFydE5ldyhHYW1lTWFpbik7CiAgICAgICAgfQoKICAgICAgICBwcml2YXRlIHZvaWQgR2FtZU1haW4oKQogICAgICAgIHsKICAgICAgICAgICAgR2FtZUluaXRpYWxpemUoKTsKICAgICAgICAgICAgRG9QYWludCA9IFBhaW50R2FtZU1haW47CiAgICAgICAgICAgIERvVXBkYXRlID0gVXBkYXRlR2FtZU1haW47CiAgICAgICAgICAgIERvS2V5SW5wdXQgPSBJbnB1dEdhbWVNYWluOwoKICAgICAgICAgICAgd2hpbGUgKHRydWUpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIERvVXBkYXRlKCk7CgogICAgICAgICAgICAgICAgSW52YWxpZGF0ZSgpOwogICAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICBwcml2YXRlIHZvaWQgR2FtZUluaXRpYWxpemUoKQogICAgICAgIHsKICAgICAgICAgICAgTG9hZE1hcCgxKTsKICAgICAgICAgICAgCiAgICAgICAgfQoKICAgICAgICBwcml2YXRlIHZvaWQgTG9hZE1hcChpbnQgbWFwTm8pCiAgICAgICAgewogICAgICAgICAgICB1c2luZyh2YXIgc3IgPSBuZXcgU3RyZWFtUmVhZGVyKEAibWFwIiArIG1hcE5vICsgIi5kYXQiKSkKICAgICAgICAgICAgdXNpbmcgKHZhciB0ciA9IHNyIGFzIFRleHRSZWFkZXIpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIExpc3Q8c3RyaW5nPiBzcyA9IG5ldyBMaXN0PHN0cmluZz4oKTsKICAgICAgICAgICAgICAgIHdoaWxlICghc3IuRW5kT2ZTdHJlYW0pCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgc3MuQWRkKHNyLlJlYWRMaW5lKCkpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgbVRpbGVzID0gbmV3IFRpbGVbc3MuQ291bnQoKSwgc3NbMF0uTGVuZ3RoXTsKCiAgICAgICAgICAgICAgICBmb3IgKGludCB5ID0gMDsgeSA8IHNzLkNvdW50KCk7IHkrKykKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICB2YXIgcyA9IHNzW3ldOwogICAgICAgICAgICAgICAgICAgIGZvciAoaW50IHggPSAwOyB4IDwgcy5MZW5ndGg7IHgrKykKICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIG1UaWxlc1t5LCB4XSA9IChUaWxlKUNvbnZlcnQuVG9JbnQzMihzW3hdICsgIiIpOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KCiAgICAgICAgcHJpdmF0ZSB2b2lkIElucHV0R2FtZU1haW4oUHJldmlld0tleURvd25FdmVudEFyZ3MgZSkKICAgICAgICB7CiAgICAgICAgICAgIG1LZXkgPSBlLktleUNvZGU7CiAgICAgICAgfQoKICAgICAgICBwcml2YXRlIHZvaWQgUGFpbnRHYW1lTWFpbihQYWludEV2ZW50QXJncyBlKQogICAgICAgIHsKICAgICAgICAgICAgZy5DbGVhcihDb2xvci5CbGFjayk7CgogICAgICAgICAgICBmb3IoaW50IHkgPSAwIDsgeSA8IG1UaWxlcy5HZXRMZW5ndGgoMCkgOyB5KyspCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGZvcihpbnQgeCA9IDAgOyB4IDwgbVRpbGVzLkdldExlbmd0aCgxKSA7IHgrKykKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBUaWxlIHQgPSBtVGlsZXNbeSwgeF07CiAgICAgICAgICAgICAgICAgICAgLy/lo4Hmj4/nlLsKICAgICAgICAgICAgICAgICAgICBpZiAodCA9PSBUaWxlLkthYmUpCiAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICBnLkZpbGxSZWN0YW5nbGUoQnJ1c2hlcy5Ccm93biwgeCAqIFNaLCB5ICogU1osIFNaLCBTWik7CiAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgICAvL+iNt+eJqee9ruWgtOaPj+eUuwogICAgICAgICAgICAgICAgICAgIGlmICh0ID09IFRpbGUuT2tpYmEpCiAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICBnLkZpbGxSZWN0YW5nbGUoQnJ1c2hlcy5BcXVhLCAoeCAqIFNaKSArIDEwLCAoeSAqIFNaKSArIDEwLCA0LCA0KTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgIC8v6I2354mp5o+P55S7CiAgICAgICAgICAgICAgICAgICAgaWYgKCh0ICYgVGlsZS5OaW1vdHUpID09IFRpbGUuTmltb3R1KQogICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgZy5GaWxsUmVjdGFuZ2xlKEJydXNoZXMuWWVsbG93LCB4ICogU1osIHkgKiBTWiwgU1osIFNaKTsKICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgICAgIC8v44OX44Os44Kk44Ok5o+P55S7CiAgICAgICAgICAgICAgICAgICAgaWYgKCh0ICYgVGlsZS5QbGF5ZXIpID09IFRpbGUuUGxheWVyKQogICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgZy5GaWxsRWxsaXBzZShCcnVzaGVzLlJlZCwgeCAqIFNaLCB5ICogU1osIFNaLCBTWik7CiAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQoKICAgICAgICAgICAgZS5HcmFwaGljcy5EcmF3SW1hZ2UoYm1wLCAwLCAwKTsKCiAgICAgICAgfQoKICAgICAgICBwcml2YXRlIHZvaWQgVXBkYXRlR2FtZU1haW4oKQogICAgICAgIHsKICAgICAgICAgICAgaWYgKG1LZXkgPT0gS2V5cy5VcCkKICAgICAgICAgICAgewoKICAgICAgICAgICAgfQoKCiAgICAgICAgfQoKICAgICAgICBwcm90ZWN0ZWQgb3ZlcnJpZGUgdm9pZCBPblBhaW50KFBhaW50RXZlbnRBcmdzIGUpCiAgICAgICAgewogICAgICAgICAgICBEb1BhaW50KGUpOwogICAgICAgIH0KCiAgICAgICAgcHJpdmF0ZSB2b2lkIEZvcm0xX1ByZXZpZXdLZXlEb3duKG9iamVjdCBzZW5kZXIsIFByZXZpZXdLZXlEb3duRXZlbnRBcmdzIGUpCiAgICAgICAgewogICAgICAgICAgICBEb0tleUlucHV0KGUpOwogICAgICAgIH0KCiAgICB9Cn0K
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