Esempio n. 1
0
 void OnDestroy()
 {
     if (instance == this)
     {
         instance = null;
     }
 }
Esempio n. 2
0
        public void checkCheckTest()
        {
            /*By moving the white bishops to a panel where it would
            *  put the black king in check (and clearing the rest of
            *  the board, this procedure ensures check is recognised*/
            BoardGen board = new BoardGen();

            Panel[,] gen = board.GenerateBoard();
            foreach (Piece p in board.getPieces().ToList())
            {
                if (!p.getType().Contains("King") && !(p.getType() == "WBishop"))
                {
                    board.RemovePiece(p);
                }
            }
            board.setPanelsInUse();

            foreach (Piece p in board.getPieces())
            {
                if (p.getType() == "WBishop")
                {
                    p.setPanel(gen[0, 4]);
                    p.setMoves(board, false, false);
                    if (!(p.checkCheck(board)))
                    {
                        Assert.Fail();
                    }
                }
            }
        }
Esempio n. 3
0
        public static string[] ShipCoords(Player player, Ship ship)
        {
            var menu = new Menu {
                Title                 = $"Place size {ship.Size} {ship.Title}",
                DisableGoBackItem     = true,
                DisplayQuitToMainMenu = true,
                ClearConsole          = false,
                MenuTypes             = new List <MenuType> {
                    MenuType.Input, MenuType.ShipCoordInput
                },
                MenuItems = new List <MenuItem> {
                    new MenuItem {
                        Description = "Input format: <a..> <1..> <direction>"
                    },
                    new MenuItem {
                        Description = "<direction> is right/r or down/d"
                    }
                }
            };

            while (true)
            {
                Console.Clear();
                Console.WriteLine();
                BoardGen.GenSingleBoard(player, $"Place {player.Name}'s ships");
                Console.WriteLine();

                var input = menu.RunMenu();

                if (input.ToUpper().Equals(MenuInitializers.QuitToMainItem.Shortcut))
                {
                    return(null);
                }

                var split = input.Split(" ");

                if (split.Length != 3)
                {
                    Console.WriteLine("Invalid number of arguments!");
                    Console.ReadKey(true);
                    continue;
                }

                var strX   = split[0].Trim();
                var strY   = split[1].Trim();
                var strDir = split[2].Trim();

                if (strX.Length < 1 || strX.Length > 16 ||
                    strY.Length < 1 || strY.Length > 16 ||
                    strDir.Length < 1 || strDir.Length > 16)
                {
                    Console.WriteLine("Invalid input length!");
                    Console.ReadKey(true);
                    continue;
                }

                return(new[] { strX, strY, strDir });
            }
        }
Esempio n. 4
0
        public void getValueTest()
        {
            BoardGen board = new BoardGen();

            Panel[,] gen = board.GenerateBoard();
            Piece TestPiece = new Bishop("WBishop", gen[3, 4], true);

            if (TestPiece.getValue(board) != 31)
            {
                Assert.Fail();
            }
        }
Esempio n. 5
0
        public static string[] AttackCoords(Player p1, Player p2)
        {
            var menu = new Menu {
                Title                 = "Enter attack coordinates",
                DisableGoBackItem     = true,
                DisplayQuitToMainMenu = true,
                ClearConsole          = false,
                MenuTypes             = new List <MenuType> {
                    MenuType.Input, MenuType.CoordInput
                },
                MenuItems = new List <MenuItem> {
                    new MenuItem {
                        Description = "Input format: <a..> <1..>"
                    }
                }
            };

            while (true)
            {
                Console.Clear();
                Console.WriteLine();
                BoardGen.GenTwoBoards(p1, p2);
                Console.WriteLine();

                var input = menu.RunMenu();

                if (input.ToUpper().Equals(MenuInitializers.QuitToMainItem.Shortcut))
                {
                    return(null);
                }

                var split = input.Split(" ");

                if (split.Length != 2)
                {
                    Console.WriteLine("Invalid number of arguments!");
                    Console.ReadKey(true);
                    continue;
                }

                var strX = split[0].Trim();
                var strY = split[1].Trim();

                if (strX.Length < 1 || strX.Length > 16 || strY.Length < 1 || strY.Length > 16)
                {
                    Console.WriteLine("Invalid input length!");
                    Console.ReadKey(true);
                    continue;
                }

                return(new[] { strX, strY });
            }
        }
Esempio n. 6
0
 void Awake()
 {
     if (instance && instance != this)
     {
         Destroy(this.gameObject);
     }
     else
     {
         instance = this;
         board    = null;
         DontDestroyOnLoad(this);
     }
 }
Esempio n. 7
0
        public void getMovesTestPawn()
        {
            /*By putting the pawn on a specific panel, I have looked at
             * what moves the pawn should have on this panel, and made sure
             * this is the same as what the function getMoves() returns*/
            BoardGen board = new BoardGen();

            Panel[,] gen = board.GenerateBoard();
            Piece TestPiece = new Pawn("WPawn", gen[3, 4], true);

            TestPiece.setMoves(board, false, false);
            List <Panel> DesiredPossibleMoves = new List <Panel> {
                gen[3, 3], gen[3, 4]
            };

            if (TestPiece.getMoves().Except(DesiredPossibleMoves).ToList().Count() != 0)
            {
                Assert.Fail();
            }
        }
Esempio n. 8
0
        private static bool InitializeShips()
        {
            foreach (var player in ActiveGame.Players)
            {
                while (true)
                {
                    // Ask to auto-place ships
                    var t = $"Creating {player.Name}'s ships";
                    var autoPlaceShips = YesNoQuitMenu(t, "Automatically place ships", "Manually place ships", true);

                    // Player requested to quit to main menu
                    if (autoPlaceShips == null)
                    {
                        return(false);
                    }

                    if ((bool)autoPlaceShips)
                    {
                        if (!GameLogic.AutoPlaceShips(player))
                        {
                            PlayerLogic.ResetShips(player);
                            Console.WriteLine("Could not place ships...");
                            Console.ReadKey(true);
                        }
                    }
                    else
                    {
                        // Manually place ships
                        foreach (var ship in player.Ships)
                        {
                            while (true)
                            {
                                var input = ShipCoordsMenu(player, ship);

                                // Player wants to quit game
                                if (input == null)
                                {
                                    return(false);
                                }

                                var validLoc = InputValidator.CheckValidShipPlacementLoc(player, ship.Size, input[0],
                                                                                         input[1], input[2], out var pos, out var dir);
                                if (!validLoc)
                                {
                                    Console.WriteLine("Invalid location!");
                                    Console.ReadKey(true);
                                    continue;
                                }

                                ship.SetLocation(pos, dir);
                                break;
                            }
                        }
                    }

                    Console.Clear();
                    BoardGen.GenSingleBoard(player, $"{player.Name}'s board");
                    Console.WriteLine();

                    // Ask to re-place the ships
                    var accept = YesNoQuitMenu("Ship menu", "Accept positions", "Redo placement", false);

                    // Player requested to quit to main menu
                    if (accept == null)
                    {
                        return(false);
                    }

                    if (!(bool)accept)
                    {
                        PlayerLogic.ResetShips(player);
                        continue;
                    }

                    break;
                }
            }

            // Ships were successfully placed
            return(true);
        }