id stringlengths 36 36 | text stringlengths 1 1.25M |
|---|---|
5ea86248-8b05-45e1-9d8e-a1a4b1756b72 | public Cell[] getCells() {
return cells;
} |
fd784964-443c-4064-bca9-db32429866d0 | public Board() {
// Initialize blocks and cells
this.blocks = new Block[9];
for (int index = 0; index < this.blocks.length; index++) {
this.blocks[index] = new Block();
}
// Create cell map
this.cells = new Cell[9][9];
for (int blockIndex = 0; blockIndex < 9; blockIndex++) {
Block block = this.blocks[blockIndex];
for (int cellIndex = 0; cellIndex < 9; cellIndex++) {
Cell cell = block.getCells()[cellIndex];
int row = this.getCellRow(blockIndex, cellIndex);
int column = this.getCellColumn(blockIndex, cellIndex);
this.cells[row][column] = cell;
}
}
} |
04a8ba50-94dd-434c-94f7-df179bd479c8 | public Block[] getBlocks() {
return this.blocks;
} |
78c512fc-4e0c-4b89-8d3d-3fc006740a6d | public Cell[][] getCells() {
return this.cells;
} |
bd4143ca-8bf8-406e-9a47-2e832dd889f3 | public void updateCellPosibilities() {
int blockIndex = 0;
for (Block block : this.getBlocks()) {
int cellIndex = 0;
for (Cell cell : block.getCells()) {
if (cell.getValue() != Cell.Empty) {
continue;
}
for (int value : this.getValuesInBlock(block)) {
cell.removeValuePossibility(value);
}
for (int value : this.getValuesInHorizontal(blockIndex, cellIndex)) {
cell.removeValuePossibility(value);
}
for (int value : this.getValuesInVertical(blockIndex, cellIndex)) {
cell.removeValuePossibility(value);
}
cellIndex++;
}
blockIndex++;
}
} |
fcb104d1-415a-413c-81d6-e21837b9f848 | public String printBoard() {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
Cell cell = this.cells[i][j];
builder.append(cell.getValue());
builder.append(" ");
}
builder.append("\r\n");
}
return builder.toString();
} |
e016d835-7645-48ec-bd9a-98dc6c72e2f8 | public String printCellPosibilities() {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
Cell cell = this.cells[i][j];
builder.append(cell.getValuePossibilities().toString());
builder.append("\t");
}
builder.append("\r\n");
}
return builder.toString();
} |
3964dbf0-9563-4915-9b92-150ea5944b70 | private ArrayList<Integer> getValuesInBlock(Block block) {
ArrayList<Integer> values = new ArrayList<Integer>();
for (Cell cell : block.getCells()) {
int cellValue = cell.getValue();
if (cellValue != Cell.Empty) {
values.add(cellValue);
}
}
return values;
} |
9cccae49-ffbd-47d1-83c1-364d9b5f0ed3 | private ArrayList<Integer> getValuesInHorizontal(int blockIndex, int cellIndex) {
ArrayList<Integer> values = new ArrayList<Integer>();
int row = this.getCellRow(blockIndex, cellIndex);
for (int column = 0; column < 9; column++) {
Cell cell = this.cells[row][column];
int cellValue = cell.getValue();
if (cellValue != Cell.Empty) {
values.add(cellValue);
}
}
return values;
} |
35fee2cc-2559-49b3-a6ad-d7b09929ad2a | private ArrayList<Integer> getValuesInVertical(int blockIndex, int cellIndex) {
ArrayList<Integer> values = new ArrayList<Integer>();
int column = this.getCellColumn(blockIndex, cellIndex);
for (int row = 0; row < 9; row++) {
Cell cell = this.cells[row][column];
int cellValue = cell.getValue();
if (cellValue != Cell.Empty) {
values.add(cellValue);
}
}
return values;
} |
9bd7b361-7363-4e56-a456-9a03ac41a38d | private int getCellRow(int blockIndex, int cellIndex) {
int row = (blockIndex / 3) * 3;
row += (cellIndex / 3);
return row;
} |
42a029f3-97f0-45dd-adc0-3c6617bf98cd | private int getCellColumn(int blockIndex, int cellIndex) {
int column = (blockIndex % 3) * 3;
column += (cellIndex % 3);
return column;
} |
2c0c3a33-8e65-47e0-bbac-11c54e829bff | public Cell() {
this.value = Cell.Empty;
this.valuePossibilities = new ArrayList<>();
this.initializeValuePossibilities();
} |
91988d07-9695-4478-b54f-a0e930c5f413 | public int getValue() {
return this.value;
} |
f3ccc5e6-c311-42e8-a40e-b11b03db023b | public void setValue(int value) {
if (value < 0 || value > 9) {
throw new IllegalArgumentException("the value of the Cell should be between 0 and 9");
}
this.value = value;
this.onValueChanged();
} |
ba53588b-8ce4-49ec-8bb4-6aab8f365e95 | public void clearValue() {
this.value = Cell.Empty;
this.valuePossibilities.clear();
this.initializeValuePossibilities();
} |
02dc2fda-1d93-496f-9831-429232e2b8ee | public Block getBlock() {
return block;
} |
c17247fe-cf5d-4e99-9684-370871ec6da9 | public ArrayList<Integer> getValuePossibilities() {
return valuePossibilities;
} |
f7847243-1d5d-41a1-9e6f-f60d742451bc | public void addValuePossibility(int valuePossibility) {
if (valuePossibility < 1 || valuePossibility > 9) {
throw new IllegalArgumentException("the value posibility should be between 1 and 9");
}
if (!this.valuePossibilities.contains(valuePossibility)) {
this.valuePossibilities.add(valuePossibility);
}
} |
cee76153-3350-437d-95e8-2d2a8543c2b4 | public void removeValuePossibility(int valuePossibility) {
if (valuePossibility < 1 || valuePossibility > 9) {
throw new IllegalArgumentException("the value posibility should be between 1 and 9");
}
this.valuePossibilities.remove((Object)valuePossibility);
} |
58cb4c89-6ad3-4798-b398-ecbcea81bada | protected void onValueChanged() {
this.valuePossibilities.clear();
if (this.value == Cell.Empty) {
this.clearValue();
}
} |
bba613c5-9e3b-4b81-a9a2-71df700c35b6 | private void initializeValuePossibilities() {
for (int i = 1; i < 10; i++) {
this.valuePossibilities.add(i);
}
} |
7b511bc3-c4f1-4141-a3e7-fb783a22a181 | public static void main(String[] args) {
JFrame window = new JFrame("SudokuSolver");
window.setSize(600, 600);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
final JSudokuBoard board = new JSudokuBoard();
p.add(board);
JButton button = new JButton("Calculate posibilities");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
board.getBoard().updateCellPosibilities();
}
});
p.add(button);
JButton button2 = new JButton("Print posibilities");
button2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.print(board.getBoard().printCellPosibilities());
}
});
p.add(button2);
window.add(p);
window.setVisible(true);
} |
57772b0f-0c4b-414c-a307-75adc502484e | @Override
public void actionPerformed(ActionEvent e) {
board.getBoard().updateCellPosibilities();
} |
710df35f-4503-4e1f-907f-a0f336d42f30 | @Override
public void actionPerformed(ActionEvent e) {
System.out.print(board.getBoard().printCellPosibilities());
} |
38172244-3da9-462e-991b-00563c703987 | public JSudokuBoard() {
this.board = new Board();
this.initBoard();
} |
6626aa18-2a84-423e-ae0c-8fcb5b3f1200 | public Board getBoard() {
return this.board;
} |
7cd33690-241c-44d9-9d3e-60443f7387c0 | private void initBoard() {
this.setLayout(new GridLayout(3, 3));
LineBorder blockBorder = new LineBorder(Color.black, 2);
LineBorder cellBorder = new LineBorder(Color.black, 1);
for (Block block : this.board.getBlocks()) {
JPanel blockPanel = new JPanel();
blockPanel.setLayout(new GridLayout(3, 3));
blockPanel.setBorder(blockBorder);
for (final Cell cell : block.getCells()) {
final JTextField cellTextField = new JTextField();
int cellValue = cell.getValue();
if (cellValue != 0) {
cellTextField.setText(String.format("{0}", cellValue));
}
cellTextField.setBorder(cellBorder);
cellTextField.getDocument().addDocumentListener(
new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
this.updateCell();
}
@Override
public void insertUpdate(DocumentEvent e) {
this.updateCell();
}
@Override
public void changedUpdate(DocumentEvent e) {
this.updateCell();
}
private void updateCell() {
String cellText = cellTextField.getText();
int cellValue = Cell.Empty;
if (!cellText.isEmpty()) {
cellValue = Integer.parseInt(cellText);
}
cell.setValue(cellValue);
}
});
blockPanel.add(cellTextField);
}
this.add(blockPanel);
}
} |
5a2a3196-75c4-4897-88af-681c7c730cd3 | @Override
public void removeUpdate(DocumentEvent e) {
this.updateCell();
} |
32b5e441-48ce-438c-9484-872944efcf03 | @Override
public void insertUpdate(DocumentEvent e) {
this.updateCell();
} |
ee90e30a-9186-4072-959d-93481d7704ad | @Override
public void changedUpdate(DocumentEvent e) {
this.updateCell();
} |
9a43c6e2-b0ec-4554-9e2e-df99bc1e653c | private void updateCell() {
String cellText = cellTextField.getText();
int cellValue = Cell.Empty;
if (!cellText.isEmpty()) {
cellValue = Integer.parseInt(cellText);
}
cell.setValue(cellValue);
} |
4adda9ef-c134-4700-be2f-f566fbfd09a7 | public SaveGame() {
lives = 0;
score = 0;
brainX = 0;
brainY = 0;
zombieX = 0;
} |
5ff5bf7e-8207-4994-b67c-b62b9f8316d1 | public SaveGame(int l, int s, int bx, int by, int zx) {
lives = l;
score = s;
brainX = bx;
brainY = by;
zombieX = zx;
} |
1cc12147-ee91-4d20-99ac-4670739fc859 | @Override
public String toString(){
return "" + lives + ", " + score + ", " + brainX + ", " + brainY + ", " + zombieX;
} |
e34ed5c3-d2e1-4d23-a0d6-e8f93fb8a5ce | public Animacion(){
cuadros = new ArrayList();
duracionTotal = 0;
iniciar();
} |
f7c2fee7-4ae0-4649-a50d-a91486414d6b | public synchronized void sumaCuadro(Image imagen, long duracion) {
duracionTotal += duracion;
cuadros.add(new cuadroDeAnimacion(imagen, duracionTotal));
} |
7a8acdfa-1dfc-442d-90a5-8da7aa031ebf | public synchronized void iniciar(){
tiempoDeAnimacion = 0;
indiceCuadroActual = 0;
} |
2d041b9b-1fd8-41ea-b926-cf8f31fa03ea | public synchronized void actualiza(long tiempoTranscurrido) {
if (cuadros.size() > 1){
tiempoDeAnimacion += tiempoTranscurrido;
if (tiempoDeAnimacion >= duracionTotal){
tiempoDeAnimacion = tiempoDeAnimacion % duracionTotal;
indiceCuadroActual = 0;
}
while (tiempoDeAnimacion > getCuadro(indiceCuadroActual).tiempoFinal){
indiceCuadroActual++;
}
}
} |
a73b3422-e735-4531-807c-f860bba9dcc7 | public synchronized Image getImagen() {
if (cuadros.size() == 0){
return null;
}
else {
return getCuadro(indiceCuadroActual).imagen;
}
} |
4eceba05-5a70-4d99-a68c-f75364d504cd | public synchronized Image getImagen0() {
return getCuadro(0).imagen;
} |
d5cbf585-dfcb-49b2-9fb9-6e58d3a8c01b | private cuadroDeAnimacion getCuadro(int i){
return (cuadroDeAnimacion)cuadros.get(i);
} |
bf02dc55-21ba-4aa9-8f80-abe033a62873 | public cuadroDeAnimacion(){
this.imagen = null;
this.tiempoFinal = 0;
} |
57976216-1543-4ca4-b5d3-fd029cb3bac2 | public cuadroDeAnimacion(Image imagen, long tiempoFinal){
this.imagen = imagen;
this.tiempoFinal = tiempoFinal;
} |
8774c2c1-dac3-432a-b2f1-dcb0c91b4f98 | public Image getImagen(){
return imagen;
} |
ad0ac983-6465-46e4-aecb-8f8860bfdc0b | public long getTiempoFinal(){
return tiempoFinal;
} |
cdec1367-4387-4eec-b23a-d5fec13664c1 | public void setImagen (Image imagen){
this.imagen = imagen;
} |
0bfd021b-d046-45fd-9d89-a83723a59d89 | public void setTiempoFinal(long tiempoFinal){
this.tiempoFinal = tiempoFinal;
} |
2254f590-011d-46c9-9ef1-924a3c882bf4 | public int getWidth(){
if (cuadros.isEmpty()){
return -1;
}
else {
return getCuadro(indiceCuadroActual).imagen.getWidth(null);
}
} |
eab6bf28-a6dc-483c-86d5-44e834be835c | public int getHeight(){
if (cuadros.isEmpty()){
return -1;
}
else {
return getCuadro(indiceCuadroActual).imagen.getHeight(null);
}
} |
12dd7912-84df-4479-8cda-c9d3946aafaa | public SoundClip() {
try {
//crea el Buffer de sonido
clip = AudioSystem.getClip();
} catch (LineUnavailableException e) {
}
} |
a8998126-470b-4108-8628-b6310d5ae927 | public SoundClip(String filename) {
//Llama al constructor default.
this();
//Carga el archivo de sonido.
load(filename);
} |
4d93b7d8-de6f-4189-99ef-31f0ae0153a1 | public Clip getClip() {
return clip;
} |
29c82246-114f-48b9-89c7-420213c2aef9 | public void setLooping(boolean looping) {
this.looping = looping;
} |
6b7efdfe-e849-4f20-9928-455b416f9fa6 | public boolean getLooping() {
return looping;
} |
bb7d95fd-60a7-4819-8c77-907248eeb791 | public void setRepeat(int repeat) {
this.repeat = repeat;
} |
09a893fa-8607-4449-adf4-d1e1b4b1d02c | public int getRepeat() {
return repeat;
} |
1a8b6f89-453b-444f-96f7-178df895fe8d | public void setFilename(String filename) {
this.filename = filename;
} |
a96b9b75-c467-4999-a6b4-6cf512037880 | public String getFilename() {
return filename;
} |
8cd98a11-9fa0-4757-9e18-65498175af52 | public boolean isLoaded() {
return (boolean)(sample != null);
} |
b8f36dd6-63e9-4fad-ac5f-ebef4600d49b | private URL getURL(String filename) {
URL url = null;
try {
url = this.getClass().getResource(filename);
}
catch (Exception e) {
}
return url;
} |
53cd6311-2cc2-4e53-b5eb-ad4d0bdb3708 | public boolean load(String audiofile) {
try {
setFilename(audiofile);
sample = AudioSystem.getAudioInputStream(getURL(filename));
clip.open(sample);
return true;
} catch (IOException e) {
return false;
} catch (UnsupportedAudioFileException e) {
return false;
} catch (LineUnavailableException e) {
return false;
}
} |
70a7e554-f3f1-4cd4-9e0f-1fdcaca3a1ef | public void play() {
//se sale si el sonido no a sido cargado
if (!isLoaded())
return;
//vuelve a empezar el sound clip
clip.setFramePosition(0);
//Reproduce el sonido con repeticion opcional.
if (looping)
clip.loop(Clip.LOOP_CONTINUOUSLY);
else
clip.loop(repeat);
} |
833e5f42-28a5-4384-bd6d-755fcfe5f749 | public void stop() {
clip.stop();
} |
79b397e9-2870-4f75-9995-f78ae3e14273 | public TiroParabolico() {
init();
start();
} |
322ead79-a3f4-406c-a6c9-f258bd75924f | public void init() {
//Inicializacion de variables
setSize(1200,700);
lives = 5;
fallCount = -1;
score = 0;
dificultad = 1;
estado = 0;
guardar = false;
cargar = false;
sound = false;
tirando = false;
alegria = new SoundClip("resources/alegria.wav"); // Sonido cuando chocas con un malo
alegria.setLooping(false);
tristeza = new SoundClip("resources/tristeza.wav"); // Sonido cuando chocas con la pared
tristeza.setLooping(false);
background = Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("resources/background.jpg"));
// Se cargan las imágenes para la animación
Image brain1 = Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("resources/brain1.png"));
Image brain2 = Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("resources/brain2.png"));
Image brain3 = Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("resources/brain3.png"));
Image brain4 = Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("resources/brain4.png"));
Image brain5 = Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("resources/brain5.png"));
Image brain6 = Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("resources/brain6.png"));
Image brain7 = Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("resources/brain7.png"));
Image brain8 = Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("resources/brain8.png"));
Image zombie1 = Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("resources/zombieHappy1.png"));
Image zombie2 = Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("resources/zombieHappy2.png"));
Image zombie3 = Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("resources/zombieHappy3.png"));
Image zombie4 = Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("resources/zombieSad1.png"));
Image zombie5 = Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("resources/zombieSad2.png"));
// Se crea la animación
Animacion anim1 = new Animacion(), anim2 = new Animacion();
int brainFrameTime = 80, zombieFrameTime = 150;
anim1.sumaCuadro(brain1, brainFrameTime);
anim1.sumaCuadro(brain2, brainFrameTime);
anim1.sumaCuadro(brain3, brainFrameTime);
anim1.sumaCuadro(brain4, brainFrameTime);
anim1.sumaCuadro(brain5, brainFrameTime);
anim1.sumaCuadro(brain6, brainFrameTime);
anim1.sumaCuadro(brain7, brainFrameTime);
anim1.sumaCuadro(brain8, brainFrameTime);
anim2.sumaCuadro(zombie1, zombieFrameTime);
anim2.sumaCuadro(zombie2, zombieFrameTime);
anim2.sumaCuadro(zombie3, zombieFrameTime);
anim2.sumaCuadro(zombie4, zombieFrameTime);
anim2.sumaCuadro(zombie5, zombieFrameTime);
// Se agrega la animacion a los objetos
brain = new Base(0,0,anim1);
brain.setY(getHeight()-brain.getHeight());
zombie = new Base(0,552,anim2);
zombie.setX((int) ((Math.random()*600 + 408)));
setResizable(false);
setBackground(new Color(43, 48, 51));
addKeyListener(this);
addMouseListener(this);
} |
0ecfbfd8-5802-4579-81c0-b9618678a685 | public void start () {
// Declaras un hilo
Thread th = new Thread(this);
// Empieza el hilo
th.start();
} |
c5237b9c-2c63-44ba-b4df-e5cac5e18ea9 | @Override
public void run () {
while (true) {
actualiza();
checaColision();
// Se actualiza el <code>Applet</code> repintando el contenido.
repaint();
try {
// El thread se duerme.
Thread.sleep (20);
}
catch (InterruptedException ex) {
System.out.println("Error en " + ex.toString());
}
}
} |
2a11c10d-cf3d-4b5b-8e6f-ae7b828cc8cf | public void actualiza() {
if(guardar){
guardar = false;
try {
grabaArchivo();
} catch(IOException e) {
System.out.println("Error en guardar");
}
}
if(cargar){
cargar = false;
try {
leeArchivo();
} catch(IOException e) {
System.out.println("Error en cargar");
}
}
if (estado == 0) {
// Determina el tiempo que ha transcurrido desde que el Applet inicio su ejecución
long tiempoTranscurrido = System.currentTimeMillis() - tiempoActual;
// Guarda el tiempo actual
tiempoActual += tiempoTranscurrido;
// Actualiza la posicion y la animación en base al tiempo transcurrido
if (tirando) {
if (brain.getX() == 0) {
deg = (Math.random()*0.7) + 0.5;
double vel = sqrt((Math.random()*500 + 550)/sin(2*deg));
velX = vel*cos(deg);
velY = -vel*sin(deg);
}
brain.actualiza(tiempoTranscurrido);
brain.setX((int) (brain.getX()+velX*dificultad));
brain.setY((int) (brain.getY()+velY*dificultad));
velY += dificultad;
}
if (dir == 'l') {
zombie.actualiza(tiempoTranscurrido);
int newX = zombie.getX()-5;
if (newX >= getWidth()/2) {
zombie.setX(newX);
}
} else if (dir == 'r') {
zombie.actualiza(tiempoTranscurrido);
int newX = zombie.getX()+5;
if (newX <= getWidth()-zombie.getWidth()) {
zombie.setX(newX);
}
}
}
if(lives == 0){
estado = 3;
}
} |
7ad5a75d-4680-40fc-81b6-b93c36eb9124 | public void leeArchivo() throws IOException{
//Lectura del archivo el cual tiene las variables del juego guardado
BufferedReader fileIn;
try {
fileIn = new BufferedReader(new FileReader("Guardado"));
} catch (FileNotFoundException e){
File puntos = new File("Guardado");
PrintWriter fileOut = new PrintWriter(puntos);
fileOut.println("100,demo");
fileOut.close();
fileIn = new BufferedReader(new FileReader("Guardado"));
}
String dato = fileIn.readLine();
deg = (Double.parseDouble(dato));
dato = fileIn.readLine();
score = (Integer.parseInt(dato));
dato= fileIn.readLine();
tiempoActual = (Long.parseLong(dato));
dato = fileIn.readLine();
brain.setX(Integer.parseInt(dato));
dato =fileIn.readLine();
brain.setY(Integer.parseInt(dato));
dato = fileIn.readLine();
zombie.setX(Integer.parseInt(dato));
dato = fileIn.readLine();
tirando = Boolean.parseBoolean(dato);
dato = fileIn.readLine();
estado = Integer.parseInt(dato);
dato = fileIn.readLine();
velX = Double.parseDouble(dato);
dato = fileIn.readLine();
velY = Double.parseDouble(dato);
dato = fileIn.readLine();
fallCount = Integer.parseInt(dato);
fileIn.close();
} |
e13281c6-7b19-4a9c-ba9e-2cc08e8cf50a | public void grabaArchivo() throws IOException{
//Grabar las variables necesarias para reiniciar el juego de donde se quedo el usuario en un txt llamado Guardado
PrintWriter fileOut= new PrintWriter(new FileWriter("Guardado"));
fileOut.println(String.valueOf(deg));
fileOut.println(String.valueOf(score));
fileOut.println(String.valueOf(tiempoActual));
fileOut.println(String.valueOf(brain.getX()));
fileOut.println(String.valueOf(brain.getY()));
fileOut.println(String.valueOf(zombie.getX()));
fileOut.println(String.valueOf(tirando));
fileOut.println(String.valueOf(estado));
fileOut.println(String.valueOf(velX));
fileOut.println(String.valueOf(velY));
fileOut.println(String.valueOf(fallCount));
fileOut.close();
} |
df0afc21-e129-494b-ad10-363c2e7ea4b9 | public void checaColision() {
// Colision con el Applet dependiendo a donde se mueve.
if (brain.getY() + brain.getHeight() > getHeight()) {
tirando = false;
brain.setX(0);
brain.setY(getHeight()-brain.getHeight());
fallCount++;
if (fallCount == 3) {
fallCount = 0;
lives--;
dificultad += 0.5;
}
if (sound) {
tristeza.play();
}
}
// Colision entre objetos
if (zombie.intersecta(brain)) {
tirando = false;
brain.setX(0);
brain.setY(getHeight()-brain.getHeight());
score += 2;
if (sound) {
alegria.play();
}
}
} |
0e55edd8-e42b-4efc-b6c4-ff8b8ce31f18 | @Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_LEFT) { //Presiono flecha izquierda/a
dir = 'l';
} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { //Presiono flecha derecha/d
dir = 'r';
} else if (e.getKeyCode() == KeyEvent.VK_S) { //Presiono tecla s / para quitar sonido
sound = !sound;
} else if (e.getKeyCode() == KeyEvent.VK_I) {
// Mostrar/Quitar las instrucciones del juego
if(estado ==2){
estado=0;
}else{
estado =2;
}
} else if (e.getKeyCode() == KeyEvent.VK_G) { //Presiono tecla G para guardar el juego
guardar = true;
} else if (e.getKeyCode() == KeyEvent.VK_C) { //Presiono tecla C para cargar el juego
cargar = true;
} else if (e.getKeyCode() == KeyEvent.VK_P) { //Presiono tecla P para parar el juego en ejecuccion
if(estado==1){
estado=0;
}else{
estado =1;
}
}
} |
8d50c8b4-90b1-4906-b614-5bd3a2d04a86 | @Override
public void keyReleased(KeyEvent e){
//Si se deja de presionar la tecla izquierda el zombie se dejara de mover, lo mismo sucede con la tecla derecha
if (e.getKeyCode() == KeyEvent.VK_LEFT) {
dir = '.';
} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
dir = '.';
}
} |
76b6c2fe-6018-46a2-aee4-12af9d4ad5cf | @Override
public void keyTyped(KeyEvent e){} |
eb14f14d-bae9-47d1-8bf7-01d25c9f69d3 | @Override
public void mousePressed(MouseEvent e) {
// Para a brain si se le da click/vuelve a moverse
if (brain.didClickInside(e.getX(), e.getY())) {
if (!tirando) {
tirando = !tirando;
}
}
} |
ed1708d0-e82a-4988-b2b8-c0205f19bc2e | @Override
public void mouseClicked(MouseEvent e) {} |
bd0ce419-8ef2-4c97-b4ce-7aa9baaac94c | @Override
public void mouseReleased(MouseEvent e){} |
356d9d36-1aa5-4e47-99f5-66e0760fe510 | @Override
public void mouseEntered(MouseEvent e) {} |
9a34793c-ebb2-4a54-b73c-401fb47f1c9c | @Override
public void mouseExited(MouseEvent e) {} |
6fae7ab8-303c-4d71-b30c-fac88df6f7c9 | @Override
public void paint(Graphics g) {
// Inicializan el DoubleBuffer
dbImage = createImage (this.getSize().width, this.getSize().height);
dbg = dbImage.getGraphics ();
// Actualiza la imagen de fondo.
dbg.setColor(getBackground ());
dbg.fillRect(0, 0, this.getSize().width, this.getSize().height);
// Actualiza el Foreground.
dbg.setColor(getForeground());
paint1(dbg);
// Dibuja la imagen actualizada
g.drawImage (dbImage, 0, 0, this);
} |
68432e67-cf0d-43be-b3a2-e5581ed114e6 | public void paint1(Graphics g) {
g.setFont(new Font("Helvetica", Font.PLAIN, 20)); // plain font size 20
g.setColor(Color.white); // black font
if (brain != null && zombie != null) {
// Dibuja la imagen en la posicion actualizada
g.drawImage(background, 0, 0, this);
if(estado == 0){
// Dibuja el estado corriendo del juego
if (tirando) {
g.drawImage(brain.getImage(), brain.getX(),brain.getY(), this);
} else {
g.drawImage(brain.getImage0(), brain.getX(),brain.getY(), this);
}
if (dir != '.') {
g.drawImage(zombie.getImage(), zombie.getX(),zombie.getY(), this);
} else {
g.drawImage(zombie.getImage0(), zombie.getX(),zombie.getY(), this);
}
g.drawString("Score: " + String.valueOf(score), 10, 50); // draw score at (10,25)
g.drawString("Vidas: " + String.valueOf(lives), 10, 75); // draw score at (10,25)
} else if(estado == 1){
// Dibuja el estado de pausa en el jframe
g.drawString("PAUSA", getWidth()/2 - 100, getHeight()/2);
} else if(estado == 2){
// Dibuja el estado de informacion para el usuario en el jframe
g.drawString("INSTRUCCIONES", getWidth()/2 - 210, 200);
g.drawString("Para jugar debes presionar con el", getWidth()/2 - 210, 250);
g.drawString("mouse en el cerebro de la izquierda con", getWidth()/2 - 210, 280);
g.drawString("las teclas ← y → mueves el zombie.", getWidth()/2 - 210,310);
g.drawString("Se el mejor zombie y come muchos cerebros!", getWidth()/2 - 210, 340);
} else if(estado == 3){
// Dibuja el estado de creditos en el jframe
g.setColor(new Color(78, 88, 93));
g.fillRect(100, 100, getWidth() - 200, getHeight() - 200);
g.setColor(Color.white);
g.drawString("CREDITOS", getWidth()/2 - 210, 200);
g.drawString("Andres Rodriguez A00812121", getWidth()/2 - 210, 250);
g.drawString("Alejandro Sanchez A01191434", getWidth()/2 - 210, 300);
g.drawString("Manuel Sañudo A01192241", getWidth()/2 - 210, 350);
}
} else {
// Da un mensaje mientras se carga el dibujo
g.drawString("No se cargo la imagen..", 20, 20);
}
} |
019e49af-f007-4b93-9779-79cb080f02c4 | public static void main(String[] args) {
TiroParabolico examen1 = new TiroParabolico();
examen1.setVisible(true);
examen1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} |
50fd9091-4e24-49f1-89bd-9157fe5d7388 | public Base(int x, int y ,Animacion a) {
posX = x;
posY = y;
anim = a;
} |
19db0842-bdb7-438c-80c4-b6558e804a5b | public synchronized void actualiza(long t) {
anim.actualiza(t);
} |
3228cab6-d319-4709-9842-79edf389a425 | public Image getImage() {
return anim.getImagen();
} |
89b56753-c939-4de7-b9e9-d376e6c9e626 | public Image getImage0() {
return anim.getImagen0();
} |
cf365c7e-e9e2-425f-b2d9-383df24855ce | public void setX(int x) {
posX = x;
} |
a4993962-b242-4af4-95d9-842cfc5d930b | public void setY(int y) {
posY = y;
} |
566f99dd-f1e7-4ec2-bf34-57c2a8c3d078 | public void setAnimacion(Animacion a) {
anim = a;
} |
242522a2-fb39-488d-b894-5566665f1f8a | public int getX() {
return posX;
} |
33582716-578d-48a8-a83d-74902662a659 | public int getY() {
return posY;
} |
b4f44049-a794-4e83-9136-3f0187530317 | public int getWidth() {
return anim.getWidth();
} |
5e69be99-77f0-4634-8f11-95b1c929b146 | public int getHeight() {
return anim.getHeight();
} |
f7061b3c-1ca2-4811-83fe-9687fa06f8b9 | public Rectangle getPerimetro(){
return new Rectangle(getX(),getY(),getWidth(),getHeight());
} |
7a38db4a-a316-4e65-81d0-f521a41a259f | public boolean intersecta(Base obj) {
return getPerimetro().intersects(obj.getPerimetro());
} |
dd042fd3-c76a-4989-9c68-e8bfc1467117 | public boolean didClickInside(int x, int y) {
return getPerimetro().contains(new Point(x,y));
} |
8d705164-851a-4181-b815-9d83e959250e | @Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Solver");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
} |
ca89d9ff-da07-4b6b-8e47-c828f41d9682 | public static void main(String[] args) {
//launch(args);
// Lista de fatos
FactContainer initFacts = new FactContainer();
FactContainer inferedFacts = new FactContainer();
initFacts
//.addFact("P")
.addFact("J")
.addFact("L")
.addFact("M");
// Regra a ser avaliada
//String str = "(¬Q->K)^(Q->R)^(¬KvT)";
String str = "(P->K)^(K->Y)^(Y->J)^(J^L)^M";
Solver solver = new Solver(str);
//Solucionador
solver
.addRule(new ModusTolens())
.addRule(new ModusPonens())
.addRule(new Absorption())
.addRule(new ConstructiveDilemma())
.addRule(new DisjunctiveSyllogism())
.addRule(new HypotheticalSyllogism());
solver.setInferedFactContainer(inferedFacts);
solver.setInitialFactContainer(initFacts);
solver.generateFactBase();
System.out.println("--------------------------------");
if(initFacts.containsAll(inferedFacts)){
System.out.println("A sentença de entrada é verdadeira");
}else{
System.out.println("A sentença de entrada é falsa");
}
System.out.println("\n--------------------------------");
System.out.println("fatos iniciais: "+initFacts.getFactList()); // Lista de fatos iniciais
System.out.println("fatos a serem satisfeitos: "+inferedFacts.getFactList()); // Lista de fatos a serem satisfeitos
System.out.println("fatos inferidos: "+inferedFacts.getSpecialFactList()); // Lista de fatos inferidos
System.out.println("sentença: "+ str); // String inicial
System.out.println("Lista: "+solver.getLitteSentences()); // Lista final de sentenças
} |
0c59f656-ac2d-4afb-9cd2-ce378ca1971e | @Override
public boolean exec(String rule, FactContainer facts,FactContainer inferedFacts, ArrayList<String> sentences) {
if(rule.contains("->")){
StringTokenizer tokens = new StringTokenizer(rule,"->");
String leftToken = tokens.nextToken(); // lado esquerdo
String rigthToken = tokens.nextToken(); // lado direito
if(facts.contains(leftToken)){
System.out.println(rule+" - Modus Ponens");
inferedFacts.addSpecialFact(rigthToken);
//return true;
}
}
return false;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.