Jump to content
  • Advertisement

chapinch

Member
  • Content count

    63
  • Joined

  • Last visited

Community Reputation

134 Neutral

About chapinch

  • Rank
    Member
  1. chapinch

    Java main method

    Hi there I changed my scanner declaration to outside the while loop and declared and initialised my String instead of assigning it null as you advised and the code works fine thanks matey you were a great help. Kind regards Chapinch
  2. chapinch

    Java main method

    Hi there The error occurs in the main method is "cannot make a static reference to a none static field" refereing to the new addressBook variable, the error happens at compile time. Kind regards Chapinch
  3. chapinch

    Java main method

    Hi all I cannot seem to get this code to execute in eclipse please see attached, Im very new to Java so any help would be great. Kind Regards Chapinch[color="#ff0000"][color="#ff0000"] <P align="LEFT"> import java.util. *;public class AddressBook { private List<Person> members = new ArrayList<Person>(); public static void main(String[] args) { AddressBook book = new AddressBook(); } public AddressBook() { super(); this.addNewMember(); } public List<Person> getMembers() { return this.members; } public void addNewMember() { String text = null; while(!text.equals(".")) { Scanner scan = new Scanner(System.in); text = scan.nextLine(); Person newMember = new Person(text); this.getMembers().add(newMember); } this.sortAddressBook(); } public void sortAddressBook() { Collections.sort(this.getMembers()); System.out.println(this.getMembers()); } } import java.util.Comparator; public class Person implements Comparable<Person> { private String name; public String getName() { return name; } public Person(String name) { this.name = name; } public int compareTo(Person arg) { return this.getName().compareTo(arg.getName()); } } [color="#ff0000"][color="#ff0000"] [color="#ff0000"][color="#ff0000"][color="#7f0055"][color="#7f0055"]
  4. chapinch

    HTML forms and how to interact with them

    Hi Mate How do I use the debugger in IE? Kind Regards Jamie
  5. chapinch

    HTML forms and how to interact with them

    Hi there I think I quite clearly stated the problem I am unable to add text to the form gameForm. I have updated the comments and that isn't the problem either but thanks for your help. Does anyone elese have any suggestions? Kind Regards
  6. chapinch

    HTML forms and how to interact with them

    Hi there No it dosen't work and I cannot understand why here is the rest of the code hope it helps. sorry for the length but Im at a loss end as to what to do. <HTML> <HEAD> <TITLE>M150 TMA 5 : Programming : Nine Lives, Task 4 & 5</TITLE> <SCRIPT language = "javascript"> //Task 4 //TO DO: PASTE THE getRandomNumber() FUNCTION YOU WROTE FOR TASK 1 HERE /*this function generates a decimal number between 1 and the function argument it then rounds the decimal number down to a whole number between 1 and the function argument*/ function getRandomNumber(InNumber) { var numberReturned; //generating the random number numberReturned = Math.random() * + InNumber; //the number then gets rounded down to a whole number numberReturned = Math.floor(numberReturned); //the number is then returned return numberReturned; } //Task 4 //TO DO : PASTE THE pickString() FUNCTION YOU WROTE FOR TASK 2 HERE /*this function splits a sting and places the sub strings into elements in an array, then uses a random number to select one of the elements and returns it*/ function pickString(aString, aDelimiter) { //array element to be returned var index; //string is split aString = aString.split(aDelimiter); //random number is assigned index = getRandomNumber(aString.length) //the selected string is returned return aString[index]; } //Task 4 //TO DO: PASTE THE addSpaces() FUNCTION YOU WROTE FOR TASK 3 HERE /*this function takes a string as the argument and returns the same string but with spaces separating each character*/ function addSpaces(aString) { //first the string is placed into an array to separate each character aString = aString.split(''); //then the array is converted back to a string with a space between each character aString = aString.join(' '); //and then returned return aString; } //Task 4 //TO DO: PASTE THE substituteSpaces() FUNCTION YOU WROTE FOR TASK 3 HERE Returns a new string which contains the same characters as the argument, but with any space characters in the argument substituted by the string "(space)" */ function substituteSpaces(aString) { //first it is separated into sub strings using a space as the delimiter aString = aString.split(' '); //then joined back together using the word spaces as a separator aString = aString.join('(space)'); //the string is then returned return aString; } //Task 4 //TO DO: PASTE THE fillInChar() FUNCTION YOU WROTE FOR TASK 3 HERE returns a new string that contains newChar in the same positions as in targetString, otherwise the characters at the corresponding positions of otherString */ function fillInChar(targetString, otherString, newChar) { var resultArray = new Array(); //converting strings to arrays so as to compare characters easier targetString = targetString.split(''); otherString = otherString.split(''); //for loop will execute for length of targetString for(var index = 0; index < targetString.length; index = index + 1) { //if statement to compare newChar and to decide what to assign to resultArray if(targetString[index] == newChar) { resultArray[index] = targetString[index]; } else { resultArray[index] = otherString[index]; } } //convert resultArray to a string and then return resultArray = resultArray.join(''); return resultArray; } //TASK 4 (i) /* Displays text in the document form's text input fields: correctGuessesTextBox, livesTextBox, incorrectGuessesTextBox, randomTermTextBox, definitionsTextArea Takes 4 arguments: correctString, a string of underscore characters, representing unguessed characters, and any correct guesses made by the user lives, an integer holding the number of remaining lives incorrectString, a string of incorrect characters guessed by the user termArray, an array with two elements: the term picked by the computer and associated text The correctGuessesTextBox input field is populated by the characters held by the correctString argument, separated by spaces The livesTextBox is populated with the number held in the lives argument The incorrectGuessesTextBox input field is populated with the string held by the incorrectString argument The randomTermTextBox input field is populated with the string held by the first element of the termArray argument The definitionsTextArea input field is populated with the string held by the second element of the termArray argument /*this function displays a number of strings on the main screen there is no return value for the function*/ function displayText(correctString,lives,incorrectString,termArray) { //shows you all the correct guesses you have made correctString = addSpaces(correctString); document.gameForm.correctGuessesTextBox.value = correctString; //display the number of lives you have left to complete the game document.gameForm.livesTextBox.value = lives; //shows you all the incorrect guesses you have made incorrectString = substituteSpaces(incorrectString); document.gameForm.incorrectGuessesTextBox.value = incorrectSting; //displays a description of the word and for the meantime the actual word document.gameForm.randomTermTextBox.value = termArray[0]; document.gameForm.definitionsTextArea.value = termArray[1]; } //TO DO //TASK 4(ii) /* Sets up game: computer picks a term from a string of terms The document form for the game is prepared The function takes no arguments The function has no return value */ function setUp() { //string of terms and identifying numbers var termString = 'hard disk*Term 1#magnetic tape*Term 2#flash drive*Term 3#optical disc*Term 4#ram*Term 5'; var returnedString; var rightLetter; var underScoreString; var blankString; var wrongLetter; //declare variable to hold number of remaining 'lives', initialise to 9 var lives = 9; returnedString = pickString(termString, '#'); //returned string is split into two parts, term and number returnedString = returnedString.split('*'); for(var index = 0; index < returnedString[0].length; index = index + 1) { underScoreString[index] = '_'; } underScoreString = rightLetter; blankString = wrongLetter; displayText(underScoreString, lives, blankString, returnedString); //TO DO TASK 4(ii): WRITE CODE TO COMPLETE THE setUp() FUNCTION playGame(underScoreString, lives, blankString, termString); } //TO DO //Task 5(i) /* Prompts user to input a character Reprompts user while character has already been entered Function takes one argument: aString containing previous correct and incorrect guesses returns a character input by the user that has not been previously entered */ function getInput(aString) { //TO DO TASK 5(i): WRITE CODE TO COMPLETE THE getInput() FUNCTION } //TO DO // TASK 5(ii) /* Orchestrates playing of game The function takes 4 arguments: hitsSoFar, a string of underscore characters, representing unguessed characters, and any correct guesses made by the user lives, an integer representing the number of remaining lives incorrectGuesses, a string of incorrect characters guessed by the user termArray, the term picked by the computer and associated text The function has no return value */ function playGame(hitsSoFar, lives, incorrectGuesses, termArray ) { //TO DO TASK 5(ii): WRITE CODE TO COMPLETE THE playGame() FUNCTION } </SCRIPT> </HEAD> <BODY> NINE LIVES <FORM NAME = "gameForm"> <INPUT TYPE = "reset" NAME = "resetButton" VALUE = "Clear Form"> <INPUT TYPE = "button" NAME = "playGameButton" VALUE ="Play the Game" ONCLICK = " setUp() ;"> Correct Guesses: <INPUT TYPE = "text" NAME = "correctGuessesTextBox" SIZE = "50"> <INPUT TYPE = "text" NAME = "livesTextBox" SIZE = "1" > lives remaining Incorrect Guesses: <INPUT TYPE = "text" NAME = "incorrectGuessesTextBox" SIZE = "50"> Random Term: <INPUT TYPE = "text" NAME = "randomTermTextBox" SIZE = "50"> Definition: <TEXTAREA NAME = "definitionsTextArea" value = "" ROWS = "10" COLS = "50"> </TEXTAREA> </FORM> </BODY> </HTML>
  7. Hi all I have come to this forum as it always proves very helpful with what ever I need so here goes. Below is an extract of code my question is how do I write to the forms text boxes is it document.gameForm.correctGuessesTextBox.value = variableOfSomeSort. Any help would be greatly appreciated Kind Regards Jamie NINE LIVES <FORM NAME = "gameForm"> <INPUT TYPE = "reset" NAME = "resetButton" VALUE = "Clear Form"> <INPUT TYPE = "button" NAME = "playGameButton" VALUE ="Play the Game" ONCLICK = " setUp() ;"> Correct Guesses: <INPUT TYPE = "text" NAME = "correctGuessesTextBox" SIZE = "50"> <INPUT TYPE = "text" NAME = "livesTextBox" SIZE = "1" > lives remaining Incorrect Guesses: <INPUT TYPE = "text" NAME = "incorrectGuessesTextBox" SIZE = "50"> Random Term: <INPUT TYPE = "text" NAME = "randomTermTextBox" SIZE = "50"> Definition: <TEXTAREA NAME = "definitionsTextArea" value = "" ROWS = "10" COLS = "50"> </TEXTAREA> </FORM>
  8. chapinch

    PS3 media centre

    Hi all to clarify the problem a bit, I use vista and the standard media player that come with it would have been saved in the default format. This used to work before I could play the videos through the PS3, I don't know for sure but when I stared to use the hdmi cable it can find the files but says that they are all corrupt. Regards chapnch
  9. chapinch

    PS3 media centre

    Hi all I have a none game related problem but I always get good advice in this forum and so thought I would ask anyway, the problem is that since I upgraded my PS3 with a hdmi cable i cannot play any videos through my media centre it says that the files are corrupt. Do i need to change something in my setting on the PS3? Any help would be great.
  10. chapinch

    university levels what do they mean

    Thanks for all your replys they were all very helpful and have calmed me down some what lol. Kind Regards Chapinch
  11. Hi All I have posted this question because I always get very useful answers that I find helpful in this forum. I am currently studying computing at the Open University, they start at level 1 then 2 and end at level 3. My friend said that: Level 1 is GCSE Level 2 is can't remember Level 3 is A level I am a little concerned is this the case? If so then my degree is worth not a lot. Bareing in mind that my degree is an undergraduate BSc. This is in regard to the UK system Any thoughts would be great. Again sorry for this random post, but the responces are always good in this forum. Regards Chapinch
  12. chapinch

    Come Help Me Please! Need Information!

    Hi I have been learning c++ for over a year now and have been really enjoying it, I thought I would also have a look at the games side of things and found that that side of programming was much more complicated than what I had learnt. My point is I think from my point of view is that you should get a good sound knowledge of programming before you attempt to program games but this just my opinion everyone does things different. Hope this helps
  13. Hi All I have been studying c++ for over a year now and have decided to dable a bit in the games side of things, I have bought a book call GAME PROGRAMMING IN C++: START TO FINISH, by Erik Yuzwa. It is an asteriod game. I have tried to run a sample program on my computer that uses SDL see below. I have linked up the peon engine that I am using to my compiler (VC2008) and the SDL also but this error occurs: 1>MSVCRTD.lib(cinitexe.obj) : warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library Do you have any ideas on how I can solve this. /** * This source code is part of the samples for "Game Programming in C++: Start to Finish". * * This example SDL code will load up a bitmap image of the SDL logo, and just display * it in a window for you. It's very bare bones. * * @Author : Erik Yuzwa * @Date : 09/01/2005 * @Version: 1.0 */ #include <SDL.h> int main(int argc, char* argv[]) { //initialize SDL and the video subsystem if(SDL_Init( SDL_INIT_VIDEO ) < 0) return -1; //create an SDL_Surface object which represents the //game window SDL_Surface* screen = SDL_SetVideoMode(640, 480, 0, 0); //signal SDL to change the text of the main window //to "Hello World" SDL_WM_SetCaption("Hello World", "Hello World"); //load the SDL logo bitmap to a temporary surface SDL_Surface* temp = SDL_LoadBMP("data\\textures\\sdl_logo.bmp"); //create the working SDL_Surface which matches the //display format of the temporary surface SDL_Surface* bg = SDL_DisplayFormat(temp); //free the memory allocated to the temporary SDL_Surface SDL_FreeSurface(temp); SDL_Event event; bool quit = false; //This is the main message loop of the game while(!quit) { //check the message queue for an event if (SDL_PollEvent(&event)) { //if an event was found switch (event.type) { //check to see if the window was closed via the "x button" case SDL_QUIT: //set the quit flag to true quit = true; break; //check the keyboard to see if the ESC key was pressed case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_ESCAPE: //set our quit flag to true quit = true; break; } break; } } //draw the background sprite SDL_BlitSurface(bg, NULL, screen, NULL); //update the current window SDL_UpdateRect(screen, 0, 0, 0, 0); } //free the allocated memory for the background surface SDL_FreeSurface(bg); //quit SDL and allow it to clean up everything SDL_Quit(); //return control to Windows with no errors return 0; } PS: I have encountered a number of errors trying to run this simple program and have managed to solve them all but this one I am stumped. Vista what I am using wasn't out when the book was published in 2005 but there is a mention of it and the author was aware if this helps.
  14. chapinch

    SDL and VC2008

    Hi All How do I make a SDL libraray part of my defaults in VC2008 so that I can use it in the normal fashion. #include <SDL.h> Any help would br great thanks.
  15. Hi all below is a small program were I'am have created a box using objects and then placed another object inside it so that it cannot get out (the start of a very basic game). My question is do I have to use objects or is there another way? #include <iostream.h> #include <conio.h> #include <stdlib.h> class wall { public: wall(int row, int col); int get_row() {return wall_row;} int get_col() {return wall_col;} private: int wall_row; int wall_col; }; wall::wall(int col, int row) { wall_row = row; wall_col = col; gotoxy(col, row); cout << "h" << endl; } int const NUM = 40; int main() { int me = 0; int col = 13; int row = 13; int wall_col = 0; int wall_row = 0; char move; int count = 0; int num = 0; wall* array[NUM]; gotoxy(col, row); cout << me << endl; randomize(); for(int index = 0; index < 10; index++) { wall_col = index + 10; wall_row = 10; array[num] = new wall(wall_col, wall_row); num++; } for(index = 0; index < 10; index++) { wall_col = index + 10; wall_row = 21; array[num] = new wall(wall_col, wall_row); num++; } for(index = 0; index < 10; index++) { wall_col = 10; wall_row = 11 + index; array[num] = new wall(wall_col, wall_row); num++; } for(index = 0; index < 10; index++) { wall_col = 19; wall_row = 11 + index; array[num] = new wall(wall_col, wall_row); num++; } do { count = 0; move = getch(); switch(move) { case 'a': for(index = 0; index < NUM; index++) { if(((col - 1) == array[index] -> get_col()) && (row == array[index] -> get_row())) { count = 1; } } if(count == 0) { col--; gotoxy(col, row); cout << me << endl; gotoxy(col + 1, row); cout << " " << endl; } break; case 'w': for(index = 0; index < NUM; index++) { if((col == array[index] -> get_col()) && ((row - 1) == array[index] -> get_row())) { count = 1; } } if(count == 0) { row--; gotoxy(col, row); cout << me << endl; gotoxy(col, row + 1); cout << " " << endl; } break; case 's': for(index = 0; index < NUM; index++) { if(((col + 1) == array[index] -> get_col()) && (row == array[index] -> get_row())) { count = 1; } } if(count == 0) { col++; gotoxy(col, row); cout << me << endl; gotoxy(col - 1, row); cout << " " << endl; } break; case 'z': for(index = 0; index < NUM; index++) { if((col == array[index] -> get_col()) && ((row + 1) == array[index] -> get_row())) { count = 1; } } if(count == 0) { row++; gotoxy(col, row); cout << me << endl; gotoxy(col, row - 1); cout << " " << endl; } break; } } while(move != 't'); return 0; }
  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!