zoukankan      html  css  js  c++  java
  • 例题:二维数组打印推箱子地图

       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,0,2,0,0,0,1,0,0,1},

                    {1,0,0,0,0,0,1,0,0,1},

                    {1,0,0,0,0,0,0,1,0,1},

                    {1,0,0,0,0,0,0,1,0,1},

                    {1,0,0,1,0,0,0,0,0,1},

                    {1,1,1,1,0,0,0,0,0,1},

                    {1,0,0,0,8,0,0,0,9,1},

                    {1,1,1,1,1,1,1,1,1,1},

                };

        for (int i = 0; i < 10; i++)
                {
                    for (int j = 0; j < 10; j++)
                    {
                        if (map[i, j] == 1)
                        {
                            Console.Write("□");//墙壁
                        }
                        else if (map[i, j] == 0)
                        {
                            Console.Write("  ");
                        }
                        else if (map[i, j] == 2)
                        {
                            Console.Write("○");//箱子
                        }
                        else if (map[i,j]==9)
                        {
                            Console.Write("★");//把箱子推到的位置
                        }
                        else if (map [i,j]==8)
                        {
                            Console.Write("人");
                        }/把地图显示出来

  • 相关阅读:
    个人介绍
    C++ 之 第四课 C++中的运算符、表达式
    Delphi 之 第六课 过程与函数
    Delphi 之 第五课 流程语句
    VB 之 第三课 VB API 字体函数的应用
    C++ 之 第三课 C++数据类型
    Delphi 之 第四讲 自定义数据类型
    Delphi 之 第三课 详解数据类型
    C++ 之 第二课 C++类、函数的讲解
    VB API 第二课 之 字符串大小写转换
  • 原文地址:https://www.cnblogs.com/275147378abc/p/4431770.html
Copyright © 2011-2022 走看看