1 / 13

計算機程式及實習 題目:數字比大小

計算機程式及實習 題目:數字比大小. 南台科技大學 機械工程系 奈米一乙 學號 :49914008 姓名 : 涂智清 老師 : 謝慶存. 使用說明. 打開檔案之後按下 之後即可開始遊戲 小涂請按 即可出現數字 Pk 者請按 即可出現數字 接下來看比數,數字大者獲勝,小者則輸。 按下 按鍵即可退出遊戲。. 輸出介面. 程式碼設計. Public Class Form1 Dim a, b As Integer

buck
Télécharger la présentation

計算機程式及實習 題目:數字比大小

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. 計算機程式及實習題目:數字比大小 南台科技大學 機械工程系 奈米一乙 學號:49914008 姓名:涂智清 老師:謝慶存

  2. 使用說明 • 打開檔案之後按下 之後即可開始遊戲 • 小涂請按 即可出現數字 • Pk者請按 即可出現數字 • 接下來看比數,數字大者獲勝,小者則輸。 • 按下 按鍵即可退出遊戲。

  3. 輸出介面

  4. 程式碼設計 • Public Class Form1 • Dim a, b As Integer • Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click • Dim btn(2) As Button • btn(1) = Button1 : btn(2) = Button2 • If sender.Equals(Button1) Then • Randomize() • a = Int(Rnd() * 99 + 1) • TextBox1.Text = "你得到數字 " & vbCrLf & vbCrLf & a • TextBox1.Font = New Font("新細明體", 16, FontStyle.Bold) • End If • End Sub

  5. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click • Dim btn(2) As Button • btn(1) = Button1 : btn(2) = Button2 • If sender.Equals(Button2) Then • Randomize() • b = Int(Rnd() * 99 + 1) • TextBox2.Text = "你得到數字 " & vbCrLf & vbCrLf & b • TextBox2.Font = New Font("新細明體", 16, FontStyle.Bold) • End If • End Sub

  6. Private Sub btnstart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnstart.Click • Dim btn(2) As Button • btn(1) = Button1 : btn(2) = Button2 • Dim txt(2) As TextBox • txt(1) = TextBox1 : txt(2) = TextBox2 • btnstart.Text = "再比一次" • For i = 1 To btn.GetUpperBound(0) • btn(i).Enabled = True • For j = 1 To txt.GetUpperBound(0) • txt(j).Text = "" • Next • Next • End Sub

  7. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load • Dim btn(2) As Button • btn(1) = Button1 : btn(2) = Button2 • For i = 1 To btn.GetUpperBound(0) • btn(i).Enabled = False • btn(i).Tag = i • Next • For j = 2 To btn.GetUpperBound(0) • AddHandler btn(j).Click, AddressOf btnEvent • Next • End Sub

  8. Sub Buttonfail() • Dim btn(2) As Button • btn(1) = Button1 : btn(2) = Button2 • For i As Integer = 1 To btn.GetUpperBound(0) • btn(i).Enabled = False • Next • End Sub

  9. Private Sub btnend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnend.Click • MsgBox("遊戲結束") • Console.ReadLine() • End • End Sub

  10. Private Sub btnEvent(ByVal sender As System.Object, ByVal e As System.EventArgs) • Dim btnHit As Button • btnHit = CType(sender, Button) • If a > b Then • Buttonfail() • MsgBox(" 小 涂 獲 勝 ") • Return • End If • If a < b Then • Buttonfail() • MsgBox(" P K 者 獲 勝 ") • Return • End If • If a = b Then • MsgBox(" 平 手 喔 ") • End If • End Sub

  11. End Sub Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click End Sub End Class

  12. 參考文獻 • Visual Basic 2008 程式設計作者: 葉倍宏 全華2008 • Visual Basic 2008教學範本古頤榛 編著 碁峰資訊2009

  13. 心得 • 這次報告真的花了我不少的時間,也讓我學習到了很多.學會做一個小遊戲真開心

More Related