RSP game...application


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: RSP game...application

  1. #1
    kry Guest

    RSP game...application




    Subject:
    Paper, Rock, Scissors HELP!!
    Date:
    6 Mar 2001 12:54:28 -0800
    From:
    "KSA" <lander_gal@yahoo.com>
    Newsgroups:
    java.getting.started



    I am having trouble writing this application of Paper, Rocks and scissors.
    If you can help me i sure would appreciate it.

    The first portion is what
    the application is suppose to do, and the second part is the code that
    I
    have already written.


    This application is suposse to stimulate the user against teh computer.
    It must maintain the overall score and report it at the end. It must
    use
    three methods other than main, handle mutiple roudns, and include error
    trapping,
    and count the rounds down. It must randomly generate the computers
    generation
    of rock, paper and scissors.
    A rock can break the scissors
    the scissors can cut the paper
    the paper can cover the rock.
    0 = rock
    1 = scissors
    2 = paper


    This is a sample of whta the application should look like:

    Welcome to eh Rock, Paper, Scissors game.
    How many rounds do you want to play? 2
    This is roudns 2
    Enter a number from 0 to 2, where 0 is for rock, 1 is for scissors,
    and 2
    is for paper.
    I will show you min when you press enter.
    0. I WIN. Paper gets teh rock

    This is round 1
    Enter a number from 0 to 2, where 0 is for rock, 1 is for scissors,
    and 2
    is for paper.
    I will show you mine when you press enter.
    4. Out of range. The number should be between 0 and 2.
    2. A tie.
    WE both show paper.
    I have a score of 1 bu you have a score of 0.







    mport Keyboard.*;

    class RockScissorPaper {
    // This program simulates the game of Rock Scissors Paper

    public static int randNum (int low, int high) {
    // returns a random number between low & high, inclusive
    return ((int)((high-low+1)*Math.random())+low);

    } // randNum

    public static int readNumber (int value) {
    // returns a number between low and high, inclusive, provided
    by
    // the user
    // it provides an error message and asks for the number again
    each
    //time a number out of range is provided
    value =Keyboard.readInt();
    do
    System.out.println ("ERROR");
    while (value > 2 && value < 0);
    return (value);

    } // readNumber

    public static void displayWord (int num) {
    // displays Rock for 0, Scissors for 1, and Paper for 2
    for(num=0; num<=2; num++);
    if (num == 0)
    System.out.println ("ROCK");
    if (num == 1)
    System.out.println ("SCISSORS");
    if (num == 2)
    System.out.println ("PAPER");


    } // displayWord

    static void pressEnter2continue () {
    char ch;
    System.out.print ("Press Enter To Continue!");
    do
    ch = Keyboard.readChar();

    while (ch != (char)10);

    } // pressEnter2continue



    public static void RSPgame() {
    // plays a series of rounds of rock, scissors, and paper

    int cptrnum,
    cptrword,
    rounds,
    count,
    humnum,
    humpts = 0,
    cptrpts = 0;

    System.out.println ("Welcome to the computer game of Rocks, Scissors,
    and Paper!");
    pressEnter2continue();

    //rounds
    System.out.println("How may rounds would you like to

    play?");
    //rounds = Keyboard.readInt();
    //for(count=rounds; count <=rounds; count--);

    System.out.println ("Please enter a number between 0 and 2");
    System.out.println ("0 = ROCK, 1 = SCISSORS, and 2 =
    PAPER");
    displayWord();
    System.out.println ("I will show you mine when you press ENTER!");
    pressEnter2continue();
    cptrnum = randNum (0,2);
    System.out.println ("I choose " + cptrnum + "!");
    displayWord(cptrnum);

    //{ if (cptrnum == 0)
    // System.out.print ("ROCK");
    // if (cptrnum == 1)
    // System.out.print ("SCISSORS");
    // if (cptrnum ==2)
    // System.out.print ("PAPER"); }

    // { if (cptrnum == 2 && humnum == 0)
    // System.out.println ("I WIN! Paper covers Rock");
    // if (cptrnum == 0 && humnum == 1)
    // System.out.println ("I WIN! Rock breaks the Scissors");
    // if (cptrnum == 1 && humnum == 2)
    // System.out.println ("I WIN! Scissors cut Paper");
    // if (humnum == 2 && cptrnum == 0)
    // System.out.println ("I WIN! Paper covers Rock");
    // if (humnum == 0 && humnum == 1)
    // System.out.println ("I WIN! Rock breaks the Scissors");
    // if (cptrnum == 1 && humnum == 2)

    // System.out.println ("I WIN! Scissors cut Paper"); }
    //



    } // RSPgame

    public static void main (String [] args) {

    RSPgame();



    } // main

    } // class RockScissorPaper





    This is the application that he gave us to start with, so mine might
    be alittle
    wrong...i don't know!
    import Keyboard.*;

    class RockScissorPaper {
    // This program simulates the game of Rock Scissors Paper

    public static int randNum (int low, int high) {
    // returns a random number between low & high,
    inclusive



    } // randNum

    public static int readNumber (int high, int low) {
    // returns a number between low and high, inclusive,
    provided by the user
    // it provides an error message and asks for the number
    again each time
    //

    } // readNumber

    public static void displayWord () {
    // displays Rock for 0, Scissors for 1, and Paper for
    2




    } // displayWord




    public static void RSPgame() {
    // plays a series of rounds of rock, scissors, and paper



    } // RSPgame

    public static void main (String [] args) {

    RSPgame();



    } // main

    } // class RockScissorPaper



  2. #2
    Paul Clapham Guest

    Re: RSP game...application

    I've seen this posted about a dozen times over the last week or so. If you
    asked a question or stated a problem you would be more likely to get an
    answer, I think...

    PC2

    kry <lander_gal@yahoo.com> wrote in message news:3aa931d3$1@news.devx.com...
    >
    >
    >
    > Subject:
    > Paper, Rock, Scissors HELP!!
    > Date:
    > 6 Mar 2001 12:54:28 -0800
    > From:
    > "KSA" <lander_gal@yahoo.com>
    > Newsgroups:
    > java.getting.started
    >
    >
    >
    > I am having trouble writing this application of Paper, Rocks and

    scissors.
    > If you can help me i sure would appreciate it.
    >





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center