Need guidance in menu based football game

Write your question here.
So i wanted to make a Hand football game in c++

the game works as such: the ball starts with the player . The player has to input a number between 0 and 2. If the computer also by chance gets the same number, the computer "tackles" the ball.
now the computer has the ball.
if the numbers are different each turn is called a "pass".
if one has(either the player or computer) 3 passes in a row without ANY tackle by the opposite team, the player having the ball gets a "Scoring chance"
here the player has to input a number between 4 and 6 . if the computer chooses the same numbers, the goal is saved . If the numbers are diffrent, then a goal is awarded to the person who made the 3 passes .
the game ends after 3 goals .
i cant make it to work . anyone help??
thanks in advance :)



here is an example of 2 players A and B playing
A has the ball at start
A takes out: 1 B takes out:2
A takes out:0 B takes out:0( The numbers are equal thus the ball has been tackled . the ball is now in the possession of B. The passes have been reset)
A takes out: 2 B takes out:0
A takes out: 1 B takes out:2
A takes out: 1 B takes out:0

Now B has 3 continuous passes without any tackle thus B is awarded with a scoring chance
A takes out: 4 B takes out:6
as the numbers are diffrent, B scores a goal .
the game now starts with the goalkeeper (A) having the ball, the no, of passes is reset
alternative( A takes out: 5 B takes out:5) thus the goal would not have been scored and the game would have started again with goalkeeper A having the ball
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
  
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<stdlib.h>
#include <time.h>
#include <dos.h>
void music()    //dos.h for music
{
   sound(900);
   delay(1000);
   nosound();
   sound(1000);
   delay(1000);
   nosound();
   sound(800);
   delay(1000);
   nosound();
   sound(500);
   delay(1000);
   nosound();
}




void intro_game()
{        clrscr();
cout<<" \n  ____________         __________                             ____________				  ";
cout<<" \n |============        /          \\       |\\            /|    |===========          					 ";
cout<<" \n ||                 /              \\     |  \\        /  |    |	       	   					 ";
cout<<" \n ||                |                |    |    \\    /    |    |---		   				";
cout<<" \n ||                |================|    |      \\/      |    |======		   				  ";
cout<<" \n ||     ======|    |                |    |              |    |======		   					  ";
cout<<" \n ||	      |    |	            |    |              |    |---		  						 ";
cout<<" \n |___________ |    |                |    |              |    |     						   ";
cout<<" \n |=========== |    |                |    |              |    |===========               					 ";
cout<<" \n                                                              ------------                                                               ";
getch();
clrscr();
}

void exit_game()
{

 intro_game();

 cout<<" \n         _________                         ________    _______                                                                                 ";
 cout<<" \n        /          \  |              |    |           |       \                                                            ";
 cout<<" \n       |            | |              |    |           |       |                                                          ";
 cout<<" \n       |            | |              |    |===        |______/                                                             ";
 cout<<" \n       |            |   |          |      |====       |\\                                                                     ";
 cout<<" \n       |            |     |      |        |===        |  \\								   ";
 cout<<" \n       |            |       |  |          |           |    \\                                                             ";
 cout<<" \n        \ ________ /          |           |_________  |      \\                                                                           ";
 cout<<" \n                                                                                                                       ";
   music();
   getch();
   exit(1);
}

int goal_chance(int a)
{    randomize();



   int goal_flag,ball;
 //check who has ball
 if(ball%2==0) //player has ball
 {
   cout<<"Goaling chance for player";
   int goal;
   cin>>goal;
   int rand2;
   rand2=random(7-4+1)+4;
   cout<<rand2;


     /* for(;rand2<4;)  //eliminates 0 1 2 3 from random value
   {
   rand2=random(7);
   }   */
   if(goal==rand2)  //goal scored
   {
    cout<<"Player scores a goal!";
     goal_flag=0;     //the goal flag tells the switch case what has happened
   }
   else
   {
    cout<<"The goal was saved by the computer";
     goal_flag=1;

   }

 }
 else //computers goaling chance
 {
   cout<<"Goaling chance for computer";
   int goal;
   cin>>goal;
   int rand2;
   for(;rand2<4;)  //eliminates 0 1 2 3 from random value
   {
   rand2=random(7);
   }
   if(goal==rand2)  //goal scored
   {
    cout<<"Computer scores a goal!";
    goal_flag=2;
   }
   else
   {
   cout<<"Goal was saved ny the player";
   goal_flag=3;
   }

 }




 return goal_flag;
}

void main()

{  intro_game();


  cout<<"Welcome to the Football game";
  cout<<"\n"<<"Enter H for help, P to play or E to exit! ";
  char choice;
  cin>>choice;

  if(choice=='h'||choice=='H')
    { //run help section . 
      cout<<"   rules";
      cout<<" mode 1= passing";
      cout<<"mode 2= goal scoring/saving";
      getch();
      goto start;


    }
    else

    if(choice=='p'||choice=='P')
    { //enter game here
      start:
      int rand,R,pass,a,ball,yh,goal_flag;  //the randomly generated number
      randomize();
      pass=0;
      ball=0;

      for(int sd=0;sd<=20;sd++)
      {
      if(ball%2==0)
      {
       cout<<"Enter your number for the pass"<<"\n";
       cin>>R;
       }
       else
       {
       cout<<"enter the number to tackle";
       cin>>R;          //R is the input which ranges from 0 to 2
	}
       rand=random(3);
       if(R>2)
       {
	cout<<"Awwww snap. we encountered an error.";
	goto error_debug;
       }
       else
       if(R==rand)
       {    //both numbers are equal, ball is tackled
	cout<<"R is equal to rand";
	ball++;
	pass=0;	  //ball is 0 at start, even= player has,odd= computer
       }
       else //acts when both numbers are not equal ie game continues
       {

	pass++; // pass starts from 0
	 cout<<"\n"<<"Ball is tackled"<<"\n";
	if(pass==3) //checks for goaling chance
	{a=0;
	 yh= goal_chance(a);

	}

       }

       //tells score
       if(a==1)   //checks whether goal chance occurred
       {
       switch(yh)
       {
	case 0: cout<<"scored by player(switch)  "<<"\n";
	break;
	case 1: cout<<"saved by computer (switch) "<<"\n";
	break;
	case 2: cout<<"computer scores (switch)";
	break;
	case 3: cout<<"saved by player (switch) ";

       }
       if(a==1)
       {
       break;
       }
       else
       continue;
	}
      }

       getch();



    error_debug:
    char choice2;
    cout<<"\n"<<"Enter C to continue or E(or anything else) to exit";
     cin>>choice2;
     if(choice2=='c'||choice=='C')
      {
	goto start ;
      }
      else
      exit_game();
    }

    else


    if(choice=='e'||choice=='E')        //lol there was no need for this, would exit anyway...
    exit_game();

    else
    {
    cout<<"\n"<<"Invalid choice , Exiting";
    getch();
    exit_game();
     }


}
Last edited on
Topic archived. No new replies allowed.