博饼只能小海龟?C++也行!

前言

我看许多人用小海龟来做博饼,于是,我掏出了C++。

(一股强劲的音乐响起)

C++,启动!

画图

C++不像小海龟能随意地飘来飘去,只能用字符来画骰子

void S(int ForgC, int BackC) {
	WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
}
void func(int x){
	if(x==1){
		cout<<"--------"<<endl;
		cout<<"|      |"<<endl;
		cout<<"|  ";
		S(12,0);
		cout<<"●";
		S(15,0);
		cout<<"  |"<<endl;
		cout<<"|      |"<<endl;
		cout<<"--------"<<endl;
	}
	if(x==2){
		cout<<"--------"<<endl;
		cout<<"|  ";
		S(9,0);
		cout<<"●";
		S(15,0);
		cout<<"  |"<<endl;
		cout<<"|      |"<<endl;
		cout<<"|  ";
		S(9,0);
		cout<<"●";
		S(15,0); 
		cout<<"  |"<<endl;
		cout<<"--------"<<endl;
	}
	if(x==3){
		cout<<"--------"<<endl;
		cout<<"|";
		S(9,0);
		cout<<"●";
		S(15,0);
		cout<<"    |"<<endl;
		cout<<"|  ";
		S(9,0);
		cout<<"●";
		S(15,0);
		cout<<"  |"<<endl;
		cout<<"|    ";
		S(9,0);
		cout<<"●";
		S(15,0); 
		cout<<"|"<<endl;
		cout<<"--------"<<endl;
	}
	if(x==4){
		cout<<"--------"<<endl;
		cout<<"|";
		S(12,0);
		cout<<"●  ●";
		S(15,0);
		cout<<"|"<<endl;
		cout<<"|      |"<<endl;
		cout<<"|";
		S(12,0);
		cout<<"●  ●";
		S(15,0);
		cout<<"|"<<endl;
		cout<<"--------"<<endl;
	}
	if(x==5){
		cout<<"--------"<<endl;
		cout<<"|";
		S(9,0);
		cout<<"●  ●";
		S(15,0);
		cout<<"|"<<endl;
		cout<<"|  ";
		S(9,0);
		cout<<"●";
		S(15,0);
		cout<<"  |"<<endl;
		cout<<"|";
		S(9,0);
		cout<<"●  ●";
		S(15,0);
		cout<<"|"<<endl;
		cout<<"--------"<<endl;
	}
	if(x==6){
		cout<<"--------"<<endl;
		cout<<"|";
		S(9,0);
		cout<<"●  ●";
		S(15,0);
		cout<<"|"<<endl;
		cout<<"|";
		S(9,0);
		cout<<"●  ●";
		S(15,0);
		cout<<"|"<<endl;
		cout<<"|";
		S(9,0);
		cout<<"●  ●";
		S(15,0);
		cout<<"|"<<endl;
		cout<<"--------"<<endl;
	}
}

其中,S为颜色函数,负责调整颜色。

main函数

博饼讲究随机,随机数不能少。

srand(time(NULL));

随后每输入一次,就随机出6个骰子(突发恶疾)

再简简单单判断一下是神么

cout<<"输入任何符号抽取"<<endl;
		cin>>c;
		system("cls");
		for(int i=1;i<=6;i++){
			a[i]=rand()%6+1;
			func(a[i]);
			b[i]=0;
			Sleep(15);
		}
		for(int i=1;i<=6;i++)b[a[i]]++; 
		if(b[4]==4&&b[1]==2){
			S(14,0);
			cout<<"★插金花★"<<endl;
			S(15,0);
			Sleep(300);
		}else if(b[4]==6){
			S(14,0);
			cout<<"★红六勃★"<<endl;
			S(15,0);
			Sleep(300);
		}else if(b[1]==6){
			S(14,0);
			cout<<"★遍地锦★"<<endl;
			S(15,0);
			Sleep(300);
		}else if(b[2]==6||b[3]==6||b[5]==6||b[6]==6){
			S(14,0);
			cout<<"★黑六勃★"<<endl;
			S(15,0);
			Sleep(300);
		}else if(b[4]==5){
			S(14,0);
			cout<<" ★五红★"<<endl;
			S(15,0);
			Sleep(200);
		}else if(b[1]==5||b[2]==5||b[3]==5||b[5]==5||b[6]==5){
			S(14,0);
			cout<<"★五子登科★"<<endl;
			S(15,0);
			Sleep(300);
		}else if(b[4]==4){
			S(14,0);
			cout<<" ★四红★"<<endl;
			S(15,0);
			Sleep(300);
		}else if(b[1]==1&&b[2]==1&&b[3]==1&&b[4]==1&&b[5]==1&&b[6]==1){
			S(14,0);
			cout<<"对堂"<<endl;
			S(15,0);
			Sleep(200);
		}else if(b[4]==3){
			cout<<"三红"<<endl;
			S(15,0);
		}else if(b[1]==4||b[2]==4||b[3]==4||b[5]==4||b[6]==4){
			cout<<"四进"<<endl;
			S(15,0);
		}else if(b[4]==2){
			cout<<"二举"<<endl;
			S(15,0);
		}else if(b[4]==1){
			cout<<"一秀"<<endl;
			S(15,0);
		}else{
			cout<<"无"<<endl;
			S(15,0);
		} 

总代码

#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int a[7],b[7];
char c;
void S(int ForgC, int BackC) {
	WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
}
void func(int x){
	if(x==1){
		cout<<"--------"<<endl;
		cout<<"|      |"<<endl;
		cout<<"|  ";
		S(12,0);
		cout<<"●";
		S(15,0);
		cout<<"  |"<<endl;
		cout<<"|      |"<<endl;
		cout<<"--------"<<endl;
	}
	if(x==2){
		cout<<"--------"<<endl;
		cout<<"|  ";
		S(9,0);
		cout<<"●";
		S(15,0);
		cout<<"  |"<<endl;
		cout<<"|      |"<<endl;
		cout<<"|  ";
		S(9,0);
		cout<<"●";
		S(15,0); 
		cout<<"  |"<<endl;
		cout<<"--------"<<endl;
	}
	if(x==3){
		cout<<"--------"<<endl;
		cout<<"|";
		S(9,0);
		cout<<"●";
		S(15,0);
		cout<<"    |"<<endl;
		cout<<"|  ";
		S(9,0);
		cout<<"●";
		S(15,0);
		cout<<"  |"<<endl;
		cout<<"|    ";
		S(9,0);
		cout<<"●";
		S(15,0); 
		cout<<"|"<<endl;
		cout<<"--------"<<endl;
	}
	if(x==4){
		cout<<"--------"<<endl;
		cout<<"|";
		S(12,0);
		cout<<"●  ●";
		S(15,0);
		cout<<"|"<<endl;
		cout<<"|      |"<<endl;
		cout<<"|";
		S(12,0);
		cout<<"●  ●";
		S(15,0);
		cout<<"|"<<endl;
		cout<<"--------"<<endl;
	}
	if(x==5){
		cout<<"--------"<<endl;
		cout<<"|";
		S(9,0);
		cout<<"●  ●";
		S(15,0);
		cout<<"|"<<endl;
		cout<<"|  ";
		S(9,0);
		cout<<"●";
		S(15,0);
		cout<<"  |"<<endl;
		cout<<"|";
		S(9,0);
		cout<<"●  ●";
		S(15,0);
		cout<<"|"<<endl;
		cout<<"--------"<<endl;
	}
	if(x==6){
		cout<<"--------"<<endl;
		cout<<"|";
		S(9,0);
		cout<<"●  ●";
		S(15,0);
		cout<<"|"<<endl;
		cout<<"|";
		S(9,0);
		cout<<"●  ●";
		S(15,0);
		cout<<"|"<<endl;
		cout<<"|";
		S(9,0);
		cout<<"●  ●";
		S(15,0);
		cout<<"|"<<endl;
		cout<<"--------"<<endl;
	}
}
int main(){
	srand(time(NULL));
	cout<<"食用前请开全屏~"<<endl;
	Sleep(2500);
	system("cls"); 
	while(true){
		cout<<"输入任何符号抽取"<<endl;
		cin>>c;
		system("cls");
		for(int i=1;i<=6;i++){
			a[i]=rand()%6+1;
			func(a[i]);
			b[i]=0;
			Sleep(15);
		}
		for(int i=1;i<=6;i++)b[a[i]]++; 
		if(b[4]==4&&b[1]==2){
			S(14,0);
			cout<<"★插金花★"<<endl;
			S(15,0);
			Sleep(300);
		}else if(b[4]==6){
			S(14,0);
			cout<<"★红六勃★"<<endl;
			S(15,0);
			Sleep(300);
		}else if(b[1]==6){
			S(14,0);
			cout<<"★遍地锦★"<<endl;
			S(15,0);
			Sleep(300);
		}else if(b[2]==6||b[3]==6||b[5]==6||b[6]==6){
			S(14,0);
			cout<<"★黑六勃★"<<endl;
			S(15,0);
			Sleep(300);
		}else if(b[4]==5){
			S(14,0);
			cout<<" ★五红★"<<endl;
			S(15,0);
			Sleep(200);
		}else if(b[1]==5||b[2]==5||b[3]==5||b[5]==5||b[6]==5){
			S(14,0);
			cout<<"★五子登科★"<<endl;
			S(15,0);
			Sleep(300);
		}else if(b[4]==4){
			S(14,0);
			cout<<" ★四红★"<<endl;
			S(15,0);
			Sleep(300);
		}else if(b[1]==1&&b[2]==1&&b[3]==1&&b[4]==1&&b[5]==1&&b[6]==1){
			S(14,0);
			cout<<"对堂"<<endl;
			S(15,0);
			Sleep(200);
		}else if(b[4]==3){
			cout<<"三红"<<endl;
			S(15,0);
		}else if(b[1]==4||b[2]==4||b[3]==4||b[5]==4||b[6]==4){
			cout<<"四进"<<endl;
			S(15,0);
		}else if(b[4]==2){
			cout<<"二举"<<endl;
			S(15,0);
		}else if(b[4]==1){
			cout<<"一秀"<<endl;
			S(15,0);
		}else{
			cout<<"无"<<endl;
			S(15,0);
		} 
	}
	return 0;
}

球球点个赞吧!

  • 5
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
是一种传统的中国民间游戏,也可以作为一种小游戏在Java中实现。在游戏中,玩家通过掷骰子来获得不同的点数组合,根据不同的点数组合来判断获得的奖励或者惩罚。 在Java中实现小游戏,可以按照以下步骤进: 1. 创建一个Dice类,用于表示骰子。该类可以包含一个roll()方法,用于随机生成一个1到6之间的整数作为骰子的点数。 2. 创建一个Player类,用于表示玩家。该类可以包含一个rollDice()方法,用于掷骰子并返回点数组合。 3. 创建一个Game类,用于控制游戏的进。该类可以包含一个start()方法,用于开始游戏。在游戏进过程中,可以通过调用Player类的rollDice()方法来获取玩家的点数组合,并根据不同的点数组合来判断奖励或者惩罚。 下面是一个简单的示例代码: ```java import java.util.Random; class Dice { public int roll() { Random random = new Random(); return random.nextInt(6) + 1; } } class Player { private Dice dice; public Player(Dice dice) { this.dice = dice; } public int[] rollDice() { int[] diceValues = new int[6]; for (int i = 0; i < 6; i++) { diceValues[i] = dice.roll(); } return diceValues; } } class Game { private Player player; public Game(Player player) { this.player = player; } public void start() { int[] diceValues = player.rollDice(); // 根据点数组合进判断奖励或者惩罚的逻辑 // ... } } public class Main { public static void main(String[] args) { Dice dice = new Dice(); Player player = new Player(dice); Game game = new Game(player); game.start(); } } ``` 这是一个简单的小游戏的Java实现示例。在实际的游戏中,你可以根据需求进更加详细和复杂的设计和实现。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值