Inheritance: GameStateAction
        public static GameStateTurnAction Deserialize(string s)
        {
            string[] ss = s.Split(new char[] { '|' });

            GameState gs = GameState.Deserialize(ss[0]);

            ss = ss[1].Split(' ');

            int        time   = int.Parse(ss[0]);
            TurnAction action = (TurnAction)Enum.Parse(typeof(TurnAction), ss[1]);

            GameStateTurnAction gsta = new GameStateTurnAction(gs, time, action);

            return(gsta);
        }
        public static GameStateTurnAction Deserialize(string s)
        {
            string[] ss = s.Split(new char[] { '|' });

            GameState gs = GameState.Deserialize(ss[0]);

            ss = ss[1].Split(' ');

            int time = int.Parse(ss[0]);
            TurnAction action = (TurnAction)Enum.Parse(typeof(TurnAction), ss[1]);

            GameStateTurnAction gsta = new GameStateTurnAction(gs, time, action);

            return gsta;
        }
 public static string Serialize(GameStateTurnAction gsta)
 {
     return(GameState.Serialize(gsta.GameState) + "|" + gsta.time + " " + gsta.turnAction.ToString());
 }
Exemplo n.º 4
0
        private void buttonRoll_Click(object sender, EventArgs e)
        {
            watch.Stop();

            GameStateTurnAction gsta = new GameStateTurnAction(currentGameState.Clone(), watch.ElapsedMilliseconds, TurnAction.Roll);

            turns.Add(gsta);

            textBoxLog.Text += "Turn action added" + " " + watch.ElapsedMilliseconds + "ms." + Environment.NewLine;
            textBoxLog.SelectionStart = textBoxLog.Text.Length;
            textBoxLog.ScrollToCaret();

            buttonRoll.Enabled = false;
            buttonRoll.Visible = false;

            currentGameState.SetDice(random.Next(1, 7), random.Next(1, 7));
            originalGameState = currentGameState.Clone();

            legalPlays = currentGameState.Board.LegalPlays(currentGameState.PlayerOnRoll, currentGameState.Dice);

            if (legalPlays.Count == 0)
            {
                this.Render();
                this.Refresh();

                legalPlays.Clear();
                madeMoves.Clear();
                unusedDice.Clear();

                currentGameState.ChangeTurn();

                Thread.Sleep(1000);

                UpdateControls();

                return;
            }

            unusedDice.AddRange(currentGameState.Dice);

            if (currentGameState.Dice[0] == currentGameState.Dice[1])
                unusedDice.AddRange(currentGameState.Dice);

            UpdateControls();
        }
Exemplo n.º 5
0
        private void buttonDouble_Click(object sender, EventArgs e)
        {
            watch.Stop();

            GameStateTurnAction gsta = new GameStateTurnAction(currentGameState.Clone(), watch.ElapsedMilliseconds, TurnAction.Double);

            turns.Add(gsta);

            textBoxLog.Text += "Turn action added" + " " + watch.ElapsedMilliseconds + "ms." + Environment.NewLine;
            textBoxLog.SelectionStart = textBoxLog.Text.Length;
            textBoxLog.ScrollToCaret();

            currentGameState.Double();

            Render();
            this.Refresh();

            DoubleResponseHint hint = gnubg.DoubleResponseHint(currentGameState);

            Thread.Sleep(thinker.TimeOnDoubleOffer(currentGameState, hint));

            if (hint.Response == DoubleResponse.Pass)
            {
                status = GameStatus.GameOver;
                return;
            }

            if (hint.Response == DoubleResponse.Take)
            {
                currentGameState.Take();
            }

            UpdateControls();
        }
 public static string Serialize(GameStateTurnAction gsta)
 {
     return GameState.Serialize(gsta.GameState) + "|" + gsta.time + " " + gsta.turnAction.ToString();
 }