Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我无法正确打印ics的图形_C#_Visual Studio 2010_For Loop_Move_Helper - Fatal编程技术网

C# 我无法正确打印ics的图形

C# 我无法正确打印ics的图形,c#,visual-studio-2010,for-loop,move,helper,C#,Visual Studio 2010,For Loop,Move,Helper,我在用c#做一个练习,在这个练习中,我必须在矩形内移动一个字符。问题在于,该框架位于sfasa右侧(见图)。我找不到错误有人能帮我吗 主要类别: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ricorsione2 { class Program { stat

我在用c#做一个练习,在这个练习中,我必须在矩形内移动一个字符。问题在于,该框架位于sfasa右侧(见图)。我找不到错误有人能帮我吗

主要类别:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ricorsione2
{
    class Program
    {
        static void Main(string[] args)
        {
           World mappa = new World(10,30,4,4);//grande 10X10 parte indice y,x
           char cho;
           do
           {


               Console.Clear();
               mappa.print();
               Console.WriteLine("\n\nDove vuoi andare?");
               cho = char.Parse(Console.ReadLine());
               mappa.choose(cho);
              
           
           }

           while (true);
           Console.ReadLine();

        }

    
            


        }

        
    }
世界级:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ricorsione2
{
    class World
    {

        
        int myLung;
        int myAltezza;
        int myX;
        int myY;
        public int startX;
        public int startY;


        public World(int lungArray, int altezzaArray, int xStartded, int yStarted)
        {
            this.myLung = lungArray;
            this.myAltezza = altezzaArray;
            this.myX = xStartded;
            this.myY = yStarted;
            startX = myX;
            startY = myY;
            

        }

        public void choose(char pos)
        {
            
                    switch(pos)
                    {

                        case'r':
                            move(1, 0); //x,y
                            break;

                        case'l':
                            move(-1, 0);
                            break;

                        case'u':
                            move(0, -1);
                           
                            break;

                        case'd':
                            move(0, 1); 
                            break;

                    }


        }



        public void move(int horizontal, int vertical)
        {
                    myX = (myX + vertical);
                    myY = (myY + horizontal);
        }
           
        
        
        public void print()
        {
            for(int i = 0; i<=myLung;i++)
            {
                Console.Write('\n');
                for(int j=0; j<=myAltezza; j++)
                {
                    if (i == myX && j == myY)

                        Console.Write('.');

                    if ((i == 0 || i == myLung) || (j == 0 || j == myAltezza))
                    

                        Console.Write('*');
                         
                    else

                        Console.Write(" ");

                   
                   
                    

                   
                }

            }

        }

    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
名称空间ricorsione2
{
阶级世界
{
英特迈隆;
内迈尔特扎;
int-myX;
int-myY;
公共int startX;
公共国际标准;
公共世界
{
this.myLung=lungArray;
this.myAltezza=altezzaArray;
this.myX=xstarted;
this.myY=yStarted;
startX=myX;
startY=myY;
}
公共无效选择(字符位置)
{
开关(pos)
{
案例“r”:
移动(1,0);//x,y
打破
案例“l”:
移动(-1,0);
打破
案例“u”:
移动(0,-1);
打破
案例d':
移动(0,1);
打破
}
}
公共空心移动(整数水平、整数垂直)
{
myX=(myX+垂直);
myY=(myY+水平);
}
公开作废印刷品()
{

对于(int i=0;i我想,您应该在
if
语句中添加
else
语句:

    if (i == myX && j == myY)
        Console.Write('.');
    else if ((i == 0 || i == myLung) || (j == 0 || j == myAltezza))
        Console.Write('*');
    else
        Console.Write(" ");

我找到了,当您打印点
然后您的代码继续时,您应该使用
继续;
转到下一个
I

将代码更改为:

if (i == myX && j == myY)
{
    Console.Write('.');
    continue;
}