Ejemplo n.º 1
0
        private void btnOpenSave_Click(object sender, RoutedEventArgs e)
        {
            // Creating \Pentegames directory so there is no error
            System.IO.Directory.CreateDirectory(@"\CardGameGallery\War");
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = @"C:\CardGameGallery\War";
            openFileDialog.Multiselect      = true;
            openFileDialog.Filter           = "War Saves|*.War";
            //openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            if (openFileDialog.ShowDialog() == true)
            {
                try
                {
                    // Get the file path chosen by the user
                    stream = new FileStream(@$ "{openFileDialog.FileName}", FileMode.Open, FileAccess.Read);
                    // Deserializing the game save file to a GameSave object
                    WarSaveGame save = (WarSaveGame)formatter.Deserialize(stream);
                    // Opening the play window with the GameSave object
                    PlayWarWindow playWar = new PlayWarWindow(save, openFileDialog.FileName, this);
                    // Hiding main menu withle play window is up
                    Hide();
                    // Displaying the play window
                    playWar.Show();
                    // CLosing the stream to free up resources
                    stream.Close();
                }
                catch
                {
                    // If an error occurs while opening save file
                    MessageBox.Show("Something went wrong, try again.");
                }
            }
        }
Ejemplo n.º 2
0
 public PlayWarWindow(WarSaveGame save, string savePath, WarWindow calledFrom)
 {
     InitializeComponent();
     this.war        = save;
     this.savePath   = savePath;
     this.calledFrom = calledFrom;
     BindNames();
 }
Ejemplo n.º 3
0
 public PlayWarWindow(WarSaveGame newWar, WarWindow calledFrom)
 {
     InitializeComponent();
     this.calledFrom = calledFrom;
     war             = newWar;
     HandleLogicSetup();
     BindNames();
 }
Ejemplo n.º 4
0
        public List <List <Card> > GetPlayersCardsForNormalPlay(WarSaveGame war)
        {
            List <List <Card> > cfw = new List <List <Card> >();

            for (int i = 0; i < war.Players.Length; i++)
            {
                cfw.Add(new List <Card>());
            }
            HandleGettingCardsForWar(war, cfw, CARDS_FOR_NORMAL_PLAY);
            return(cfw);
        }
Ejemplo n.º 5
0
        private void btnPlay_Click(object sender, RoutedEventArgs e)
        {
            Player[] players = new Player[PLAYERS];
            players[0] = new Player(txtName1.Text, false, new List <Card>(), 0);
            players[1] = new Player(txtName2.Text, (bool)p2.IsChecked, new List <Card>(), 0);
            WarSaveGame   newWar  = new WarSaveGame(players);
            PlayWarWindow playWar = new PlayWarWindow(newWar, this);

            Hide();
            playWar.Show();
        }
Ejemplo n.º 6
0
        // Saves teh current state of the game, returns whether the file was saved or not
        public bool SaveGame(WarSaveGame war, string saveGamePath)
        {
            try
            {
                // Save files name is the current time
                string time = DateTime.Now.ToString("T");

                time = time.Replace(':', '-');

                IFormatter formatter = new BinaryFormatter();
                System.IO.Directory.CreateDirectory(@"\CardGameGallery\War");
                string path   = saveGamePath.Equals("") ? @$ "\CardGameGallery\War\{time}.War" : saveGamePath;
                Stream stream = new FileStream(@$ "{path}", FileMode.Create, FileAccess.Write);

                formatter.Serialize(stream, war);
                stream.Close();
                return(true);
            }
Ejemplo n.º 7
0
        public void DealCards(WarSaveGame war)
        {
            war.Deck.Shuffle();
            int pIndex = 0;

            while (war.Deck.DeckNotEmpty())
            {
                Card temp = war.Deck.DrawCard();
                war.Players[pIndex].cards.Add(temp);
                if (pIndex == war.Players.Length - 1)
                {
                    pIndex = 0;
                }
                else
                {
                    pIndex++;
                }
            }
        }