Universidad Interamericana de P.R. Departamento de Informática

Anuncio
Universidad Interamericana de P.R.
Departamento de Informática
Programa para entregar
Valor 100 puntos
Comp 2300
Dr. Rafael A. Nieves
Esto es un ejemplo del programa 14 capítulo 8 del libro de texto del curso. Va a ser un trabajo en grupo
el cual va a presentar en la clase.
Favor de escribirme un email para enviarle los dibujos
1
Public Class Form1
' Class-level onstants for the game selections
Const intROCK As Integer = 1
Const intPAPER As Integer = 2
Const intSCISSORS As Integer = 3
Private Sub picRock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles picRock.Click
' Variables
Dim intUser As Integer
' The user's selection
Dim intComputer As Integer ' The computer's selection
' Get the computer's choice.
intComputer = PlayerChoice()
Private Sub picPaper_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles picPaper.Click
' Variables
Dim intUser As Integer
' The user's selection
Dim intComputer As Integer ' The computer's selection
' Get the computer's choice.
intComputer = PlayerChoice()
' Set the user's choice to paper.
intUser = intPAPER
2
Private Sub picScissors_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles picScissors.Click
' Variables
Dim intUser As Integer
' The user's selection
Dim intComputer As Integer ' The computer's selection
' Get the computer's choice.
intComputer = PlayerChoice()
Private Function PlayerChoice() As Integer
' Variable to hold a random number.
Dim intNum As Integer
' Declare a Random object.
Dim rand As New Random
' The ChoiceName function accepts an integer representing a game
' selection. The return value is determined as follows:
'
If the argument equals intROCK, the function returns "Rock"
'
If the argument equals intPAPER, the function returns "Paper"
'
If the argument equals intSCISSORS, the function returns "Scissors"
'
Otherwise the function returns "Unknown"
Private Function ChoiceName(ByVal intChoice As Integer) As String
' Variable to hold the return value
Dim strChoice As String
' Determine the choice.
Select Case intChoice
Case intROCK
strChoice = "Rock"
' The DetermineWinner function accepts integer arguments for the user's
' selection and the computer's selection. It displays the game results
' in a message box.
Private Sub DetermineWinner(ByVal intUser As Integer, ByVal intComputer As Integer)
' Determine the winner.
If intUser = intROCK Then
If intComputer = intROCK Then
MessageBox.Show("It's a tie!")
ElseIf intComputer = intPAPER Then
MessageBox.Show("The computer wins! Paper wraps rock.")
ElseIf intComputer = intSCISSORS Then
3
Descargar