By contrast, a computer program is dynamic It doesn’t change. Once put into place, its various objects just stand there in a certain relation to each other. Grid positions–i.e., we always start counting from zero at the origin (topĪ kitchen model is mostly static It doesn’t change. This means we will always used zero-based indexing when referring to The gridĪbove is 10 by 10 in size, where coordinates run from 0 up to and includingĩ. Represented in our grid and is located at the top left corner. Also notice that the origin (0, 0) is explicitly It is 4 cells horizontally to the right of the origin, and 2 cells verticallyĭown from the origin. So the highlighted cell in the grid shown above is at location (4, 2), since Though it is the opposite of what is typical in studying geometry!). We use a left-handed orientation for our axesīecause that convention is predominant in computer programming contexts (even The y axis points downward in our grid, making thisĪ left-handed Cartesian plane. The origin horizontally, and y (the second coordinate) represents the distanceįrom the origin vertically. Backgrounds for health and energy barsĬanvas.We will use a variation of Cartesian coordinates to write any location asĪn (x, y) pair, where x (the first coordinate) represents the distance from While(pState.getHealth() > 0 & eState.getHealth() > 0) ("You have accepted a challenge to a duel against " + eState.getName() + ".") Your name is " + pState.getName() + ".") Public Game(String playerName, String enemyName) * The game, which will have a player and an enemy Note: I also removed the playerName and enemyName parameters from the Game constructor because in BlueJ you cannot both have an applet and an object of Game on the bench interact with each other, as far as I know. #BLUEJ PROGRAM TO MAKE A GAME CODE#I heard about repaint() but when putting the KeyListener code and the current health and energy levels into repaint(), I think they did not even display, and the whole screen minus the background still blinked every time I typed in a key. Currently, I have everything in paint(Graphics canvas) and each time I press a key, the whole screen except the background (whose color is in init()) blinks, as if the applet is implicitly looping paint() and keyTyped(). #BLUEJ PROGRAM TO MAKE A GAME HOW TO#I want to know how to set up the program so I can have the game screen with the background, the black backgrounds for the maximum amount of health and energy for player and enemy, the player's skill bar icons and text, and the game message window (a white rectangle), remain constant during the game, and only have the game messages and current health and energy levels be updated, based upon the calculations that take place when a user enters a skill, and when the enemy uses a skill. I could probably figure out how to make it take user input and print relevant messages, but finally here is my main problem. So, I have tried to implement a KeyListener, and found a simple example of it through a Google search. I have added the code for the original text game and the new graphics game below.Īs I understand it, one cannot have the terminal take user input, and then have the applet repaint things like the health and energy levels graphically based on the calculations that took place. The loop ends if the player or enemy's health falls to or below 0, and a congratulatory or sorry! message is printed depending on which fell to or below 0 first. A message indicating which skill the player and enemy used is then printed, and the health and energy of player and enemy are displayed. After the player enters a skill, a random integer 1-8 is generated and conditional statements similar to the ones for the player make relevant calculations to the enemy's state. For example, if a player enters "2" (a damage skill), that integer will act as the element of the ArrayList, and subtract health from the enemy state and energy from the player state. The integer between 1 and 8 that the user enters is stored in a Scanner variable, and then conditional statements based on whether the skill is damage, healing, or energy regen, make calculations to the player's or enemy's state, 2 classes which have 2 fields, health and energy. When the game starts, it prints a welcome message and instructions to the terminal and asks the user to "use" a skill. It has 6 interacting classes, 2 of which were ArrayLists, each with a collection of 8 "skills", which are objects that have a name, energy cost, delta, and type ("damage," "healing" or "energy regen"). The original game worked by printing messages to and getting user input from the terminal. I learned how to implement basic graphics by using a java applet and using the paint() method to create the game screen. I am writing a simple java game for a programming class and I would like to know how to integrate graphics into it (I am using BlueJ).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |