PS:您必须从http中取出()的链接,因为我没有足够的重复点或其他东西。
董事会:
package game;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Board extends JPanel implements ActionListener {
Turn_Ticker turn = new Turn_Ticker();
Bank bank = new Bank();
Image Background;
Timer timer;
String time="";
public Board() {
setFocusable(true);
ImageIcon icon = new ImageIcon("res/Level1.png"); // calls image for background
Background = icon.getImage(); // sets variable background to icon image
timer = new Timer(5,this); // sets how fast page refreshes
timer.start();
}
public void actionPerformed(ActionEvent event) { // Refreshes page according to timer
repaint();
}
public void paint(Graphics paint) { // paints on frame
super.paint(paint);
Graphics2D p = (Graphics2D) paint;
turn.getTick();
bank.subBank();
p.drawImage(Background, 0, 0, null);
p.drawString(bank.getBank()+"",125,70);
p.drawString(bank.getEnemy_Bank()+"",125,115);
p.drawString(turn.getSecond()+" Second(s) Turn: "+turn.getTurn(), 120, 200);
if(turn.getTick())
p.drawString("Ticker = true", 500,500);/*
if(turn.getNum()==0)
p.drawString("Number = 0", 500,550);
if(turn.getNum()==0&&turn.getTick()){
bank.subBank();
p.drawString("Both are =", 500, 600);
}*/
//System.out.println("X: "+mouse.getX()+" Y: "+mouse.getY());
}
}
Turn_Ticker:
package game;
public class Turn_Ticker {
long before,after,difference;
boolean checkTime=true;
int seconds=0;
boolean ticker=false;
int turn=1;
int num=0;
public Turn_Ticker(){
if (checkTime == true)
before=System.currentTimeMillis();
checkTime=false;
}
public int getSecond() {
after=System.currentTimeMillis();
difference= after-before;
if(difference >= 1000) {
before=System.currentTimeMillis();
if(seconds<=0) {
seconds=30;
ticker=true;
num=0;
}
else {
seconds-=1;
num=1;
ticker=false;
}
}
return seconds;
}
public boolean getTick() {
if(ticker&&num==0) {
turn++;
}
return ticker;
}
public int getNum(){
return num;
}
public int getTurn() {
return turn;
}
public boolean getTickVar(){
return ticker;
}
}
行:
package game;
public class Bank {
Turn_Ticker turn = new Turn_Ticker();
int bank=5, enemy_Bank=5;
int baseRein=3, reinforcements,num=0;
public Bank(){
if(turn.getTick()==false)
num=0;
}
public int getBank(){
return bank;
}
public int getEnemy_Bank(){
return enemy_Bank;
}
public void subBank(){
if(turn.getNum()==0&&turn.getTick())
bank--;
}
public void subEn_Bank(){
enemy_Bank-=1;
}
}
框:
package game;
import javax.swing.*;
import java.awt.Font;
public class Frame {
public Frame() {
JFrame frame = new JFrame();
frame.add(new Board());
frame.setTitle("WSMD");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1024,768);
frame.setVisible(true);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.setLocationRelativeTo(null);
}
public static void main(String[] args){
new Frame();
}
}
我的问题是,在我的生活中,我不能弄明白为什么它不会从银行中减去-1(bank.subBank())
。我打印出代码并逐步完成。