Thursday, 13 August 2020

PUZZLE GAME IN JAVA

 This is a simple puzzle game in java. I am going to add new levels and update this post from time to time. There are fifteen levels currently.

  • Start your java IDE and make a new class named Game.
  • Type the following code:

import java.util.Scanner;



public class Game {


public static void main(String[] args) {

System.out.println("Enter your username");

Scanner scan=new Scanner(System.in);

String name=scan.nextLine();

System.out.println("Well, "+name+", welcome to Puzzler: The best puzzle set in the world!");

System.out.println("Remember this game is case sensitive");

System.out.println("Let's start, shall we?");

//ONE

System.out.println("LEVEL ONE");

System.out.println("What's your username?");

myloop:{

for(;;){

if (scan.nextLine().equals(name)) {break myloop;}

System.out.println("Nope. Try again");}}

System.out.println("Well, I admit, it was easy. But wait!");

//TWO

System.out.println("LEVEL TWO");

System.out.println("What's the middle of the middle and the end of the end?");

myloop:{

for(;;){

if (scan.nextLine().equals("d")) {break myloop;}

System.out.println("Nope. Try again");}}

System.out.println("Wonderful!(This is actually a puzzle from Harry Potter and The Goblet of Fire)");

//THREE

System.out.println("LEVEL THREE");

System.out.println("Enter the code to pass this level");

myloop:{

for(;;){

if (scan.nextLine().equals("the code")) {break myloop;}

System.out.println("Nope. Try again");}}

System.out.println("You are learning fast! Keep going!");

//FOUR

System.out.println("LEVEL FOUR");

System.out.println("What's the square root of -1?(The one character answer, please)");

myloop:{

for(;;){

if (scan.nextLine().equals("i")) {break myloop;}

System.out.println("Nope. Try again");}}

System.out.println("You're a mathematician too? That's great!");

//FIVE

System.out.println("LEVEL FIVE");

System.out.println("What's the full name of J.K.Rowling? (No net surfing!)");

myloop:{

for(;;){

if (scan.nextLine().equals("Joanne Kathleen Rowling")) {break myloop;}

System.out.println("Nope. Try again");}}

System.out.println("Fan of Harry Potter? I see...");

//SIX

System.out.println("LEVEL SIX");

System.out.println("sin(theta)/cos(theta)=?(give answer in format shown in question.)");

myloop:{

for(;;){

if (scan.nextLine().equals("tan(theta)")) {break myloop;}

System.out.println("Nope. Try again");}}

System.out.println("Good!");

//SEVEN

System.out.println("LEVEL SEVEN");

System.out.println("Sam's mother has three children.");

System.out.println("If the first two are June and July then waht's the name of the third one?");

myloop:{

for(;;){

if (scan.nextLine().equals("Sam")) {break myloop;}

System.out.println("Nope. Try again");}}

System.out.println("Good one, wasn't it?");

//EIGHT

System.out.println("LEVEL EIGHT");

System.out.println("Which vehicle is spelled backwards remains the same?(all in caps)");

myloop:{

for(;;){

if (scan.nextLine().equals("RACECAR")) {break myloop;}

System.out.println("Nope. Try again");}}

System.out.println("You love cars, don't you?");

//NINE

System.out.println("LEVEL NINE");

System.out.println("What's the java code to declare a integer x with value of 10?(the one-liner one)");

myloop:{

for(;;){

if (scan.nextLine().equals("int x=10;")) {break myloop;}

System.out.println("Nope. Try again");}}

System.out.println("Java coder, huh?");

//TEN

System.out.println("LEVEL TEN");

System.out.println("How do  you rate this game?(1-7)");

myloop:{

for(;;){

if (scan.nextLine().equals("7")) {break myloop;}

System.out.println("Nope. Try again");}}

System.out.println("Thanks for the rating ,"+name+"!");

//ELEVEN

    System.out.println("LEVEL ELEVEN");

System.out.println("What comes once in a minute, twice in a moment, but never in a thousand years?");

myloop:{

for(;;){

if (scan.nextLine().equals("m")) {break myloop;}

System.out.println("Nope. Try again");}}

System.out.println("Good, wasn't it?");

//TWELVE

System.out.println("LEVEL TWELVE");

System.out.println("Which palindrome has been used many time in this game?(only the word,in all-caps)");

myloop:{

for(;;){

if (scan.nextLine().equals("LEVEL")) {break myloop;}

System.out.println("Nope. Try again");}}

    System.out.println("Good going, "+name+"!");

    //THIRTEEN

System.out.println("LEVEL THIRTEEN");

System.out.println("Re-arrange the letters, OOUSWTDNEJR, to spell just one word. What is it?(in all-caps)");

myloop:{

for(;;){

if (scan.nextLine().equals("JUST ONE WORD")) {break myloop;}

System.out.println("Nope. Try again");}}

    System.out.println("Tricked!");

    //FOURTEEN

System.out.println("LEVEL FOURTEN");

System.out.println("How mnay wodrs are splet wromg in tihs lebel?");

myloop:{

for(;;){

if (scan.nextLine().equals("7")) {break myloop;}

System.out.println("Nope. Try again");}}

System.out.println("Didn't count the fourteen, did you?");

//FIFTEEN

System.out.println("LEVEL FIFTEEN");

System.out.println("What is more useful when it is broken?(one word, all-caps, singular.)");

myloop:{

for(;;){

if (scan.nextLine().equals("EGG")) {break myloop;}

System.out.println("Nope. Try again");}}

System.out.println("Hah, tricked, weren't you?");

//END

System.out.println("You won, "+name+"! Three cheers for "+name+"! Hip, hip, hurray!");

System.out.println("Don't forget to recommend you friends this game!");

}

}

  • Press run.
  • Play the game and enjoy.

Algorithmic Pixel Art: The Beauty of Aliasing

Discussed  here More images in  Google drive Some outputs: Forward to anyone who says aliasing is ugly.