private void MainMenuBtnSave_Click(object sender, EventArgs e)
 {
     try
     {
         Saves.MakeGame(Saves.Filename);
         SbMain.MessageQueue.Enqueue("Game successfully saved to " + System.IO.Path.GetFileName(Saves.Filename));
     }
     catch (Exception ex)
     {
         ((App)Application.Current).ShowException("Couldn't save game correctly", ex);
     }
 }
        private void OpenGame()
        {
            try
            {
                Saves.LoadGame(Saves.Filename, Saves.Characters, Saves.Items, Saves.Places);
                Saves.AddToRecents(new GameFileData(Saves.Filename, System.IO.Path.GetFileName(Saves.Filename), DateTime.Now));

                SbMain.MessageQueue.Enqueue("Game loaded sucessfully");
                RbRooms.IsChecked = true;
            }
            catch (FileNotFoundException ex)
            {
                ((App)Application.Current).ShowException("File not found", ex);
            }
        }
        private void MainMenuBtnNew_Click(object sender, EventArgs e)
        {
            Saves.Filename   = "newgme.tmp";
            Saves.Characters = new List <Character>();
            Saves.Items      = new List <Item>();
            Saves.Places     = new List <Place>();

            Place startRoom = new Place();

            startRoom.id          = Saves.FindFreeID(1, 1000, Saves.Places.GetIDs());
            startRoom.Description = "A new room";
            startRoom.North       = 0;
            startRoom.South       = 0;
            startRoom.East        = 0;
            startRoom.West        = 0;
            startRoom.Up          = 0;
            startRoom.Down        = 0;
            Saves.Places.Add(startRoom);

            OpenGame();
        }
        /// <summary>
        /// Adds an item to the Items list with the place as its location
        /// </summary>
        /// <param name="itemid"></param>
        /// <param name="name"></param>
        /// <param name="description"></param>
        /// <param name="status"></param>
        /// <param name="commands"></param>
        /// <param name="results"></param>
        /// <returns></returns>
        public int AddItem(int itemid, string name, string description, List <string> status, List <string> commands, List <string[]> results)
        {
            Item newItem = new Item();

            if (itemid == -1)
            {
                int[] idList = Saves.Items.GetIDs();
                newItem.ID = Saves.FindFreeID(2001, 9999, idList);
            }
            else
            {
                newItem.ID = itemid;
            }
            newItem.Name        = name;
            newItem.Description = description;
            newItem.Location    = id;
            newItem.OverWriteStatus(status);
            newItem.OverWriteCommands(commands);
            newItem.OverWriteResults(results);

            Saves.Items.Add(newItem);

            return(newItem.ID);
        }
        public Place(int[] idList)
        {
            new Place();

            id = Saves.FindFreeID(1, 1999, idList);
        }
Exemple #6
0
        private void UserControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            List <GameFileData> gfd = Saves.GetRecents();

            LvRecents.ItemsSource = gfd;
        }
        private void BtnDoorCreate_Click(object sender, RoutedEventArgs e)
        {
            string errorMessage = "";

            if (LvDoorColours.SelectedItems.Count != 1)
            {
                errorMessage += "Please choose a door colour\n";
            }
            if (CbDoorStatus.SelectedItem == null)
            {
                errorMessage += "Please choose a door status";
            }
            if (errorMessage.Length != 0)
            {
                MessageBox.Show(errorMessage, "Failed to add door");
            }
            else
            {
                // Create/edit the primary door
                Item primaryDoor   = new Item();
                Item secondaryDoor = new Item();

                primaryDoor.Name        = LvDoorColours.SelectedItem.ToString().ToLower() + " door";
                primaryDoor.Description = "It is a " + primaryDoor.Name;
                primaryDoor.Location    = RoomID;
                primaryDoor.Status      = ((ComboBoxItem)CbDoorStatus.SelectedItem).Content.ToString().ToLower();
                primaryDoor.Commands    = "open,close";
                primaryDoor.Results     = PrimaryRoomDirection.LocToString().ToLower() + "," + TargetRoomID.ToString() +
                                          ";" + PrimaryRoomDirection.LocToString().ToLower() + ",0";

                // Create the secondary door
                secondaryDoor.Name        = primaryDoor.Name;
                secondaryDoor.Description = primaryDoor.Description;
                secondaryDoor.Location    = TargetRoomID;
                secondaryDoor.Status      = primaryDoor.Status;
                secondaryDoor.Commands    = primaryDoor.Commands;
                secondaryDoor.Results     = SecondaryRoomDirection.LocToString().ToLower() + "," + RoomID.ToString() +
                                            ";" + SecondaryRoomDirection.LocToString().ToLower() + ",0";

                if (Create)
                {
                    primaryDoor.ID   = Saves.FindFreeID(2001, 9999, Saves.Items.GetIDs());
                    secondaryDoor.ID = primaryDoor.ID + 10000;
                    Saves.Items.Add(primaryDoor);
                    Saves.Items.Add(secondaryDoor);
                }
                else if (PrimaryDoorID != 0 && SecondaryDoorID != 0)
                {
                    primaryDoor.ID   = PrimaryDoorID;
                    secondaryDoor.ID = SecondaryDoorID;
                    Saves.Items[Saves.Items.GetIndexFromID(primaryDoor.ID)]   = primaryDoor;
                    Saves.Items[Saves.Items.GetIndexFromID(secondaryDoor.ID)] = secondaryDoor;
                }
                else
                {
                    throw new Exception("Pre-existing doors must be specified with an ID");
                }

                switch (((ComboBoxItem)CbDoorStatus.SelectedItem).Content.ToString().ToLower())
                {
                case "open":
                    Saves.Places[Saves.Places.GetIndexFromID(RoomID)].SetDirection(PrimaryRoomDirection, TargetRoomID);
                    Saves.Places[Saves.Places.GetIndexFromID(TargetRoomID)].SetDirection(SecondaryRoomDirection, RoomID);
                    break;

                case "close":
                    Saves.Places[Saves.Places.GetIndexFromID(RoomID)].SetDirection(PrimaryRoomDirection, 0);
                    Saves.Places[Saves.Places.GetIndexFromID(TargetRoomID)].SetDirection(SecondaryRoomDirection, 0);
                    break;

                case "locked":
                    Saves.Places[Saves.Places.GetIndexFromID(RoomID)].SetDirection(PrimaryRoomDirection, 0);
                    Saves.Places[Saves.Places.GetIndexFromID(TargetRoomID)].SetDirection(SecondaryRoomDirection, 0);
                    break;

                default:
                    throw new InputException(((ComboBoxItem)CbDoorStatus.SelectedItem).Content.ToString().ToLower() + " is not a valid status");
                }

                OnDoorCreation?.Invoke(sender, EventArgs.Empty);
            }
        }