Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
// Example program
#include <iostream>
#include <string>
using namespace std;
class MyClass { // The class
public: // Access specifier
string Board[15][15];
bool outofBounds = false;
int score;
int x;
int y;
int turn = 1;
//string one[10] = {"a","e","i","o","u","l","n","s","t","r"};
//string two[2] = {"d","g"};
//string three[4] = {"b","c","m","p"};
//string four[5] = {"f","h","v","w","y"};
//string five[1] = {"k"};
//string eight[2]{"j","x"};
//string ten[2] = {"q","z"};
string points[26] = {"a","e","i","o","u","l","n","s","t","r","d","g","b","c","m","p","f","h","v","w","y","k","j","x","q","z"};
string word;
string direction;
void boardStart(){
for(int i = 0; i < 15; i++){
for(int u = 0; u < 15; u++){
Board[i][u] = {" "};
}
}
Board[7][7] = {"*"};
}
void boardBuild() { // Method function which builds the scrabble board
//Board[y][x] the first value is the y axis and 2nd value is the x axis
cout<<" ";
for(int i = 0; i < 10; i++){
cout <<" "<< i<< " ";
}
for(int i = 1; i < 6; i++){
cout <<" "<< 1<<" "<< i-1 << " ";
}
cout<<endl;
for(int i = 0; i < 10; i++){
cout <<" " << i;
for(int u = 0; u < 15; u++){
cout<<" [";
cout<<Board[i][u];
cout<<"] ";}
cout<<endl<<endl;
}
for(int i = 10; i < 15; i++){
cout << i;
for(int u = 0; u < 15; u++){
cout<<" ["<<Board[i][u]<<"] ";}
cout<<endl<<endl;
}
cout<<endl;
}
void turnPlayer(){
cout<< "Turn "<< turn <<endl;
cout<<"Input the starting x and y coordinates for your word input."<<endl;
cout<<"x = ";
cin>>x;
cout<<"y = ";
cin>>y;
cout<<"r for right and d for down = ";
cin>>direction;
cout<<"Input your word = ";
cin>>word;
cout<<endl;
if(direction == "r"){
for(int u = 0; u < word.length(); u++){
if(word.length() + x > 15){
outofBounds = true;
}
else{
Board[y][u + x] = word[u];}
}
}
else if(direction == "d"){
for(int u = 0; u < word.length(); u++){
if(word.length() + y > 15){
outofBounds = true;
}
else{
Board[u + y][x] = word[u];}
}
}
if (turn == 1 && Board[7][7] == "*"){
boardStart();
cout<<"You did not input a word in the middle point"<<endl;
turnPlayer();
}
else{
boardBuild();
if(outofBounds == false){
turn += 1;
//for(int i = 0; i < word.length(); i++){
//for
//}
for(int i = 0; i < 26; i++){
for(int u = 0; u < word.length(); u++){
if(points[i] == word[u] && i < 10){
score += 1;
}
else if(points[i] == word[u] && i < 12){
score += 2;
}
else if(points[i] == word[u] && i < 16){
score += 3;
}
else if(points[i] == word[u] && i < 21){
score += 4;
}
else if(points[i] == word[u] && i < 22){
score += 5;
}
else if(points[i] == word[u] && i < 24){
score += 8;
}
else if(points[i] == word[u] && i < 26){
score += 10;
}
}
}
}
else{
cout<<"Out of bounds please try again ! ! ! ! !"<<endl<<endl;
cout<<"Out of bounds please try again ! ! ! ! !"<<endl<<endl;
cout<<"Out of bounds please try again ! ! ! ! !"<<endl<<endl;
cout<<"Out of bounds please try again ! ! ! ! !"<<endl<<endl;
cout<<"Out of bounds please try again ! ! ! ! !"<<endl<<endl;
outofBounds == false;
}
cout<<endl;
cout<<"SCORE = "<< score;
turnPlayer();
}
}
};
int main()
{
MyClass myObj;
myObj.boardStart();
myObj.boardBuild();
myObj.turnPlayer();
}