Thursday, August 30, 2012

Layout Diagram- Pizza Ordering System


This program is designed to function as a pizza ordering system for a...
Well, for a pizza business. 


The program is meant to be able calculate the total price of a pizza order. The user enters their name, selects one type of pizza which they may want and then select their toppings. After calculating the price, they can enter a special request for the business to fulfil. Not shown is the ability to order more than one pizza. 

I chose to design this  interface as shown as the user can work downwards filling out the order. An alternative was to have the options listed horizontally, so the user would work left to right, but that would ultimately make the interface too large. It's better to have a compact window than a really wide window.

Finished Program with Code- Paper, Scissors, Rock!


Private Sub btnRock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRock.Click
        If lblP_Score.Text = "72" Then
            End
        End If
        'End game when score reaches 72 and Rock is selected

        lblPlayer.Text = "Rock"
        'assigns player as Rock

        lblAI_Comment.Text = ""

        picPlayer.ImageLocation = "M:\Visual Basic\Unit 2 AoS2  Projects\PSR Vs The Computer\HumanRock.png"
        'changes player icon to rock

        lblAI.Text = Int(Rnd() * 9 + 1)
        'generates a random number between 1 and 9

        Select lblAI.Text
            Case 1
                lblAI.Text = "Rock"
                picAI.ImageLocation = "M:\Visual Basic\Unit 2 AoS2  Projects\PSR Vs The Computer\AIRock.png"
            Case 2
                lblAI.Text = "Paper"
                picAI.ImageLocation = "M:\Visual Basic\Unit 2 AoS2  Projects\PSR Vs The Computer\AIPaper.png"
            Case 3
                lblAI.Text = "Scissors"
                picAI.ImageLocation = "M:\Visual Basic\Unit 2 AoS2  Projects\PSR Vs The Computer\AIScissors.png"
            Case 4
                lblAI.Text = "Paper"
                picAI.ImageLocation = "M:\Visual Basic\Unit 2 AoS2  Projects\PSR Vs The Computer\AIPaper.png"
            Case 5
                lblAI.Text = "Scissors"
                picAI.ImageLocation = "M:\Visual Basic\Unit 2 AoS2  Projects\PSR Vs The Computer\AIScissors.png"
            Case 6
                lblAI.Text = "Rock"
                picAI.ImageLocation = "M:\Visual Basic\Unit 2 AoS2  Projects\PSR Vs The Computer\AIRock.png"
            Case 7
                lblAI.Text = "Scissors"
                picAI.ImageLocation = "M:\Visual Basic\Unit 2 AoS2  Projects\PSR Vs The Computer\AIScissors.png"
            Case 8
                lblAI.Text = "Paper"
                picAI.ImageLocation = "M:\Visual Basic\Unit 2 AoS2  Projects\PSR Vs The Computer\AIPaper.png"
            Case 9
                lblAI.Text = "Rock"
                picAI.ImageLocation = "M:\Visual Basic\Unit 2 AoS2  Projects\PSR Vs The Computer\AIRock.png"
        End Select
        'selects random image for computer depending on the random number generated


        If lblAI.Text = "Paper" Then
            lblAI_Score.Text = lblAI_Score.Text + 1

            lblAI_Comment.Text = Int(Rnd() * 3 + 1)
            Select Case lblAI_Comment.Text
                Case 1
                    lblAI_Comment.Text = "I WIN!"
                Case 2
                    lblAI_Comment.Text = "Superior" & vbCrLf & "Paper!"
                Case 3
                    lblAI_Comment.Text = "Mere" & vbCrLf & "mortals!"
            End Select
            'If paper was selected, add one to the score for the AI
            'Selects a winning comment to display

        End If
        lblTitle.Text = "Paper, Scissors, Rock!"

        If lblAI.Text = "Scissors" Then
            lblP_Score.Text = lblP_Score.Text + 1

            lblAI_Comment.Text = Int(Rnd() * 3 + 1)
            Select Case lblAI_Comment.Text
                Case 1
                    lblAI_Comment.Text = "I lost?!"
                Case 2
                    lblAI_Comment.Text = "Not..." & vbCrLf & "like this!"
                Case 3
                    lblAI_Comment.Text = "Beaten by" & vbCrLf & "a mortal!"
            End Select
            'If paper was selected, add one to the score for the player
            'Selects a defeat comment to display
        End If
        lblTitle.Text = "Paper, Scissors, Rock!"
    End Sub

  Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        lblAI.Text = ""
        lblAI_Score.Text = "0"
        lblP_Score.Text = "0"
        lblAI_Comment.Text = ""
        'clear all scores and selections for both computer and player

        picPlayer.ImageLocation = ""
        picAI.ImageLocation = ""
        'clear all player and computer images
    End Sub


There are a multitude of varying programming techniques used in this program.
Firstly, there is the function to generate a random number. This is used to generate a integer between a set range (i.e. 1-9) . This was used in conjunction with the Select Case statement function. Depending on the number which was generated, the function will perform a set task.


These two functions were used to decide the AI's decision for either Rock, Paper or Scissors.  They were also used in conjunction to form the AI's winning or losing comment. 


A case select is when something occurs depending on the value of an expression. In this case,  when the case select detected the number in the AI label was one, it displayed Rock for the picture. 

TOE Chart w/ Psudeocode- Paper Scissors Rock!


Object
Event
Task
Psuedocode
btnRock
Left Mouse Click on button
Show picture of rock in Player Picture Box

Choose Rock, Paper or Scissors to show in Computer Picture Box
Display picRock in rectPlayer

Generate random number between 1-3

If it’s 1, display picRock in rectCPU

If it’s 2, display picPaper in rectCPU

If it’s 3, display picScissors in rectCPU

btnPaper
Left Mouse Click on button
Show picture of Paper in Player Picture Box

Choose Rock, Paper or Scissors to show in Computer Picture Box
Display picPaper in rectPlayer

Generate random number between 1-3

If it’s 1, display picPaper in rectCPU

If it’s 2, display picRock in rectCPU

If it’s 3, display picScissors in rectCPU

btnScissors
Left Mouse Click on button
Show picture of Scissors in Player Picture Box

Choose Rock, Paper or Scissors to show in Computer Picture Box
Display picPaper in rectPlayer

Generate random number between 1-3

If it’s 1, display picScissors in rectCPU

If it’s 2, display picPaper in rectCPU

If it’s 3, display picRock in rectCPU
btnReset
Left Mouse Click on button
Remove all scores shown on screen
Clear all text in txtP_Score and txtAI_Score

btnExit
Left Mouse Click on button
Exit Program
Exit program

txtTitle



txtP_Score

Display score for Player

txtAI_Score

Display score for Computer


rectPlayer


When displays picPaper
If rectCPU shows picRock
Add  1 to txtP_Score

When displays picRock
If rectCPU shows picScissors
Add  1 to txtP_Score

When displays picScissors
If rectCPU shows picPaper
Add  1 to txtP_Score
rectCPU


When displays picPaper
If rectPlayer shows picRock
Add  1 to txtAI_Score

When displays picRock
If rectPlayer shows picScissors
Add  1 to txtAI_Score

When displays picScissors
If rectPlayer shows picPaper
Add  1 to txtAI_Score

Monday, August 20, 2012

Layout Diagram- Paper,Scissors, Rock!



This is my layout diagram for the program "Paper, Scissors, Rock!"

The program is designed as a game. In the game, you choose either Rock, Paper or Scissors by pressing the buttons to the side of the output picture. Once you have selected a "weapon", the AI will randomly select as well.

The choices are diplayed in the form of a picture in the middle of the game window. Whoever wins, one point will be added to the total score, displayed below the picture.

The reset button resets all scores obatained.

"I would definitely play this game. 10/10, looks amazing" -Patrick Stewart