ActionScript - Ayuda con un Script

 
Vista:
sin imagen de perfil

Ayuda con un Script

Publicado por Jorge (1 intervención) el 18/03/2015 22:43:46
Buenas tardes, desearia que alguien me ayude con un script para hacer un botón de reiniciar y un contador de tiempo que al minuto diga game over en un juego de concentrese
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Alejandro

Creación de botón de reinicio y contador de tiempo en un juego de concentración

Publicado por Alejandro (369 intervenciones) el 28/06/2023 19:09:10
Buenas tardes, Jorge, aquí te proporciono un ejemplo de script en ActionScript para crear un botón de reinicio y un contador de tiempo que muestre "Game Over" después de un minuto en un juego de concentración:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Importar las clases necesarias
import flash.utils.Timer;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.text.TextField;
 
// Variables
var timer:Timer = new Timer(60000); // 1 minuto en milisegundos
var contador:int = 0;
var gameOver:Boolean = false;
 
// Crear el contador de tiempo
var tiempoTextField:TextField = new TextField();
tiempoTextField.text = "Tiempo: 0";
addChild(tiempoTextField);
 
// Crear el botón de reinicio
var reiniciarButton:TextField = new TextField();
reiniciarButton.text = "Reiniciar";
reiniciarButton.border = true;
reiniciarButton.background = true;
reiniciarButton.backgroundColor = 0xFF0000; // Color rojo
reiniciarButton.textColor = 0xFFFFFF; // Color blanco
reiniciarButton.x = 100;
reiniciarButton.y = 50;
reiniciarButton.width = 100;
reiniciarButton.height = 30;
reiniciarButton.addEventListener(MouseEvent.CLICK, reiniciarJuego);
addChild(reiniciarButton);
 
// Configurar el evento del temporizador
timer.addEventListener(TimerEvent.TIMER, actualizarContador);
 
// Función para actualizar el contador de tiempo
function actualizarContador(event:TimerEvent):void {
  contador++;
  tiempoTextField.text = "Tiempo: " + contador;
 
  if (contador == 60) {
    gameOver = true;
    tiempoTextField.text = "Game Over";
    timer.stop();
  }
}
 
// Función para reiniciar el juego
function reiniciarJuego(event:MouseEvent):void {
  contador = 0;
  gameOver = false;
  tiempoTextField.text = "Tiempo: 0";
  timer.start();
}

Este script crea un temporizador (`Timer`) que se activa cada minuto (`60000` milisegundos). Cada vez que se activa el temporizador, se incrementa un contador y se actualiza un campo de texto (`TextField`) para mostrar el tiempo transcurrido.

Además, se crea un botón de reinicio que restablece el contador y el campo de texto a cero cuando se hace clic en él. Después de un minuto, el temporizador se detiene y se muestra el mensaje "Game Over" en lugar del contador de tiempo.

Ten en cuenta que este es solo un ejemplo básico y puede adaptarse según las necesidades específicas de tu juego de concentración. También es importante tener en cuenta la estructura general de tu juego y cómo se integra este script en el mismo.

Espero que esto te sea útil.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar