1. మైదానం యొక్క కణాలతో పని చేయడం
ఆట మైదానాన్ని మనం కణాలుగా విభజించడం గొప్ప విషయం. కానీ కణాలతో మనం ఏమి చేయగలం?
మైదానంలోని ప్రతి సెల్ కోసం, మేము సెట్ చేయవచ్చు:
- సెల్ రంగు (సెల్ యొక్క నేపథ్య రంగు);
- టెక్స్ట్ (ఇది టెక్స్ట్ లేదా సంఖ్య కావచ్చు);
- టెక్స్ట్ రంగు;
- సెల్ పరిమాణంలో ఒక శాతంగా వచన పరిమాణం.
మైదానంలోని కణాలతో పని చేసే పద్ధతులను పరిశీలిద్దాం:
void setCellColor(int x, int y, Color color)
సెల్ రంగును (x, y)
సమానమైన కోఆర్డినేట్లతో సెట్ చేస్తుంది color
.
ఉదాహరణలు:
setCellColor(0, 0, Color.RED);
setCellColor(3, 6, Color.BLACK);
setCellColor(6, 8, Color.NONE);
Color getCellColor(int x, int y)
కోఆర్డినేట్లతో సెల్ రంగును అందిస్తుంది (x, y)
.
ఉదాహరణ:
Color myColor = getCellColor(2, 0);
void setCellValue(int x, int y, String value)
String value
కోఆర్డినేట్లతో సెల్కి వచనాన్ని కేటాయిస్తుంది (x, y)
.
ఉదాహరణలు:
setCellValue(3, 3, "text");
setCellValue(0, 8, "W");
setCellValue(4, 1, "2222");
setCellValue(6, 6, "");
String getCellValue(int x, int y)
కోఆర్డినేట్లతో సెల్లో ఉన్న వచనాన్ని అందిస్తుంది (x, y)
.
ఉదాహరణలు:
String s = getCellValue(3, 3);
System.out.println(getCellValue(4, 1));
void setCellTextSize(int x, int y, int size)
సెల్లోని టెక్స్ట్ పరిమాణాన్ని కోఆర్డినేట్లతో సెట్ చేస్తుంది (x, y)
, ఇక్కడ size
సెల్ ఎత్తులో టెక్స్ట్ ఎత్తు శాతంగా ఉంటుంది.
ఉదాహరణ:
setCellTextSize(2, 0, 70); // 70% of the cell height
int getCellTextSize(int x, int y)
కోఆర్డినేట్లతో సెల్లోని కంటెంట్ పరిమాణాన్ని అందిస్తుంది (x, y)
.
ఉదాహరణ:
int size = getCellTextSize(2 , 0);
void setCellNumber(int x, int y, int value)
int value
కోఆర్డినేట్లతో సెల్కు నంబర్ను కేటాయిస్తుంది (x, y)
.
ఉదాహరణలు:
setCellNumber(3, 3, 40);
setCellNumber(0, 8, -8);
setCellNumber(4, 1, 2222);
setCellNumber(6, 6, 0);
int getCellNumber(int x, int y)
కోఆర్డినేట్లతో సెల్లో ఉన్న సంఖ్యను అందిస్తుంది (x, y)
. సెల్ సంఖ్యను కలిగి ఉండకపోతే, అది 0ని అందిస్తుంది.
ఉదాహరణలు:
int i = getCellNumber(3, 3);
System.out.println(getCellNumber(4, 1));
void setCellTextColor(int x, int y, Color color)
సెల్ యొక్క కంటెంట్ (టెక్స్ట్) రంగును అక్షాంశాలతో సెట్ చేస్తుంది (x, y)
.
ఉదాహరణలు:
setCellTextColor(2, 1, Color.GREEN);
setCellTextColor(0, 1, Color.NONE);
Color getCellTextColor(int x, int y)
కోఆర్డినేట్లతో సెల్ యొక్క కంటెంట్ (టెక్స్ట్) రంగును అందిస్తుంది (x, y)
.
ఉదాహరణ:
Color textColor = getCellTextColor(1, 3);
setCellValueEx()
మీ సౌలభ్యం కోసం, విభిన్న సెట్ల పారామితులతో అనేక పద్ధతులు ఉన్నాయి :
void setCellValueEx(int x, int y, Color cellColor, String value)
సెల్ యొక్క నేపథ్య రంగు మరియు వచనాన్ని వరుసగా మరియు (x, y)
కు సమానమైన కోఆర్డినేట్లతో సెట్ చేస్తుంది .cellColor
value
ఉదాహరణ:
setCellValueEx(0, 2, Color.BLUE, "56");
void setCellValueEx(int x, int y, Color cellColor, String value, Color textColor)
సెల్ యొక్క నేపథ్య రంగు, వచనం మరియు వచన రంగులను వరుసగా , , మరియు లకు (x, y)
సమానమైన అక్షాంశాలతో సెట్ చేస్తుంది .cellColor
value
textColor
ఉదాహరణ:
setCellValueEx(0, 2, Color.BLACK, "56", Color.GREEN);
void setCellValueEx(int x, int y, Color cellColor, String value, Color textColor, int textSize);
సెల్ యొక్క నేపథ్య రంగు, వచనం, వచన రంగు మరియు వచన పరిమాణాన్ని వరుసగా , , , మరియు (x, y)
లకు సమానమైన కోఆర్డినేట్లతో సెట్ చేస్తుంది.cellColor
value
textColor
textSize
ఉదాహరణ:
setCellValueEx(0, 2, Color.BLACK, "56", Color.GREEN, 70);
2. రంగుతో పని చేయడం
కోడ్జిమ్ గేమ్ ఇంజిన్ Color
148 రంగులకు ప్రత్యేకమైన విలువలను కలిగి ఉన్న ప్రత్యేక రకాన్ని కలిగి ఉంది. NONE
ఇది రంగు లేకపోవడాన్ని సూచించే ప్రత్యేక విలువను కూడా కలిగి ఉంది .
రంగుతో పని చేసే ఉదాహరణలు
Color myColor = Color.WHITE; // The color white is assigned to the myColor variable.
Color redColor = Color.RED; // The color red is assigned to the redColor variable.
Color blueColor = Color.BLUE; // The color blue is assigned to the blueColor variable.
మీరు ఆదేశాన్ని ఉపయోగించి సెల్ రెడ్ కలర్ చేయవచ్చు:
setCellColor(0, 2, Color.RED);
మీరు సెల్ ఒక నిర్దిష్ట రంగు కాదా అని ఇలాంటి కమాండ్తో తనిఖీ చేయవచ్చు:
if (getCellColor(0,2) == Color.GREEN)
{
}
కొన్నిసార్లు మీరు సాధ్యమయ్యే ప్రతి రంగు యొక్క శ్రేణిని పొందవలసి ఉంటుంది. దీన్ని చేయడానికి, values()
పద్ధతిని ఉపయోగించండి.
ఉదాహరణ:
// An array containing every available color is assigned to the colors variable.
Color[] colors = Color.values();
రంగుల పాలెట్లో రంగుల సూచికను పొందడం చాలా సులభం - ఈ ordinal()
పద్ధతిని ఉపయోగించండి:
Color color = Color.RED;
int redIndex = color.ordinal(); // Index of the color red
int blueIndex = Color.BLUE.ordinal(); // Index of the color blue
మీరు దాని సూచిక ద్వారా రంగును కూడా సులభంగా పొందవచ్చు:
// The color whose index is 10 in the Color enum is assigned to the color variable.
Color color = Color.values()[10];
3. డైలాగ్ బాక్స్లు
ఆట ముగిసే సమయానికి, అతను లేదా ఆమె గెలిచాడా లేదా ఓడిపోయాడో మనం ఆటగాడికి తెలియజేయాలి. దీని కోసం మరియు ఇతర సందర్భాల్లో, కోడ్జిమ్ గేమ్ ఇంజిన్ ప్రత్యేక void showMessageDialog(Color cellColor, String message, Color textColor, int textSize)
పద్ధతిని కలిగి ఉంది, ఇది సందేశంతో కూడిన డైలాగ్ బాక్స్ను ప్రదర్శిస్తుంది message
.
ఈ పద్ధతి యొక్క పారామితులు:
cellColor
డైలాగ్ బాక్స్ యొక్క నేపథ్య రంగుmessage
అనేది సందేశం యొక్క వచనంtextColor
సందేశం యొక్క టెక్స్ట్ యొక్క రంగుtextSize
సందేశం యొక్క టెక్స్ట్ పరిమాణం
వినియోగదారు స్పేస్ బార్ను నొక్కినప్పుడు లేదా మౌస్తో డైలాగ్ బాక్స్పై క్లిక్ చేస్తే డైలాగ్ బాక్స్ మూసివేయబడుతుంది.
ఈ పద్ధతిని పిలవడానికి ఉదాహరణ:
// Display a dialog box with a message
showMessageDialog(Color.BLACK, "EPIC FAIL", Color.RED, 80);
4. యుటిలిటీ పద్ధతులు
గేమ్లను వ్రాసేటప్పుడు, మీరు తరచుగా యాదృచ్ఛిక సంఖ్యలను ఉపయోగిస్తారు. యాదృచ్ఛిక సంఖ్యలను పొందడం సులభతరం చేయడానికి, మీరు గేమ్ ఇంజిన్ యొక్క యుటిలిటీ పద్ధతులను ఉపయోగించవచ్చు:
int getRandomNumber(int max)
0
నుండి కలుపుకొని యాదృచ్ఛిక సంఖ్యను అందిస్తుంది (max–1)
.
int getRandomNumber(int min, int max)
min
నుండి కలుపుకొని యాదృచ్ఛిక సంఖ్యను అందిస్తుంది (max–1)
.
5. JDK 11+
IntelliJ IDEA నుండి మీ ప్రోగ్రామ్ను రన్ చేస్తున్నప్పుడు, గేమ్ క్లాస్ని వారసత్వంగా పొందే తరగతి కింది లోపాన్ని సృష్టించవచ్చు:
Error: JavaFX runtime components are missing, and are required to run this application
ఈ సందర్భంలో, అటువంటి ప్రతి తరగతికి, మీరు ఈ దశలను ఒకసారి చేయాలి:
- రన్ → ఎడిట్ కాన్ఫిగరేషన్ తెరవండి
- VM ఎంపికల విలువ కోసం , కింది వాటిని నమోదు చేయండి:
--module-path ./lib/javafx-sdk-16/lib --add-modules=javafx.controls,javafx.fxml,javafx.base
శ్రద్ధ:
IntelliJ IDEA యొక్క ఇటీవలి సంస్కరణల్లో, "VM ఎంపికలు" ఫీల్డ్ డిఫాల్ట్గా చూపబడదు. దీన్ని ప్రదర్శించడానికి, ALT+V నొక్కండి
- నొక్కండి: వర్తించు → సరే
- ఆటను అమలు చేయండి.
GO TO FULL VERSION