8.2 Game Design in Java (Part 2 of 2)

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
2,642
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Jul 27, 2009

Learn to work through higher level application design with this unique tutorial. I know I move kind of fast, but hopefully you have followed along with my other videos and are sharp on all of the code I implement here. Good Luck! :)

code:

import java.util.Scanner;

class SimpleGame {

public static void main(String args[]) {
Actor myActor = new Actor();

System.out.println("Guessing Game 5000");
System.out.println("------------------");

while(true) {
myActor.MakeNumber();
myActor.GetInput();
myActor.CheckResponse();
}

}
}

class Actor {
int x, Response, score;

void MakeNumber() {
x = (int)(Math.random()*11);

while (x == 0) {

x = (int)(Math.random()*11);

}

}

void GetInput() {
Scanner myScanner = new Scanner(System.in);

System.out.println("");
System.out.println("Please enter your guess");
Response = myScanner.nextInt();

}

void CheckResponse() {

if (Response == x) {

score++;
System.out.println("That's Right");
System.out.println("Score: " + score);
System.out.println("");

}

else {

System.out.println("That's Wrong");
System.out.println("The number was: " + x);
System.out.println("Score: " + score);

}

}

}


Please check out my other vids for more tutorials. Also, please leave comments with any suggestions.
Subscribe, comment, rate.

  • likes, 0 dislikes

Link to this comment:

Share to:
see all

All Comments (4)

Sign In or Sign Up now to post a comment!
  • sure.... i'll sub... thanks :)

  • Thank you for your tutorials.

  • Nice one,Subscribed.

Loading...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more