string[,] erwei=New string[Ten,Ten] { {"■","■","■","■","■","■","■","■","■","■"}, {"■"," "," "," "," ","■"," "," "," ","■"}, {"■"," ","■"," "," ","■"," ","■"," ","■"}, {"■"," ","■","■"," ","■"," "," "," ","■"}, {"■"," "," ","■"," "," "," "," "," ","■"}, {"■"," "," ","■"," "," "," ","■"," ","■"}, {"■"," ","■","■"," ","■"," ","■"," ","■"}, {"■"," "," "," "," ","■"," "," "," ","■"}, {"■"," ","■"," ","■"," "," "," "," ","■"}, {"■","■","■","■","■","■","■","■","■","■"} }; intReny =1; intRenx =1; Erwei[reny, Renx]="♂"; while(true) { //Print Map for(intj =0; J <Ten; J + +) { for(inti =0; I <Ten; i++) {Console.Write (erwei[j, I]); } console.write ("\ n");//line Break} erwei[reny, Renx]=" ";//empty the "♂" symbol before operationConsole.Write ("Please press WASD to operate"); stringCuozuo =Console.ReadLine (); if(Cuozuo = ="W") { if(erwei[reny-1, renx]==" ") {Reny=reny-1; } } if(Cuozuo = ="s") { if(Erwei[reny +1, Renx] = =" ") {Reny= Reny +1; } } if(Cuozuo = ="a") { if(Erwei[reny, renx-1] ==" ") {Renx= Renx-1; } } if(Cuozuo = ="D") { if(Erwei[reny, renx+1] ==" ") {Renx= Renx +1; }} Erwei[reny, Renx]="♂";//The new position of the output person in a multidimensional arrayConsole.clear ();//Clear the previous trail} console.readline ();
Initial position
After 4-step s operation
Multidimensional Array (push box map and people run)