コード例 #1
0
        private void btnLoadGamestate_Click(object sender, EventArgs e)
        {
            var FD = new System.Windows.Forms.OpenFileDialog();
            if (FD.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string fileToOpen = FD.FileName;

                GameState gameState = new GameState();

                XmlSerializer deserializer = new XmlSerializer(typeof(GameState));
                TextReader reader = new StreamReader(fileToOpen);
                gameState = (GameState)deserializer.Deserialize(reader);

                gameState.DieSet.Dice.RemoveRange(0, 5);
                reader.Close();

                //Console.WriteLine(playerList.Count);
                MainForm gameForm = new MainForm();

                gameForm.ProcessGameState(gameState);
                gameForm.UpdateActivePlayer();

                gameForm.Show();

                Close();
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: jsgalla/YahtzeeNetwork
        public void ProcessGameState(GameState gameState)
        {
            this.PlayerList.Players = gameState.Players.Players;
            this.dieSet = gameState.DieSet;

            RenderDice(dieSet);

            //foreach (Player player in PlayerList.Players)
            //{
            //    player.ScoreSheet.setupGame("Yahtzee");
            //}

            this.createScoreSheet();

            int tempIndex = 0;

            foreach (Player player in PlayerList.Players)
            {
                ScoreSheet scoreSheet = player.ScoreSheet;

                List<YahtzeeCore.ScoringCategories.ScoringCategory> scoreSheetPrint = player.ScoreSheet.printScoreSheet();
                for (int i = 0; i < dataGridView1.RowCount; i++)
                {
                    if (scoreSheetPrint[i].HasBeenUsed)
                    {
                        dataGridView1.Rows[i].Cells[tempIndex].Value = scoreSheetPrint[i].FinalScore.ToString();
                    }
                    else
                    {
                        dataGridView1.Rows[i].Cells[tempIndex].Value = "";
                    }
                }

                tempIndex++;

            }
        }
コード例 #3
0
        public void CheckSerialization()
        {
            PlayerList playerList = new PlayerList();
            Turn turn = new Turn();
            DieSet dieSet = new DieSet();

            HumanPlayer hp = new HumanPlayer("Test Player Name");
            ComputerPlayer cp = new ComputerPlayer("Test Computer Player", new GreedyAIStrategy());

            playerList.Players.Add(hp);
            playerList.Players.Add(cp);

            dieSet.Roll();

            GameState gameState = new GameState();
            gameState.Players = playerList;
            gameState.Turn = turn;

            XmlSerializer serializer = new XmlSerializer(typeof(GameState));
            using (TextWriter writer = new StreamWriter(@"C:\GameStateTest.xml"))
            {
                serializer.Serialize(writer, gameState);
            }
        }
コード例 #4
0
        private void btnStartGame_Click(object sender, EventArgs e)
        {
            // Going to send out a GameState object here???
            // What is needed by the clients at this point to begin a new game?
            List<string> connected = YahtzeeNetworking.NetworkUtility.GetConnectedPlayerNames();
            GameState game = new GameState();
            PlayerList players = new PlayerList();
            foreach (string name in YahtzeeNetworking.NetworkUtility.GetConnectedPlayerNames())
            {
                players.Players.Add(new NetworkPlayer(name));
            }

            /* TEST CODE TO SIMULATE NETWORK
            players.Players.Add(new NetworkPlayer("Test"));*/

            players.makeNamesUnique();

            game.Players = players;

            YahtzeeNetworking.NetworkUtility.SendGameState(game);

            // TEMPORARY -- remove the echoed state
            //System.Threading.Thread.Sleep(500);
            //YahtzeeNetworking.NetworkUtility.RemoveGameState();
            // END TEMPORARY

            startGame(game);
        }
コード例 #5
0
        private void startGame(GameState game)
        {
            PlayerList myPlayerList = new PlayerList();

            foreach (Player player in game.Players.Players)
            {
                if (myLocalPlayers.Contains(player.Name))
                {
                    myPlayerList.Players.Add(new HumanPlayer(player.Name));
                }
                else if (myAIPlayers.Contains(player.Name))
                {
                    //myPlayerList.Players.Add(new ComputerPlayer(player.Name)); // NEED TO GET AI TYPE
                }
                else
                {
                    myPlayerList.Players.Add(new NetworkPlayer(player.Name));
                }
            }

            foreach (Player player in myPlayerList.Players)
            {
                player.ScoreSheet.setupGame("Yahtzee");
            }

            MainForm gameForm = new MainForm();

            gameForm.PlayerList.Players = myPlayerList.Players;
            gameForm.PlayerList.makeNamesUnique();
            gameForm.createScoreSheet();
            gameForm.isNetworkGame = true;

            gameForm.Show();
            Close();
        }
コード例 #6
0
ファイル: Form1.cs プロジェクト: jsgalla/YahtzeeNetwork
        private void SerializeAndStoreGameState()
        {
            GameState gameState = new GameState();
            gameState.Players = PlayerList;
            gameState.Turn = turn;
            gameState.DieSet = dieSet;

            XmlSerializer serializer = new XmlSerializer(typeof(GameState));
            using (TextWriter writer = new StreamWriter(@"C:\YahtzeeGameStates\" + DateTime.Now.ToString("mm-dd-yyyy_hh-mm-ss_") + "gameState.xml"))
            {
                serializer.Serialize(writer, gameState);
            }
        }
コード例 #7
0
ファイル: Form1.cs プロジェクト: jsgalla/YahtzeeNetwork
        private void sendGameState()
        {
            if (isNetworkGame)
            {
                GameState gameState = new GameState();
                gameState.Players = PlayerList;
                gameState.Turn = turn;
                gameState.DieSet = dieSet;
                YahtzeeNetworking.NetworkUtility.SendGameState(gameState);

                // TEMPORARY -- remove the echoed state
                Application.DoEvents();
                System.Threading.Thread.Sleep(500);
                Application.DoEvents();
                YahtzeeNetworking.NetworkUtility.RemoveGameState();
                // END TEMPORARY
            }
        }