Java console and java Console

Source: Internet
Author: User

Java console and java Console

1 import java. util. extends; 2 public class B {3 4 public static void main (String [] args) {5 inputs input = new inputs (System. in); 6 int [] [] map = new int [15] [15]; // map 7 int rx = 1; 8 int ry = 2; // coordinate 9 int xx = 13; 10 int xy = 12; // coordinate 11 int mx = 10; 12 int my = 3; // destination coordinate 13 14 map [rx] [ry] = 1; // set the coordinates of a person to 1 15 map [xx] [xy] = 2; // set the Coordinate Position of the box to 2 16 map [mx] [my] = 3; // set the Coordinate Position of the destination to 3 17 boolean tt = false; 18 19 while (true) {20 for (int I = 0; I <15; I ++) {21 for (int j = 0; j <15; j ++) {22 if (map [I] [j] = 1) {23 System. out. print ("prisoner"); // character 24} else if (map [I] [j] = 2) {25 System. out. print ("▲"); // box 26} else if (map [I] [j] = 3) {27 System. out. print ("★"); // Destination 28} else {29 System. out. print ("□"); // map 30} 31} 32 System. out. println (); // wrap 33} 34 if (tt) {// judge 35 System. out. print ("the box is successfully pushed to the end! "); 36 break; // jump out of loop 37} 38 System. out. print ("where to go (w, s, a left, d right):"); // user input 39 String f = input. next (); // only receives one character 40 41 if (f. equals ("w") {// 42 // determine whether a person is going to the edge 43 if (rx-1 <0) {44 continue; 45} 46 // determine whether a person pushes a box 47 if (map [rx-1] [ry] = 2) {48 // determine whether the box is on the edge 49 if (rx-2 <0) {50 continue; 51} 52 // determine whether the box enters the destination 53 if (map [rx-2] [ry] = 3) {54 tt = true; 55} 56 // box step 57 map [rx-2] [ry] = 2; 58} 59 // determine whether a person is going to the destination 60 if (map [rx-1] [ry] = 3) {61 map [rx] [ry] = 0; 62 rx --; 63 continue; 64} else if (map [rx] [ry] = 3) {// determine whether a person is going out of the destination 65 map [rx] [ry] = 3; 66 rx --; 67 map [rx] [ry] = 1; 68 continue; 69} 70 map [rx] [ry] = 0; 71 rx --; 72 map [rx] [ry] = 1; 73 74} else if (f. equals ("s") {// next 75 // judge whether a person has reached the edge 76 if (rx + 1> 14) {77 continue; 78} 79 // judge whether a person pushes the box 80 if (map [rx + 1] [ry] = 2) {81 // determine whether the box is on the edge 82 if (rx + 2> 14) {83 continue; 84} 85 // determine whether the box enters the destination 86 if (map [rx + 2] [ry] = 3) {87 tt = true; 88} 89 // box step 90 map [rx + 2] [ry] = 2; 91} 92 // determine whether a person has reached the destination. 93 if (map [rx + 1] [ry] = 3) {94 map [rx] [ry] = 0; 95 rx ++; 96 continue; 97} else if (map [rx] [ry] = 3) {// determine whether a person has stepped out of the destination 98 map [rx] [ry] = 3; 99 rx ++; 100 map [rx] [ry] = 1; 101 continue; 102} 103 map [rx] [ry] = 0; 104 rx ++; 105 map [rx] [ry] = 1; 106 107} else if (f. equals ("a") {// left 108 // determines whether a person is going to the edge 109 if (ry-1 <0) {110 continue; 111} 112 // determine whether the person pushes the Box 113 if (map [rx] [ry-1] = 2) {114 // determine whether the box is on the side 115 if (ry-2 <0) {116 continue; 117} 118 // determine whether the box enters the destination 119 if (map [rx] [ry-2] = 3) {120 tt = true; 121} 122 // box step by step 123 map [rx] [ry-2] = 2; 124} 125 // determine whether a person has reached the destination 126 if (map [rx] [ry-1] = 3) {127 map [rx] [ry] = 0; 128 ry --; 129 continue; 130} else if (map [rx] [ry] = 3) {// determine whether a person is out of the destination. 131 map [rx] [ry] = 3; 132 ry --; 133 map [rx] [ry] = 1; 134 continue; 135} 136 map [rx] [ry] = 0; 137 ry --; 138 map [rx] [ry] = 1; 139} else if (f. equals ("d") {// right 140 // determine whether a person has reached the edge 141 if (ry + 1> 14) {142 continue; 143} 144 // determine whether a person pushes a box 145 if (map [rx] [ry + 1] = 2) {146 // determine whether the box is on the edge 147 if (ry + 2> 14) {148 continue; 149} 150 // determine whether the box enters the destination 151 if (map [rx] [ry + 2] = 3) {152 tt = true; 153} 154 // The box goes one step. 155 map [rx] [ry + 2] = 2; 156} 157 // determine whether a person has reached the destination 158 if (map [rx] [ry + 1] = 3) {159 map [rx] [ry] = 0; 160 ry ++; 161 continue; 162} else if (map [rx] [ry] = 3) {// determine whether a person has stepped out of the destination: 163 map [rx] [ry] = 3; 164 ry ++; 165 map [rx] [ry] = 1; 166 continue; 167} 168 map [rx] [ry] = 0; 169 ry ++; 170 map [rx] [ry] = 1; 171} 172 173} 174} 175}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.