コード例 #1
0
ファイル: Ship.cs プロジェクト: mbassara/battleships_csharp
 public Ship(int x, int y, GameBoard.BoardType boardType, bool state)
 {
     this.x = x;
     this.y = y;
     this.boardType = boardType;
     this.SIZE = boardType == GameBoard.BoardType.MAIN_BOARD ? 30 : 13;
     this.State = state ? ShipState.SHIP : ShipState.NOT_SHIP;
     Width = SIZE;
     Height = SIZE;
     BackColor = System.Drawing.Color.Transparent;
 }
コード例 #2
0
        private void myInitialization()
        {
            this.ClientSize = new System.Drawing.Size(350, 550);
            int topMargin = MARGIN + 20;
            int width = this.ClientSize.Width;
            int height = this.ClientSize.Height;

            hostButton = new ImageButton("Host Game");
            hostButton.Location = new Point(width / 2 - hostButton.Width / 2, height / 2 - 2 * hostButton.Height);
            hostButton.Click += delegate(object sender, EventArgs e) { creatingShipsLayout(GAME_MODE.HOST); };
            this.Controls.Add(hostButton);

            joinButton = new ImageButton("Join Game");
            joinButton.Location = new Point(width / 2 - joinButton.Width / 2, height / 2 - joinButton.Height + 5);
            joinButton.Click += delegate(object sender, EventArgs e) { creatingShipsLayout(GAME_MODE.CLIENT); };
            this.Controls.Add(joinButton);

            exitButton = new ImageButton("Exit");
            exitButton.Location = new Point(width / 2 - exitButton.Width / 2, height / 2 + joinButton.Height + 5);
            exitButton.Click += delegate(object sender, EventArgs e) { Close(); };
            this.Controls.Add(exitButton);

            backButton = new ImageButton("Back");
            backButton.Location = new Point(width / 4 - backButton.Width / 2, topMargin);
            backButton.Click += delegate(object sender, EventArgs e) { mainMenuLayout(); };

            nextButton = new ImageButton("Next");
            nextButton.Location = new Point(width / 2 + width / 4 - nextButton.Width / 2, topMargin);
            nextButton.Click += StartGame;

            randomButton = new ImageButton("Random");
            randomButton.Location = new Point(width / 2 - randomButton.Width / 2, topMargin + randomButton.Height + 10);
            randomButton.Click += delegate(object sender, EventArgs e) { mainBoard.setShips(GameBoard.generateMatrix()); };

            mainBoard = new GameBoard(GameBoard.BoardType.MAIN_BOARD, GameBoard.empty);
            mainBoard.Enabled = false;
            mainBoard.addToWindow(this);
            mainBoard.Visible = false;

            prevBoard = new GameBoard(GameBoard.BoardType.PREVIEW_BOARD, GameBoard.empty);
            prevBoard.Enabled = false;
            prevBoard.addToWindow(this);
            prevBoard.Visible = false;
        }
コード例 #3
0
 //The constructor seeds the random number generator and takes the gameboard to initialise as an argument.
 public AIShipInitialiser(GameBoard boardThatNeedsInitialisation)
 {
     boardToInitialise     = boardThatNeedsInitialisation;
     randomNumberGenerator = new Random(DateTime.Now.Millisecond);
 }
コード例 #4
0
        private void myInitialization()
        {
            this.ClientSize = new System.Drawing.Size(350, 550);
            int topMargin = MARGIN + 20;
            int width     = this.ClientSize.Width;
            int height    = this.ClientSize.Height;

            hostButton          = new ImageButton("Host Game");
            hostButton.Location = new Point(width / 2 - hostButton.Width / 2, height / 2 - 2 * hostButton.Height);
            hostButton.Click   += delegate(object sender, EventArgs e) { creatingShipsLayout(GAME_MODE.HOST); };
            this.Controls.Add(hostButton);

            joinButton          = new ImageButton("Join Game");
            joinButton.Location = new Point(width / 2 - joinButton.Width / 2, height / 2 - joinButton.Height + 5);
            joinButton.Click   += delegate(object sender, EventArgs e) { creatingShipsLayout(GAME_MODE.CLIENT); };
            this.Controls.Add(joinButton);

            exitButton          = new ImageButton("Exit");
            exitButton.Location = new Point(width / 2 - exitButton.Width / 2, height / 2 + joinButton.Height + 5);
            exitButton.Click   += delegate(object sender, EventArgs e) { Close(); };
            this.Controls.Add(exitButton);

            backButton          = new ImageButton("Back");
            backButton.Location = new Point(width / 4 - backButton.Width / 2, topMargin);
            backButton.Click   += delegate(object sender, EventArgs e) { mainMenuLayout(); };

            nextButton          = new ImageButton("Next");
            nextButton.Location = new Point(width / 2 + width / 4 - nextButton.Width / 2, topMargin);
            nextButton.Click   += StartGame;

            randomButton          = new ImageButton("Random");
            randomButton.Location = new Point(width / 2 - randomButton.Width / 2, topMargin + randomButton.Height + 10);
            randomButton.Click   += delegate(object sender, EventArgs e) { mainBoard.setShips(GameBoard.generateMatrix()); };

            mainBoard         = new GameBoard(GameBoard.BoardType.MAIN_BOARD, GameBoard.empty);
            mainBoard.Enabled = false;
            mainBoard.addToWindow(this);
            mainBoard.Visible = false;

            prevBoard         = new GameBoard(GameBoard.BoardType.PREVIEW_BOARD, GameBoard.empty);
            prevBoard.Enabled = false;
            prevBoard.addToWindow(this);
            prevBoard.Visible = false;
        }