C # Push Box (only one off)

Source: Internet
Author: User

Class Program
{
static void Ditu (int[,] map)//The function of building a mapping, 10x10
{
for (int i = 0; i <; i++)
{
for (int j = 0; J <; J + +)
{
if (Map[i, j] = = 0)
{
Console.Write ("");
}
else if (map[i, j] = = 1)
{
Console.Write ("");
}
else if (map[i, j] = = 2)
{
Console.Write ("");
}
else if (map[i, j] = = 3)
{
Console.Write ("★");
}
else if (map[i, j] = = 4)
{
Console.Write ("♀");
}
}
Console.WriteLine ();
}

}
static void Main (string[] args)
{
int[,] Map = new int[10, 10]
{
{1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,1,0,0,1},
{1,4,2,0,0,0,1,0,0,1},
{1,0,0,0,0,0,1,1,1,1},
{1,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,0,0,1},
{1,0,0,1,0,0,1,0,0,1},
{1,3,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1},
};
int x = 2, y = 1, t = 0, T1 = 0, tx = 0;
while (true)
{
Ditu (MAP);
if (tx = = 100)//The last step refers to the front.
{
Console.WriteLine ("Congratulations on the first pass. ");

Break
}
Consolekeyinfo s = Console.readkey (); Assigning a variable to a key
#region = = up
if (s.key.tostring () = = "UpArrow")
{
if (map[x-1, y] = = 2 && map[x-2, y] = = 0)//two times bubbling
{
t = map[x-2, y];
Map[x-2, Y] = map[x-1, y];
Map[x-1, y] = t;

T1 = map[x-1, y];
Map[x-1, Y] = map[x, y];
Map[x, y] = t1;
x--;
}
Else if (map[x-1, y] = = 0)
{
T = map[x-1, y];
Map[x-1, Y] = map[x, y];
Map[x, y] = t;
x--;
}
Else if (map[x-1, y] = = 1 | | (map[x-1, y] = = 2 && map[x-2, y] = = 1))
{
Console.WriteLine ("You have not learned to wear wall surgery, please go to the Mall to buy!") ");
Console.ReadLine ();//Wall Enter
}
}
#endregion
#region = = down
if (s.key.tostring () = = "DownArrow")
{
if (map[x + 1, y] = = 2 && map[x + 2, y] = = 0)
{
T = map[x + 2, y];
Map[x + 2, y] = map[x + 1, y];
Map[x + 1, y] = t;

T1 = map[x + 1, y];
Map[x + 1, y] = map[x, y];
Map[x, y] = t1;
X + +;
}
Else if (map[x + 1, y] = = 0)
{
T = map[x + 1, y];
Map[x + 1, y] = map[x, y];
Map[x, y] = t;
X + +;
}
Else if (map[x + 1, y] = = 1 | | (map[x + 1, y] = = 2 && map[x + 2, y] = = 1))
{
Console.WriteLine ("You have not learned to wear wall surgery, please go to the Mall to buy!") ");
Console.ReadLine ();//Wall Enter
}
}
#endregion
#region = right
if (s.key.tostring () = = "RightArrow") br> {
if (map[x, y + 1] = = 2 && map[x, y + 2] = = 0)
{
T = map[x, y + 2];
Map[x, y + 2] = map[x, y + 1];
Map[x, y + 1] = t;

T1 = map[x, y + 1];
Map[x, y + 1] = map[x, y];
Map[x, y] = t1;
y++;
}
Else if (map[x, y + 1] = = 0)
{
T = map[x, y + 1];
Map[x, y + 1] = map[x, y];
Map[x, y] = t;
y++;
}
Else if (map[x, y + 1] = = 1 | | (map[x, y + 1] = = 2 && map[x, y + 2] = = 1))
{
Console.WriteLine ("You have not learned to wear wall surgery, please go to the Mall to buy!") ");
Console.ReadLine ();//Wall Enter
}
}
#endregion
#region = = left
if (s.key.tostring () = = "Leftarrow")
{
if (map[x, y-1] = = 2 && map[x, y-2] = = 0)
{
T = map[x, y-2];
Map[x, y-2] = map[x, y-1];
Map[x, y-1] = t;

T1 = map[x, y-1];
Map[x, y-1] = map[x, y];
Map[x, y] = t1;
y--;
}
else if (map[x, y-1] = = 0)
{
t = map[x, y-1];
Map[x, y-1] = map[x, y];
Map[x, y] = t;
y--;
}
else if (map[x, y-1] = = 1 | | (map[x, y-1] = = 2 && map[x, y-2] = = 1))
{
Console.WriteLine ("You have not learned to wear wall surgery, please go to the Mall to buy!") ");
Console.ReadLine (); Hit the wall enter
}
}
#endregion
#region = = End
if (map[x, y-1] = = 2 && map[x, y-2] = = 3)
{
Map[x, y-2] = map[x, y-1];

Map[x, y-1] = map[x, y];
Map[x, y] = t;
tx = 100; Arbitrary assignment of a variable as the operating condition of the subsequent if.
}

#endregion
Console.clear (); Refresh the map once for each run.

}

Console.ReadLine ();
}
}

C # Push Box (only one off)

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.