I don't know why, but score label node dissapears after first round.I have two scores, one for human ,other for computer :
-(void)scoreCount{
if(scoreLabel == nil){
NSString* scoretxt =[NSString stringWithFormat:#"0"];
[scoreLabel setText:scoretxt];
scoreLabel = [SKLabelNode labelNodeWithFontNamed:#"ROTORcapExtendedBold"];
scoreLabel.fontSize = 65.f;
scoreLabel.fontColor = [UIColor grayColor];
scoreLabel.position = CGPointMake(CGRectGetMidX(self.frame)/2,CGRectGetMaxY(self.frame)-70);
scoreLabel.zPosition = -1;
[self addChild:scoreLabel];
}
scoreLabel.text = [NSString stringWithFormat:#"%ld",(long)score];
if(scoreLabelCom == nil){
NSString* scoretxtcom =[NSString stringWithFormat:#"0"];
[scoreLabelCom setText:scoretxtcom];
scoreLabelCom = [SKLabelNode labelNodeWithFontNamed:#"ROTORcapExtendedBold"];
scoreLabelCom.fontSize = 65.f;
scoreLabelCom.fontColor = [UIColor grayColor];
scoreLabelCom.position = CGPointMake(CGRectGetMidX(self.frame)+(CGRectGetMidX(self.frame)/2),CGRectGetMaxY(self.frame)-70);
scoreLabelCom.zPosition = -1;
[self addChild:scoreLabelCom];
}
scoreLabelCom.text = [NSString stringWithFormat:#"%ld",(long)scoreCom];
}
this method is called every time somebody is getting a point, and I put in
-(void)update:(CFTimeInterval)currentTime {
[self scoreCount];
}
because, without it scoreCount wont show 0 points, but only show up after first point, but, when new round starts, ScoreCout wont show up at all.
how can I correct it? And why it is happening?
This (long)score and (long)scoreCom
You can add value to it by now.
score = score + 1; //Before add to nsstring
scoreLabel.text = [NSString stringWithFormat:#"%ld",(long)score];
And
scoreCom = scoreCom + 1;//Before add to nsstring
scoreLabelCom.text = [NSString stringWithFormat:#"%ld",(long)scoreCom];
Well, I don't know how good it is but I add scoreLabel = nil and scoreLabelCom = nil at didBeginContactwhen game ends, and it works now.
Related
I wish to display HH:MM at a UILabel when I adjust a custom slider. Currently my custom slider is returning me float values, for example, 2.89, 24.87... I wish to take the float value say 24.87 and change it to 24:52 I got everything working at the following code but I think it is not the most efficient way. Can anyone improve it? Thank you
- (void)slideValueChanged:(id)control
{
NSLog(#"Slider value changed: (%.2f,%.2f)",
_rangeSlider.lowerValue, _rangeSlider.upperValue);
lblStart.text = [NSString stringWithFormat:#"Start Time : %#", [self floatToTime:_rangeSlider.lowerValue]];
lblEnd.text = [NSString stringWithFormat:#"End Time : %#",[self floatToTime:_rangeSlider.upperValue]];
}
- (NSString*)floatToTime:(float)floatTime {
NSInteger iHour = floatTime;
CGFloat floatMin = floatTime - iHour;
NSString *sHour = [NSString stringWithFormat:#"%li", (long)iHour];
if (floatMin == 0.99) { //=== When the float is 0.99, convert it to 0, if not 60*0.99 = 59.4, will never get to 0
floatMin = 0;
}else{
floatMin = floatMin * 60;
}
NSInteger iMin = floatMin; //=== Take the integer part of floatMin
NSString *sMin = [[NSString alloc] init];
if (iMin <10){ //=== Take care if 0,1,2,3,4,5,6,7,8,9 to be 00,01,02,03...
sMin = [NSString stringWithFormat: #"0%li", iMin];
}else{
sMin = [NSString stringWithFormat: #"%li", iMin];
}
NSString *strFloatTime = [NSString stringWithFormat:#"%#:%#", sHour,sMin];
return strFloatTime;
}
You can use a format to show two digits, this simplifies creating a time string:
CGFloat time = 24.87;
int hours = fabs(time);
int minutes = (int)((time - hours) * 60.0);
NSLog(#"Time: %02d:%02d", hours, minutes);
Result: "Time: 24:52"
'02' is the number of digits.
i haveNSDictionary like this:
(
{
bp = "158/56";
dateTime = "05/12/2016 11:51:12 AM";
doc = {
"email_id" = "gkalal64#gmail.com";
exception = 0;
gender = Male;
id = 0;
"mobile_no" = 8149910113;
name = Kabadia;
"profile_id" = 0;
qualification = MBBS;
"reg_id" = 100;
salutation = Mr;
"wellness_id" = IN8S2D29A2;
};
"follow_up" = 14;
id = 6;
medicine = (
"Injection,Crocin,5,0-1-0,After Meal,2",
"Powder,churan,10,1-0-0,Before Meal,14",
no,
no,
no,
no,
no,
no,
no,
no
);
patient = {
"email_id" = "bishtrohit1989#gmail.com";
exception = 0;
gender = Male;
id = 0;
"mobile_no" = 8624088776;
name = kamlesh;
"profile_id" = 0;
qualification = "";
"reg_id" = 101;
salutation = Mr;
"wellness_id" = IND16HRR65;
};
weight = 47;
}
)
I want to display above information like following way:
But i have no idea about how to do that. i searched for this but i didn't get exactly how to do this.
What i did:
In previous View controller i have displayed multiple prescription title. after click on particular cell, i called this view and i got above response from server, which i want to display like above image.
I have taken UITableView on screen for this.
I have taken 1 static custom cell for this.
But i don't know how to do.
Please anyone can solve my issue. help will be appreciable.
As per your data structure i guess your data is kind of single object so it's clear that its not a collection(array) of same kind of object so i would suggest you to create only single custom cell for this entire single record.
In this case your TableView will have only single row.
In the Custom cell: lets call it 'PatientDetail'
Add all the labels and controls which you want to show for each
property and connect outlets whatever is required.
If you are using an Autolayout then give relative constraints to all the controls else set frame of each control dynamically by calculating the height of it's content.
How it will work ?
As you said its detail screen of particular list so we will show single row in tableview with all the details in it.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
In the follwing code
responseDict the NSDictionary which is the first object of response as your response is kind of array.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
PatientDetail *cell=[tableView dequeueReusableCellWithIdentifier:#"PatientDetail" forIndexPath:indexPath];
//Setting
[cell.lbDateTime setText:[responseDict valueForKey:#"dateTime"]];
//Doctor name Just
[cell.lbDoctorName setText:[[responseDict objectForKey:#"doc"]valueForKey:#"name"]];
//Follow the above steps for all the details
return cell;
}
Updated Answer
if (indexPath.row < responseArray.count){
NSString *docName = #"";
NSString *contact = #"";
NSString *wellness_id = #"";
if ([selectedDict valueForKey:#"doc"] != nil){
NSDictionary *doctorDict = [selectedDict valueForKey:#"doc"];
NSString *lDocName = [doctorDict valueForKey:#"name"];
if(lDocName.length > 0){
docName = lDocName;
}
NSString *qulification = [doctorDict valueForKey:#"qualification"];
if(qulification.length > 0){
docName = [NSString stringWithFormat:#"%# %#", docName, qulification];
}
NSString *mobile_no = [doctorDict valueForKey:#"mobile_no"];
if(mobile_no.length > 0){
contact = mobile_no;
}
NSString *email_id = [doctorDict valueForKey:#"email_id"];
if(email_id.length > 0){
contact = [NSString stringWithFormat:#"%# / %#", contact, email_id];
}
NSString *wellness_idTemp = [doctorDict valueForKey:#"wellness_id"];
if(wellness_idTemp.length > 0){
wellness_id= [NSString stringWithFormat:#"Wellness_Id : %#", wellness_idTemp];
}
}
cell.docNameLabel.text = docName;
cell.contact.text = contact;
cell.wellnessID.text = wellness_id;
NSString *patientName = #"";
NSString *patientcontact = #"";
NSString *patientWellness_id = #"";
NSString *bloodPressure = [selectedDict valueForKey:#"bp"];
NSString *weight = [selectedDict valueForKey:#"weight"];
if ([selectedDict valueForKey:#"patient"] != nil){
NSDictionary *patientDict = [selectedDict valueForKey:#"patient"];
NSString *lName = [patientDict valueForKey:#"name"];
if(lName.length > 0){
patientName = lName;
}
NSString *mobile_no = [patientDict valueForKey:#"mobile_no"];
if(mobile_no.length > 0){
patientcontact = mobile_no;
}
NSString *email_id = [patientDict valueForKey:#"email_id"];
if(email_id.length > 0){
patientcontact = [NSString stringWithFormat:#"%# / %#", contact, email_id];
}
NSString *wellness_idTemp = [patientDict valueForKey:#"wellness_id"];
if(wellness_idTemp.length > 0){
patientWellness_id = [NSString stringWithFormat:#"Wellness Id : %#", wellness_idTemp];
}
}
cell.patientNameLabel.text = patientName;
cell.contact.text = patientcontact;
cell.wellnessID.text = wellness_id;
cell.bp.text = bloodPressure;
cell.weight.text = weight;
}
Hope this will help.
For some reason, the highscore on the game over page is not properly displayed. After a round of play, both the score and highscore are displayed on the game over menu. The score is displayed fine, but in the event that the user beats their highscore, it doesn't update, until the menu is reloaded.
If thats confusing:
Game 1: score = 30, previous highscore displayed = 10
Game 2: score = 40, previous highscore displayed = 30
Game 3: score = 10, highscore displayed = 30
So essentially it doesn't display the new highscore when it is achieved, until the next time the game over menu is loaded.
This is the code:
-(void)update:(CFTimeInterval)currentTime {
score = _debris.count + _debris2.count;
_scoreLabel.text = [NSString stringWithFormat:#"%d", score];
}
and in the initWithSize method:
highScoreNumber = [[NSUserDefaults standardUserDefaults] integerForKey:#"highScoreSaved"];
if (score > highScoreNumber) {
highScoreNumber = score;
[[NSUserDefaults standardUserDefaults] setInteger:highScoreNumber forKey:#"highScoreSaved"];
That's the code in the game, and this is the code on the game over menu:
SKLabelNode *highScore = [SKLabelNode labelNodeWithFontNamed:#"DIN Condensed"];
highScore.fontSize = 40;
highScore.alpha = 0.7;
highScore.fontColor = [SKColor whiteColor];
highScore.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)-15);
highScoreNumber = [[NSUserDefaults standardUserDefaults] integerForKey:#"highScoreSaved"];
highScore.text = [NSString stringWithFormat:#"BEST: %d", highScoreNumber];
Based on this, is there any reason as to why the highscore isn't updating when there is a new highscore, but instead waiting until the gamoever screen is reloaded?
Are you calling [[NSUserDefaults standardUserDefaults] synchronize] right after [[NSUserDefaults standardUserDefaults] setInteger:highScoreNumber forKey:#"highScoreSaved"];? That will ensure the data is saved immediately.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Whats the proper way, I've been using if statements but the way everything is set up is wrong I believe because the scores and coins are not being added up as a whole number they are being replaced by the if statements...
Example:
- (IBAction)btncheck:(id)sender {
NSString *answer = [_textbox.text stringByReplacingOccurrencesOfString:#" " withString:#""];
// to block user from getting incorrect answer with no text in text field
if([answer isEqualToString:#""]){
}
else
if ([answer isEqualToString:#"q"]) {
// String is correct, resign keyboard
_keyboard.hidden = YES;
_textXclear.hidden = YES;
//Perfect button
[_closeone setHidden:NO];
[_wrongone setHidden:YES];
score = MAX (score +100, 0);
[scoreLabel setText:[NSString stringWithFormat:#"score: %d", score]];
coins = coins +5;
if (score == 100) {coins = 8;}
if (score == 0) {coins = 0;}
if (score == 4) {coins = 4;}
if (score == 3) {coins = 3;}
if (score == 2) {coins = 2;}
if (score == 1) {coins = 1;}
[coinsLabel setText:[NSString stringWithFormat:#"%d", coins]];
}
else {
// Was not correct. Notify user, or just don't do anything
[_wrongone setHidden:NO];
score = MIN(score -5, 0);
[scoreLabel setText:[NSString stringWithFormat:#"score: %d", score]];
}
if (score < 100) {
closeonechange.text = #"Correct!";
_imageCorP.image = [UIImage imageNamed:#"boxg_25.png"];
} else {
closeonechange.text = #"Perfect!";
_imageCorP.image = [UIImage imageNamed:#"telioo.png"];
}
//correct button - perfect button
}
//Perfect & Correct button sets it hidden
- (IBAction)closeone:(id)sender {
[_closeone setHidden:YES];
}
Oh and I'd like the user to start with at least 50 coins before the game starts, I'm having trouble figuring out how to do that as well..
By setting
coins = 8;
etc. in your if statements you replace the value of coins with the new value (here: 8) - if you want to add it up you have to write
coins = coins + 8;
, like you also did for counting up the coins in the line
coins = coins + 5;
Some more tips:
You should use if (...) { } else if (...) { } statements instead of only using if's - by that once an if statement is true, all others won't be executed anymore.
If you want to get rid of leading and trailing spaces of the user input you should use
NSString* inputText = [_textBox.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceANdNewlineCharacterSet];
I am working on a Game Center based board game. All seems to be running grew with a few bugs and quirks here and there. The most annoying of those quirks is that when viewing a match that has ended, it always seems to think that the viewing player has lost.
When I end a match with a game winning move, I run this:
// Act if the game is over because of that move
if ([board playerHasWon:activePlayer]) {
board.canMove = NO;
match = [CNFTurnBasedMatchHelper sharedInstance].currentMatch;
NSUInteger currentIndex = [match.participants indexOfObject:match.currentParticipant];
NSUInteger nextIndex = (currentIndex == 0 ? 1 : 0);
GKTurnBasedParticipant *nextParticipant = [match.participants objectAtIndex:nextIndex];
match.currentParticipant.matchOutcome = GKTurnBasedMatchOutcomeWon;
nextParticipant.matchOutcome = GKTurnBasedMatchOutcomeLost;
[match endMatchInTurnWithMatchData:[[board stringValue] dataUsingEncoding:NSUTF8StringEncoding] completionHandler:nil];
}
However, I suspect the real problem lies in my retrieval of that matchOutcome.
When loading a match I run this if the it's not the current players turn:
if (match.status == GKTurnBasedMatchStatusEnded) {
// These lines get the board to show the winning line
[board playerHasWon:1];
[board playerHasWon:2];
board.canMove = NO;
if (match.currentParticipant.matchOutcome == GKTurnBasedMatchOutcomeWon) statusLabel.text = #"You won!";
else statusLabel.text = #"You lost!";
}
Well, I solved my own problem just by really laying it out.
if ([((GKTurnBasedParticipant*)[match.participants objectAtIndex:0]).playerID isEqualToString:[GKLocalPlayer localPlayer].playerID]) {
if ([board playerHasWon:1]) statusLabel.text = #"You won!";
else statusLabel.text = #"You lost!";
}
else {
if ([board playerHasWon:2]) statusLabel.text = #"You won!";
else statusLabel.text = #"You lost!";
}