0

Hi there, I'm a beginner c# programmer, for practice I did the following code for a rock scissor paper game, the computer picks out it's choice randomly and compares with the player's choice. This code seem not to work properly, please help :?:

<%@ Page Language="c#" %>
<script runat="server">
void Page_Load()
{

    if (Page.IsPostBack)
    {
    public String toSring()
    {
    int intcomputerChoice=1;

         if(computerChoice==1)
         {
         return(Rock);
       }
       if(computerChoice==2)
         {
         return(Paper);
       }
       if(computerChoice==3)
         {
         return(Scissors);
       }
       }
       if (Page.IsPostBack)
      {
       int intvalue;
        Random rand = new Random(3);
        value = Convert.ToInt32(rand.Next(3)) + 1;
         if (Page.IsPostBack)
        {
        int intOption;
        intOption =
        Convert.ToInt32(Option.SelectedItem.Value);
         if (intOption == 1 && value == 2)
            {
                message.Text =
                computerChoice.ToString() + "You Lose!";
            }
            else if (intOption == 1 && value == 3)
            {
                message.Text =
                    "ROCK beats scissor! You win!";
            }
            else if (intOption == 2 && value == 1)
            {
                message.Text =
                    "PAPER beats rock! You win!";
            }
            else if (intOption == 2 && value == 3)
            {
                message.Text =
                    "SCISSOR beats paper! You lose!";
            }
            else if (intOption == 3 && value == 1)
            {
                message.Text =
                    "ROCK beats scissors! You lose!";
            }
            else if (intOption == 3 && value == 2)
            {
                message.Text =
                "SCISSORS beats paper! You win!";
            }
        }
    }     
}
</script>
<html>
<head><title></title></head>
<body>
<form id="Form1" runat="server">
Welcome to Rock,Paper,Scissors Game
<br /><br />
Choose: Rock, Paper or Scissors?
<asp:dropdownlist id="Option" runat="server">
<asp:listitem Value="1">Rock</asp:listitem>
<asp:listitem Value= "2">Paper</asp:listitem>
<asp:listitem Value= "3">Scissors</asp:listitem>

</asp:dropdownlist>
<br />
<br />
<input type="submit" value="Challenge Computer" />
<asp:label id="message" runat="server"/>


</body>
</html>

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Lusiphur
0

Well, for starters, when you say it's not working properly... what exactly is it doing compared to what it should be doing? Are you receiving any error messages? Are you simply receiving incorrect results?

A bit more information would be helpful to determine the nature of the problem, particularly as the above code is a mix between page code and code-behind with 0 formatting applied to it (there are code formatting tags available on this site that allow code to retain some semblance of readability).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.