示例#1
0
 public FildColor(Fild fg)
 {
     FildColorArray = new ConsoleColor[fg.FildGame.GetLength(0), fg.FildGame.GetLength(1)];
     for (int y = 0; y < fg.FildGame.GetLength(0); y++)
     {
         for (int x = 0; x < fg.FildGame.GetLength(1); x++)
         {
             FildColorArray[y, x] = Settings.ConsColBackground;
         }
     }
 }
示例#2
0
文件: Run.cs 项目: Dblind/TETRISV1.0
        public static void RunGame()
        {
            haveGame = true;
            isSave   = false;
            Console.CursorVisible = false;
            Console.Clear();
            GameFild = new Fild(Settings.FildHeight, Settings.FildWidth);

            GameFild.NewFigure();

            bodyWhile();
        }
示例#3
0
 public static void TakeOutFigForm(Fild fg)
 {
     for (int i = 0; i < fg.FigNow.Form.GetLength(0); i++)
     {
         for (int j = 0; j < fg.FigNow.Form.GetLength(1); j++)
         {
             if (fg.FigNow.Form[i, j] == true)
             {
                 fg.FildGame[i + dotMove[0], j + dotMove[1]] = false;
                 if (fg.DelBrickColor != null)
                 {
                     fg.DelBrickColor(i + dotMove[0], j + dotMove[1], Settings.ConsColBackground);
                 }
             }
         }
     }
 }
示例#4
0
 public static void SetFigForm(Fild fg)
 {
     for (int i = 0; i < fg.FigNow.Form.GetLength(0); i++)
     {
         for (int j = 0; j < fg.FigNow.Form.GetLength(1); j++)
         {
             if (fg.FigNow.Form[i, j] == true)
             {
                 fg.FildGame[i + dotMove[0], j + dotMove[1]] = true;
                 if (fg.AddBrickColor != null)
                 {
                     fg.AddBrickColor(dotMove[0] + i, dotMove[1] + j, fg.FigNow.FigureColor);
                 }
             }
         }
     }
 }
示例#5
0
 public static bool CheckRight(Fild fg)
 {
     if (Move.dotMove[1] + fg.FigNow.Form.GetLength(1) == fg.FildGame.GetLength(1))
     {
         return(false);
     }
     else
     {
         Move.dotMove[1]++;
         if (SupportMethods.Intersection(fg.FigNow.Form, fg))
         {
             Move.dotMove[1]--; return(true);
         }
         else
         {
             Move.dotMove[1]--; return(false);
         }
     }
 }
示例#6
0
 public static bool CheckLeft(Fild fg)
 {
     if (Move.dotMove[1] == 0)
     {
         return(false);
     }
     else
     {
         Move.dotMove[1]--;
         if (SupportMethods.Intersection(fg.FigNow.Form, fg))
         {
             Move.dotMove[1]++; return(true);
         }
         else
         {
             Move.dotMove[1]++; return(false);
         }
     }
 }
示例#7
0
        public static void CheckRows(Fild fg)
        {
            Move.SetFigForm(fg);
            var flag = 0b11;

            for (int i = 0; i < fg.FildGame.GetLength(0); i++)
            {
                flag = flag | 0b10;
                for (int j = 0; j < fg.FildGame.GetLength(1); j++)
                {
                    if (fg.FildGame[i, j] == false)
                    {
                        flag = flag & 0b01; break;
                    }
                }
                if ((flag & 0b10) == 0b10)
                {
                    FallWall(i); fg.Score += fg.FildGame.GetLength(1);
                }
            }
            void FallWall(int row)
            {
                for (int i = row; i > 0; i--)
                {
                    for (int j = 0; j < fg.FildGame.GetLength(1); j++)
                    {
                        fg.FildGame[i, j] = fg.FildGame[i - 1, j];
                        if (Run.GameFild.FallWallColorScreen != null)
                        {
                            Run.GameFild.FallWallColorScreen(i, j);
                        }
                    }
                }
                for (int i = 0, j = 0; j < fg.FildGame.GetLength(1); j++)
                {
                    fg.FildGame[i, j] = false;
                    if (Run.GameFild.ClearUpLine != null)
                    {
                        Run.GameFild.ClearUpLine(i, j);
                    }
                }
            }
        }
示例#8
0
        public static void Push(ConsoleKeyInfo key, Fild GameFild)
        {
            char ch = key.KeyChar;

            if (ch.Equals(Settings.controlsKeys[0]))
            {
                ch = 'h';
            }
            else if (ch.Equals(Settings.controlsKeys[1]))
            {
                ch = 'k';
            }
            else if (ch.Equals(Settings.controlsKeys[2]))
            {
                ch = 'j';
            }
            else if (ch.Equals(Settings.controlsKeys[3]))
            {
                ch = 'u';
            }
            else if (ch.Equals(Settings.controlsKeys[4]))
            {
                ch = 'q';
            }
            else
            {
                return;
            }

            switch (ch)
            {
            case ('h'):
                if (Move.CheckLeft(GameFild))
                {
                    Move.MoveLeft(GameFild);
                    GameFild.ScreenRender();
                }
                break;

            case ('k'):
                if (Move.CheckRight(GameFild))
                {
                    Move.MoveRight(GameFild);
                    GameFild.ScreenRender();
                }
                break;

            case ('j'):
                if (Move.CheckDowd(GameFild))
                {
                    if (!Run.FlagFastFall)
                    {
                        Move.MoveDowd(GameFild);
                    }
                    Run.FlagFastFall = !Run.FlagFastFall;
                    Run.count        = 0;
                    Run.StepFall     = Run.FlagFastFall ? 10 : 99;
                }
                else
                {
                    GameFild.NewFigure();
                }
                GameFild.ScreenRender();
                break;

            case ('u'):
                GameFild.FigNow.Rotate(GameFild);
                GameFild.ScreenRender();
                break;

            case ('q'):
                GameFild.RunGame = false;
                Console.ResetColor();
                Console.CursorVisible = true;
                break;
            }
        }
示例#9
0
文件: Fild.cs 项目: Dblind/TETRISV1.0
        public static void PrintCharScreen(Fild fg)
        {
            Move.SetFigForm(fg);
            System.Console.CursorTop = 0; Console.CursorLeft = 0;
            Console.BackgroundColor  = Settings.ConsColBackground;
            Console.ForegroundColor  = Settings.ConsColBrick;
            for (int i = 0; i < fg.FildGame.GetLength(0); i++)
            {
                for (int j = 0; j < fg.FildGame.GetLength(1); j++)
                {
                    if (fg.FildGame[i, j])
                    {
                        System.Console.Write(Settings.keyBuild);
                    }
                    else
                    {
                        System.Console.Write(Settings.keyBackground);
                    }
                }
                System.Console.WriteLine();
            }
            Move.TakeOutFigForm(fg);

            Console.ResetColor();
            System.Console.WriteLine(Fild.counter);

            // print Score
            Console.CursorTop       = 0;
            Console.CursorLeft      = fg.FildGame.GetLength(1) + 3;
            Console.ForegroundColor = ConsoleColor.Red;
            System.Console.WriteLine(String.Format($"{fg.Score,10}"));

            // clear place for view NextFig
            for (int i = 0; i < fg.FigNext.Form.GetLength(0); i++)
            {
                ClearLine();
                for (int j = 0; j < fg.FigNext.Form.GetLength(1); j++)
                {
                    if (fg.FigNext.Form[i, j])
                    {
                        System.Console.Write(Settings.keyBuild);
                    }
                    else
                    {
                        System.Console.Write(Settings.keyBackground);
                    }
                }
            }
            if (fg.FigNext.Form.GetLength(0) < 3)
            {
                ClearLine(); ClearLine();
            }
            else if (fg.FigNext.Form.GetLength(0) < 4)
            {
                ClearLine();
            }
            void ClearLine()
            {
                System.Console.WriteLine();
                Console.CursorLeft = fg.FildGame.GetLength(1) + 3;
                System.Console.Write($"    ");
                Console.CursorLeft = fg.FildGame.GetLength(1) + 3;
            }

            // Task
            System.Console.WriteLine();
            System.Console.WriteLine();
            Console.CursorLeft = fg.FildGame.GetLength(1) + 3;
            System.Console.Write("Q: quit.");
        }
示例#10
0
 public static void MoveRight(Fild fg)
 {
     Move.dotMove[1]++;
 }
示例#11
0
 public static void MoveLeft(Fild fg)
 {
     Move.dotMove[1]--;
 }
示例#12
0
 public static void MoveDowd(Fild fg)
 {
     Move.dotMove[0]++;
 }