📄 testgame.java
字号:
package de.tsr.jsol.game;
import javax.microedition.lcdui.*;
import de.tsr.jsol.logic.*;
import de.tsr.jsol.util.*;
public class TestGame extends Game {
private ScoreCounter _scoreCounter = new ScoreCounter();
private CardWaste _waste;
private CardStack _stack;
private int _horizontalCardDistance = 0;
private int _verticalCardDistance = 2;
private int _screenWidth;
private int _screenHeight;
private CardFoundation _f1;
private CardFoundation _f2;
private CardFoundation _f3;
private CardFoundation _f4;
private CardTableau _t1;
private CardTableau _t2;
private CardTableau _t3;
private CardTableau _t4;
private CardTableau _t5;
private CardTableau _t6;
public TestGame( int screenWidth, int screenHeight ) {
CalculateCardSizeAndDistances(screenWidth, screenHeight );
_screenHeight = screenHeight;
_screenWidth = screenWidth;
_waste = new CardWaste( Card.width + _horizontalCardDistance , 0 );
_stack = new CardStack( 0, 0, _waste );
_f1 = new CardFoundation( ( Card.width +
_horizontalCardDistance )*2, 0, _scoreCounter);
_f2 = new CardFoundation( ( Card.width +
_horizontalCardDistance )*3, 0, _scoreCounter);
_f3 = new CardFoundation( ( Card.width +
_horizontalCardDistance )*4, 0, _scoreCounter);
_f4 = new CardFoundation( ( Card.width +
_horizontalCardDistance )*5, 0, _scoreCounter);
_t1 = new CardTableau( 0, Card.height + _verticalCardDistance,
_verticalCardDistance );
_t2 = new CardTableau( Card.width + _horizontalCardDistance,
Card.height + _verticalCardDistance, _verticalCardDistance );
_t3 = new CardTableau( ( Card.width + _horizontalCardDistance )*2,
Card.height + _verticalCardDistance, _verticalCardDistance);
_t4 = new CardTableau( ( Card.width + _horizontalCardDistance )*3,
Card.height + _verticalCardDistance, _verticalCardDistance);
_t5 = new CardTableau( ( Card.width + _horizontalCardDistance )*4,
Card.height + _verticalCardDistance, _verticalCardDistance);
_t6 = new CardTableau( ( Card.width + _horizontalCardDistance )*5,
Card.height + _verticalCardDistance, _verticalCardDistance);
PackOfCards cards = new PackOfCards();
cards.Shuffle();
Card c = cards.GetCard().TurnToFront();
_t1.Push( c );
_t2.Push( cards.GetCard() );
c = cards.GetCard().TurnToFront();
_t2.Push( c );
_t3.Push( cards.GetCard() );
_t3.Push( cards.GetCard() );
c = cards.GetCard().TurnToFront();
_t3.Push( c );
_t4.Push( cards.GetCard() );
_t4.Push( cards.GetCard() );
_t4.Push( cards.GetCard() );
c = cards.GetCard().TurnToFront();
_t4.Push( c );
_t5.Push( cards.GetCard() );
_t5.Push( cards.GetCard() );
_t5.Push( cards.GetCard() );
_t5.Push( cards.GetCard() );
c = cards.GetCard().TurnToFront();
_t5.Push( c );
_t6.Push( cards.GetCard() );
_t6.Push( cards.GetCard() );
_t6.Push( cards.GetCard() );
_t6.Push( cards.GetCard() );
_t6.Push( cards.GetCard() );
c = cards.GetCard().TurnToFront();
_t6.Push( c );
while( cards.HasMoreCards()) {
_stack.AddCard(cards.GetCard());
}
_cursorPosition = _stack;
ConnectLeftRight( _stack, _waste );
ConnectLeftRight( _waste, _f1 );
ConnectLeftRight( _f1, _f2 );
ConnectLeftRight( _f2, _f3 );
ConnectLeftRight( _f3, _f4 );
ConnectLeftRight( _f4, _stack );
ConnectLeftRight( _t1, _t2 );
ConnectLeftRight( _t2, _t3 );
ConnectLeftRight( _t3, _t4 );
ConnectLeftRight( _t4, _t5 );
ConnectLeftRight( _t5, _t6 );
ConnectLeftRight( _t6, _t1 );
ConnectUpDown( _stack, _t1 );
ConnectUpDown( _t1, _stack );
ConnectUpDown( _waste, _t2 );
ConnectUpDown( _t2, _waste );
ConnectUpDown( _f1, _t3 );
ConnectUpDown( _t3, _f1 );
ConnectUpDown( _f2, _t4 );
ConnectUpDown( _t4, _f2 );
ConnectUpDown( _f3, _t5 );
ConnectUpDown( _t5, _f3 );
ConnectUpDown( _f4, _t6 );
ConnectUpDown( _t6, _f4 );
_waste.AddSingleClickDestination(_f1);
_waste.AddSingleClickDestination(_f2);
_waste.AddSingleClickDestination(_f3);
_waste.AddSingleClickDestination(_f4);
_t1.AddSingleClickDestination(_f1);
_t1.AddSingleClickDestination(_f2);
_t1.AddSingleClickDestination(_f3);
_t1.AddSingleClickDestination(_f4);
_t2.AddSingleClickDestination(_f1);
_t2.AddSingleClickDestination(_f2);
_t2.AddSingleClickDestination(_f3);
_t2.AddSingleClickDestination(_f4);
_t3.AddSingleClickDestination(_f1);
_t3.AddSingleClickDestination(_f2);
_t3.AddSingleClickDestination(_f3);
_t3.AddSingleClickDestination(_f4);
_t4.AddSingleClickDestination(_f1);
_t4.AddSingleClickDestination(_f2);
_t4.AddSingleClickDestination(_f3);
_t4.AddSingleClickDestination(_f4);
_t5.AddSingleClickDestination(_f1);
_t5.AddSingleClickDestination(_f2);
_t5.AddSingleClickDestination(_f3);
_t5.AddSingleClickDestination(_f4);
_t6.AddSingleClickDestination(_f1);
_t6.AddSingleClickDestination(_f2);
_t6.AddSingleClickDestination(_f3);
_t6.AddSingleClickDestination(_f4);
}
public void Paint( Graphics g ) {
_stack.Paint( g );
_waste.Paint( g );
_f1.Paint( g );
_f2.Paint( g );
_f3.Paint( g );
_f4.Paint( g );
_t1.Paint( g );
_t2.Paint( g );
_t3.Paint( g );
_t4.Paint( g );
_t5.Paint( g );
_t6.Paint( g );
g.setColor(0,0,0);
g.drawString("Score: " + _scoreCounter.Score(), 0,
_screenHeight- g.getFont().getHeight(), Card.textLocation);
}
public boolean isGameWon() {
Card c1 = _f1.CardOnTop();
Card c2 = _f2.CardOnTop();
Card c3 = _f3.CardOnTop();
Card c4 = _f4.CardOnTop();
if( c1 != null && c1.Rank() == Card.KING
&& c2 != null && c2.Rank() == Card.KING
&& c3 != null && c3.Rank() == Card.KING
&& c4 != null && c4.Rank() == Card.KING
) {
return true;
}
return false;
}
public Position CursorPosition() {
return _cursorPosition.GetCursorPosition();
}
private void CalculateCardSizeAndDistances( int screenWidth, int screenHeight ) {
if( screenWidth/ 6 > 14 ) {
Card.width = 14;
_horizontalCardDistance = screenWidth / 6 - Card.width;
}
else {
Card.width = screenWidth / 6;
_horizontalCardDistance = 0;
}
if( screenHeight > 100 ) {
_verticalCardDistance = 7;
Card.height = 20;
}
else if( screenHeight > 75 ) {
_verticalCardDistance = 5;
Card.height = 10;
}
else {
_verticalCardDistance = 2;
Card.height = 7;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -