Hi, I'm new to java and I just started getting into what I feel is more complicated stuff and I spent all morning making a cheesy fighting game involving people I know (so don't mind the cheese), but when I try to compile I get 100 errors, hopefully due to a few small mistakes shifting the entire code. I'm sorry for the length and amount of probably unnecessary code, but I'm new.
Also, Don't mind anything involving the class GameHelper or .getUserInput, these are in a separate class file that I got from my book's website to enable user input.
Thanks for your help
What I try to do in this code:
- Have each person choose which character by inputting a number from 0 to 3, and assign a name and an array of attack styles
- Have each player choose a type of attack (0=weak, 1=strong, 2=guard, 3=heal) and have damage done scaled to that
- Tell the players what attack was used and for how much damage/heal for how much
- When a character is at 0 or lower health, end the game and say the winner
If you do take the time to help, thank you, and please try to explain in a way that a newbie can understand.
class Character { String[] AttackStyle; int Health=100; String name; public void getAttackStyle(String charNum) { int Selection=Integer.parseInt(charNum); if (Selection==0) { name="Garrett"; AttackStyle={"throws a game disc at", "punches", "kicks", "throws a grand piano at", "smashes a coke bottle over the head of", "bores to death", "guards against", "sleeps and doesn't fight"}; } else if (Selection==1) { name="Kathy"; AttackStyle={"throws an apple at", "punches", "knees", "takes a paint brush and stabs", "takes a ball of ribbon and strangles", "radiates cuteness, setting on fire", "guards against", "naps and doesn't fight"}; } else if (Selection==2) { name="Kevin"; AttackStyle={"throws a chess piece at", "closes a chess tutorial book on", "swings homework at", "throws a grand piano at", "lights college apps on fire, setting fire to", "unleashes k-pop star powers on", "guards against", "naps and doesn't fight"}; } else { name="Cheyenne"; AttackStyle={"licks, transferring tapeworm to", "stratches", "whimpers loudly at", "slams her massive body into", "snarls and bites", "falls down the stairs onto", "guards against", "sleeps and doesn't fight"}; } } public int loseHealth(int att) { Health=Health-att; return Health; } public int gainHealth(int heal) { Health=Health+heal; return Health; } } public class Fighting { public static void main(String[] args) { Character[] ch=new Character[2]; ch[0]=new Character(); ch[1]=new Character(); GameHelper g1=new GameHelper(); GameHelper g2=new GameHelper(); GameHelper g3=new GameHelper(); GameHelper g4=new GameHelper(); System.out.println(); System.out.println("0=Garrett"); System.out.println("1=Kathy"); System.out.println("2=Kevin"); System.out.println("3=Cheyenne"); String a=g1.getUserInput("Player 1, Choose your Character!"); ch[0].getAttackStyle(a); System.out.println("Player 1 chooses "+ch[0].name+"."); String b=g2.getUserInput("Player 2, choose your Character!"); ch[1].getAttackStyle(b); System.out.println("Player 2 chooses "+ch[1].name+"."); String n1=ch[0].name; String n2=ch[1].name; System.out.println(); int attackStrength1=0; int attackStrength2=0; int h1=100; int h2=100; int d1=0; int d2=0; int a1=0; int a2=0; int heal1=0; int heal2=0; String v1s=n1+" is charging a strong attack! They are vulnerable!"); String v1h=n1+" is healing! They are vulnerable!"); String v2s=n2+" is charging a strong attack! They are vulnerable!"); String v2h=n2+" is healing! They are vulnerable!"); boolean GameGoing=true; System.out.println("0=weak attack (weak but no vulnerability)"); System.out.println("1=Strong attack (Strong but more vulnerable)"); System.out.println("2=guard (Lessens opponent's damage)"); System.out.println("3=sleep (regains health but leaves vulnerable)"); System.out.println(); System.out.println("Both players have 100 Health"); try { Thread.sleep(500); } catch (InterruptedException) { } System.out.print("."); try { Thread.sleep(500); } catch (InterruptedException) { } System.out.print("."); try { Thread.sleep(500); } catch (InterruptedException) { } System.out.print("."); try { Thread.sleep(500); } catch (InterruptedException) { } System.out.print("Fight!"); String c=" "; String d=" "; String p1=n1+" "+ch[0].AttackStyle[a1]+" "+n2+" who now has "+h2+" health left!"; String p2=n2+" "+ch[1].AttackStyle[a2]+" "+n1+" who now has "+h1+" health left!"; String bw="But wait!"; while (GameGoing==true) { c=g3.getUserInput(n1+", attack style?"); d=g4.getUserInput(n2+", attack style?"); attackStrength1=Integer.parseInt(c); attackStrength2=Integer.parseInt(d); if (attackStrength1==0) { a1=(int)(Math.random()*3); if (attackStrength2==0) { a2=(int)(Math.random()*3); d1=(int)(Math.random()*10); d2=(int)(Math.random()*10); h1=ch[0].loseHealth(d2); h2=ch[1].loseHealth(d1); System.out.println(p1); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } System.out.println("bw"); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } System.out.println(p2); } if (attackStrength2==1) { System.out.println(v2s); try { Thread.sleep(1000); } catch (InterruptedException) { } a2=(int)((Math.random()*3)+3); d1=(int)(Math.random()*18); d2=(int)(Math.random()*28); h1=ch[0].loseHealth(d2); h2=ch[1].loseHealth(d1); System.out.println(p1); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } System.out.println(bw); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } System.out.println(p2); } if (attackStrength2==2) { a2=7; d1=(int)(Math.random()*5); d2=0 h1=ch[0].loseHealth(d2); h2=ch[1].loseHealth(d1); System.out.println(p1); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } System.out.println("bw"); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } System.out.println(p2); } if (attackStrength2==3) { System.out.println(v2h); try { Thread.sleep(1000); } catch (InterruptedException ie) { } a2=8; d1=(int)(Math.random()*20); d2=0; heal2=(int)(Math.random()*14); h2=ch[1].loseHealth(d1); System.out.println(p1); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } System.out.println("bw"); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } h2=ch[1].gainHealth(heal2); System.out.println(n2+" "+ch[1].AttackStyle[a2]+"to heal and now has "+h2+" health!"); } } else if (attackStrength1==1) { a1=(int)((Math.random()*3)+3); System.out.println(v1s); try { Thread.sleep(1000); } catch (InterruptedException ie) { } if (attackStrength2==0) { a2=(int)(Math.random()*3); d1=(int)(Math.random()*28); d2=(int)(Math.random()*18); h1=ch[0].loseHealth(d2); h2=ch[1].loseHealth(d1); System.out.println(p1); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } System.out.println("bw"); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } System.out.println(p2); } if (attackStrength2==1) { System.out.println(v2s); try { Thread.sleep(1000); } catch (InterruptedException) { } a2=(int)((Math.random()*3)+3); d1=(int)(Math.random()*38); d2=(int)(Math.random()*38); h1=ch[0].loseHealth(d2); h2=ch[1].loseHealth(d1); System.out.println(p1); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } System.out.println(bw); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } System.out.println(p2); } if (attackStrength2==2) { a2=7; d1=(int)(Math.random()*10); d2=0 h1=ch[0].loseHealth(d2); h2=ch[1].loseHealth(d1); System.out.println(p1); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } System.out.println("bw"); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } System.out.println(p2); } if (attackStrength2==3) { System.out.println(v2h); try { Thread.sleep(1000); } catch (InterruptedException ie) { } a2=8; d1=(int)(Math.random()*30); d2=0; heal2=(int)(Math.random()*20); h2=ch[1].loseHealth(d1); System.out.println(p1); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } System.out.println("bw"); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } h2=ch[1].gainHealth(heal2); System.out.println(n2+" "+ch[1].AttackStyle[a2]+" to heal and now has "+h2+" health!"); } } else if (attackStrength1==2) { a1=7; if (attackStrength2==0) { a2=(int)(Math.random()*3); d1=0; d2=(int)(Math.random()*5); h1=ch[0].loseHealth(d2); h2=ch[1].loseHealth(d1); System.out.println(p1); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } System.out.println("bw"); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } System.out.println(p2); } if (attackStrength2==1) { System.out.println(v2s); try { Thread.sleep(1000); } catch (InterruptedException) { } a2=(int)((Math.random()*3)+3); d1=0; d2=(int)(Math.random()*10); h1=ch[0].loseHealth(d2); h2=ch[1].loseHealth(d1); System.out.println(p1); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } System.out.println(bw); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } System.out.println(p2); } if (attackStrength2==2) { a2=7; d1=0; d2=0; h1=ch[0].loseHealth(d2); h2=ch[1].loseHealth(d1); System.out.println(p1); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } System.out.println("bw"); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } System.out.println(p2); } if (attackStrength2==3) { System.out.println(v2h); try { Thread.sleep(1000); } catch (InterruptedException ie) { } a2=8; d1=0; d2=0; heal2=(int)(Math.random()*20); h2=ch[1].loseHealth(d1); System.out.println(p1); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } System.out.println("bw"); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } h2=ch[1].gainHealth(heal2); System.out.println(n2+" "+ch[1].AttackStyle[a2]+" to heal and now has "+h2+" health!"); } } else { System.out.println(v1h); try { Thread.sleep(1000); } catch (InterruptedException ie) { } a1=8; if (attackStrength2==0) { a2=(int)(Math.random()*3); d1=0; d2=(int)(Math.random()*20); h2=ch[1].loseHealth(d1); System.out.println(p2); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } System.out.println("bw"); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } heal1=(int)(Math.random()*20); h1=ch[0].gainHealth(heal1); System.out.println(n1+" "+ch[0].AttackStyle[a1]+"to heal and how has "+h1+" health!"); } if (attackStrength2==1) { System.out.println(v2s); try { Thread.sleep(1000); } catch (InterruptedException ie) { } a2=(int)((Math.random()*3)+3); d1=0; d2=(int)(Math.random()*30); h2=ch[1].loseHealth(d1); System.out.println(p2); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } System.out.println("bw"); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } heal1=(int)(Math.random()*20); h1=ch[0].gainHealth(heal1); System.out.println(n1+" "+ch[0].AttackStyle[a1]+" to heal and how has "+h1+" health!"); } if (attackStrength2==2) { a2=7; d1=0; d2=0; h2=ch[1].loseHealth(d1); System.out.println(p2); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } System.out.println("bw"); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } heal1=(int)(Math.random()*20); h1=ch[0].gainHealth(heal1); System.out.println(n1+" "+ch[0].AttackStyle[a1]+"to heal and how has "+h1+" health!"); } if (attackStrength2==3) { a2=8; d1=0; d2=0; heal1=(int)(Math.random()*20); h1=ch[0].gainHealth(heal1); System.out.println(n1+" "+ch[0].AttackStyle[a1]+"to heal and how has "+h1+" health!"); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } System.out.println("bw"); try { Thread.sleep(1000); } catch (Interrupted Exception ie) { } heal2=(int)(Math.random()*20); h2=ch[0].gainHealth(heal2); System.out.println(n2+" "+ch[1].AttackStyle[a2]+"to heal and how has "+h2+" health!"); } } if (h1<1) { GameGoing=false; try { Thread.sleep.(1500); } catch (InterruptedException ie) { } System.out.println(n2+" wins with "+h2+" health left!!"); } else if (h2<1) { GameGoing=false; try { Thread.sleep.(1500); } catch (InterruptedException ie) { } System.out.println(n1+" wins with "+h1+" health left!!"); } } } }