1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
# include <iostream>
# include <string.h>
# include <time.h>
# include <cstdlib>
# include <stdio.h>
# include <termios.h>
# include <unistd.h>
# include <iomanip>
using namespace std;
///////////////////////////////////////////////////////////////////////
int getch()
{
struct termios oldt, newt;
int ch;
tcgetattr(STDIN_FILENO, &oldt);
newt=oldt;
newt.c_lflag &= ~( ICANON | ECHO );
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
ch=getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
return ch;
}
///////////////////////////////////////////////////////////////////////
int MakeCard(int Board[5][15][2])
{
srand(time(NULL));
int x,y,z,temp,random,swap;
for (y=0;y<15;y++)
for (x=0;x<5;x++)
Board[x][y][0]=x*15+y+1;
for (y=0;y<5;y++)
{
for (x=0;x<5;x++)
{
random=rand()%15;
temp=Board[x][random][0];
Board[x][random][0]=Board[x][y][0];
Board[x][y][0]=temp;
}
}
for (z=0;z<5;z++)
for (y=0;y<5;y++)
for (x=0;x<5;x++)
if (Board[x][y][0]>Board[x][y+1][0])
{
swap=Board[x][y][0]; // Sort dice
Board[x][y][0]=Board[x][y+1][0];
Board[x][y+1][0]=swap;
}
for (y=0;y<5;y++)
for (x=0;x<5;x++)
Board[x][y][1]=0;
return 0;
}
///////////////////////////////////////////////////////////////////////
int Color(int Board[5][15][2],int posx,int posy)
{
char normal[]={ 0x1b, '[', '0', ';', '3', '9', 'm', 0 }; //Declare Variables
char red[]={ 0x1b, '[', '0', ';', '3', '1', 'm', 0 };
char blue[]={ 0x1b, '[', '0', ';', '3', '4', 'm', 0 };
char green[]={ 0x1b, '[', '0', ';', '3', '2', 'm', 0 };
char purple[]={ 0x1b, '[', '0', ';', '3', '5', 'm', 0 };
char cyan[]={ 0x1b, '[', '1', ';', '3', '6', 'm', 0 };
char yellow[]={ 0x1b, '[', '0', ';', '3', '3', 'm', 0 };
int x,y;
cout<<blue<<" B "<<green<<" I "<<red<<" N "<<purple<<" G "<<yellow<<" O "<<normal<<"\n";
cout<<cyan<<"╔════╦════╦════╦════╦════╗\n";
for (y=0;y<5;y++)
{
for (x=0;x<5;x++)
{
cout<<cyan<<"║ ";
if (Board[x][y][0]<10) cout<<" ";
if (Board[x][y][0]<76) cout<<" ";
if ((x==posx)&&(y==posy)) cout<<blue;
else if (Board[x][y][0]==0) cout<<red;
else
cout<<normal;
cout<<Board[x][y][0];
}
cout<<cyan<<"║\n";
}
cout<<cyan<<"╚════╩════╩════╩════╩════╝\n"<<normal;
cout<<"\n\n";
for (y=0;y<5;y++)
{
for (x=0;x<5;x++)
{
cout<<Board[x][y][1]<<" ";
}
cout<<"\n";
}
return 0;
}
///////////////////////////////////////////////////////////////////////
int DetectBingo(int Board[5][15][2])
{
int x,y,loseH,loseV,loseD1,loseD2;
for (y=0;y<5;y++)
{
loseH=0;
loseV=0;
loseD1=0;
loseD2=0;
for (x=0;x<5;x++)
{
loseH=Board[x][y][0];
loseV=Board[x][y][0];
loseD1+=Board[x][y][0];
loseD2+=Board[4-x][y][0];
}
if (!loseH) cout<<Board[x][0][0]<<Board[0][y][0]<<"BINGO!";
if (!loseV) cout<<"Bingo!";
if (!loseD1)cout<<"Bingo!";
if (!loseD2)cout<<"Bingo!";
}
return 0;
}
///////////////////////////////////////////////////////////////////////
int main()
{
int x=2,y=2,Board[5][15][2],input;
MakeCard(Board);
do
{
system("clear");
Color(Board,x,y);
system("sleep .01");
input=toupper(getch());
if (input=='D') x++;
if (input=='A') x--;
if (input=='S') y++;
if (input=='W') y--;
if (input==' ')
{
if (Board[x][y][0]!=0)
{
Board[x][y][1]=Board[x][y][0];
Board[x][y][0]=0;
}
}
}while ((input!=27)||(DetectBingo(Board)));
//Declare Variables
//Input
//Calculations
//Output
return 0;
}
| |