Poll

i don't see why i always lose can any1 help me plz?

can i clean the code and make it smaller?
0 (0%)
can any1 help to fix the lose problem..?
0 (0%)

Total Members Voted: 0

Author Topic: always lose  (Read 1549 times)

krapgras

  • Guest
always lose
« on: January 30, 2014, 03:09:53 pm »
Code: [Select]
//====================================================
// App.cpp
//====================================================
#include "DragonFireSDK.h"

int LogoImage;
int LogoView;
int start;
int credits;
int aanval;
int verdediging;
int heal;
int Styletype1;
int life=100;
int hit;
int enemylife=100;
bool turn=false;
int addlive;

int OnButton(int id)
{
switch (id)
{
case 1:
life=100;
PushButtonSetVisible(start, 0);
PushButtonSetVisible(credits, 0);
PushButtonSetVisible(aanval, 1);
PushButtonSetVisible(verdediging, 1);
PushButtonSetVisible(heal, 1);
break;
case 2:
LogoImage=ImageAdd("Images/black.jpg"); // file location: Debug/Assets/Images/Logo.png
LogoView=ViewAdd(LogoImage,0,0);
Styletype1=FontAdd("Styletyp1");
TextAdd(10,220,"   A production of stig",Styletype1);
break;
case 3:
if(turn=false){
do
{
hit=Random(26);
} while (hit<=0);
enemylife= enemylife-hit;
hit=0;
turn=true;
}
if (turn=true)
{
do
{
hit=Random(26);
} while (hit<=0);
life= life-hit;
hit=0;
turn=false;
}
else
{
break;
}
case 4:
if(turn=false){

turn=true;
}
if (turn=true)
{
do
{
hit=Random(26);
} while (hit<=0);
life= life-hit;
hit=0;
turn=false;
}
else{
break;
}
case 5:
if(turn=false){
do
{
addlive=Random(50);
} while (addlive<=0);
life=life+addlive;
turn=true;
}
if (turn=true)
{
do
{
hit=Random(26);
} while (hit<=0);
life= life-hit;
hit=0;
turn=false;
}
else{
break;
}
default:
break;
}
return(0);
};
void AppMain()
{
// Application initialization code goes here.  Create the items / objects / etc.
// that your app will need while it is running.
// file location: Debug/Assets/Images/Logo.png
LogoImage=ImageAdd("Images/gut.jpg");
LogoView=ViewAdd(LogoImage,0,0);
start = ButtonAdd("images/start",10,440,OnButton,1);
credits = ButtonAdd("images/credits",200,440,OnButton,2);
aanval = ButtonAdd("images/fireball",10,440,OnButton,3);
verdediging = ButtonAdd("images/shield",120,440,OnButton,4);
heal = ButtonAdd("images/pill",200,440,OnButton,5);
PushButtonSetVisible(aanval, 0);
PushButtonSetVisible(verdediging, 0);
PushButtonSetVisible(heal, 0);
}

void AppExit()
{
// Application exit code goes here.  Perform any clean up your app might
// need to do in the event of interruption by a phone call or the user
// pressing the Home button, or some other event that would cause your
// application to terminate.
}

void OnTimer()
{
if (enemylife<=0){
LogoImage=ImageAdd("Images/black.jpg"); // file location: Debug/Assets/Images/Logo.png
LogoView=ViewAdd(LogoImage,0,0);
Styletype1=FontAdd("Styletyp1");
TextAdd(60,220,"   You win",Styletype1);
enemylife=100;
}
if(life<=0){
LogoImage=ImageAdd("Images/black.jpg"); // file location: Debug/Assets/Images/Logo.png
LogoView=ViewAdd(LogoImage,0,0);
Styletype1=FontAdd("Styletyp1");
TextAdd(60,220,"   Game Over",Styletype1);
life=100;
}
}

the problem is i always lose i try to make a 3 button game with life bar and atk/def/heal function
and second problem if i try to put
Code: [Select]
if (turn=true)
{
do
{
hit=Random(26);
} while (hit<=0);
life= life-hit;
hit=0;
turn=false;
}
inside the OnTimer() method i lose much faster because it look like it just ignores the false of the start!!

And sry for the poll im new
« Last Edit: January 30, 2014, 04:46:07 pm by krapgras »

expleo

  • Jr. Member
  • **
  • Posts: 57
  • Karma: +0/-0
    • View Profile
Re: always lose
« Reply #1 on: January 31, 2014, 08:57:59 am »
Hi, I didnt study your code in-deptht, but I noticed at least one problem area (repeated several places).

You have an if statement that says if(turn=false), this is wrong. A singler = is used to assign a value to a variable, like in turn=false;, but if you want to check the value you must do a double == as in

if (turn==false){
}

so start by fix that.

krapgras

  • Guest
Re: always lose
« Reply #2 on: February 02, 2014, 08:19:46 am »
this fixed the lose but if life of me is same as opponent i always win but i can lose if i lower my health so this alrdy works the rest i will find myself i gues tnx anyway :)

expleo

  • Jr. Member
  • **
  • Posts: 57
  • Karma: +0/-0
    • View Profile
Re: always lose
« Reply #3 on: February 03, 2014, 05:37:16 am »
Hi, I don't quite understand what you mean, but I Notice 2 other issues with your app:

one is that you have used for image reference images/ and also Images (capital and lowercase i/I). Now, for this to work on the device, this is case sensitive. So if your folder is called Images, you must use "Images" in your code (capital I). Simulator will show image regardless, but on device it will not. I have spent many hours griefing over this myself :D

so, the other issue you might or might not have. I see you use a random number. Without using the Randomizer(); function, random will create the same string of numbers every time you play. To use Randomize();, put it under main(){ and also at top have

#include <time.h>

(same place include <dragonfiresdk.h> is

This might or might not solver your issue, but at least it will take a few steps closer to working as intended.

m4unot

  • Guest
Re: always lose
« Reply #4 on: February 03, 2014, 11:52:18 am »

1) Don't use while inside OnButton, becouse the button get called anyway every time you touch it.


2) Don't use add functions like ImageAdd, ViewAdd, FontAdd, TextAdd..etc..inside OnTimer, instead define/init them in AppMain and change them later in OnTimer later with ViewSetImage.


3) UseRandomize() function inside AppMain. Now you'll get fresh random numbers on each
run.


4) instead of saying " life=life+addlive; " just say " life +=addlive; " and instead of "
life= life-hit; " just say " life -= hit;


5) to check if it is 0, don't say " addlive<=0 ", but " if(addlive <=0 || addlive == 0 ) "

6) correct the file path's to your images.