-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArcadeGame.java
More file actions
160 lines (151 loc) · 4.58 KB
/
Copy pathArcadeGame.java
File metadata and controls
160 lines (151 loc) · 4.58 KB
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
/****
* Project: Unit 4 Assignment
* Programmer: Daniyal Naqvi
* Date: Oct 14, 2021
* Program Name: Unit 2 - JavaAssignment.java
* Desc: Unit 4 - Arcade, Assignment
****/
package javaarcade;
import java.util.Scanner;
public class JavaArcade
{
public static void main(String[] args)
{
//import scanner
Scanner scanN = new Scanner(System.in);
//declare the variables
int cpuNum = (int)(1 + Math.random()*(50));
int choiceinput;
int guess = 0;
int numofguess = 0;
int rock = 1;
int paper = 2;
int scissors = 3;
int player = 0;
int cpu = 0;
int games = 0;
int choice;
int game = 0;
int answer;
int count = 0;
do
{
System.out.println("\n*****************************************"
+ "\n*\t\t\t\t\t*"
+ "\n*\t \t\t\t\t*"
+ "\n*\tWELCOME TO DANIYALS ARCADE\t*"
+ "\n*\t\t\t \t\t*"
+ "\n*\t\t\t\t\t*"
+ "\n*****************************************"
+ "\nWhat game would you like to play"
+ "\n1. Number Game"
+ "\n2. Rock, Paper, Scissors, Game!"
+ "\n3. Exit");
choice = scanN.nextInt();
switch (choice)
{
case 1:
do
{
System.out.println("Welcome to Guess The Number - Press 1 to Start");
answer = scanN.nextInt();
count++;
}
while ((answer != cpuNum)&&(count<1));
//start of the for loop
for(numofguess=0; numofguess<=4; numofguess++)
{
System.out.println("Type in a guess for the number:");
guess = scanN.nextInt();
if(cpuNum > guess)
{
System.out.println("Guess again, but higher!");
}
else if (cpuNum < guess)
{
System.out.println("Guess again, but lower!");
}
else if (cpuNum == guess)
{
System.out.println("Congratulations! You guessed it in: ");
}
}//end of for loop
//if statement for running out of number guesses
if (numofguess>4)
{
System.out.println("You ran out of guesses");
}
break;
/*************************************************
* Second Game, Rock Paper Scissors. *
* Loops used: "While" *
* Desc: Used because im running multiple times *
*************************************************/
case 2:
while (games < 3) //start of while loop
{
System.out.println("\nRock = 1\nPaper = 2\nScissors = 3");
//declaring game variables
choiceinput = scanN.nextInt();
int cpuinput = (int)(Math.random()*3);
//start if statements
//If cpu does paper and player does rock
if (cpuinput == 2 && choiceinput == 1)
{
System.out.println("Paper wins!\n CPU won!");
games++;
cpu++;
}
//If player does paper and cpu does rock
else if (choiceinput == 2 && cpuinput == 1)
{
System.out.println("Paper wins!\n Player won!");
games++;
player++;
}
//If player does rock and cpu does scissors
else if (cpuinput == 1 && choiceinput == 3)
{
System.out.println("Rock wins!" +
"\nPlayer won!");
games++;
player++;
}
//If cpu does rock and player does scissors
else if (choiceinput == 1 && cpuinput == 3)
{
System.out.println("Rock wins!" +
"\nCPU won!");
games++;
cpu++;
}
//If cpu does scissors and player does paper
else if (cpuinput == 3 && choiceinput == 2 )
{
System.out.println("Scissors wins!\nCPU won!");
games++;
cpu++;
}
//If player does scissors and player does paper
else if (choiceinput == 3 && cpuinput == 2 )
{
System.out.println("Scissors wins!\nPlayer won");
games++;
player++;
}
//IF Ties
//If both do rock
else
System.out.println("\n*****************************************"
+ "\n*\t\t\t\t\t*"
+ "\n*\t \t\t\t\t*"
+ "\n*\t\tITS A TIE\t\t*"
+ "\n*\t\t\t \t\t*"
+ "\n*\t\t\t\t\t*"
+ "\n*****************************************");
}
break;
}
} while (choice >= 3);
}
}