Exemple #1
0
 public static void UpdateChessBoardColors(Button[,] board)
 {
     foreach (Button square in board)
     {
         MoveLogic.Coordinates c = GetCoordinatesOfButton(square);
         square.BackColor = (c.X + c.Y) % 2 == 0 ?
                            ChessUtils.Settings.Color.darkSquareColor :
                            ChessUtils.Settings.Color.lightSquareColor;
     }
 }
Exemple #2
0
        private void addGameButton_Click(object sender, EventArgs e)
        {
            if (gamesList.SelectedRows.Count > 0)
            {
                // Get the game ID from the row
                int gameId = (int)gamesList.SelectedRows[0].Cells[0].Value;

                // Match the game ID with the appropriate CustomGame in the list
                CustomGame game = gameList.Single(x => x.GameID == gameId);

                // Convert the list of pieces into a double array (board)
                MoveLogic.Piece[][] pieces = new MoveLogic.Piece[8][];
                for (int i = 0; i < 8; ++i)
                {
                    pieces[i] = new MoveLogic.Piece[8];
                }
                foreach (MoveLogic.Piece piece in game.Pieces)
                {
                    MoveLogic.Coordinates c = piece.Coordinates;
                    pieces[c.X][c.Y] = new MoveLogic.Piece();
                    pieces[c.X][c.Y] = piece;
                }

                Random rand     = new Random(Guid.NewGuid().GetHashCode());
                double randNum  = rand.NextDouble();
                bool   hostTurn = true;// (randNum < 0.5);

                moveLogic.myTurn  = hostTurn;
                moveLogic.myColor = moveLogic.myTurn ?
                                    moveLogic.myColor = MoveLogic.pieceColor.white :
                                                        moveLogic.myColor = MoveLogic.pieceColor.black;

                MoveLogic.pieceColor guestColor = (moveLogic.myColor == MoveLogic.pieceColor.white) ?
                                                  MoveLogic.pieceColor.black :
                                                  MoveLogic.pieceColor.white;

                // Create the new session to add to the lobby table
                Session mySession = new Session()
                {
                    HostPlayer       = game.Username,
                    GuestPlayer      = "",
                    GameTimerSeconds = game.GameTimer,
                    MoveTimerSeconds = game.MoveTimer,
                    CustomGameMode   = 3 /* Custom game */,
                    BoardPieces      = pieces,
                    GameID           = gameId,
                    GuestColor       = (int)guestColor
                };

                // Create the signal to send
                TCPSignal signal = new TCPSignal()
                {
                    SignalType = Signal.CreateSession,
                    NewSession = mySession
                };

                // Send the json over to the server
                string json       = JsonConvert.SerializeObject(signal) + "\r";
                byte[] jsonBytes  = ASCIIEncoding.ASCII.GetBytes(json);
                byte[] readBuffer = new byte[65535];
                lobby.stream.Write(jsonBytes, 0, jsonBytes.Length);

                lobby.RefreshTable();
                mySession.SessionID = (int)lobby.GetLobbyTable().Rows[lobby.GetLobbyTable().Rows.Count - 1].Cells[0].Value;

                GameSession session = new GameSession(me, new User("", ""), stream, mySession, lobby, moveLogic, game);
                session.ShowDialog();
                Hide();
                Close();
            }
        }
Exemple #3
0
        public void SetBoard(List <MoveLogic.Piece> pieces)
        {
            foreach (MoveLogic.Piece piece in pieces)
            {
                MoveLogic.Coordinates c = piece.Coordinates;
                board[c.X, c.Y].Tag = piece.Name;

                switch (piece.Name)
                {
                case "wPawn":
                    board[c.X, c.Y].Image = ChessUtils.Settings.Image.WhitePawn;
                    break;

                case "wKnight":
                    board[c.X, c.Y].Image = ChessUtils.Settings.Image.WhiteKnight;
                    break;

                case "wBishop":
                    board[c.X, c.Y].Image = ChessUtils.Settings.Image.WhiteBishop;
                    break;

                case "wRook":
                    board[c.X, c.Y].Image = ChessUtils.Settings.Image.WhiteRook;
                    break;

                case "wQueen":
                    board[c.X, c.Y].Image = ChessUtils.Settings.Image.WhiteQueen;
                    break;

                case "wKing":
                    board[c.X, c.Y].Image = ChessUtils.Settings.Image.WhiteKing;
                    break;

                case "bPawn":
                    board[c.X, c.Y].Image = ChessUtils.Settings.Image.BlackPawn;
                    break;

                case "bKnight":
                    board[c.X, c.Y].Image = ChessUtils.Settings.Image.BlackKnight;
                    break;

                case "bBishop":
                    board[c.X, c.Y].Image = ChessUtils.Settings.Image.BlackBishop;
                    break;

                case "bRook":
                    board[c.X, c.Y].Image = ChessUtils.Settings.Image.BlackRook;
                    break;

                case "bQueen":
                    board[c.X, c.Y].Image = ChessUtils.Settings.Image.BlackQueen;
                    break;

                case "bKing":
                    board[c.X, c.Y].Image = ChessUtils.Settings.Image.BlackKing;
                    break;

                case "NoPiece":
                    board[c.X, c.Y].Image = null;
                    break;
                }
            }
        }