0
朱宥宇
新手光能
新手光能
#include<iostream>
#include<cstdlib>
#include<ctime>
#include<windows.h>
class SlotMachine{
int credits;
int symbols[3];
public:
SlotMachine():credits(100){
srand(time(0));}
void spin(){
if(credits<10){
std::cout<<"余额不足!"<<std::endl;
return;}
credits-=10;
for(int i=0;i<3;i++)
symbols[i]=rand()%7;
display();
checkWin();}
void display(){
system("cls");
std::cout<<"余额:"<<credits<<" 下注:10"<<std::endl;
std::cout<<"-------------"<<std::endl;
for(int i=0;i<3;i++){
std::cout<<"|";
switch(symbols[i]){
case 0:std::cout<<"七";break;
case 1:std::cout<<"星";break;
case 2:std::cout<<"铃";break;
case 3:std::cout<<"橙";break;
case 4:std::cout<<"梅";break;
case 5:std::cout<<"花";break;
case 6:std::cout<<"币";break;}
std::cout<<"|";}
std::cout<<std::endl;
std::cout<<"-------------"<<std::endl;
std::cout<<"按回车转动,按q退出"<<std::endl;}
void checkWin(){
if(symbols[0]==symbols[1]&&symbols[1]==symbols[2]){
int prize=0;
switch(symbols[0]){
case 0:prize=100;break;
case 1:prize=50;break;
case 2:prize=30;break;
default:prize=20;break;}
credits+=prize;
std::cout<<"赢得"<<prize<<"分!"<<std::endl;}}
void run(){
char input;
display();
while(true){
input=getchar();
if(input=='q')break;
if(input=='\n')spin();}}
int getCredits()const{return credits;}};
int main(){
SlotMachine game;
game.run();
return 0;}