Bowling game

ShawnCplus 0 Tallied Votes 2K Views Share

I created a bowling game, Which for the most part works correctly. I toiled for hours trying to figure out how to do the scoring so i gave up. Its fairly simple code so not much of a description needed.

/*This Is the longest project I have planned, It will likeley take over
a month and It will be a hard one. I plan on creating a bowling game in which
you choose the power, spin, and location and the game will determine how
many pins that combination will knock down, add it to your score and change
the frame. If a strike occurs on the last (tenth) frame it will allow for another
frame. Hopefully like my other project I will include a highscore list to see
the skillful bowlers in this wonky bowling attempt*/  
#include <iostream.h>//required files
#include <stdlib.h>
#include <time.h>
#include <fstream.h>
#define MAX_SCORE 300
#define MAX_RANGE 10
main ()
{system("color 70");
system("title Text'o'Rama Bowling");
char highscore, name[20], instra;
int frames=0;
long pins;
int spin, power, arrow, score, roll, total, BASE, framescore, divy, divider;
     int tries;
     pins=10;
     tries=0;
     total=0;
     framescore=0;
         // Get random between 1 and MAX_RANGE
     cout<<"                 Welcome to Shawn Biddle's Text'o'Rama Bowling\n";
  cout<<"Please enter your name for the highscore list:";
  cin>> name;
  cout<<"Would you like to see the instructions?"<< endl;
  cin>> instra;
  if (instra=='y'){instra:
cout<<"The objective is simple, Knock down the pins... Yeah I know you \ncan't see them. ";

cout<<"Choose Your power, spin and alignment. Power being\nfairly obvious, spin is how ";

cout<<"much spin is on the ball \ntherefor how far it will go to either side of your placement.\n";

cout<<"Finally placement or alignment being which marker on \nthe lane you line up your bowler ";

cout<<"with."<< endl;
system("PAUSE");
goto begin;}
  else {  
  begin:  
  do{
          newframe:
                   frames++;
          roll+total;          
          framestart:
                     tries++;
                      if (tries==1){framescore=0;}
  else if (tries>1){framescore=roll;}
                     if (tries==3){tries=0;goto newframe;}
            system("cls");score=total;
      cout<<"|   |  0 0 0 0  |   |\n";
cout<<"|   | (_0_0_0_) |   |\n";
cout<<"|   |  (_0_0_)  |   |\n";
cout<<"|   |   (_0_)   |   |\n";
cout<<"|   |    (_)    |   |\n";
cout<<"|   |           |   |\n";
cout<<"|   |           |   |\n";
cout<<"|   |^         ^|   |\n";
cout<<"|   |1 ^  ^  ^ 5|   |\n";
cout<<"|   |  2  3  4  |   |\n";
cout<<"---------------------\n";
      cout<<name<<" You are in frame "<<frames<<".Score:"<<total<<"\n";
      cout<<"There are "<<pins-framescore<<" pins left. Try "<<tries<<"\n";
      cout<<"Alignment (1-5):\n";
    cin>> arrow;
    system("cls");
    if (arrow==1){
cout<<"|   |  0 0 0 0  |   |\n";
cout<<"|   | (_0_0_0_) |   |\n";
cout<<"|   |  (_0_0_)  |   |\n";
cout<<"|   |   (_0_)   |   |\n";
cout<<"|   |    (_)    |   |\n";
cout<<"|   |           |   |\n";
cout<<"|   |           |   |\n";
cout<<"|   |^         ^|   |\n";
cout<<"|   |1 ^  ^  ^ 5|   |\n";
cout<<"|   |  2  3  4  |   |\n";
cout<<"-----V---------------\n";}
    if (arrow==2){
cout<<"|   |  0 0 0 0  |   |\n";
cout<<"|   | (_0_0_0_) |   |\n";
cout<<"|   |  (_0_0_)  |   |\n";
cout<<"|   |   (_0_)   |   |\n";
cout<<"|   |    (_)    |   |\n";
cout<<"|   |           |   |\n";
cout<<"|   |           |   |\n";
cout<<"|   |^         ^|   |\n";
cout<<"|   |1 ^  ^  ^ 5|   |\n";
cout<<"|   |  2  3  4  |   |\n";
cout<<"-------V-------------\n";}
    else if (arrow==3){
cout<<"|   |  0 0 0 0  |   |\n";
cout<<"|   | (_0_0_0_) |   |\n";
cout<<"|   |  (_0_0_)  |   |\n";
cout<<"|   |   (_0_)   |   |\n";
cout<<"|   |    (_)    |   |\n";
cout<<"|   |           |   |\n";
cout<<"|   |           |   |\n";
cout<<"|   |^         ^|   |\n";
cout<<"|   |1 ^  ^  ^ 5|   |\n";
cout<<"|   |  2  3  4  |   |\n";
cout<<"----------V----------\n";}
    else if (arrow==4){
         cout<<"|   |  0 0 0 0  |   |\n";
cout<<"|   | (_0_0_0_) |   |\n";
cout<<"|   |  (_0_0_)  |   |\n";
cout<<"|   |   (_0_)   |   |\n";
cout<<"|   |    (_)    |   |\n";
cout<<"|   |           |   |\n";
cout<<"|   |           |   |\n";
cout<<"|   |^         ^|   |\n";
cout<<"|   |1 ^  ^  ^ 5|   |\n";
cout<<"|   |  2  3  4  |   |\n";
cout<<"-------------V-------\n";}
    else if (arrow==5){cout<<"|   |  0 0 0 0  |   |\n";
cout<<"|   | (_0_0_0_) |   |\n";
cout<<"|   |  (_0_0_)  |   |\n";
cout<<"|   |   (_0_)   |   |\n";
cout<<"|   |    (_)    |   |\n";
cout<<"|   |           |   |\n";
cout<<"|   |           |   |\n";
cout<<"|   |^         ^|   |\n";
cout<<"|   |1 ^  ^  ^ 5|   |\n";
cout<<"|   |  2  3  4  |   |\n";
cout<<"---------------V-----\n";}
    cout<<"Ok "<<name<<" You are in frame "<<frames<<".Score:"<<total<<"\n";
    cout<<"Power (1-10):\n";
    cin>> power;
    cout<<"Spin (0-10):\n";
    cin>> spin;
     pins=10;
             divy=pins-framescore;
if (tries==2){srand ( time (NULL) );roll = rand()%divy+1;}
             else {srand ( time (NULL) );roll = rand()%MAX_RANGE+1;}
    if (roll==0){cout<<"*CRASH* *THUMP*  GUTTERBALL!\n";} 
    if (roll==10){cout<<"   STEEEEEEEEERIKE!\n";}
  else if (roll>0 && roll<6){cout<<"Well Atleast You Hit Something.\n";}
  else if (roll>6){cout<<"Good Roll, Candyass!\n";}
  cout<<"You knocked down "<< roll <<"\n";
  total=score+roll;
cout<<"Your score is "<< total <<" in frame "<<frames<<"\n";
  divider=total/frames;
  system("PAUSE");
  if (frames==10 && roll==10){goto newframe;}
  if (roll==10){tries=0;goto newframe;}
 while (tries<3 && roll<10 && frames<10){pins-roll;goto framestart;}
  }while(frames<10);
          ofstream examplefile ("highscore.txt", ios::ate | ios::app);
  if (examplefile.is_open())
  {
     examplefile << ""<< name <<"--------"<< total <<"\n";    
     examplefile.close();  }
 bah: cout<<"Would you like to see the highscore list? [Y][N]"<< endl;
    cin>> highscore;
    if (highscore=='y'){ 
    system("cls");
    char buffer[256];
  ifstream examplefile ("highscore.txt");
  if (! examplefile.is_open()) { cout << "Error opening file"; exit (1); }
  while (! examplefile.eof() ){
        examplefile.getline (buffer,100);
        cout << buffer <<endl;}}
  else {cout<<"Thanks for playing!\n";
  system("PAUSE"); 
  return 0;} 
cout<<"Thank You very much for playing my game!"<< endl;
system("PAUSE");
return 0;}}
ShawnCplus 456 Code Monkey Team Colleague

sorry for the overlapping text, and despite the look here, the big blocky things do actually look like a lane with bowling pins in a console window

A.FATHA 0 Newbie Poster

I LIKE THIS PROGRAM, BECAUSE HELP ME TO MAKE MY PROJEK TUTORIAL . THANK YOU! SO MUCH
:lol:

manutd 2 Junior Poster

1)Main should have a type: int main (void) 2) O-o-out dated: goto begin; 3) What's with the indentation?
4) Seed rand only once, at the start of the app.
5) Could you have made this any less portable?

manutd 2 Junior Poster

6) Take out the .h's:

include <iostream>
//etc...
ShawnCplus 456 Code Monkey Team Colleague

sorry mautd, when I wrote this program I had no formal experience my entire knowledge of C++ was based off tutorials. and there was no real reason to make it portable, if you are speaking of linux then just include the cstdlib header and replace "cls" with "clear".
As to A.FATHA I'm glad I could help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.