• What Do You Need Help With? V6
    7,544 replies, posted
Hey there, trying to write a Command Prompt style shell in Java. Here's my code: [code]import java.io.*; import java.util.*; public class shell { public static void main(String[] args) throws java.io.IOException { String command; BufferedReader console = new BufferedReader (new InputStreamReader(System.in)); while (true) { // read what the user entered System.out.print("My shell>"); command = console.readLine(); { // if the user entered a return, just loop again if (command.equals("")) { continue; } else if (command.equalsIgnoreCase("exit")) { System.out.println("Goodbye"); System.exit(0); } try { Runtime rt = Runtime.getRuntime(); Process pr = rt.exec("cmd /k " + command); BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream())); String line=null; while((line=input.readLine()) != null) { System.out.println(line); } int exitVal = pr.waitFor(); System.out.println("Exited with error code " + exitVal); } catch(Exception e) { System.out.println(e.toString()); e.printStackTrace(); } } } } }[/code] It's just that I am unable to get back to the prompt after writing a command or, in fact, print an error when the command is executed.
[code]player.x -1 sprites.tileWidth() 16 m_camera.left -416.000000 float(-1 * 16) - -416.000000 400.00000000000000 float(player.x * sprites.tileWidth()) - m_camera.left 4.29496781e+009[/code] I... just... what?
[QUOTE=blacksam;43478939][CODE] public static void main(String[] args) { String word = getPlayerOnesWord(); int wordLength = word.length(); boolean gameFinished = false; int incorrectGuesses = 0; String matchWord = null; boolean[] hiddenWord = new boolean[wordLength]; String[] correctGuesses = new String[wordLength]; for (int k = 0; k < correctGuesses.length; k++) { correctGuesses[k] = "-"; }[/CODE] [CODE]int pos = word.indexOf(matchWord); if (word.contains(matchWord)) { hiddenWord[pos] = true; } for (int j = pos; j < correctGuesses.length; j++) { for (int i = pos; i < hiddenWord.length; i++) { if (hiddenWord[i] == true) { correctGuesses[j] = matchWord; } else { } } break;[/CODE] The full code: [url]http://pastebin.com/Zmk0HMhF[/url] So I came back to finish my hangman program finally after the busy holiday. My issue right now is filling the array with the same letter twice. I can get a full word! As long as the word doesn't have any repeating letters... How do I have it fill the array twice with two of the same letters in different positions? For example - the word is beer What is expected if I type in 'e': -ee- What my program does when I type in e: -e--[/QUOTE] So I did as Dienes said and tried to change it into one for loop that iterates over the length of the word. However, I still don't know how to account for duplicate letters. [CODE] int pos = word.indexOf(matchWord); for (int i = 0; i < word.length(); i++) { if (i == pos) { hiddenWord[i] = true; if (hiddenWord[i] == true){ correctGuesses[i] = matchWord;} } }[/CODE]
[QUOTE=Chris220;43511655][code]player.x -1 sprites.tileWidth() 16 m_camera.left -416.000000 float(-1 * 16) - -416.000000 400.00000000000000 float(player.x * sprites.tileWidth()) - m_camera.left 4.29496781e+009[/code] I... just... what?[/QUOTE] The third calculation is of type double (as evident by the longer output). I think the literals with decimal point default to that in whatever language you're using as is common. The fourth one apparently runs with floats, but that still doesn't explain why it seems to be off by a few orders of magnitude...
Argh, I'm an idiot. My [B]sprites.tileWidth()[/B] value was a uint, and I didn't realise that uint * int = uint.
[QUOTE=blacksam;43511699]So I did as Dienes said and tried to change it into one for loop that iterates over the length of the word. However, I still don't know how to account for duplicate letters. [CODE] int pos = word.indexOf(matchWord); for (int i = 0; i < word.length(); i++) { if (i == pos) { hiddenWord[i] = true; if (hiddenWord[i] == true){ correctGuesses[i] = matchWord;} } }[/CODE][/QUOTE] Another part of my advice was to get rid of indexOf(), because it will only return the first occurance of the character. Instead, check if word[i] is the character you are looking for.
How do you change working directory in Windows using Java?
Not possible([URL="http://stackoverflow.com/questions/840190/changing-the-current-working-directory-in-java"]http://stackoverflow.com/questions/840190/changing-the-current-working-directory-in-java[/URL])
Well, it can't be done in a general way, but certainly there is some way to do so in a platform-specific way, no? Like calling SetCurrentDirectory via a JNI wrapper or [url=https://github.com/twall/jna]JNA[/url].
So I've got a confusing question to ask.. If any of you have seen "Indie Game: The Movie", there is a scene with Phil Fish (God bless my soul and forgive me) where he's designing levels for Fez, but he's simply just dropping blocks in and adding/removing stuff to create the levels, obviously all of the code for each asset is in there along with the art, but does anyone know how to do it? Simply just add the art asset into something to design levels but with all of the code for each art attached? I've tried to look for a video but I can't find anything which shows it which isn't in the full documentary, any help is appreciated!
Ruby teacher gave us an assignment to complete this code golf [url]http://codegolf.com/99-bottles-of-beer[/url] with 210 characters. I've done my best so far, I don't know how to make it any shorter. Any ideas? [ruby]def f(i,j=1)a="#{i} bottle#{i>1?'s':''} of beer";a+=j>0?' on the wall':''end 99.downto(2){|i|puts f(i)+", #{f(i,0)}." puts"take one down, pass it around, #{f(i-1)}. "} puts"Go to the store to buy some more. #{f(99)}."[/ruby] I'm at 218 characters right now, I am thinking that I could make the function to write "bottle(s) of beer on the wall" shorter by not assigning it to a variable twice but I can't find how to do that.
[QUOTE=Erasus;43516428]So I've got a confusing question to ask.. If any of you have seen "Indie Game: The Movie", there is a scene with Phil Fish (God bless my soul and forgive me) where he's designing levels for Fez, but he's simply just dropping blocks in and adding/removing stuff to create the levels, obviously all of the code for each asset is in there along with the art, but does anyone know how to do it? Simply just add the art asset into something to design levels but with all of the code for each art attached? I've tried to look for a video but I can't find anything which shows it which isn't in the full documentary, any help is appreciated![/QUOTE] I'm not sure I understand your question, but they used a custom editor for Fez as far as I'm aware.
How can i create a questionnaire of unknown size in android/java? I don't know how many activities(pages) I will have before i run the app. Is the only option to have it scrollable for as long as needed or is there another way to create or simulate an activity with a 'next' button? I'm importing questionnaire data from a database at a point in the app so it is as follows Login Home Questionnaire import Questionnaire End and return to home
I'm having so many issues debugging this code, every time I step through the code it seems to be working fine; it isn't. [code] using SFML.Graphics; namespace Platformer { class AnimatedEntity : Sprite { public int FrameInterval { get; set; } public bool Loop = true; public bool Flip = true; private int frameWidth; private int frameCount; private int currentFrame; private int currentTime; public AnimatedEntity(Texture _texture, int _frameWidth) { Texture = _texture; frameWidth = _frameWidth; FrameInterval = 30; ResetAnimation(); Program.OnUpdate += Update; } private void Update() { int newTime = Program.ElapsedGameTime; if (newTime > currentTime + FrameInterval) { currentFrame++; System.Console.WriteLine(currentFrame.ToString()); currentTime = newTime; if (currentFrame > frameCount) { currentFrame = 1; } int width = frameWidth; int x = 0; if (Flip) { x = width; width = -width; } IntRect framePosition = new IntRect(frameWidth * (currentFrame - 1) + x, 0, width, (int)Texture.Size.Y); TextureRect = framePosition; } } private int overrideFramecount = 0; public void ResetAnimation() { if (overrideFramecount != 0) { frameCount = overrideFramecount; } else frameCount = (int)Texture.Size.X / frameWidth; currentFrame = 1; currentTime = Program.ElapsedGameTime; int width = frameWidth; int x = 0; if (Flip) { x = width; width = -width; } IntRect framePosition = new IntRect(x, 0, width, (int)Texture.Size.Y); TextureRect = framePosition; } public void PlayAnimation(Texture texture, int _frameWidth, int interval, bool flip, int _framecount = 0) { overrideFramecount = _framecount; Flip = flip; Texture = texture; frameWidth = _frameWidth; FrameInterval = interval; ResetAnimation(); } } } [/code] So sometimes when an animation is played it will only loop twice instead of infinitely. There is also an issue where if I play an animation during another animation on a certain frame the sprite will lock to one frame for a long time, this makes no sense to me because I am resetting everything when an animation is played. I think I've been staring at it for too long to spot anything.
[QUOTE=Z_guy;43517468]I'm not sure I understand your question, but they used a custom editor for Fez as far as I'm aware.[/QUOTE] Yup, just loaded it up and looked at that scene again. Since Fez is an XNA game, I'm almost certain it's a custom editor made with winforms and a custom Control to display the XNA world.
[QUOTE=Erasus;43516428]So I've got a confusing question to ask.. If any of you have seen "Indie Game: The Movie", there is a scene with Phil Fish (God bless my soul and forgive me) where he's designing levels for Fez, but he's simply just dropping blocks in and adding/removing stuff to create the levels, obviously all of the code for each asset is in there along with the art, but does anyone know how to do it? Simply just add the art asset into something to design levels but with all of the code for each art attached? I've tried to look for a video but I can't find anything which shows it which isn't in the full documentary, any help is appreciated![/QUOTE] It's definitely custom made. I think Renaud Bédard mentioned on his formspring that he abstracted away all the programming from the level editor, so it's very possible he just hardcoded the behaviours and inserted the blocks/art and whatnot manually. [editline]13th January 2014[/editline] There's a scripting menu though, so at least some of it seems to be dynamic.
This is a really simple Python script from the tutorials on Codeacademy that is supposed to teach us how to implement functions. [code] def cube(n): return n**3 def by_three(n): if n%3==0: print cube(n) return n else: False userInput = raw_input("Please enter a number divisible by three: ") userInput = int(userInput) by_three(userInput) [/code] My question is, why does Python default to storing the user's input as a string (which I then have to convert to an integer), and is it because I'm doing something wrong? I was pretty confused about the errors I was getting for a while because I had assumed that my number was an integer all along. I was under the assumption that Python chose variable type similar to C#'s var command, but I think that I just made the assumption on my own.
I need a better way of fixing my time step if possible. I threw this solution together and it works but it's a bit slow to adapt to large framerate changes. [code] int currentTime = DateTime.Now.Second; int totalFrameCount = 0; double frameInterval = 1000/60;//Estimate. int lastElapsed = 1000; int updatesRun = 0; int imperfectFrames = 0; while(Window.IsOpen()) { Window.Clear(new Color(100, 100, 100)); int newTime = DateTime.Now.Second; if (currentTime < newTime) { imperfectFrames = -(totalFrameCount - lastElapsed); lastElapsed = totalFrameCount; frameInterval = (totalFrameCount + imperfectFrames) / 70; totalFrameCount = 0; currentTime = newTime; } totalFrameCount++; if (updatesRun > frameInterval) { updatesRun = 0; Window.DispatchEvents(); if (OnUpdate != null) OnUpdate.Invoke(); ElapsedGameTime++; } updatesRun++; if (OnEarlyDraw != null) OnEarlyDraw.Invoke(); if (OnDraw != null) OnDraw.Invoke(); Window.Display(); } [/code] It spreads each step throughout the second using an estimate from the amount of frames in the last second. I am doing it like this and not like it's done in [url]http://gafferongames.com/game-physics/fix-your-timestep/[/url] for a reason as no doubt someone would link me to that if I didn't explain. If I understand correctly, in Gafferon Games's solution all of the frames are run right away. This seems to mess with SFML's event dispatching, e.g. input will only register for the first part of a second.
[QUOTE=Bloodsh0t;43518271]How can i create a questionnaire of unknown size in android/java? I don't know how many activities(pages) I will have before i run the app. Is the only option to have it scrollable for as long as needed or is there another way to create or simulate an activity with a 'next' button? I'm importing questionnaire data from a database at a point in the app so it is as follows Login Home Questionnaire import Questionnaire End and return to home[/QUOTE] You only need one View(activity), which you populate with the questionnaire data, after next is pressed you take the next questionnaire data from the ArrayList and populate the same View with that data.
[QUOTE=Cittidel;43520975] My question is, why does Python default to storing the user's input as a string (which I then have to convert to an integer), and is it because I'm doing something wrong? [/QUOTE] [url]http://docs.python.org/2/library/functions.html#input[/url] [url]http://docs.python.org/2/library/functions.html#raw_input[/url]
[QUOTE=Erasus;43516428]So I've got a confusing question to ask.. If any of you have seen "Indie Game: The Movie", there is a scene with Phil Fish (God bless my soul and forgive me) where he's designing levels for Fez, but he's simply just dropping blocks in and adding/removing stuff to create the levels, obviously all of the code for each asset is in there along with the art, but does anyone know how to do it? Simply just add the art asset into something to design levels but with all of the code for each art attached? I've tried to look for a video but I can't find anything which shows it which isn't in the full documentary, any help is appreciated![/QUOTE] I know I already replied saying it's a custom editor, but that reminded me that a while ago I wrote a basic winforms + OpenTK editor a while ago for a game I was working on. I wouldn't consider it a pinnacle of well-designed software, but it worked pretty well for what we were doing (minus us never figuring out the raycasting for clicking on objects. We just pretended it was a orthographic projection, you get used to clicking on objects at an offset) [url]https://github.com/LightningDevStudios/CircuitCrawlerEditor[/url]
Could anybody recommend a good Java tutorial for Java Apps?
[QUOTE=Erasus;43526044]Could anybody recommend a good Java tutorial for Java Apps?[/QUOTE] Do you mean android apps, or java GUI programs?
Android Apps. :)
So, I seem to be struggling with getting the screen resolution to change in XNA when a certain boolean is equal to true. Shouldn't it just be as easy as: [code] if (battle == true) { graphics.PreferredBackBufferHeight = 500; graphics.PreferredBackBufferWidth = 700; graphics.ApplyChanges(); } if (battle == false) { graphics.PreferredBackBufferHeight = 318; graphics.PreferredBackBufferWidth = 1152; graphics.ApplyChanges(); } [/code] Also, is there a simpler way to add basic collision on what is just the image of a pixel, walking over another image? I've literally just been putting this a bunch of times for each tile I didn't want the player to be able to walk. [code] if (trainer.X == 0 && trainer.Y == 144) { trainer.Y += TRAINER_SIZE; } [/code] (Replace "trainer.X" with the X coords, and "trainer.Y" with the Y coords of the tiles.)
[QUOTE=Erasus;43528206]Android Apps. :)[/QUOTE] The documentation on the [URL="http://developer.android.com/training/index.html"]android developer site[/URL] was enough to get me started and I don't have a lot of programming experience. Otherwise I've gotten along just searching for articles or tutorials for doing what I want to do, there are tons of answers to specific questions&answers online
[QUOTE=Cittidel;43520975]This is a really simple Python script from the tutorials on Codeacademy that is supposed to teach us how to implement functions. [code] def cube(n): return n**3 def by_three(n): if n%3==0: print cube(n) return n else: False userInput = raw_input("Please enter a number divisible by three: ") userInput = int(userInput) by_three(userInput) [/code] My question is, why does Python default to storing the user's input as a string (which I then have to convert to an integer), and is it because I'm doing something wrong? I was pretty confused about the errors I was getting for a while because I had assumed that my number was an integer all along. I was under the assumption that Python chose variable type similar to C#'s var command, but I think that I just made the assumption on my own.[/QUOTE] See the above comment with a few links to Python documentation. Also, you can just do [code]userInput = int(raw_input("Please enter a number divisible by three: "))[/code]
[QUOTE=Datzy;43530273]See the above comment with a few links to Python documentation. Also, you can just do [code]userInput = int(raw_input("Please enter a number divisible by three: "))[/code][/QUOTE] Doesn't Python have automatic type conversion? if( /*input*/9 == "9" /*string comparison*/) should return true?
[code]$ python >>> 9 == "9" False[/code]
I'm making a multiplayer game where all communication uses UDP sockets. I understand that if the server is behind a router, you need to forward ports so that it can receive packets. I haven't been able to test this yet, but wouldn't the clients need to do the same thing? Is there a way to set up the net code so that the clients don't need to port forward to receive packets from the server?
Sorry, you need to Log In to post a reply to this thread.