Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6173537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:35:37+00:00 2026-05-23T23:35:37+00:00

I’m programming in xcode for fun. I got the idea to create a console

  • 0

I’m programming in xcode for fun. I got the idea to create a console app where the computer plays train (a game using dominoes) against other generated “players”, and counts up the number of times it wins and loses, based on the strategies I program it to follow. My problem is, I want the computer to create 79 dominoes for the game. I have now programmed it to make one domino and print the value of dots, just for a test. I would like to know how to generate a set number without having to write “domino *dom1… domino *dom2…” and so on.
I was thinking i could make the number of the domino an integer (int num) and create a loop creating objects and num++ until num == 79. Obviously that didn’t work. I’m 16 and doing this mostly to practice objective c and OOP. If anyone could help me out with this early stage in development, I’d really appreciate it.

Here’s the code i’ve got so far:

//obj1.h

#import <Foundation/Foundation.h>
#import <stdlib.h>
@interface Domino : NSObject {
    int dotS1;      //number of upper dots on domino
    int dotS2;      //number of lower dots on domino
    bool played;    //is the domino on the board (not yet implemented)
    bool inHand;    //is the domino in your hand (not yet implemented)
}
-(void) createDomino;
@property(getter=updom) int dotS1;  //returns the integer representing the upper dots on the domino
@property(getter=ddom) int dotS2;   //returns the integer representing the lower dots on the domino
@end

@implementation Domino

-(void) createDomino{
    dotS1 = arc4random() % 12;  //randomizes the number of dots on the upper part of the domino between 0 and 12
    dotS2 = arc4random() % 12;  //randomizes the number of dots on the lower part of the domino between 0 and 12
};
@synthesize dotS1;
@synthesize dotS2;
@end



//  main.m

#import "obj1.h"    //imports the header where i keep objects, for organization


int main (int argc, const char * argv[])
{

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    Domino *dom1;   //creates domino object "dom1"
    dom1 = [[Domino alloc] init];   //allocates space in ram for "dom1"
    [dom1 createDomino];    //makes "dom1" a domino with upper and lower dots
    NSLog(@"TOP: %i", [dom1 updom]);    //prints the number of dots on the top of the domino
    NSLog(@"BOTTOM: %i", [dom1 ddom]);  //prints the number of dots on the bottom of the domino


    [pool drain];
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:35:38+00:00Added an answer on May 23, 2026 at 11:35 pm
    +(NSArray*)createSetOfDominoes
    {
        NSMutableArray *dominoSet = [NSMutableArray array];
        for(int top = 0; top < 12; top++) {
            for(int bottom = 0; bottom < 12; bottom++) {
                Domino *d = [[Domino new] autorelease];
                d.dotS1 = top;
                d.dotS2 = bottom;
                [dominoSet addObject: d];
            }
        }
        return dominoSet;
    }
    

    That’d be a class method on your Domino class. Call it by something like NSArray dSet = [Domino setOfDominoes];.

    I would suggest against doing getter= in your @property; just name the ivar and the property the same for consistency’s sake (actually, you can drop the ivar declaration, too, as it is no longer needed in modern Objective-C).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am writing an app with both english and french support. The app requests
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.