Beispiel #1
0
 static void FinishOffShip(int[,] fieldUser, int[,] radarComp, ref Hit hitXY, ref BlownDeckCount bdc)
 {
     hitXY.DoMove(fieldUser, radarComp, ref bdc);
 }
Beispiel #2
0
        static void Start()
        {
            var bdc       = new BlownDeckCount();
            var fieldUser = ReadArrayFromFile();
            var radarUser = new int[Z, Z];

            var fieldComp = CreateCompArray();
            var radarComp = new int[Z, Z];

            int x = 1;
            int y = 1;

            Hit hitXY = new Hit(0, 0, 0)
            {
                Killed = true
            };

            bool endUserMove = false;

            Console.SetWindowSize(50, 40);
            ConsoleKeyInfo info;

            Console.WriteLine("Press any key to start");
            info = Console.ReadKey(true);

            do
            {
                PrintField(radarUser, fieldUser);
                PrintMove("User Move    ", ConsoleColor.Green, 1);
                PrintMove("                     ", ConsoleColor.Red, 2);
                if (bdc.TestWin())
                {
                    break;
                }
                Console.SetCursorPosition(y, x);

                if (!endUserMove)
                {
                    info = Console.ReadKey(true);
                    switch (info.Key)
                    {
                    case ConsoleKey.DownArrow:
                    {
                        if (TestXY(x + 1, y))
                        {
                            continue;
                        }
                        x++;
                        break;
                    }

                    case ConsoleKey.UpArrow:
                    {
                        if (TestXY(x - 1, y))
                        {
                            continue;
                        }
                        x--;
                        break;
                    }

                    case ConsoleKey.RightArrow:
                    {
                        if (TestXY(x, y + 1))
                        {
                            continue;
                        }
                        y += 2;
                        break;
                    }

                    case ConsoleKey.LeftArrow:
                    {
                        if (TestXY(x, y - 1))
                        {
                            continue;
                        }
                        y -= 2;
                        break;
                    }

                    case ConsoleKey.Enter:
                    {
                        if (TestUserMove(radarUser, x, y))
                        {
                            continue;
                        }
                        endUserMove = UserMove(fieldComp, radarUser, x, y, ref bdc);
                        TestFlooding(radarUser);
                        break;
                    }
                    }
                }
                else
                {
                    if (!hitXY.Killed)
                    {
                        if (hitXY.LastHit)
                        {
                            FinishOffShip(fieldUser, radarComp, ref hitXY, ref bdc);
                            TestFlooding(radarComp);
                            TestFlooding(fieldUser);
                            Thread.Sleep(1000);
                        }
                        else
                        {
                            endUserMove   = false;
                            hitXY.LastHit = true;
                        }
                    }
                    else
                    {
                        PrintMove("Computer Move", ConsoleColor.Red, 1);
                        endUserMove = CompMove(fieldUser, radarComp, ref hitXY, ref bdc) ? false : true;
                        Thread.Sleep(1000);
                    }
                }
            } while (info.Key != ConsoleKey.Escape);
        }