Anda di halaman 1dari 6

/**

This is a game programme in BlueJ background, where one has to enter numbers from 1-10 and
compete with an opponent to reach 100 as quickly as possible. Each number entered will be
summed up to reach 100.

*/

package GAMES;

import java.util.*;

import java.io.*;

class Pogo

static int s = 0, c = 1,i = 0,z = 0; char m; String S1 = "", S2 = " ";

public static void main()throws IOException

if(z++ == 0)

new Time("P 0 G 0","10s");

Scanner sc = new Scanner(System.in);

Pogo pg = new Pogo();

s = 0; c = 1;

System.out.print("\f\n\t~*~*~*~*~*~*~*P 0 G 0*~*~*~*~*~*~*~\n\n\tM E N U\n\n 1. Play\n


2. Exit\n\n Enter your choice : ");

if((c =(int)sc.nextDouble()) == 1)

pg.accept(sc);

else if(c == 2)

{System.out.println("\n\n\t\t~~~~~~~*T H A N K\tY O
U*~~~~~~~\n\n\t\t\t\t\t\t\t\t\t\tPRESENTING YOU BUY : S - GAMES"); return;}

main();

public void accept(Scanner sc)throws IOException

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.print("\nRule : Your aim is to reach 100 first, by entering any number between 1 to
10.\n\tIf you enter any number outside this range, you will be penalized.\n\nPress 'Enter' to
continue : ");
br.readLine();

System.out.print("\f\nPlease Choose :\n\n1. Paly versus 'Human'.\n2. Paly versus


'Computer'.\n\nPlease enter your choice : ");

switch((int)sc.nextDouble())

default: System.out.println("Wrong Choice!!\nBut, by default, you need to play agains


computer.");

case 2: computer(sc);

break;

case 1: humman(sc);

display();

br.readLine();

public void humman(Scanner sc)

System.out.print("\fPlease enter name of player - 1 : ");

S1 = sc.next()+sc.nextLine().trim();

System.out.print("Please enter name of player - 2 : ");

S2 = sc.next()+sc.nextLine().trim();

while(s < 100)

System.out.print(S1+ "'s turn : ");

if((i =(int)sc.nextDouble()) < 1 || (i > 10))

System.out.println("\nDear "+S1+",\nYour entry is not accepted.\nIt is changed to


"+(i=1)+"\n\n"+S2+ "'s turn : ");

if((s += i) >= 100)

break;

System.out.print(S2+ "'s turn : ");

if((i =(int)sc.nextDouble()) < 1 || (i > 10))

System.out.println("\nDear "+S2+",\nYour entry is not accepted.\nIt is changed to "+(i=1));

System.out.println("\nSum : " +(s += i)+"\n");


c = (s >= 100)?2:1;

public void computer(Scanner sc)

System.out.print("\nPlease enter your name : ");

S1 = sc.next()+sc.nextLine().trim();

System.out.print("\f\tL e v e l\n\nE. Easy\nM. Medium\nH. Hard\n\nPlease enter your choice :


");

if((m = sc.next().toUpperCase().charAt(0)) == 'E' || m == 'M' || m == 'H')

while(s < 100)

System.out.print("\n"+S1+ ", its your turn : ");

if((i =(int)sc.nextDouble()) < 1 || (i > 10))

System.out.println("\nDear "+S1+",\nYour entry is not accepted.\nIt is changed to "+(i=1));

if((s += i) >= 100)

break;

i = ((s >= 65 && m == 'E') || (s >= 70 && m == 'M') || (s >= 20 && m == 'H'))?hard():((s >= 50
&& m == 'E') || (s >= 40 && m == 'M') || (s >= 0 && m ==
'H'))?medium():(int)((Math.random()*10)+1);

System.out.println("\nMy call : "+i+"\n\nSum : " +(s += i)+"\n");

c = (s >= 100)?2:1;

else

System.out.println("\nSorry!! "+S1+",\nYour choosed level does not exist.");

public int hard()

return(((((s / 10)*11)+1) > s)?(((s / 10)*11)+1)-s:((((((s / 10)+1)*11)+1)-s) <= 10)?((((s /


10)+1)*11)+1)-s:(s < 90)?i=1:100-s);
}

public int medium()

return(((((s / 10)*11)+1) > s)?(((s / 10)*11)+1)-s:(s < 90)?1:100-s);

public void display()

if(c == 1 && S2.charAt(0) == ' ' && (m == 'E' || m == 'M' || m == 'H'))

System.out.print("\fSum : " +s+"\nCongratulations!!\n"+S1+" Won!\n\nPress 'Enter' to


continue : ");

else if (c == 1 && S2.charAt(0) != ' ')

System.out.print("\fSum : " +s+"\n"+S1+ " won!!\n\nPress 'Enter' to continue : ");

else if(c == 2 && S2.charAt(0) == ' ' && (m == 'E' || m == 'M' || m == 'H'))

System.out.print("\fSum : " +s+"\nSorry!! "+S1+"\nYou lost.\nBetter luck next time.\n\nPress


'Enter' to continue : ");

else if(c == 2 && S2.charAt(0) != ' ')

System.out.print("\fSum : " +s+"\n"+S2+" Won!!\n\nPress 'Enter' to continue : ");

}
package GAMES;

import java.util.*;

import java.io.*;

class Time

Time(String n, String t)throws IOException

System.out.print(n);

n = "";

StringTokenizer sts = new StringTokenizer(t,"s");

if(sts.countTokens() == 2 || t.charAt(t.length()-1) == 's')

sec(Integer.valueOf(n = sts.nextToken()));

if(t.charAt(t.length()-1) >= '0' && t.charAt(t.length()-1) <= '9')

if(n.equals(""))

milli(Integer.valueOf(t));

else

milli(Integer.valueOf(sts.nextToken()));

void sec(int s)

GregorianCalendar date = new GregorianCalendar();

s += date.get(Calendar.SECOND);

if(s >= 60)

s -= 60;
while(true)

GregorianCalendar dt = new GregorianCalendar();

if(dt.get(Calendar.SECOND) == s)

break;

void milli(int ms)

GregorianCalendar date = new GregorianCalendar();

ms += date.get(Calendar.MILLISECOND);

if(ms >= 1000)

ms -= 1000;

while(true)

GregorianCalendar dt = new GregorianCalendar();

if(dt.get(Calendar.MILLISECOND) == ms)

break;

Anda mungkin juga menyukai