Java程式編寫 • 【第5章 程式:賭博遊戲】

.馮上發表於2020-12-16

本章節總結

返回作業目錄


  • 練習一
  • 賭博遊戲

在這裡插入圖片描述


import java.util.Scanner;
public class day4_03 {
	public static void main(String[]args){
		int qian=20000;
		int jj=(int)(Math.random()*(20000-0+1));
		int dj=(int)(Math.random()*(100-0+1));
		int mai1=100;
		int mai2=1000;
		int mai3=10000;
		int mai4=50000;
		Scanner a=new Scanner(System.in);
		System.out.println("*全部家當:"+qian+"¥");
		System.out.println("*<彩票>專案:100¥\t\t*一張中獎範圍:0-200¥");
		System.out.println("*請輸入<1>買1張<彩票>\t*<2>買10張<彩票>\t    *<3>買100張<彩票>:");
		while(qian<5000000&&qian>=10){
			while(qian>=100&&qian<50000){
				boolean c=a.hasNextInt();
				int A=a.nextInt();
				int b=3373650;
				if(A==1&&c==true){
					b=3373651;
				}else if(A==2){
					b=3373652;
				}else if(A==3){
					b=3373653;
				}
					if(b==3373651){
						if(qian>=100){
							qian=qian-mai1;
							jj=(int)(Math.random()*(200-0+1));
							System.out.println("*你刮開了彩票...");
							System.out.println("*恭喜你,中了"+jj+"¥");
							qian=jj+qian;
							System.out.println("*全部家當:"+qian+"¥");
								A=0;
								b=3373650;
						}else{
							System.out.println("*你看了看你的錢包");
							A=0;
							b=3373650;
						}
					}else if(b==3373652){
						if(qian>=1000){
							qian=qian-mai2;
							jj=(int)(Math.random()*(2000-0+1));
							System.out.println("*你刮開了彩票...");
							System.out.println("*恭喜你,中了"+jj+"¥");
							qian=jj+qian;
							System.out.println("*全部家當:"+qian+"¥");
								A=0;
								b=3373650;
						}else{
							System.out.println("*你看了看你的錢包");
							A=0;
							b=3373650;
						}
					}else if(b==3373653){
						if(qian>=10000){
							qian=qian-mai3;
							jj=(int)(Math.random()*(20000-0+1));
							System.out.println("*你刮開了彩票...");
							System.out.println("*恭喜你,中了"+jj+"¥");
							qian=jj+qian;
							System.out.println("*全部家當:"+qian+"¥");
								A=0;
								b=3373650;
						}else{
							System.out.println("*你看了看你的錢包");
							A=0;
							b=3373650;
						}
					}else{
					System.out.println("*請輸入數字<1><2><3>");
					}
					if(qian>=50000){
						System.out.println("*恭喜你,已積攢50000¥,解鎖:<老虎機>");
						System.out.println("*<老虎機>專案:50000¥\t\t*一張中獎範圍:0-1000000¥");
						System.out.println("*請輸入<4>搖動<老虎機>");
					}
			}
			while(qian>=50000&&qian<5000000){
				int A=a.nextInt();
				int b=3373650;
				if(A==1){
					b=3373651;
				}else if(A==2){
					b=3373652;
				}else if(A==3){
					b=3373653;
				}else if(A==4){
					b=3373654;
				}
					if(b==3373651){
						if(qian>=100){
							qian=qian-mai1;
							jj=(int)(Math.random()*(200-0+1));
							System.out.println("*你刮開了彩票...");
							System.out.println("*恭喜你,中了"+jj+"¥");
							qian=jj+qian;
							System.out.println("*全部家當:"+qian+"¥");
								A=0;
								b=3373650;
						}else{
							System.out.println("*你看了看你的錢包");
							A=0;
							b=3373650;
						}
					}else if(b==3373652){
						if(qian>=1000){
							qian=qian-mai2;
							jj=(int)(Math.random()*(2000-0+1));
							System.out.println("*你刮開了彩票...");
							System.out.println("*恭喜你,中了"+jj+"¥");
							qian=jj+qian;
							System.out.println("*全部家當:"+qian+"¥");
								A=0;
								b=3373650;
						}else{
							System.out.println("*你看了看你的錢包");
							A=0;
							b=3373650;
						}
					}else if(b==3373653){
						if(qian>=10000){
							qian=qian-mai3;
							jj=(int)(Math.random()*(20000-0+1));
							System.out.println("*你刮開了彩票...");
							System.out.println("*恭喜你,中了"+jj+"¥");
							qian=jj+qian;
							System.out.println("*全部家當:"+qian+"¥");
								A=0;
								b=3373650;
						}else{
							System.out.println("*你看了看你的錢包");
							A=0;
							b=3373650;
						}
					}else if(b==3373654){
						dj=(int)(Math.random()*(100-0+1));
						if(dj==100){
							qian=qian-mai4;
							System.out.println("*你搖動了老虎機...");
							System.out.println("*恭喜你!!!中了1 0 0 0 0 0 0¥,你媽買菜必超級加倍");
							qian=1000000+qian;
							System.out.println("*全部家當:"+qian+"¥");
							A=0;
							b=3373650;
						}else if(dj==0){
							qian=qian-mai4;
							System.out.println("*你搖動了老虎機...");
							System.out.println("*恭喜你,中了5 0 0 0 0 0¥,祝你玩鬥地主3456沒有7");
							qian=500000+qian;
							System.out.println("*全部家當:"+qian+"¥");
								A=0;
								b=3373650;
						}else{
							qian=qian-mai4;
							jj=(int)(Math.random()*(98000-0+1));
							System.out.println("*你搖動了老虎機...");
							System.out.println("*恭喜你,中了"+jj+"¥");
							qian=jj+qian;
							System.out.println("*全部家當:"+qian+"¥");
								A=0;
								b=3373650;
						}
					}else{
					System.out.println("*請輸入數字<1><2><3><4>");
					}
			}
			if(qian<10){
				System.out.println("*你輸的只剩條褲衩了");
			}
		}
	}
}

相關文章