6 Replies - 361 Views - Last Post: 10 September 2012 - 05:11 AM Rate Topic: -----

#1 Tech2012  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 05-July 12

Help with some code for my basic game

Posted 29 August 2012 - 07:56 PM

Hello everyone!
I am quite the newbie at Java programming so please forgive my poorly written code. I wanted to create a very basic, and I mean, very basic game. I have developed some code so far and I needed some help with what I'm doing wrong and what I should be doing.

package p1;
import java.util.Scanner;
import java.util.Random;
public class c1 {
public static void characteristicsPlayer(int attackpower, int defensepower){
int avg=attackpower+defensepower/2;	
}
public static void characteristicsCPU(int attackpower, int defensepower){
int avg=attackpower+defensepower/2;
}
public static void main(String[] args){
Random generation=new Random();
Random generation2=new Random();
Random cpuSkillsEngine=new Random();
int cpuSkills=cpuSkillsEngine.nextInt(2)+1;
int cpushipcountatstartoff=generation2.nextInt(4)+1;
int usersshipcountatstartoff=generation.nextInt(4)+1;
System.out.println("Welcome to the game!\n You will start off with "+usersshipcountatstartoff+" ships.\n");
System.out.println("Please choose your strength. 1 for attack or 2 for defense");
Scanner input=new Scanner(System.in);
int strength=input.nextInt();
// 
if(strength==1){
characteristicsPlayer(9,3);
}else if(strength==2){
characteristicsPlayer(3,9);	
}else{
System.out.println("ERROR. Please start the game over.");	
}
//
Random a=new Random();
Random b=new Random();
if(cpuSkills==1){
int attack=a.nextInt(10)+6;
int defense=b.nextInt(3)+1;
}else{
int attack=a.nextInt(3)+1;
int defense=b.nextInt(10)+6;
}
}
{
if(characteristicsPlayer.avg>characteristicsCPU.avg){
System.out.println("Congratulations, you win!");	

}else if(characteristicsPlayer.avg<characteristicsCPU.avg){
System.out.println("I'm sorry, you lost.");	
}else{
System.out.println("Weird, there was no winner in this battle.");	
}
}
}



Thanks again!
Tech2012

Is This A Good Question/Topic? 0
  • +

Replies To: Help with some code for my basic game

#2 ILoveJava  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 389
  • Joined: 12-March 12

Re: Help with some code for my basic game

Posted 29 August 2012 - 08:05 PM

Well, what is the point of this game? What are you meant to do? What is meant to happen? What is actually happening?
Without any information we can't be of much help. You should also look up Java coding conventions to get some tips on your programming style.
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Help with some code for my basic game

Posted 29 August 2012 - 08:08 PM

and a single Random object for a whole application should be sufficient
Why would you need more than one ?
Was This Post Helpful? 0
  • +
  • -

#4 ILoveJava  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 389
  • Joined: 12-March 12

Re: Help with some code for my basic game

Posted 29 August 2012 - 08:15 PM

You should also consider renaming your methods/variables to something a little.. shorter. Easier to remember, and something that conforms to convention. So instead of using "characteristicsPlayer", you could use "playerKarma". Also instead of using "cpushipcountatstartoff", you could use "cpuShipCount"
Was This Post Helpful? 0
  • +
  • -

#5 Tech2012  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 05-July 12

Re: Help with some code for my basic game

Posted 30 August 2012 - 08:49 AM

View PostILoveJava, on 29 August 2012 - 08:15 PM, said:

You should also consider renaming your methods/variables to something a little.. shorter. Easier to remember, and something that conforms to convention. So instead of using "characteristicsPlayer", you could use "playerKarma". Also instead of using "cpushipcountatstartoff", you could use "cpuShipCount"

Never mind. I'll go try another forum where people are respectful.
Was This Post Helpful? 0
  • +
  • -

#6 ILoveJava  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 389
  • Joined: 12-March 12

Re: Help with some code for my basic game

Posted 10 September 2012 - 04:39 AM

Sorry, I just saw this. How are people on this forum not respectful?

We are here to help you, some more than others. What myself and Pbl have both mentioned are just ways to try and help you improve your code, and your way of programming.

I guess some people just don't want to learn.
Was This Post Helpful? 0
  • +
  • -

#7 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,468
  • Joined: 27-December 08

Re: Help with some code for my basic game

Posted 10 September 2012 - 05:11 AM

A few things:
  • First, what specific problems or errors are you encountering? We can't help you if we don't know what is wrong.
  • Second, please make sure to properly indent and format your code. It will make it easier for everyone, including yourself, to read and maintain.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1