重慶分公司,新征程啟航
為企業提供網站建設、域名注冊、服務器等服務
為企業提供網站建設、域名注冊、服務器等服務
別說了,我 寫個for循環 輸出 1-2000,把它拆開寫,輸出1,2,3,4,5...... 2000
成都創新互聯公司提供高防服務器租用、云服務器、香港服務器、成都移動機房托管等
2000行就到手了
然后你對你們老師說
老師,你看我這段代碼厲害嗎。 這段代碼 省去了 昂貴的虛擬函數之間的調用。而且代碼簡單易懂。而且還有2000行。
/**
需求:獎客富翁游戲。
菜單為:
1.注冊用戶信息。填寫用戶名,密碼,電腦隨機輸出一個4位
數字作為會員卡號。提示用戶名,密碼,及會員卡號。可選擇第二步了
2.登陸。校驗是否已注冊(是否存在會員卡號)。如果為空,
提示用戶不存在。
如果用戶名通過,密碼錯誤,提示用戶名和密碼不匹配。如果
驗證成功結束。如果輸入的用戶名密碼均匹配,給出登陸成功提示。
可選擇第三步了。
3.先判斷用戶是否已登陸(是否存在會員卡)
詢問是否進行抽獎,選Y,電腦隨機輸出5個4位
數字。如果其中有一個數字與用戶卡號相同,則為中獎,獎勵
人民幣為卡號數字的金額。否則,謝謝參與。程序退出。
*/
import?java.util.Scanner;
import?java.util.Random;
public?class?RichPerson?{
public?static?void?main(String[]?args)?{
//?輸出菜單。
for?(int?a?=?0;?a??6;?a++)?{
System.out.print("*");
}
System.out.print("歡迎進入獎客富翁系統");
for?(int?b?=?0;?b??6;?b++)?{
System.out.print("*");
}
System.out.print("\n\t\t1.注冊\n"?+?"\t\t2.登錄\n"?+?"\t\t3.抽獎\n");
for?(int?c?=?0;?c??31;?c++)?{
System.out.print("*");
}
//?輸出菜單結束。
int?caidan?=?0;//?操作菜單
String?name?=?null;//?會員注冊名字
String?myname?=?null;//?會員登錄名字
String?password?=?null;//?會員注冊密碼
String?mypassword?=?null;//?會員登錄密碼
int?number?=?0;//?會員卡號
//?int?luckynumber=0;//幸運號碼
String?str?=?null;//?詢問是否重試
//?輸入數字選擇菜單。
Scanner?input?=?new?Scanner(System.in);
Random?output?=?new?Random();
do?{
System.out.println("\n請選擇菜單:");
caidan?=?input.nextInt();
switch?(caidan)?{
case?1:
System.out.println("歡迎注冊富翁,請依次輸入用戶名和密碼");
System.out.println("用戶名:");
name?=?input.next();
System.out.println("密碼:");
password?=?input.next();
//?隨機給出4位數的會員卡號
number?=?output.nextInt(8999)?+?1000;
System.out.println("注冊成功!您的用戶名:"?+?name?+?",密碼:"?+?password
+?",會員卡號:"?+?number?+?"。請牢記!");
break;
case?2:
//?先判斷用戶是否已注冊。
if?(name?==?null)?{
System.out.println("您好,請先注冊!");
break;
}?else?{
System.out.println("歡迎登錄富翁,請依次輸入用戶名和密碼!");
//?用戶名和密碼匹配校驗次數設置為3次。
for?(int?x?=?0;?x??3;?x++)?{
System.out.println("用戶名:");
myname?=?input.next();
if?(!myname.equals(name))?{
System.out.println("用戶"?+?myname?+?"不存在!請重試,剩余次數"
+?(2?-?x)?+?"次!");
}?else?{
System.out.println("密碼:");
}
mypassword?=?input.next();
if?(!mypassword.equals(password))?{
System.out.println(myname?+?"密碼錯誤!"?+?"請重試,剩余次數"
+?(2?-?x)?+?"次!");
}?else?{
System.out.println("登陸成功!");
break;
}
}
}
break;
case?3:
//?判斷用戶是否已注冊,是否已登錄。
if?(mypassword?==?null)?{
System.out.println("您好,請先登錄!");
break;
}?else?if?(!mypassword.equals(password))?{
System.out.println("您好,請先重試登錄!");
break;
}?else?if?(mypassword.equals(password))?{
System.out.println("歡迎進入富翁,請問是否進行幸運抽獎(y/n)?");
String?choujiang?=?input.next();
if?(choujiang.equals("y"))?{
int[]?luckynumber?=?new?int[5];
for?(int?m?=?0;?m??5;?m++)?{
luckynumber[m]?=?output.nextInt(8999)?+?1000;
}
for?(int?m?=?0;?m??5;?m++)?{
System.out.print(luckynumber[m]?+?"\t");
}
System.out.println("\n"?+?number);
for?(int?m?=?0;?m??5;?m++)?{
if?(number?==?luckynumber[m])?{
System.out.println("\n中獎!金額為:"?+?luckynumber);
break;
}?else?{
System.out.println("\n木有中獎!");
break;
}
}
這個需要建立一個數據庫和配置數據源才能夠正常保存游戲游戲記錄
如果沒有數據庫的話,執行起來沒有問題,
但是在猜中之后,數據不能保存
而且會報跟數據庫相關的錯誤。。。
不過對于初學來說,足夠了。。。
//猜數字游戲
//版本1.1
//作者:lymeng
//創建時間 2008/10/10
//最后修改時間 2008/10/14
import java.io.*;
import java.sql.*;
public class caishuzi
{
public static void main(String args[])
{
int suijishu; //產生的隨機數
String name; //玩家的名字
int nandu=-1; //選擇的難度
int caice=-1; //玩家所猜測的數字
int point=0; //記錄玩家猜測的次數
int a; //判斷是否保存信息成功
boolean fac=true;
String str;//用來判斷是否啟用了秘籍
shuru sr=new shuru();
zhuanhuan zh=new zhuanhuan();
baocun bc=new baocun();
suijishu sjs=new suijishu();
System.out.print("請輸入你的名字:");
name=sr.xinxi();
System.out.println("歡迎"+name+"來到猜數字的世界,請輸入整數");
System.out.println("數字越大 難度越高!");
System.out.print("難度: ");
while(fac)
{
nandu=zh.zhuanhuan1(sr.xinxi());
if(nandu-1)
{
System.out.print("你選擇的難度為:"+nandu);
fac=false;
}
else
{
System.out.println("請選擇正確的難度");
System.out.print("難度: ");
}
}
suijishu=sjs.suiji(nandu);
while(!fac)
{
System.out.print("請輸入你要猜測的數字: ");
str=sr.xinxi();
if(str.equals("lymeng"))
{System.out.println("正確數字是: "+suijishu);}
else
caice=zh.zhuanhuan1(str);
if(caice-1)
{
if(suijishu==caice)
{
System.out.println("恭喜你 猜對啦!");
point++;
//將玩家資料保存到數據庫中
a=bc.charu(name,point,nandu);
if(a-1)
System.out.println("信息保存成功");
else
System.out.println("信息保存失敗");
break;
}
else if(suijishucaice)
{
System.out.println("太小了!請重新輸入!");
point++;
}
else
{
System.out.println("太大了!請重新輸入!");
point++;
}
System.out.println("你已經猜測了"+point+"次");
}
else
{
System.out.println("請輸入一個正確的數字");
}
}
}
}
//根據難度產生隨機數
class suijishu
{
public int suiji(int a)
{
int realnum;
realnum=(int)(Math.random()*50*a);
return realnum;
}
}
//記錄鍵盤得到的信息
class shuru
{
private String str;
public String xinxi()
{
try{
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
str=bf.readLine();
str=str.trim();
}catch(Exception ex)
{System.out.println("出錯啦笨蛋");}
return str;
}
}
//將鍵盤輸入的字符轉換為數字
class zhuanhuan
{
private int a;
public int zhuanhuan1(String str)
{
try{
a=Integer.parseInt(str);
return a;
}catch(Exception ex){return -1;}
}
}
class baocun
{
public int charu(String name,int point,int nandu)
{
int a=-1;
String sql;
Connection con=null;
PreparedStatement ps=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:caishuzi");
sql="insert into user(uname,cishu,nandu) values(?,?,?)";
ps = con.prepareStatement(sql);
ps.setString(1, name);
ps.setInt(2, point);
ps.setInt(3, nandu);
a=ps.executeUpdate();
//System.out.println("aaaaaaa");
ps.close();
con.close();
}catch(Exception ex)
{System.out.println("儲存出錯啦!");
ex.printStackTrace();
}
return a;
}
}
java項目的大小衡量標準:
微型:只是一個人,甚至是半日工作在幾天內完成的軟件; ?
小型:一個人半年內完成的?2000?行以內的程序;
中型:?5?個人在?1?年多的時間內完成的?5000-50000?行的程序;
大型:?5-10?人在兩年內完成的?50000-100000?行的程序;
甚大型:?100-1000?人參加用?4-5?年完成的具有?100?,?0000?行的軟件項目;
極大型:?2000-5000?人參加,?10?年內完成的?1000?萬行以內的程序;
以上摘自:《軟件工程概論》???鄭人杰、殷人民編
這樣的觀點是以代碼行作為計量標準的,認為代碼行多的自然項目也就大了。
我有計算器程序
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashMap;
/**
* 我的計算器。MyCalculator 繼承于 JFrame,是計算器的界面
*/
public class Calculator extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private Border border = BorderFactory.createEmptyBorder(5, 5, 5, 5);
private JTextField textbox = new JTextField("0");
private CalculatorCore core = new CalculatorCore();
private ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
JButton b = (JButton) e.getSource();
String label = b.getText();
String result = core.process(label);
textbox.setText(result);
}
};
public Calculator(String title) throws HeadlessException {
super(title); // 調用父類構造方法
setupFrame(); // 調整窗體屬性
setupControls(); // 創建控件
}
private void setupControls() {
setupDisplayPanel(); // 創建文本面板
setupButtonsPanel(); // 創建按鈕面板
}
// 創建按鈕面板并添加按鈕
private void setupButtonsPanel() {
JPanel panel = new JPanel();
panel.setBorder(border);
panel.setLayout(new GridLayout(4, 5, 3, 3));
createButtons(panel, new String[]{
"7", "8", "9", "+", "C",
"4", "5", "6", "-", "CE",
"1", "2", "3", "*", "", // 空字符串表示這個位置沒有按鈕
"0", ".", "=", "/", ""
});
this.add(panel, BorderLayout.CENTER);
}
/**
* 在指定的面板上創建按鈕
*
* @param panel 要創建按鈕的面板
* @param labels 按鈕文字
*/
private void createButtons(JPanel panel, String[] labels) {
for (String label : labels) {
// 如果 label 為空,則表示創建一個空面板。否則創建一個按鈕。
if (label.equals("")) {
panel.add(new JPanel());
} else {
JButton b = new JButton(label);
b.addActionListener(listener); // 為按鈕添加偵聽器
panel.add(b);
}
}
}
// 設置顯示面板,用一個文本框來作為計算器的顯示部分。
private void setupDisplayPanel() {
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.setBorder(border);
setupTextbox();
panel.add(textbox, BorderLayout.CENTER);
this.add(panel, BorderLayout.NORTH);
}
// 調整文本框
private void setupTextbox() {
textbox.setHorizontalAlignment(JTextField.RIGHT); // 文本右對齊
textbox.setEditable(false); // 文本框只讀
textbox.setBackground(Color.white); // 文本框背景色為白色
}
// 調整窗體
private void setupFrame() {
this.setDefaultCloseOperation(EXIT_ON_CLOSE); // 當窗體關閉時程序結束
this.setLocation(100, 50); // 設置窗體顯示在桌面上的位置
this.setSize(300, 200); // 設置窗體大小
this.setResizable(false); // 窗體大小固定
}
// 程序入口
public static void main(String[] args) throws Exception {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
Calculator frame = new Calculator("我的計算器");
frame.setVisible(true); // 在桌面上顯示窗體
}
}
/**
* 計算器核心邏輯。這個邏輯只能處理 1~2 個數的運算。
*/
class CalculatorCore {
private String displayText = "0"; // 要顯示的文本
boolean reset = true;
int MaxLen = 30;
private BigDecimal number1, number2;
private String operator;
private HashMapString, Operator operators = new HashMapString, Operator();
private HashMapString, Processor processors = new HashMapString, Processor();
CalculatorCore() {
setupOperators();
setupProcessors();
}
// 為每種命令添加處理方式
private void setupProcessors() {
processors.put("[0-9]", new Processor() {
public void calculate(String command) {
numberClicked(command);
}
});
processors.put("\\.", new Processor() {
public void calculate(String command) {
dotClicked();
}
});
processors.put("=", new Processor() {
public void calculate(String command) {
equalsClicked();
}
});
processors.put("[+\\-*/]", new Processor() {
public void calculate(String command) {
operatorClicked(command);
}
});
processors.put("C", new Processor() {
public void calculate(String command) {
clearClicked();
}
});
processors.put("CE", new Processor() {
public void calculate(String command) {
clearErrorClicked();
}
});
}
// 為每種 operator 添加處理方式
private void setupOperators() {
operators.put("+", new Operator() {
public BigDecimal process(BigDecimal number1, BigDecimal number2) {
return number1.add(number2);
}
});
operators.put("-", new Operator() {
public BigDecimal process(BigDecimal number1, BigDecimal number2) {
return number1.subtract(number2);
}
});
operators.put("*", new Operator() {
public BigDecimal process(BigDecimal number1, BigDecimal number2) {
return number1.multiply(number2);
}
});
operators.put("/", new Operator() {
public BigDecimal process(BigDecimal number1, BigDecimal number2) {
return number1.divide(number2, 30, RoundingMode.HALF_UP);
}
});
}
// 根據命令處理。這里的命令實際上就是按鈕文本。
public String process(String command) {
for (String pattern : processors.keySet()) {
if (command.matches(pattern)) {
processors.get(pattern).calculate(command);
break;
}
}
return displayText;
}
// 當按下 CE 時
private void clearErrorClicked() {
if (operator == null) {
number1 = null;
} else {
number2 = null;
}
displayText = "0";
reset = true;
}
// 當按下 C 時,將計算器置為初始狀態。
private void clearClicked() {
number1 = null;
number2 = null;
operator = null;
displayText = "0";
reset = true;
}
// 當按下 = 時
private void equalsClicked() {
calculateResult();
number1 = null;
number2 = null;
operator = null;
reset = true;
}
// 計算結果
/**
*
*/
private void calculateResult() {
number2 = new BigDecimal(displayText);
Operator oper = operators.get(operator);
if (oper != null) {
try {
BigDecimal result = oper.process(number1, number2);
displayText = result.toString();
} catch (RuntimeException e) {
clearClicked();//將計算器置為初始狀態
JOptionPane.showMessageDialog(null,"不能用零作除數","出錯了",JOptionPane.OK_OPTION);
//e.printStackTrace();
}
}
}
// 當按下 +-*/ 時(這里也可以擴展成其他中間操作符)
private void operatorClicked(String command) {
if (operator != null) {
calculateResult();
}
number1 = new BigDecimal(displayText);
operator = command;
reset = true;
}
// 當按下 . 時
private void dotClicked() {
if (displayText.indexOf(".") == -1) {
displayText += ".";
} else if (reset) {
displayText = "0.";
}
reset = false;
}
// 當按下 0-9 時
private void numberClicked(String command) {
if (reset) {
displayText = command;
} else {
if(displayText.length() MaxLen)
displayText += command;
else
JOptionPane.showMessageDialog(null,"輸入的數字太長了","出錯了",JOptionPane.OK_OPTION);
}
reset = false;
}
// 運算符處理接口
interface Operator {
BigDecimal process(BigDecimal number1, BigDecimal number2);
}
// 按鈕處理接口
interface Processor {
void calculate(String command);
}
}
import?java.awt.Color;
import?java.awt.Graphics;
import?java.awt.Toolkit;
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?java.awt.event.InputEvent;
import?java.awt.event.KeyEvent;
import?java.awt.event.KeyListener;
import?javax.swing.JCheckBoxMenuItem;
import?javax.swing.JFrame;
import?javax.swing.JMenu;
import?javax.swing.JMenuBar;
import?javax.swing.JMenuItem;
import?javax.swing.JOptionPane;
import?javax.swing.KeyStroke;
public?class?貪吃蛇?extends?JFrame?implements?ActionListener,?KeyListener,Runnable?{
private?static?final?long?serialVersionUID?=?1L;//表明實現序列化類的不同版本間的兼容性默認的是1L,不加有異常。
private?JMenuBar?menuBar;
private?JMenu?youXiMenu,nanDuMenu,fenShuMenu,guanYuMenu;
private?JMenuItem?kaiShiYouXi,exitItem,zuoZheItem,fenShuItem;
private?JCheckBoxMenuItem?cJianDan,cPuTong,cKunNan;
private?int?length?=?6;
private?Toolkit?toolkit;
private?int?i,x,y,z,objectX,objectY,object=0,growth=0,time;//bojecx,y是食物的坐標z為蛇前進方向。。
private?int?m[]=new?int[50];
private?int?n[]=new?int[50];
private?Thread?she?=?null;?//靜態對象蛇
private?int?life=0;?//初始化變量?食物分數
private?int?foods?=?0;
private?int?fenshu=0;
public?void?run(){
time=500;
for(i=0;i=length-1;i++){
m[i]=90-i*10;n[i]=60;
}
x=m[0];
y=n[0];
z=4;
while(she!=null){
check();
try{
Thread.sleep(time);
}catch(Exception?ee){
System.out.println(z+"");
}
}
}
public?貪吃蛇()?{
//創建新的對象
setVisible(true);
menuBar?=?new?JMenuBar();
toolkit=getToolkit();
//設計界面元素?游戲菜單對象
youXiMenu?=?new?JMenu("游戲菜單");
kaiShiYouXi?=?new?JMenuItem("開始游戲");
exitItem?=?new?JMenuItem("退出游戲");
//游戲困難對象
nanDuMenu?=?new?JMenu("困難程度");
cJianDan?=?new?JCheckBoxMenuItem("簡單");
cPuTong?=?new?JCheckBoxMenuItem("普通");
cKunNan?=?new?JCheckBoxMenuItem("困難");
//游戲分數菜單對象
fenShuMenu?=?new?JMenu("積分排行");
fenShuItem?=?new?JMenuItem("最高記錄");
//關于對象菜單
guanYuMenu?=?new?JMenu("關于");
zuoZheItem?=?new?JMenuItem("關于作者");
//設置關于作者菜單
guanYuMenu.add(zuoZheItem);?//關于作者
//關于困難程度菜單
nanDuMenu.add(cJianDan);?//難度簡單
nanDuMenu.add(cPuTong);?//普通
nanDuMenu.add(cKunNan);?//困難
//關于游戲菜單欄
fenShuMenu.add(fenShuItem);?//設置分數欄
youXiMenu.add(kaiShiYouXi);?//?設置加開始游戲欄
youXiMenu.add(exitItem);?//?設置游戲結束欄
menuBar.add(youXiMenu);?//設置?游戲菜單欄
menuBar.add(nanDuMenu);?//設置困難程度菜單欄
menuBar.add(fenShuMenu);?//設置分數(積分)菜單欄
menuBar.add(guanYuMenu);?//設置關于菜單欄
zuoZheItem.addActionListener(this);?//監聽注冊
kaiShiYouXi.addActionListener(this);
exitItem.addActionListener(this);
addKeyListener(this);?//添加指定的按鍵偵聽器,以接收發自此組件的按鍵事件
fenShuItem.addActionListener(this);
//設置?游戲快捷鍵
KeyStroke?keyOpen?=?KeyStroke.getKeyStroke('O',InputEvent.CTRL_DOWN_MASK);
kaiShiYouXi.setAccelerator(keyOpen);
KeyStroke?keyExit?=?KeyStroke.getKeyStroke('X',InputEvent.CTRL_DOWN_MASK);
exitItem.setAccelerator(keyExit);
//設置游戲框架
setJMenuBar(menuBar);
setTitle("貪吃蛇");
setResizable(false);
setBounds(300,200,400,400);
validate();?//驗證有效性
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public?static?void?main(String?args[])?{
new?貪吃蛇();//菜單監聽
}
public?void?actionPerformed(ActionEvent?e){
if(e.getSource()==kaiShiYouXi){?//菜單監聽點擊開始游戲
length?=?6;?//設置貪吃蛇的初始長度大小為?6個方塊
life?=?0;?//生命?即分數為0
foods?=?0;?//所吃食物為0
if(she==null){
she=new?Thread(this);
she.start();
}else?if(she!=null){
she=null;
she=?new?Thread(this);
she.start();
}
}
if(e.getSource()==exitItem){
System.exit(0);
}
if(e.getSource()==zuoZheItem){
JOptionPane.showMessageDialog(this,?"等制作"+"\n\n"+"?"+"上下左右控制沒有暫停哦"+"\n");
}
if(e.getSource()==fenShuItem){
JOptionPane.showMessageDialog(this,"最高記錄為"+fenshu+"");
}
}
//測試一下
public?void?check(){
isDead();
if(she!=null){
if(growth==0){
reform();?//得到食物
}else{
upgrowth();?//生成食物
}
if(x==objectXy==objectY){
object=0;
growth=1;
toolkit.beep();
}
//食物坐標
if(object==0){
object=1;
objectX=(int)Math.floor(Math.random()*39)*10;
objectY=(int)Math.floor(Math.random()*29)*10+50;
}
this.repaint();?//重新生成食物
}
}
void?isDead(){
//判斷游戲是否結束的方法
if(z==4){?//Z代表蛇的移動方向?x?y代表物體坐標?設置了x?y?窗口大小(判斷蛇是否吃到食物)
x=x+10;
}else?if(z==3){
x=x-10;
}else?if(z==2){
y=y+10;
}else?if(z==1){
y=y-10;
}
if(x0||x390||y50||y390){?//判斷是否撞墻
she=null;
}
for(i=1;ilength;i++){
if(m[i]==xn[i]==y){
she=null;
}
}
}
public?void?upgrowth(){
//當蛇吃到東西時的方法
if(length50){
length++;?//長度累加
}
growth--;
time=time-10;?//當蛇吃到一個?時間打九折?懂????吃的越多蛇運動的越快
reform();
life+=100;
if(fenshulife){
fenshu?=?life;//分數就是吃一個食物給一百分。。。
}
foods++;
}
public?void?reform(){
for(i=length-1;i0;i--){?//?更新蛇的每一節坐標?依次把前一節付給下一節移動坐標
m[i]=m[i-1];
n[i]=n[i-1];
}
if(z==4){
m[0]=m[0]+10;
}
if(z==3){
m[0]=m[0]-10;
}
if(z==2){
n[0]=n[0]+10;
}
if(z==1){
n[0]=n[0]-10;
}
}
public?void?keyPressed(KeyEvent?e){?//按下鍵盤方向鍵
//?z代表蛇的移動方向?設置方向快捷鍵
if(she!=null){
if(e.getKeyCode()==KeyEvent.VK_UP){?//上鍵
if(z!=2){?//先前方向不為左
z=1;
check();
}
}else?if(e.getKeyCode()==KeyEvent.VK_DOWN){?//下
if(z!=1){
z=2;
check();
}
}else?if(e.getKeyCode()==KeyEvent.VK_LEFT){?//左
if(z!=4){
z=3;
check();
}
}else?if(e.getKeyCode()==KeyEvent.VK_RIGHT){?//右
if(z!=3){
z=4;
check();
}
}
}
}
public?void?keyReleased(KeyEvent?e){
}
public?void?keyTyped(KeyEvent?e){
}
//在面板上繪制界面
public?void?paint(Graphics?g)?{
g.setColor(Color.blue);?//設置背景?顏色
g.fillRect(0,50,400,400);
g.setColor(Color.yellow);//設置蛇的顏色
for(i=0;i=length-1;i++){
g.fillRect(m[i],n[i],10,10);?//食物的位置
}
g.setColor(Color.green);?//蛇的食物?的顏色
g.fillRect(objectX,objectY,10,10);?//蛇的初始位置
g.setColor(Color.white);
g.drawString("當前?分數"+this.life,6,60);
g.drawString("當前已吃食物數"+this.foods,6,72);
}
}