Ejemplo n.º 1
0
        public void UpdateText()
        {
            string player     = _game.GetCurrentPlayer().ToString();
            string color      = _myColor.ToString();
            string gameState  = _game.GetCurrentGameState().ToString();
            string turnNumber = _game.Turn.ToString();

            this.Invoke((MethodInvoker)(() => { Text = "Playing as: " + color + " | " + "Waiting on: " + player + " | " + "Turn #: " + turnNumber + " | " + "Game state: " + gameState; }));

            // this.Text = "Playing as: " + color + " | " + "Waiting on: " + player + " | " + "Turn #: " + turnNumber + " | " + "Game state: " + gameState;
        }
Ejemplo n.º 2
0
        public void Update(CheckersGM newState)
        {
            this._game = newState;
            UpdateText();
            Node[,] sparseArray = this._game.SparseArray;

            if (sparseArray == null)
            {
                // TODO: Handle this in a better manner

                String _err = "Malformed sparse array sent to Form1.update";
                MessageBox.Show(String.Format("Error: {0}", _err));
                // throw new ArgumentException(_err);
            }

            if (_flip)
            {
                //Debug.WriteLine(DebugPrintSparseArrayLOCAL(sparseArray));

                int rs = sparseArray.GetLength(0) - 1, cs = sparseArray.GetLength(1) - 1;
                Node[,] temp = new Node[rs + 1, cs + 1];

                for (Int32 row = 0; row <= rs; row++)
                {
                    for (Int32 col = 0; col <= cs; col++)
                    {
                        temp[row, col] = sparseArray[rs - row, cs - col];
                    }
                }

                sparseArray = temp;

                //Debug.Write("\n--------------------------\n\n");
                //Debug.WriteLine(DebugPrintSparseArrayLOCAL(sparseArray));
            }

            for (int row = 0; row < this.board.RowCount; row++)
            {
                int sparseCol = 0;
                for (int col = 0; col < this.board.ColumnCount; col++)
                {
                    if ((col - (row % 2 == 0 ? 1 : 0)) % 2 != 0)
                    {
                        continue;
                    }

                    Control cell = this.board.GetControlFromPosition(col, row);

                    if (cell == null)
                    {
                        continue;
                        // Wut?
                    }

                    State cellState = (sparseArray[sparseCol, row]).GetState();

                    Image background = null;

                    switch (cellState)
                    {
                    case State.RED:
                        background = image_pieceRed;
                        break;

                    case State.KING_RED:
                        background = image_kingRed;
                        break;

                    case State.BLACK:
                        background = image_pieceBlack;
                        break;

                    case State.KING_BLACK:
                        background = image_kingBlack;
                        break;

                    default:                             // Implied: State.EMPTY
                        background = null;
                        break;
                    }

                    cell.BackgroundImage = background;
                    //cell.Invoke((MethodInvoker)(() => { BackgroundImage = background; }));

                    sparseCol++;
                }
            }

            GameState state = _game.GetCurrentGameState();

            if (state == GameState.BLACK_WIN || state == GameState.RED_WIN)
            {
                String message = "Game over! You {0}!";
                if ((state == GameState.BLACK_WIN && _myColor == Player.PLAYER_BLACK) || (state == GameState.RED_WIN && _myColor == Player.PLAYER_RED))
                {
                    message = String.Format(message, "won");
                }
                else
                {
                    message = String.Format(message, "lost");
                }

                MessageBox.Show(message, caption: "Game Over");

                this.clientSocket.Disconnect(false);
                this.clientSocket = null;
                clearBoard();
                this.gameOver = true;
            }
        }