messagebox and timer in visual studio - timer

Need help.
so i was making a game with my friend for college using visual studio 2017 and there's something weird about the program.
we're set it so that when the life is zero, a message box would show up and chose whether to retry the game or not, but when we tried the game, the message box show's up at least at 20 - 30 second after playing the game and the timer for the game is still going even though we add "timergame.enable = false;".
where's seems to be the problem?
private void timerGame_Tick(object sender, EventArgs e)
{
for (int i = 0; i < listOfSardine.Count; i++)
{
listOfSardine[i].Top += (int)listOfSardine[i].Tag;
if (listOfSardine[i].Bounds.IntersectsWith(pictureBoxGrass.Bounds))
{
userLives--;
labelLives.Text = "Lives: " + userLives;
listOfSardine[i].Dispose();
listOfSardine.RemoveAt(i);
if (userLives == 0)
{
highScore = userScore;
timerBonusSpeed.Enabled = false;
timerGame.Enabled = false;
timerHealth.Enabled = false;
timerMatatabi.Enabled = false;
timerSardine.Enabled = false;
DialogResult dialogResultLose = MessageBox.Show
("Sorry.... you have lost, continue?", "Continue??", MessageBoxButtons.YesNo);
if (dialogResultLose == DialogResult.Yes)
{
for (int j = 0; j < listOfHealth.Count; j++)
{
listOfHealth[j].Dispose();
}
listOfHealth.Clear();
for (int q = 0; q < listOfSardine.Count; q++)
{
listOfSardine[q].Dispose();
}
listOfSardine.Clear();
for (int k = 0; k < listOfMatatabi.Count; k++)
{
listOfMatatabi[k].Dispose();
}
listOfMatatabi.Clear();
userLives = USER_LIVES;
userScore = USER_SCORE;
timerBonusSpeed.Enabled = true;
timerGame.Enabled = true;
timerHealth.Enabled = true;
timerMatatabi.Enabled = true;
timerSardine.Enabled = true;
}
else
{
this.Visible = false;
FormMainMenu formMainMenu = new FormMainMenu();
formMainMenu.Owner = this;
formMainMenu.ShowDialog();
}
}
}
else if (listOfSardine[i].Bounds.IntersectsWith(pictureBoxMainCharacter.Bounds))
{
listOfSardine[i].Dispose();
listOfSardine.RemoveAt(i);
userScore += 1;
labelScore.Text = "Score: " + userScore;
if (userScore % 100 == 0)
{
listOfSardine[i].Top += (int)listOfSardine[i].Tag * 4;
}
if(userScore == 1000)
{
timerBonusSpeed.Enabled = false;
timerGame.Enabled = false;
timerHealth.Enabled = false;
timerMatatabi.Enabled = false;
timerSardine.Enabled = false;
highScore = userScore;
}
}
else
{
listOfSardine[i].Refresh();
}
}
for (int i = 0; i < listOfHealth.Count; i++)
{
listOfHealth[i].Top += (int)listOfHealth[i].Tag;
if (listOfHealth[i].Bounds.IntersectsWith(pictureBoxGrass.Bounds))
{
listOfHealth[i].Dispose();
listOfHealth.RemoveAt(i);
}
else if (listOfHealth[i].Bounds.IntersectsWith(pictureBoxMainCharacter.Bounds))
{
listOfHealth[i].Dispose();
listOfHealth.RemoveAt(i);
userLives++;
labelLives.Text = "Lives: " + userLives;
}
else
{
listOfHealth[i].Refresh();
}

Not enough clear what you did. However, I think you have a counter for life, and which are decreasing as per your game's event. On timer event just check life counter is equal or less than Zero or not. If so, just stop timer, give user confirmation for retry. If user want to retry, then reset life counter and start timer.

Ahh already found the answer
our problem is about the ownership of the form, we just incorrectly insert the ownership for each form
thanks for the people who have answered my question earlier

Related

fixing non-null String must be provided to a Text widget

I'm quite new in flutter.
I am working on a quiz app and try to make every quiz has five questions
I faced some problems :
1- I don't want to repeat the same question in the same quiz.[my quiz also start with question number one every time].
2- Every time it reaches my question number ten [which in array] nine my app crash.
NOTE: I'm using a JSON file to store my questions.
int j = 1;
int i = 1;
var random_array;
genrandomarray() {
var distinctIds = [];
var rand = new Random();
for (int i = 1;;) {
distinctIds.add(rand.nextInt(10));
random_array = distinctIds.toSet().toList();
if (random_array.length < 10) {
continue;
} else {
break;
}
}
print(random_array);
}
setState(() {
if (j < 5) {
i = random_array[j];
j++;
} else {
Navigator.of(context).pushReplacement(MaterialPageRoute(
builder: (context) => resultpage(marks: marks),
));
}
disableAnswer = false;
});
genrandomarray() {
var rand = new Random();
make it choose random between questions
var distinctIds = [i = rand.nextInt(10) + 1];
for (int i = 0;;) {
to not crash when it reach to 10 question
distinctIds.add(rand.nextInt(10) + 1);
random_array = distinctIds.toSet().toList();
if (random_array.length < 10) {
continue;
} else {
break;
}
}
print(random_array);
}

game maker - how to navigate a map with 2d array

I have to make a navigable map
the starting point is in the center
there are three worlds + the final stage
pressing up I have to navigate from the base to the first level of the first world and go next level in second and third
pressing down I have do go from the third to the second and from the second to the first level and from the first level of the world to the base
pressing left and right I have to change the world
now:
I already made a lot of menus using different methods, but alway using a 1d array
obj_menu:
create event:
///menu
menu[0] = "new";
menu[1] = "load";
menu[2] = "exit";
space = 55;
mpos = 0;
step event:
///move
if(inputs) {
var move = 0;
move -= max(keyboard_check_pressed(vk_up),0);
move += max(keyboard_check_pressed(vk_down),0);
if(move != 0) {
mpos += move;
if(mpos < 0) {
mpos = array_length_1d(saveload) -1;
}
if(mpos > array_length_1d(saveload) -1) {
mpos = 0;
}
}
//push
if(keyboard_check_pressed(vk_enter)) {
scr_menu();
}
}
scr_menu();
switch(mpos) {
case 0: { scr_new_game(); break; } //new
case 1: { scr_load_game(); break; } //load
case 2: { game_end(); break; } //exit
default: { break; }
}
This time I have to navigate in a 2d array
I did this:
obj_map:
create event:
///navigation setup
if(crash_to_base) { lvl[0,0] = true }
if(base_to_ruins_1) { lvl[1,0] = true }
if(ruins_1_to_ruins_2) { lvl[1,1] = true }
if(ruins_2_to_ruins_3) { lvl[1,2] = true }
if(base_to_city_1) { lvl[2,0] = true }
if(city_1_to_city_2) { lvl[2,1] = true }
if(city_2_to_city_3) { lvl[2,2] = true }
if(base_to_lab_1) { lvl[3,0] = true }
if(lab_1_to_lab_2) { lvl[3,1] = true }
if(lab_2_to_lab_3) { lvl[3,2] = true }
if(base_to_castle) { lvl[4,0] = true }
//posizione del menu
mposh = 0;
mposv = 0;
mpos[mposv,mposh] = 0;
step event:
///map navigation
if(inputs) {
moveh -= max(keyboard_check_pressed(vk_left),0);
moveh += max(keyboard_check_pressed(vk_right),0);
movev -= max(keyboard_check_pressed(vk_up),0);
movev += max(keyboard_check_pressed(vk_down),0);
if(moveh != 0) {
//mposh += move;
}
if(movev != 0) {
//mposv += move;
}
push = keyboard_check_pressed(vk_enter);
if(push) {
scr_map();
}
}
how to translate the first method to de sencond need??
Not quite sure what your having difficulty with, perhaps you could elaborate on what exactly the problem is? On a side note however your 1D menu navigation code can be greatly simplified to:
mpos += keyboard_check_pressed(vk_up) - keyboard_check_pressed(vk_down);
var len = array_length_1d(saveload);
if (mpos < 0) { mpos = len - 1; }
if (mpos > len - 1) { mpos = 0; }
and in terms of a 2d map navigation system, it might not be beneficial to use 2d arrays and instead you could use a ds_map which allows you to store all information on each location in one data structure. For instance
var lvlMap = ds_map_create()
lvlMap[?"base-title"] = "Base"
lvlMap[?"base-travel-right"] = "crash"
lvlMap[?"base-travel-left"] = "fortress"
then when you try to move right/left:
var next_location = lvlMap[?current_location+"-travel-"+direction]
current_location = next_location

My if-statement doesn't work

It's either going to be "Riktig, bokstaven forekommer" for right letter chosen or otherwise. What have i done wrong, when i start it now none of the Messages show.
btnStart.addEventListener(MouseEvent.CLICK, start);
var feil:Array = new Array ;
var riktig:Array = new Array ;
var bokstav:Array = new Array ;
bokstav[0] = "b";
bokstav[1] = "r";
bokstav[2] = "e";
bokstav[3] = "v"
var txtBokstav:TextField = new TextField( );
txtBokstav.maxChars = 1;
txtBokstav.restrict = "a-z æ ø å";
txtBokstav.type = flash.text.TextFieldType.INPUT;
addChild(txtBokstav);
function start(evt)
{
var bokstavInn:String = String(txtBokstav.text);
if (txtBokstav.text.length == 1)
{
if (bokstav.indexOf(bokstavInn) >= 0)
{
txtUtskrift.text = "Riktig, bokstaven forekommer";
riktig.push(bokstavInn);
for (var i = 0; i < riktig.length; i++)
{
txtUtskrift.appendText(riktig[i] + ", ");
}
}
else
{
txtUtskrift.text = "Feil, bokstaven forekommer ikke";
feil.push(bokstavInn);
for (var l = 0; l < feil.length; l++)
{
txtUtskrift.appendText(feil[l] + ", ");
}
}
}
}
1) Are you sure that txtUtskrift is on the Stage and visible?
2) Make sure that start() is being called (use a breakpoint or trace)
3) As askmozo suggests, place trace statements in the possible flow of execution. So, at the beginning of the start function, and within each possible if condition. You might add an else for the text.length test:
function start( evt )
{
trace( "start()..." );
if (txtBokstav.text.length == 1)
{
// ... what you already have
}
else
{
trace( "txtBokstav length not valid:", txtBokStav.text.length );
}
trace( "...start()" );
}

Can we call explicitly Watch in the controller

Can we call watch expliciltly in the controller?
Requirements:
Currently there are two angular tree structured checkboxes. one is carriergorup and another one is modes. I'm retrieving mode values based on carriergroup list. whenever the carrier group list is updated automatically modes list is updated for this i used watch.
current functionality is like.
Whenever the carriergroup list is updated then only modes list is updated. Suppose there is no change in the carrier group list, but I want to make a call for watch explicitly. Is this possible?
$scope.$watch(
'carrierGroups',
function(carrierGroups) {
alert("in carrier List");
$scope.selectedCarrierList = [];
$scope.isAllChecked = true;
for (var i = 0; i < $scope.carrierGroups.length; i++) {
/*if($scope.carrierGroups[i].checked){
cntGroupChecked = cntGroupChecked + 1;
}*/
for (var j = 0; j < $scope.carrierGroups[i].categories.length; j++) {
if ($scope.carrierGroups[i].categories[j].checked) {
$scope.selectedCarrierList
.push($scope.carrierGroups[i].categories[j]);
}else{
$scope.carrierGroups[i].checked = false;
$scope.isAllChecked = false;
}
}
}
alert("$scope.isModesWatch"+$scope.isModesWatch);
if($scope.isModesWatch){
$scope.modesList = DashboardsDataService.getModesData($scope.selectedCarrierList);
}else{
alert("$scope.filterModesList-->"+JSON.stringify($scope.filterModesList));
$scope.modesList = $scope.filterModesList;
$scope.isModesWatch = true;
}
},
true);
Like below, you can do this..
var myCustomFun = function(carrierGroups) {
alert("in carrier List");
$scope.selectedCarrierList = [];
$scope.isAllChecked = true;
for (var i = 0; i < $scope.carrierGroups.length; i++) {
/*if($scope.carrierGroups[i].checked){
cntGroupChecked = cntGroupChecked + 1;
}*/
for (var j = 0; j < $scope.carrierGroups[i].categories.length; j++) {
if ($scope.carrierGroups[i].categories[j].checked) {
$scope.selectedCarrierList
.push($scope.carrierGroups[i].categories[j]);
}else{
$scope.carrierGroups[i].checked = false;
$scope.isAllChecked = false;
}
}
}
alert("$scope.isModesWatch"+$scope.isModesWatch);
if($scope.isModesWatch){
$scope.modesList = DashboardsDataService.getModesData($scope.selectedCarrierList);
}else{
alert("$scope.filterModesList-->"+JSON.stringify($scope.filterModesList));
$scope.modesList = $scope.filterModesList;
$scope.isModesWatch = true;
}
}
$scope.$watch('carrierGroups',myCustomFun,true);
Now where you want to call custom watch function, you can simply call your function.
myCustomFun(param);

AS3 Array object showing up by ordering

I have 3 MC on stage which are all alpha=0
var mcArray:Array = [mc1,mc2,mc3];
for (var j:int = 0; j < mcArray.length; j++)
{
mcArray[j].alpha = 0;
}
I have one button which once I click then it will make 1 of the MC become alpha=1
revealBtn.buttonMode = true;
revealBtn.useHandCursor = false;
revealBtn.addEventListener(MouseEvent.CLICK, revealClick);
function revealClick(event:MouseEvent):void
{
for (var j:int = 0; j < mcArray.length; j++)
{
mcArray[j].alpha = 1;
}
}
But with the script above it will makes all 3 MC become alpha=1.
I know that this can achieve by using below code:
if(mc1.alpha!=1){
mc1.alpha=1
}
if(mc2.alpha!=1){
mc2.alpha=1
}
if(mc3.alpha!=1){
mc3.alpha=1
}
this code will give what I want to achieve but if there is more than 3 MC the lines of script will be longer.
revealBtn.buttonMode = true;
revealBtn.addEventListener(MouseEvent.CLICK, revealClick);
var mcArray:Array = [mc0,mc1,mc2];
function revealClick(event:MouseEvent):void
{
for(var i:uint = 0; i<mcArray.length; i++){
if(this['mc'+i].alpha !== 1){
this['mc'+i].alpha = 1;
break;
}
}
}
No that if statement would still turn all three to alpha 1.
Which of the three do you want to set to alpha = 1 when the click is made?
You could use something like this to set alpha = 1 on the first mc in the array which does NOT have alpha = 1
function revealClick(event:MouseEvent):void {
for (var j:int = 0; j < mcArray.length; j++){
if ( mcArray[j].alpha != 1 ){
mcArray[j].alpha = 1;
return;
}
}
}
Just use a counter.
var cnt : int = -1;
function revealClick(event:MouseEvent):void
{
if(++cnt < mcArray.length) mcArray[cnt].alpha = 1;
}

Resources