CodeGym
Promotion
CodeGym University
Learning
Courses
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme
Question
  • Reviews
  • About us
Start
Start learning
Start learning now
  • All questions
CodeGym/Help with Java Tasks/Compiler can't find method setCellValueEx(...) , even th...
Sakka Mouid
Level 19
Hannover
  • 22.04.2022
  • 538views
  • 5comments

Compiler can't find method setCellValueEx(...) , even though i implemented its class !!!

Question about the task Snake (Part 4/20)
Games,  Level 0,  Lesson 1
Resolved


One of the game objects will be an apple. Create an Apple class and make it inherit the GameObject class.

To represent an apple on the playing field, you could paint cells containing apples any particular color. Or you could draw some apple-looking symbol in the cell. Let the Apple class store this symbol in the APPLE_SIGN variable.

Add a draw(Game) method to the Apple class: it will draw an apple on the playing field. To do this, in the draw(Game game) method, you need to call game.setCellValueEx(...).

Because the Apple class uses the Game and Color classes, these (and other) engine classes are located in the com.codegym.engine.cell package. To use them, the Apple class must include the following import statement: import com.codegym.engine.cell.*;

To see what an apple will look like, in the createGame() method, create an apple with coordinates (7, 7) and call its draw(Game) method.

Requirements:
  • There must be a public Apple class.
  • The Apple class must be a descendant of the GameObject class.
  • The Apple class must have one constructor with two int parameters (x and y), which uses the keyword super to call the base class's constructor with the x and y parameters.
  • The Apple class must have a private static final String APPLE_SIGN field that is initialized when it is declared. For example, you can use the UTF-16 symbol for an apple: "\uD83C\uDF4E".
  • The Apple class must have a public void draw(Game) method.
  • The draw(Game) method must call the setCellValueEx(int, int, Color, String, Color, int) method on a Game object with the following arguments: x, y, Color.NONE, APPLE_SIGN, <color of the apple>, 75. (Replace <color of the apple> with a color you like, for example, Color.GREEN).
  • The SnakeGame class's createGame() method must create a new apple (an instance of the Apple class) with coordinates (7, 7).
  • The draw(Game) method must be called on the created apple. Pass this to the method.
  • The Apple class must have a statement that imports the entire contents of the com.codegym.engine.cell package.
package com.codegym.games.snake; import com.codegym.engine.cell.*;//nejma adhika ta3 all contents of the package! //ken n7eb na3mlou wa7di maghir codegym , kifech na3ml li packages? //Color w Game classes mawjoudin deja zouz fi engine : com.codegym.engine.cell //kifech najm nekhdem jeu mela maghir engine ta3 codegym ? public class SnakeGame extends Game { public static final int WIDTH=15; public static final int HEIGHT=15; @Override public void initialize(){ setScreenSize(HEIGHT,WIDTH); createGame();//I tried to delete the createGame() and call here directly the //drawScene() and it worked. Ma3mlnech akeka 5ater createGame() bch ta3ml //7ajet okhra zeda } private void drawScene(){ for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { setCellColor(x, y, Color.GRAY); } } } private void createGame(){ drawScene(); Apple apple = new Apple(7,7); apple.draw(this);//"this" here refers to the class //fama method te5ou class fi parameter ? } }
0
Comments (5)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Lisa L
Level 47 , Nuremberg, Germany
22 April 2022, 19:19solution
setCellValueEx != setCellValueEX and cause you comment 'why 75?'... https://codegym.cc/groups/posts/138-games-section-on-codegym-game-engine
+2
Sakka Mouid
Level 19 , Hannover, Deutschland
23 April 2022, 00:32
Hi Lisa ! Thank you for your fast helpful answers :) . This the first game i try to develop . I'm new to this and the thing here , we are using a codegym engine called Game . So my question is : functions such as setCellValueEx () and setCellColor() are they only in this codegym package available ? For example , if a create a project in Intellij, which is independent from the CodeGym Plugin (not using it), should i download another Plugin ? and in this case , should i use completely different methods ?
+1
Lisa L
Level 47 , Nuremberg, Germany
23 April 2022, 07:33
Because learning can be tedious from time to time (hihihi) CG wanted to enable the learners to code more interesting things with their still relatively small possibilities. And there we are already at the core of the matter: GUI. Actually GUI programming is not sooo hard but you use more advanced programming techniques here. You don't have to understand them to use GUI frameworks, but it's helpful. In addition, a relatively large amount of administrative code has to be written. In the end, there would be a lot of explanations that cannot be understood and distracts from the main topic: Java syntax and core. That's probably why CG wrote the Game (class) engine. Later you can look at these GUI frameworks yourself and don't need a CG game library anymore. You just write yourself what you need. No problem for a coder ;) A colleague here did exactly that just a few days ago and published his code on Github. Check it out, I think the two games are awesome. As info. CG uses JavaFX for the Game class. The few times you use GUI here in the course it is Swing (afair in 4 projects). The colleague mentioned above also uses Swing.
+1
Sakka Mouid
Level 19 , Hannover, Deutschland
12 May 2022, 16:49
Noch eine Frage : Warum haben wir nicht einfach die AWT Klasse benutzt ? Das wäre besser . um die Klasse kennenzulernen und um mit etwas allgemeiner zu arbeiten , das alle Programmierer kennen , und nicht ein GC Game class Engine. .
0
Lisa L
Level 47 , Nuremberg, Germany
12 May 2022, 17:08useful
Die game engine ist JavaFX und nicht AWT/ Swing. Davon abgesehen ist GUI Programmierung in Java keine Kleinigkeit. Ich würde sagen, du solltest schon mit dem Kurs irgendwo in der Mitte vom Multithreading Quest angekommen sein (innere Klassen und anonyme Klassen), um da überhaupt etwas verstehen zu können. Außerdem unterschätzt du den Umfang dieser Grafikbibliotheken. Die sind abartig umfangreich. Da fängst du an was zu suchen und bist verloren. Der echte Wahnsinn. Dagegen sollten die Games hier motivieren und eben nicht abschrecken, also wohl insbesondere auch von gerade hinzugekommenen Lernwilligen nachprogrammiert werden können. So ab Level 5 habe ich in Erinnerung sind die gedacht. Da ist es wohl einfacher, eine setCellValueEx() Methode aufzurufen als sich erstmal ein paar Stunden durch verwirrende Klassen zu kämpfen, deren Zusammenhang man zu diesem Zeitpunkt überhaupt nicht verstehen kann.
+1
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning, and a Java developer’s career.
Follow us
Interface language
English
Deutsch Español हिन्दी Français Português Polski বাংলা 简体中文 मराठी தமிழ் Italiano Bahasa Indonesia 繁體中文 Nederlands 日本語 한국어 Bulgarian Danish Hungarian Basa Jawa Malay Norwegian Romanian Swedish Telugu Thai Українська Filipino Turkish Azərbaycan Русский Vietnamese
Programmers Are Made, Not Born © 2025 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2025 CodeGym