@@ -64,19 +64,23 @@ function mouseDown(event) {
64
64
function onMouseMove ( event ) {
65
65
x = parseInt ( event . offsetX / 4 ) ;
66
66
y = parseInt ( event . offsetY / 4 ) ;
67
- if ( grid [ y ] [ x ] [ 0 ] != 1 ) {
68
- grid [ y ] [ x ] = [ 1 , hue ] ;
69
- const randomNumber = Math . floor ( Math . random ( ) * 4 ) + 1 ;
70
- const randomNumber1 = Math . floor ( Math . random ( ) * 4 ) + 1 ;
71
- if ( y != grid . length - 1 && ( randomNumber == 1 || randomNumber1 == 1 ) ) { grid [ y + 1 ] [ x ] = [ 1 , hue ] ; }
72
- if ( x != grid [ y ] . length && ( randomNumber == 2 || randomNumber1 == 2 ) ) { grid [ y ] [ x + 1 ] = [ 1 , hue ] ; }
73
- if ( x != 0 && ( randomNumber == 3 || randomNumber1 == 3 ) ) { grid [ y ] [ x - 1 ] = [ 1 , hue ] ; }
74
- if ( y != 0 && ( randomNumber == 4 || randomNumber1 == 4 ) ) { grid [ y - 1 ] [ x ] = [ 1 , hue ] ; }
75
- if ( isDraw == false ) {
76
- isDraw = true ;
77
- document . getElementById ( "state" ) . innerText = "Running" ;
78
- draw ( ) ;
67
+ try {
68
+ if ( grid [ y ] [ x ] [ 0 ] != 1 ) {
69
+ grid [ y ] [ x ] = [ 1 , hue ] ;
70
+ const randomNumber = Math . floor ( Math . random ( ) * 4 ) + 1 ;
71
+ const randomNumber1 = Math . floor ( Math . random ( ) * 4 ) + 1 ;
72
+ if ( y != grid . length - 1 && ( randomNumber == 1 || randomNumber1 == 1 ) ) { grid [ y + 1 ] [ x ] = [ 1 , hue ] ; }
73
+ if ( x != grid [ y ] . length && ( randomNumber == 2 || randomNumber1 == 2 ) ) { grid [ y ] [ x + 1 ] = [ 1 , hue ] ; }
74
+ if ( x != 0 && ( randomNumber == 3 || randomNumber1 == 3 ) ) { grid [ y ] [ x - 1 ] = [ 1 , hue ] ; }
75
+ if ( y != 0 && ( randomNumber == 4 || randomNumber1 == 4 ) ) { grid [ y - 1 ] [ x ] = [ 1 , hue ] ; }
76
+ if ( isDraw == false ) {
77
+ isDraw = true ;
78
+ document . getElementById ( "state" ) . innerText = "Running" ;
79
+ draw ( ) ;
80
+ }
79
81
}
82
+ } catch ( error ) {
83
+
80
84
}
81
85
}
82
86
if ( mouseUp == false ) {
0 commit comments