1 / 18

計算機程式及實習 課堂作業之口頭報告 ppt 製作 題目 : 俄羅斯方塊

期末報告 機械工程系 自控三乙 學號 :4A012901 張凱翔. 計算機程式及實習 課堂作業之口頭報告 ppt 製作 題目 : 俄羅斯方塊. 按 開始即為遊戲開始 組合物 當連成一 線可消除並且獲得分數 Level 越高速度越快 當某一行跌到最高層級為遊戲結束. 俄羅斯方塊遊戲說明. Option Strict On Imports MyGames.Tetris Imports MyGames.Tetris.TetrisBlock Partial Class TetrisGame

brone
Télécharger la présentation

計算機程式及實習 課堂作業之口頭報告 ppt 製作 題目 : 俄羅斯方塊

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 期末報告 機械工程系 自控三乙 學號:4A012901 張凱翔 計算機程式及實習課堂作業之口頭報告ppt製作題目:俄羅斯方塊

  2. 按開始即為遊戲開始 組合物 當連成一線可消除並且獲得分數 Level越高速度越快 當某一行跌到最高層級為遊戲結束 俄羅斯方塊遊戲說明

  3. Option Strict On Imports MyGames.Tetris Imports MyGames.Tetris.TetrisBlock Partial Class TetrisGame Private GameBoard As TetrisBoard Private FallingBlock As TetrisBlock Private PreviewBoard As TetrisBoard Private PreviewBlock As TetrisBlock Private Score As Double Private Level As Integer Private Speed As Integer Private Lines As Integer Private RandomNumbers As New Random Private Status As GameStatus = GameStatus.Stopped 程式碼撰寫

  4. Private EnumGameStatus Running Paused Stopped End Enum #Region "Event Handlers" Private Sub TetrisGame_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load PreviewBoard = New TetrisBoard(PreviewBox) With PreviewBoard .Rows = 4 .Columns = 4 .CellSize = New Size(20, 20) .Style = BorderStyle.FixedSingle .SetupBoard() End With PreviewBlock = New TetrisBlock(PreviewBoard) PreviewBlock.CenterCell = PreviewBoard.Cells(2, 2) PreviewBlock.Shape = GetRandomShape() 程式碼撰寫

  5. GameBoard = New TetrisBoard(GameBox) With GameBoard .Rows = 20 .Columns = 10 .CellSize = New Size(20, 20) .Style = BorderStyle.FixedSingle .SetupBoard() End With FallingBlock = New TetrisBlock(GameBoard) HelpLabel.Text = HelpLabel.Text.Replace("|", vbCrLf) StylesLabel.Text = StylesLabel.Text.Replace("|", vbCrLf) ShowMessage(String.Format("點I這o裡MI開始l", vbCrLf)) End Sub 程式碼撰寫

  6. Private Sub TetrisGame_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown Select Case e.KeyCode Case Keys.Left, Keys.Right, Keys.Down, Keys.Up If Status = GameStatus.Running Then With FallingBlock Select Case e.KeyCode Case Keys.Left If .CanMove(MoveDirection.Left) Then .Move(MoveDirection.Left) Case Keys.Right If .CanMove(MoveDirection.Right) Then .Move(MoveDirection.Right) Case Keys.Down If .CanMove(MoveDirection.Down) Then .Move(MoveDirection.Down) Case Keys.Up 程式碼撰寫

  7. If .CanRotate Then .Rotate() End Select End With End If Case Keys.P If Status <> GameStatus.Stopped Then TogglePauseGame() Case Keys.N If Status = GameStatus.Stopped Then StartNewGame() ElseIfDialogResult.Yes = MessageBox.Show("Abort current game?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) Then StartNewGame() 程式碼撰寫

  8. End If Case Keys.B GameBoard.Style = BorderStyle.FixedSingle PreviewBoard.Style = BorderStyle.FixedSingle GameBoard.Color = Color.Empty PreviewBoard.Color = Color.Empty Case Keys.M GameBoard.Style = BorderStyle.None PreviewBoard.Style = BorderStyle.None GameBoard.Color = Color.Empty PreviewBoard.Color = Color.Empty Case Keys.F GameBoard.Style = BorderStyle.None PreviewBoard.Style = BorderStyle.None GameBoard.Color = Color.Orange PreviewBoard.Color = Color.Orange 程式碼撰寫

  9. Case Keys.S GameBoard.Style = BorderStyle.None PreviewBoard.Style = BorderStyle.None GameBoard.Color = Color.SkyBlue PreviewBoard.Color = Color.SkyBlue Case Keys.W GameBoard.Style = BorderStyle.None PreviewBoard.Style = BorderStyle.None GameBoard.Color = Color.Blue PreviewBoard.Color = Color.Blue Case Keys.C GameBoard.Style = BorderStyle.None PreviewBoard.Style = BorderStyle.None GameBoard.Color = Color.Chocolate PreviewBoard.Color = Color.Chocolate End Select End Sub 程式碼撰寫

  10. Private Sub MessageLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MessageLabel.Click Select Case Status Case GameStatus.Stopped StartNewGame() Case GameStatus.Paused TogglePauseGame() End Select End Sub 程式碼撰寫

  11. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick If FallingBlock.CanMove(MoveDirection.Down) Then FallingBlock.Move(MoveDirection.Down) Else '' Fix block to base For Each cell As TetrisCell In FallingBlock.Cells cell.IsEmpty = False Next '' Remove completed rows Dim checkRows = From cell In FallingBlock.Cells _ Order By cell.Row _ Select cell.Row Distinct Dim rowsRemoved As Integer = 0 For Each row In checkRows If GameBoard.IsRowComplete(row) Then GameBoard.RemoveRow(row) rowsRemoved += 1 End If 程式碼撰寫

  12. Next '' Update Statistics Score += Math.Pow(rowsRemoved, 2) * 100 Lines += rowsRemoved Speed = 1 + Lines \ 10 If Speed Mod 10 = 0 Then Level += 1 : Speed = 1 Timer1.Interval = (10 - Speed) * 100 UpdateStatistics() '' Make the next block fall DropNextFallingBlock() '' Check if game has ended If Not FallingBlock.CanMove(FallingBlock.CenterCell) Then EndGame() End If End Sub 程式碼撰寫

  13. Region "Private Methods" Private Function GetRandomShape() As TetrisBlock.Shapes Dim number As Integer = RandomNumbers.Next(Shapes.I1, Shapes.Z4 + 1) 'first to last Return CType(number, TetrisBlock.Shapes) End Function Private Sub DropNextFallingBlock() FallingBlock.CenterCell = GameBoard.Cells(2, GameBoard.Columns \ 2) FallingBlock.Shape = PreviewBlock.Shape PreviewBlock.Shape = GetRandomShape() PreviewBlock.RefreshBackGround() PreviewBlock.Refresh() End Sub 程式碼撰寫

  14. Private Sub StartNewGame() Score = 0 Lines = 0 Speed = 1 Level = 1 Timer1.Interval = 1000 UpdateStatistics() GameBoard.SetupBoard() 'PreviewBlock.Shape = GetRandomShape() DropNextFallingBlock() MessageLabel.Visible = False Timer1.Enabled = True Status = GameStatus.Running End Sub 程式碼撰寫

  15. Private Sub EndGame() Timer1.Enabled = False Status = GameStatus.Stopped ShowMessage(String.Format("{0}{0}GAME OVER{0}{0}{0}{0}Click here to start new game", vbCrLf)) End Sub Private Sub UpdateStatistics() ScoreLabel.Text = Score.ToString("000") LinesLabel.Text = Lines.ToString LevelLabel.Text = Level.ToString SpeedLabel.Text = Speed.ToString End Sub 程式碼撰寫

  16. Private Sub TogglePauseGame() If Status = GameStatus.Paused Then Status = GameStatus.Running MessageLabel.Visible = False Timer1.Enabled = True Else Status = GameStatus.Paused ShowMessage(String.Format("{0}{0}GAME PAUSED{0}{0}{0}{0}Click here to resume.", vbCrLf)) End If End Sub Private Sub ShowMessage(ByVal message As String) MessageLabel.Text = message MessageLabel.Visible = True Timer1.Enabled = False End Sub #End Region 程式碼撰寫

  17. Private Sub HelpLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HelpLabel.Click End Sub End Class 程式碼撰寫

  18. 一開始覺得VB 跟其他程式比起來不算太難,可能是謝老師教的很詳細,VB本身介面也有許多中文解釋,還有程式只要一有錯誤,程式碼就會顯示錯誤提醒我們。 程式語言其實不單單只有大學學校所教的,程式語言在很多領域都會用到,當然以後要當一個工程師程式要有一定的水準與基礎是必要的,期末這個作業我也花很多很多的時間在思考,曾經想放棄期末作業,但後來想說謝老師這麼花心思在教導我們,總不能這麼容易就放棄,我也上網找了很多資料,也請教了很多熟悉vb的人,最後才把這個程式做出來。 謝謝老師這學期的程式教導讓我受益良多,讓我對程式感到興趣。 心得

More Related