Esempio n. 1
0
 /// <summary>
 /// Constructor for Map class. Makes a new map with random Places.
 /// </summary>
 /// <param name="size">THe size (x and y) of the map.</param>
 public Map(int size)
 {
     placeMap = new Place[size, size];
     for (int x = 0; x < placeMap.GetLength(0); x++)
     {
         for (int y = 0; y < placeMap.GetLength(1); y++)
         {
             placeMap[x, y] = new Place();
             placeMap[x, y].location = new Tuple<int, int>(x, y);
         }
     }
     for (int i = 0; i < places.Count; i++)
     {
         //get random location
         Tuple<int, int> coords = new Tuple<int, int>(Program.random.Next(0, placeMap.GetUpperBound(0)), Program.random.Next(0, placeMap.GetUpperBound(1)));
         //makse sure it's not occupied
         if (placeMap[coords.Item1, coords.Item2].GetType() == typeof(Place))
         {
             placeMap[coords.Item1, coords.Item2] = places[i];
             placeMap[coords.Item1, coords.Item2].location = coords;
             places.Remove(places[i]);
         }
         //redo it if it's occupied
         else
             i--;
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Gets the coordinate of the specified Place.
 /// NOTE: DOES NOT WORK WITH DEFAULT PLACE
 /// </summary>
 /// <param name="p">Place that needs locating</param>
 /// <returns>Returns a Tuple of ints containing the coordinates, or (-1, -1) if the place could not be found. </returns>
 public Tuple<int, int> getCoordsOf(Place p)
 {
     foreach(Place place in placeMap)
         if (place.GetType() == p.GetType())
             return place.location;
        return new Tuple<int, int>(-1, -1);
 }
Esempio n. 3
0
        /// <summary>
        /// This function is called when the user enters a command.
        /// </summary>
        /// <param name="input">The string to be operated upon.</param>
        public void HandleInput(string input)
        {
            //execute depending on the GameState
            switch (gm)
            {
                case GameState.GettingPlayerInfo:
                    //say hello
                    player.name = mainWindow.inputText.Text;
                    write("Welcome, ", "Black");
                    write(player.name, "MediumOrchid", true);
                    write(" to Realm 2.", "Black", true);
                    cw.Show();
                    mainWindow.IsEnabled = false;
                    int x = map.getCoordsOf(new SunKingdom()).Item1;
                    player.position.x = map.getCoordsOf(new SunKingdom()).Item1;
                    player.position.y = map.getCoordsOf(new SunKingdom()).Item2;
                    break;
                case GameState.Main:
                    if (!lastCommandFailed)
                    {
                        //write the current place name and description
                        write("Current Place: " + currentplace.name, "Black");
                        write(currentplace.desc, "Black");
                    }
                    writeStats();
                    //execute the command entered
                    if (input.Split().Length < 2)
                    {
                        write("Please enter an object to operate on.", "Red");
                        lastCommandFailed = true;
                        break;
                    }
                    if (!currentplace.ExecuteCommand(input.Split()[0], input.Split()[1]))
                    {
                        write("You cannot '" + input + "' here.", "Red");
                        lastCommandFailed = true;
                    }
                    else
                        lastCommandFailed = false;
                    break;
                case GameState.SunPalace:

                case GameState.Dead:
                    //close the game
                    Environment.Exit(0);
                    break;
                case GameState.Frozen:
                    //LEAVE THIS BLANK
                    break;
            }
            //if the Player's position isn't null, set the currentPlace varable to the Player's current location
            if (player.position != null)
                currentplace = map.getPlace(new Tuple<int, int>(player.position.x, player.position.y));
        }