コード例 #1
0
 static void displayPlayerLocations()
 {
     for (int playerIndex = 0; playerIndex < numPlayers; playerIndex++)
     {
         Console.Out.WriteLine("Player " + playerIndex + " is at " + PositionSystem.getCharacterPosition(0, playerIndex));
     }
 }
コード例 #2
0
        // displays a menu and asks for a movement of a player
        // returns true on continue
        // returns false on quit
        static bool doMenu()
        {
            Console.Out.WriteLine("Q to quit.  0->" + (numPlayers - 1).ToString() + " to move a player");

            string input = Console.ReadLine();

            if (input.ToLower() == "q")
            {
                return(false);
            }

            int playerIndex;

            try {
                playerIndex = int.Parse(input);
            }
            catch {
                return(true);
            }

            if (playerIndex < 0 || playerIndex >= numPlayers)
            {
                Console.Out.WriteLine("There is no player " + playerIndex);
                return(true);
            }

            Console.Out.WriteLine("'+X' to move player " + playerIndex + " in the +X direction");
            Console.Out.WriteLine("'-X' to move player " + playerIndex + " in the -X direction");
            Console.Out.WriteLine("'+Y' to move player " + playerIndex + " in the +Y direction");
            Console.Out.WriteLine("'-Y' to move player " + playerIndex + " in the -X direction");
            Console.Out.WriteLine("'T' to teleport player " + playerIndex + " to " + Vector3D.NewZero());

            input = Console.ReadLine().ToLower();

            try {
                switch (input)
                {
                case "+x":
                    PositionSystem.walkCharacterPlusX(0, playerIndex);
                    MapSystem.currentMap.events.onMove(PositionSystem.getCharacterPosition(0, playerIndex));
                    break;

                case "-x":
                    PositionSystem.walkCharacterMinusX(0, playerIndex);
                    MapSystem.currentMap.events.onMove(PositionSystem.getCharacterPosition(0, playerIndex));
                    break;

                case "+y":
                    PositionSystem.walkCharacterPlusY(0, playerIndex);
                    MapSystem.currentMap.events.onMove(PositionSystem.getCharacterPosition(0, playerIndex));
                    break;

                case "-y":
                    PositionSystem.walkCharacterMinusY(0, playerIndex);
                    MapSystem.currentMap.events.onMove(PositionSystem.getCharacterPosition(0, playerIndex));
                    break;

                case "t":
                    PositionSystem.teleportCharacterToWalkableLocation(0, playerIndex, Vector3D.NewZero());
                    MapSystem.currentMap.events.onMove(PositionSystem.getCharacterPosition(0, playerIndex));
                    break;

                default:
                    Console.Out.WriteLine("Invalid Input");
                    break;
                }
            }
            catch (PositionSystem.PositionNotOnMapException) {
                Console.Out.WriteLine("Cannot walk off the map.");
            }
            catch (PositionSystem.MoveToNewPositionIsBlockedException e) {
                Console.Out.WriteLine(e.Message);
            }
            catch (PositionSystem.NoSuchCharacterException e) {
                // this should never happen, so throw an exception
                throw e;
            }

            return(true);
        }