ACMICPC Live Archive 7373 Falling Blocks Falling Blocks is a
Solution
#include <iostream>
#include <string>
using namespace std;
int main()
{
string username;
string password;
bool success;
cout << \"\\tSecret Game\ \";
do
{
cout << \"\ Username: \";
cin >> username;
cout << \"Password: \";
cin >> password;
if (username == \"Blank\" && password == \"330\")
{
cout << \"\ Welcome to the Secret game\";
success = true;
else
{
cout << \"\ Your login failed.\";
success = false;
}
} while (!success);
return 0;
}
Here the Code For the Secret Game, I want it when the user enter the password and username its runs this code :
#include <iostream>
using namespace std;
class connectFour{
int player;
int score[2];
int board[3][10]; //3 = Rows, 10 = Columns
int move;
bool win;
public:
connectFour(){
player = 1;
score[0] = 0;
score[1] = 0;
win = false;
for (int i = 0; i < 3; i++){
for (int x = 0; x < 10; x++){
board[i][x] = 0;
}
}
}
void startTurn(){
checkWin();
if (win == true){
clearScreen();
display();
cout<< \"Player #\" << player << \" has won!\" <<endl <<endl;
}
else{
display();
gatherMove();
}
}
void display(){
clearScreen();
cout<< \" 1 2 3 4 5 6 7 8 9 10 \" <<endl;
for (int i = 0; i < 3; i++){
for (int x = 0; x < 10; x++){
cout<< \"[\" << board[i][x] << \"]\";
}
cout<< endl;
}
}
void gatherMove(){
int emptySpots = 0;
cout<< endl << \"Player #\" << player << \": Move to which space? \";
cin>> move;
if (move > 10){move = 10;}
if (move < 0){move = 0;}
for (int i = 5; i >= 0; i--){
if (board[i][move - 1] == 0){
board[i][move - 1] = player;
break;
}
else{
emptySpots += 1;
}
}
if (emptySpots == 3){
cout<< endl << \"There are no empty spots on #\" << move << \"! Try again!\";
gatherMove();
}
if (player == 1){player = 2;}
else {player = 1;}
startTurn();
}
void checkWin(){
int start = 0;
for (int i = 0; i < 3; i ++){
for (start = 0; start <= 3; start++){
if ((board[i][start] == board[i][start+1] && board[i][start+1] == board[i][start+2] && board[i][start+2] == board[i][start+3]) && (board[i][start] != 0)){
win = true;
player = board[i][start];
break;
}
}
}
for (int i = 0; i < 10; i ++){
for (start = 0; start <= 2; start++){
if ((board[start][i] == board[start+1][i] && board[start+1][i] == board[start+2][i] && board[start+2][i] == board[start+3][i]) && (board[start][i] != 0)){
win = true;
player = board[start][i];
break;
}
}
}
for (int i = 3; i < 3; i ++){
for (start = 0; start <= 3; start++){
if ((board[i][start] == board[i-1][start+1] && board[i-1][start+1] == board[i-2][start+2] && board[i-2][start+2] == board[i-3][start+3]) && (board[i][start] != 0)){
win = true;
player = board[i][start];
break;
}
}
}
for (int i = 0; i < 3; i ++){
for (start = 0; start <= 4; start++){
if ((board[i][start] == board[i+1][start+1] && board[i+1][start+1] == board[i+2][start+2] && board[i+2][start+2] == board[i+3][start+3]) && (board[i][start] != 0)){
win = true;
player = board[i][start];
break;
}
}
}
}
void clearScreen(){
system(\"clear\");
}
};
int main (int argc, char * const argv[]) {
connectFour play;
play.startTurn();
return 0;
}




