Results 1 to 2 of 2
  1. #1
    Dellzie's Avatar
    Join Date
    Jul 2016
    Gender
    male
    Posts
    14
    Reputation
    10
    Thanks
    2
    My Mood
    Yeehaw

    Little help for java game bug needed

    Hi guys,

    For context I have started learning java for school and we have our first assignment coming up and I can't seem to fix 4 bugs in the game. The code is for a piles game where basicly you pick a pile from an array and choose how many tokens from that pile you would like to remove and the player with the last token wins.

    Code:
    import java.util.Scanner;
    import java.util.Random;
    
    public class modingCode{
      private static Scanner imput = new Scanner (System.in);
      private static Random rand = new Random ();
      
      public static void main (String [] args){
        game();{
          private static void game();{
            String p1_name = name_check("Player 1 enter your name");
            String p2_name = name_check("Player 2 enter your name");
            int num_games = int_check("How many games would you like to play?");
            int [] score = new int [2];
            int [] piles = new int [5];
            int pile;
            boolean game_won;
            String turn = p1_name;
            int game_count = 0;
            while(game_count <num_games){
              game_count = game_count + 1;
              System.out.println("Game : " );
              for(int i = 0; i < 5; i++){
                piles [i] = rand.nextInt(5)+1;
              }
              while(game_won = true){
                System.out.println();
                System.out.println(turn + " its your turn ");
                for(int i = 0; i < 5; i++){
                  pile = i + 1;
                  System.out.println("Pile " + pile + " has " +
                                     piles [i] + " tokens");
                }
                int pile_to_take = int_check ("Enter the pile to take away from: ");
                int taken = int_check("Enter the number of tokens to take: ");'
                  piles [pile_to_take - 1] = piles [(pile_to_take - 1)] - taken;
                  
                  for(int i = 0; i < 5; i++){
                  piles[i] = rand.nextInt()+1;
                }
              }
            }
          }
          
          private static String name_check String prompt;{
            while(true){
              System.out.println(prompt);
              String text = input.nextLine();
              if(text.isEmpty){
                System.out.println("Please enter your name: ");
              }
              else{
                System.out.println("Hello " + test);
                return num;
              }
            }
          }
          private static int int_check String prompt;{
            while(true){
              System.out.println(prompt);
              try{
                int num = Integer.parseInt(input.nextLine);
                return num;
              }
              catch(NumberFormatException e ){
                System.out.println("Please enter a number: ");
              }
            }
          }
        }
      }
    }
    4 errors found:
    File: C:\Users\*****\Desktop\Programming\Java\Java Basics\Programming challeges\modingCode.java [line: 10]
    Error: Syntax error, insert "VariableDeclarators" to complete LocalVariableDeclaration
    File: C:\Users\*****\Desktop\Programming\Java\Java Basics\Programming challeges\modingCode.java [line: 10]
    Error: Syntax error, insert ";" to complete BlockStatements
    File: C:\Users\*****\Desktop\Programming\Java\Java Basics\Programming challeges\modingCode.java [line: 45]
    Error: Syntax error, insert ";" to complete LocalVariableDeclarationStatement
    File: C:\Users\*****\Desktop\Programming\Java\Java Basics\Programming challeges\modingCode.java [line: 58]
    Error: Syntax error, insert ";" to complete LocalVariableDeclarationStatement

    Any help on a fix would be great or a step in the right direction.

    Cheers, ya boi Dellzie.
    Last edited by Dellzie; 09-03-2016 at 09:57 PM. Reason: Fixed it finallllllllllyyyyyyyyyyyyy

  2. #2
    leonardosc's Avatar
    Join Date
    Dec 2015
    Gender
    male
    Posts
    2
    Reputation
    10
    Thanks
    0
    Your code is really ugly... There are a lot of sintaxe/logical errors.

    Do you know the basic of Java Programming Language ...?

    I've fixed only the sintaxe errors...

    Code:
    import java.util.Scanner;
    import java.util.Random;
    
    public class modingCode {
      private static Scanner input = new Scanner(System.in);
      private static Random rand = new Random();
    
      public static void main(String[] args) {
        game();
      }
    
      private static void game() {
        String p1_name = name_check("Player 1 enter your name");
        String p2_name = name_check("Player 2 enter your name");
        int num_games = int_check("How many games would you like to play?");
        int[] score = new int[2];
        int[] piles = new int[5];
        int pile;
        boolean game_won = false;
        String turn = p1_name;
        int game_count = 0;
        while (game_count < num_games) {
          game_count = game_count + 1;
          System.out.println("Game : ");
          for (int i = 0; i < 5; i++) {
            piles[i] = rand.nextInt(5) + 1;
          }
          while (!game_won) {
            System.out.println();
            System.out.println(turn + " its your turn ");
            for (int i = 0; i < 5; i++) {
              pile = i + 1;
              System.out.println("Pile " + pile + " has " +
                piles[i] + " tokens");
            }
            int pile_to_take = int_check("Enter the pile to take away from: ");
            int taken = int_check("Enter the number of tokens to take: ");
            piles[pile_to_take - 1] = piles[(pile_to_take - 1)] - taken;
    
            for (int i = 0; i < 5; i++) {
              piles[i] = rand.nextInt() + 1;
            }
          }
        }
      }
    
      private static String name_check(String prompt) {
        while (true) {
          System.out.println(prompt);
          String text = input.nextLine();
          if (text.isEmpty()) {
            System.out.println("Please enter your name: ");
          } else {
            System.out.println("Hello " + text);
            return text;
          }
        }
      }
    
      private static int int_check(String prompt) {
        while (true) {
          System.out.println(prompt);
          try {
            int num = Integer.parseInt(input.nextLine());
            return num;
          } catch (NumberFormatException e) {
            System.out.println("Please enter a number: ");
          }
        }
      }
    }

Similar Threads

  1. [Help Request] Need Help For Online game
    By joedev33 in forum Suggestions, Requests & General Help
    Replies: 1
    Last Post: 02-23-2015, 10:24 PM
  2. [Help Request] Need A little help in facebok gaming
    By muaaviya in forum Homework & Learning Section
    Replies: 1
    Last Post: 01-01-2015, 11:32 AM
  3. [Help Request] Looking for an "Introduction" and some help for a game similar to DN (I think)
    By LolwatDino in forum Dragon Nest Help
    Replies: 1
    Last Post: 04-05-2014, 09:44 PM
  4. little help for me please
    By naghal707 in forum C++/C Programming
    Replies: 18
    Last Post: 08-04-2010, 07:43 AM
  5. hi guys help for one game plz...
    By sn1p3ro12 in forum WarRock Discussions
    Replies: 13
    Last Post: 07-03-2010, 11:30 AM