Jump to content
  • Advertisement

Lucky Ace Card

Member
  • Content Count

    126
  • Joined

  • Last visited

Everything posted by Lucky Ace Card

  1. I didn't really find any good online material comparing C++ and C#, but I did manage to contact my friend's dad who has a good position at Microsoft. And he gave me some information on it. If anyone else wants to help a little and give their insight on the difference between C++ and C#, it's be appreciated. =)
  2. Is there any popular opinion on which language is stronger for game development? Or is that a very debateable issue?
  3. I didn't know C++ and C# were so different. Odd. I'll have to research more as to which I want to study right now. I'm pretty confident I could handle learning multiple languages, especially if they are relatively similar. I'll give it a shot. But yeah, knowing multiple languages really would help anyone become more marketable. I'll probably find some books on C++ or C#, whichever it is I'm gunna study now. Can anyone help me out on whether I should look at C++ or C#? I guess I'm not too sure of how C# is different.
  4. Lucky Ace Card

    How can I improve this java code?

    So I think I've written a decent check method and implemented it into the main method. I deleted all the useless methods like checkLeft and moveLeft, etc. import java.util.Scanner; public class Maze12 { public static final int RIGHT = 0; public static final int UP = 1; public static final int LEFT = 2; public static final int DOWN = 3; public static void main(String[] args) { Scanner scan = new Scanner(System.in); int currentRoom = 3; String choice = ""; int index1 = 110; System.out.println("This program is a test version of a maze."); System.out.println("==============================================================="); System.out.println("Welcome to the maze game. Type the direction you wish to travel or type 'map' to see the map."); System.out.println("Type 'quit' to quit."); System.out.println(); System.out.println("================================================================"); System.out.println("================================================================\n\n"); System.out.println(); while (choice.equalsIgnoreCase("quit") != true) //Until user types quit { choice = ""; int[] details = {}; String desc = getRoomDesc(currentRoom, index1); //Get room info. System.out.println(desc); System.out.print("\nEnter a choice: "); choice = scan.nextLine(); //Get user's choice while (choice.equalsIgnoreCase("")) { System.out.print("Enter a choice: "); choice = scan.nextLine(); //Continue prompt while invalid input } choice = choice.toLowerCase(); if (choice.equalsIgnoreCase("left")) //If left { details = move(LEFT, currentRoom, index1); //Move you left currentRoom = details[0]; //Creates new currentRoom value that user has moved to index1 = details[1]; //Creates a new place to draw 'You' } else if (choice.equalsIgnoreCase("right")) { details = move(RIGHT, currentRoom, index1); //Move you left currentRoom = details[0]; //Creates new currentRoom value that user has moved to index1 = details[1]; //Creates a new place to draw 'You' } else if (choice.equalsIgnoreCase("down")) { details = move(DOWN, currentRoom, index1); //Move you left currentRoom = details[0]; //Creates new currentRoom value that user has moved to index1 = details[1]; //Creates a new place to draw 'You' } else if (choice.equalsIgnoreCase("up")) { details = move(UP, currentRoom, index1); //Move you left currentRoom = details[0]; //Creates new currentRoom value that user has moved to index1 = details[1]; //Creates a new place to draw 'You' } else if (choice.equalsIgnoreCase("map")) viewMap(currentRoom, index1); //Prints map else if (choice.equalsIgnoreCase("quit") != true) System.out.println("Sorry, that's not a valid choice."); } } public static String getRoomDesc(int currentRoom, int index1) { viewMap(currentRoom, index1); String desc = "You are in room " + currentRoom + ".\nYou may move:\n"; if (check(RIGHT, currentRoom)) desc+="Right\n"; if (check(LEFT, currentRoom)) desc+="Left\n"; if (check(DOWN, currentRoom)) desc+="Down\n"; if (check(UP, currentRoom)) desc+="Up\n"; return desc; } public static void viewMap(int currentRoom, int index1) { String plain = "____________________________\n" + "| | | | |\n" + "| 0 | 1 | 2 | 3 |\n" + "| | | | |\n" + "|______|______|______|_____|\n" + "| |X X X |X X X |X X X|\n" + "| 4 |X 5 X |X 6 X |X 7 X|\n" + "| |X X X |X X X |X X X|\n" + "|______|______|______|_____|\n" + "| | | | |\n" + "| 8 | 9 | 10 | 11 |\n" + "| | | | |\n" + "|______|______|______|_____| "; char arrayMap[] = plain.toCharArray(); arrayMap[index1] = 'Y'; arrayMap[index1+1] = 'o'; arrayMap[index1+2] = 'u'; System.out.println(); System.out.println(arrayMap); } public static int[] move(int direction, int currentRoom, int index1) { boolean canMove; int currentRoomChange; int index1Change; final int[] currentRoomChanges = {1, -4, -1, 4}; final int[] index1Changes = {7, -116, -7, 116}; if (check(direction, currentRoom)) { currentRoom += currentRoomChanges[direction]; index1 += index1Changes[direction]; } else { System.out.println("You can not move that way. Try another direction."); } int list[] = {currentRoom, index1}; return list; } public static boolean check(int direction, int currentRoom) { //0=right //2=left //1=up //3=down boolean goodMove; boolean[] RIGHT = {true, true, true, false, false, false, false, false, true, true, true, false}; boolean[] LEFT = {false, true, true, true, false, false, false, false, false, true, true, true}; boolean[] UP = {false, false, false, false, true, false, false, false, true, false, false, false}; boolean[] DOWN = {true, false, false, false, true, false, false, false, false, false, false, false}; switch (direction) { case 0: goodMove = RIGHT[currentRoom]; break; case 1: goodMove = UP[currentRoom]; break; case 2: goodMove = LEFT[currentRoom]; break; case 3: goodMove = DOWN[currentRoom]; break; default: goodMove = false; break; } return goodMove; } } Any more suggestions? Because this topic has taught me a lot about writing clean code. The main method looks a little clunky, don't ya think..?
  5. Lucky Ace Card

    How can I improve this java code?

    Zahlman, are you like.... a Computer Science professor or something? You're amazing. And what you did actually makes perfect sense to me now that you've explained it. As soon as I finish all this work for other classes, I'm gunna give the check() method a shot. Thanks a lot for the help! I'll check back here a little later with how it's coming along.
  6. Lucky Ace Card

    How can I improve this java code?

    Alright, here's a newer version of what I have now. I mainly changed the way the word "you" is drawn, as I made it dynamic. import java.util.Scanner; public class Maze8 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int currentRoom = 3; String choice = ""; int index1 = 110; System.out.println("This program is a test version of a maze."); System.out.println("==============================================================="); System.out.println("Welcome to the maze game. Type the direction you wish to travel or type 'map' to see the map."); System.out.println("Type 'quit' to quit."); System.out.println(); System.out.println("================================================================"); System.out.println("================================================================\n\n"); System.out.println(); while (choice.equalsIgnoreCase("quit") != true) //Until user types quit { choice = ""; int[] details = {}; String desc = getRoomDesc(currentRoom, index1); //Get room info. System.out.println(desc); System.out.print("\nEnter a choice: "); choice = scan.nextLine(); //Get user's choice while (choice.equalsIgnoreCase("")) { System.out.print("Enter a choice: "); choice = scan.nextLine(); //Continue prompt while invalid input } choice = choice.toLowerCase(); if (choice.equalsIgnoreCase("left")) //If left { details = moveLeft(currentRoom, index1); //Move you left currentRoom = details[0]; //Creates new currentRoom value that user has moved to index1 = details[1]; //Creates a new place to draw 'You' } else if (choice.equalsIgnoreCase("right")) { details = moveRight(currentRoom, index1); currentRoom = details[0]; index1 = details[1]; } else if (choice.equalsIgnoreCase("down")) { details = moveDown(currentRoom, index1); currentRoom = details[0]; index1 = details[1]; } else if (choice.equalsIgnoreCase("up")) { details = moveUp(currentRoom, index1); currentRoom = details[0]; index1 = details[1]; } else if (choice.equalsIgnoreCase("map")) viewMap(currentRoom, index1); //Prints map else if (choice.equalsIgnoreCase("quit") != true) System.out.println("Sorry, that's not a valid choice."); } } public static boolean checkUp(int currentRoom) { boolean check; if (currentRoom == 0 || currentRoom == 1 || currentRoom == 2 || currentRoom == 3) check = false; else if (currentRoom == 9 || currentRoom == 10 || currentRoom == 11) check = false; else check = true; return check; } public static boolean checkLeft(int currentRoom) { boolean check; if (currentRoom == 0 || currentRoom == 4 || currentRoom == 8) check = false; else check = true; return check; } public static boolean checkDown(int currentRoom) { boolean check; if (currentRoom == 1 || currentRoom == 2 || currentRoom == 3) check = false; else if (currentRoom == 8 || currentRoom == 9 || currentRoom == 10 || currentRoom == 11) check = false; else check = true; return check; } public static boolean checkRight(int currentRoom) { boolean check; if (currentRoom == 3 || currentRoom == 4 || currentRoom == 11) check = false; else check = true; return check; } public static String getRoomDesc(int currentRoom, int index1) { viewMap(currentRoom, index1); String desc = "You are in room " + currentRoom + ".\nYou may move:\n"; if (checkRight(currentRoom)) desc+="Right\n"; if (checkLeft(currentRoom)) desc+="Left\n"; if (checkDown(currentRoom)) desc+="Down\n"; if (checkUp(currentRoom)) desc+="Up\n"; return desc; } public static int[] moveLeft(int currentRoom, int index1) { if (checkLeft(currentRoom) == true) { currentRoom -= 1; index1 -= 7; } else System.out.println("You can not move that way. Try another direction."); int[] list = {currentRoom, index1}; return list; } public static int[] moveRight(int currentRoom, int index1) { if (checkRight(currentRoom) == true) { currentRoom += 1; index1 += 7; } else System.out.println("You can not move that way. Try another direction."); int[] list = {currentRoom, index1}; return list; } public static int[] moveDown(int currentRoom, int index1) { if (checkDown(currentRoom) == true) { currentRoom += 4; index1 += 116; } else System.out.println("You can not move that way. Try another direction."); int[] list = {currentRoom, index1}; return list; } public static int[] moveUp(int currentRoom, int index1) { if (checkUp(currentRoom) == true) { currentRoom -= 4; index1 -= 116; } else System.out.println("You can not move that way. Try another direction."); int[] list = {currentRoom, index1}; return list; } public static void viewMap(int currentRoom, int index1) { String plain = "____________________________\n" + "| | | | |\n" + "| 0 | 1 | 2 | 3 |\n" + "| | | | |\n" + "|______|______|______|_____|\n" + "| |X X X |X X X |X X X|\n" + "| 4 |X 5 X |X 6 X |X 7 X|\n" + "| |X X X |X X X |X X X|\n" + "|______|______|______|_____|\n" + "| | | | |\n" + "| 8 | 9 | 10 | 11 |\n" + "| | | | |\n" + "|______|______|______|_____| "; char arrayMap[] = plain.toCharArray(); arrayMap[index1] = 'Y'; arrayMap[index1+1] = 'o'; arrayMap[index1+2] = 'u'; System.out.println(); System.out.println(arrayMap); } } Zahlman, I just read your code, and it's a bit too advanced for me. =P Mine's ugly, and I have trouble understanding some of your concepts. I understand what you do as I read it (for the most part), but I have some work to do before I can fully understand how to make it work like that without simply copying it and pasting it. My AP Computer Science teacher (who's forte isn't really java...) says the next step I should take is to make the walking character into a class so he can be a separate object. I guess that'd be a good idea. He could hold his own attributes like what room he is in, what room he was previously in, and it could even lead to having multiple characters in the same maze. I'm not exactly sure how to go about implementing an object from another class I write (I know the syntax and all that, just never actually used this concept yet). I suppose I'll go try it out.
  7. Lucky Ace Card

    How can I improve this java code?

    Thanks guys. Those are good suggestions. I think I'll try some of them out! =) About classes, I really don't know much of how I would be able to use them in this program efficiently. I've never really done it before.
  8. Lucky Ace Card

    [java] Help: Guess my Number GUI

    Yes, I'm running exactly that version. Perhaps I'll try another environment. I've tried compiling in both JCreator and command prompt's javac, and running them in each. Same effect. I'll try it on the school computers tomorrow I suppose.
  9. Lucky Ace Card

    Ahhhh keyboard failure. Help?

    Okay, thanks for your help Sneftel. I've had this problem for a long time and nobody has known how to fix it. So you're a genius.
  10. Lucky Ace Card

    [java] Help: Guess my Number GUI

    I've tried to run the debugger in Jcreator many times, and I've still never gotten it.
  11. Lucky Ace Card

    Ahhhh keyboard failure. Help?

    I can probably just do this each time the problem arises, right?
  12. Lucky Ace Card

    Ahhhh keyboard failure. Help?

    I'm not able to delete anything in that registry folder. Even the Registry Help File says I can't delete those. Any suggestions? *EDIT* I clicked the Edit button, but it added on a whole new post. Lame. Sorry about that. Anyway, deleting those sub folders fixed the problem! Thanks a lot for the help!
  13. Lucky Ace Card

    Ahhhh keyboard failure. Help?

    I'm not able to delete anything in that registry folder. Even the Registry Help File says I can't delete those. Any suggestions?
  14. Lucky Ace Card

    Another Digipen topic...

    Thanks for the help. Can anyone else give me some more insight, perhaps?
  15. Lucky Ace Card

    [java] Adding a char to a String?

    Aha, thanks a bunch. I successfully got it working. Here's how it goes now: import java.util.Scanner; public class Palindrome { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.print("Enter a potential palindrome: "); String palin = scan.nextLine(); String result = ""; for (int count = palin.length()-1; count >= 0; count--) { char current[] = {palin.charAt(count)}; String toConcat = new String(current); result = result.concat(toConcat); } palin = palin.toLowerCase(); result = result.toLowerCase(); System.out.println("\nYour word is: " + palin); System.out.println("Backwards, this is: " + result); if (palin.equals(result)) { System.out.println(); System.out.println("That word is a palindrome!"); } else { System.out.println(); System.out.println("That word is not a palindrome."); } } } Thanks for the help!
  16. Lucky Ace Card

    [java] cs1.Keyboard?

    Alright, thanks for the help. I'll just tell my teacher I'm more comfortable using Scanner, and it seems like a better method.
  17. Lucky Ace Card

    Can someone help me? AP Computer Science question

    You've got a weird name. </kidding, I envy it>
  18. Lucky Ace Card

    Can someone help me? AP Computer Science question

    It's just like... the very first chapter. For some reason it introduces hardware/software, but briefly. My teacher decided to be lame and make it a bigger deal.
  19. Lucky Ace Card

    Python vs. C++

    When I transferred from Python to Java, Python actually felt much easier not only because the lack of { and }, but mainly because not everything had to be in a class and there was no public static void things to deal with. Also, JDK was oddly hard for me to get installed properly the first time...
  20. Lucky Ace Card

    Java question - Outdated book?

    Do you think there are enough of these differences between versions that it would make learning from the older book bad? Like, if I learned from the older book, do you think I'd be using too many old things?
  21. Lucky Ace Card

    About encapsulation

    I believe it's safer to use the public getHealth() method and protected setHealth() method.
  22. Lucky Ace Card

    Java - While Loop not working

    Ah, so that's how. Thanks for the help.
  23. Lucky Ace Card

    Java - While Loop not working

    Can anyone explain to me how I could scan for input into a char variable?
  24. Lucky Ace Card

    Java - While Loop not working

    Quote:Original post by Shiny I know you've solved the problem to your satisfaction, but I just wondered: why read a single character into a string when you could use a char? i.e. String again = "y"; // storing a teeny-tiny character in a big ole string object. char again = 'y'; // storing the same in a tiny memory spot :) Yes, I am aware that java.util.Scanner doesn't have a nextChar() member function (for a good reason, you can use a Reader instead if you want character by character...) but it does seem a bit wasteful to store a single char in a string :) ~Shiny I tried using a char variable originally, but I didn't know how to scan for input for a char.
  25. Lucky Ace Card

    Which programs should I make with python

    Quote:Original post by Sria I like The Python Programming for the absolute begginer. It teaches how to make games and is very noob friendly and easy to understand and read. I think that was the one by Michael Dawson? If so, I also suggest that book. It was very well written and very helpful.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!