using System; using System.Collections.Generic; class M { Dictionary d = new Dictionary( ); int p = 9, x, y, u, v, z; char a = '@', w = '#', f = '.', q = '$', c, k; Random r = new Random( ); M( ) { x = y = p; d[ S( x, y ) ] = a; k = K( ); while ( k != 'q' ) { Console.Clear( ); u = x; v = y; switch ( k ) { case '4': case 'h': x--; break; case '6': case 'l': x++; break; case '8': case 'k': y--; break; case '2': case 'j': y++; break; } c = C( S( x, y ) ); if ( c == w ) { x = u; y = v; } if ( c == q ) { Console.WriteLine( "Win" ); K( ); return; } d[ S( u, v ) ] = f; d[ S( x, y ) ] = a; z = p * 2 - 1; for ( int j = 0; j < z; j++ ) { for ( int i = 0; i < z; i++ ) { Console.Write( C( S( i - p + x, j - p + y ) ) ); } Console.WriteLine( ); } k = K( ); } } string S( int x, int y ) { return String.Format( "{0}_{1}", x, y ); } char C( String s ) { if ( d.ContainsKey( s ) ) return d[ s ]; return d[ s ] = r.Next( 9999 ) == 9 ? q : r.Next( 9 ) < 8 ? f : w; } char K( ) { return ( Console.ReadKey( true ) ).KeyChar; } static void Main() { new M( ); } }