Marquee. Java

Source: Internet
Author: User

Public class marquee {
Int [] [] matrix;
Int N; // Number of walk-through steps
Int time; // a parameter for controlling the end
Int rank; // level
Coordinate start; // start point
Public static void main (string [] S ){
A ma = new A (12, new coordinate (0, 0 ));

Coordinate temp = ma. Start;
 
While (true ){
Int oldtime = ma. Time ();
/// Here is your step
Temp = ma. rightof (temp );
Temp = ma. downof (temp );
Temp = ma. leftof (temp );
Temp = ma. upof (temp );
//
If (oldtime = ma. Time () break;
}
Ma. Print ();
}
A (INT rank, coordinate start ){
N = 1;
This. Rank = rank;
Matrix = new int [Rank] [Rank];
Time = N;
This. Start = start;
Matrix [start. x] [start. Y] = N;
}
Public int time (){
Return this. Time;
}
Public void print (){
For (INT I = 0; I <this. rank; I ++ ){
System. Out. println ();
For (Int J = 0; j <this. rank; j ++ ){
System. Out. Print (this. Matrix [I] [J] + "");
}
}
}
// Regard the matrix as the Coordinate System
// Start from the xyrightfrom coordinate to the right until the boundary is reached or the current local vertex has been written.
// Four similar methods
Private coordinate rightof (coordinate xyrightfrom) {// xyrightfrom start point to the right
Int I = xyrightfrom. X;
Int J = xyrightfrom. Y;
While (J + 1 <rank & matrix [I] [J + 1] = 0 ){
N ++;
Matrix [I] [++ J] = N;
}
If (Matrix [I] [J] = 0) matrix [I] [J] = ++ N;
Time = N;
Return new coordinate (I, j );
}
Private coordinate downof (coordinate xydownfrom ){
Int I = xydownfrom. X;
Int J = xydownfrom. Y;
While (I + 1 <rank & matrix [I + 1] [J] = 0 ){
N ++;
Matrix [++ I] [J] = N;
}
If (Matrix [I] [J] = 0) matrix [I] [J] = ++ N;
Time = N;
Return new coordinate (I, j );
}
Private coordinate leftof (coordinate xyleftfrom ){
Int I = xyleftfrom. X;
Int J = xyleftfrom. Y;
While (J-1> = 0 & matrix [I] [J-1] = 0 ){
N ++;
Matrix [I] [-- J] = N;
}
If (Matrix [I] [J] = 0) matrix [I] [J] = ++ N;
Time = N;
Return new coordinate (I, j );
}
Private coordinate upof (coordinate xyupfrom ){
Int I = xyupfrom. X;
Int J = xyupfrom. Y;
While (I-1> = 0 & matrix [I-1] [J] = 0 ){
N ++;
Matrix [-- I] [J] = N;
}
If (Matrix [I] [J] = 0) matrix [I] [J] = ++ N;
Time = N;
Return new coordinate (I, j );
}
}
Class coordinate {
Int X;
Int y;
Coordinate (int x, int y ){
This. x = X;
This. Y = y;
}

}

 

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.