我正在iPhone上做一个项目,我是一个非常初学者。我正在制作Tic Tac Toe
应用程序,我想制作一个改变转弯的功能'X' to 'O'
所以我试着输入这个
void setTurn(){
SinglePlayer*SO=[[SinglePlayer alloc]init];
SO .turn =1;
if (SO.turn%2==0){
SO->turnLabel.text=@"O Turn";
}
else SO->turnLabel.text=@"X Turn";
SO.turn++;
}
所以意味着SinglePlayerObject
。
无论我在实现的标题中定义了什么
而当我试图在方法putSign();
下键入这个方法时
-(IBAction)PutSign2:(id)sender{
if (turn%2 !=0){
label2.text=@"X";
}
else if (turn%2 ==0){
label2.text=@"O";
}
}
它显示一个错误。
那么我如何运行与C++相同的方法,因为我有C++经验?
这是头文件
#import <UIKit/UIKit.h>
@interface SinglePlayer : UIViewController{
IBOutlet UILabel*label1;
IBOutlet UILabel*label2;
IBOutlet UILabel*label3;
IBOutlet UILabel*label4;
IBOutlet UILabel*label5;
IBOutlet UILabel*label6;
IBOutlet UILabel*label7;
IBOutlet UILabel*label8;
IBOutlet UILabel*label9;
BOOL Player;
int turn;
IBOutlet UILabel*turnLabel;
}
@property (nonatomic)int turn;
@property (nonatomic) BOOL Player;
-(IBAction)PutSign1:(id)sender;
-(IBAction)PutSign2:(id)sender;
-(IBAction)PutSign3:(id)sender;
-(IBAction)PutSign4:(id)sender;
-(IBAction)PutSign5:(id)sender;
-(IBAction)PutSign6:(id)sender;
-(IBAction)PutSign7:(id)sender;
-(IBAction)PutSign8:(id)sender;
-(IBAction)PutSign9:(id)sender;
void setTurn();
@end
这是未完成的实现
@implementation SinglePlayer
//Player=true = X
//Player=False= O
@synthesize Player;
@synthesize turn;
void setTurn(){
SinglePlayer*SO=[[SinglePlayer alloc]init];
SO .turn =1;
if (SO.turn%2==0){
SO->turnLabel.text=@"O Turn";
}
else SO->turnLabel.text=@"X Turn";
SO.turn++;
}
//this code to put the sign in the button label:-
//[sender setTitle:@"X" forState:UIControlStateNormal];
-(IBAction)PutSign1:(id)sender{
if (turn%2 !=0){
label1.text=@"X";
}
else if (turn%2 ==0){
label1.text=@"O";
}
turnLabel.text=@"O Turn";
}
putSign();
-(IBAction)PutSign2:(id)sender{
if (turn%2 !=0){
label2.text=@"X";
}
else if (turn%2 ==0){
label2.text=@"O";
}
}
putSign();
-(IBAction)PutSign3:(id)sender{
if (turn%2 !=0){
label3.text=@"X";
}
else if (turn%2 ==0){
label3.text=@"O";
}
}
putSign();
-(IBAction)PutSign4:(id)sender{
//[sender setTitle:@"X" forState:UIControlStateNormal];
}
putSign();