Jump to content

Best way to make a board game (C# object oriented)

TommyTwommy

I'm making a board game but I couldn't find a name for it in english. On english wikipedia it was: Mensh argere dich nicht. Or something like that. Literal translation would be man, don't be mad/angry.

 

Anyways I won't explain the rules, I'll just say you have 4 players and each player has 4 pawns. Now that automatically means objects. Now I don't know what is the best way to do it.

 

class Game that contains class Players that contains 4 Player and each player contains 4 pawns. Pawns..

 

I've never gotten too deep into objects oriented programming and would really like to. Is there someone who has enough times to write just a few rows that I can work with? Just empty classes.

CPU & COOLER - INTEL i9 12900K | NZXT KRAKEN X62

MBO - MSI Z690 EDGE

GPU - ASUS GEFORCE RTX 3080 TUF

RAM - 2x16GB KINGSTON FURY 3200MHZ

PSU - PHANTEKS REVOLT PRO 1000W 80 PLUS GOLD

SSD #1 - CORSAIR SN850 1TB

SSD #2 - CORSAIR SN850X 4TB

SSD #3 - INTEL 660p 2TB

CASE - PHANTEKS ECLIPSE P500A D-RGB

MOUSE #1 - LOGITECH G502 X Wireless

KEYBOARD - AKKO 5108B PLUS

SPEAKERS - SVS PB-1000 + 2x ADAM A3X

HEADSET #1 - SENNHEISER IE-300

HEADSET #2 - FOSTEX TR-X00 PURPLEHREART

AMP/DAC - MAYFLOWER ARC

OS - WINDOWS 10 PRO

DISPLAY 1 - LG OLED42C2

DISPLAY 2 - XIAOMI 2K GAMING

PHONE - SAMSUNG GALAXY S23+ 

Link to comment
Share on other sites

Link to post
Share on other sites

Its "Ludo" and don't do Players class, instead do Player and create as many instances of Player class as you need, same for pawns.

Link to comment
Share on other sites

Link to post
Share on other sites

52 minutes ago, Mr_KoKa said:

Its "Ludo" and don't do Players class, instead do Player and create as many instances of Player class as you need, same for pawns.

Yes I did do that, now each player contains 4 ints which are pawns.. And a bunch of functions.

 

How can I make the 4 ints loopable?

 

For exmaple I want to loop through them using a for each loop..

 

What type of object container is loopable?

 

Foreach(int pawn in Pawns)

{

}

CPU & COOLER - INTEL i9 12900K | NZXT KRAKEN X62

MBO - MSI Z690 EDGE

GPU - ASUS GEFORCE RTX 3080 TUF

RAM - 2x16GB KINGSTON FURY 3200MHZ

PSU - PHANTEKS REVOLT PRO 1000W 80 PLUS GOLD

SSD #1 - CORSAIR SN850 1TB

SSD #2 - CORSAIR SN850X 4TB

SSD #3 - INTEL 660p 2TB

CASE - PHANTEKS ECLIPSE P500A D-RGB

MOUSE #1 - LOGITECH G502 X Wireless

KEYBOARD - AKKO 5108B PLUS

SPEAKERS - SVS PB-1000 + 2x ADAM A3X

HEADSET #1 - SENNHEISER IE-300

HEADSET #2 - FOSTEX TR-X00 PURPLEHREART

AMP/DAC - MAYFLOWER ARC

OS - WINDOWS 10 PRO

DISPLAY 1 - LG OLED42C2

DISPLAY 2 - XIAOMI 2K GAMING

PHONE - SAMSUNG GALAXY S23+ 

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, berny22 said:

Yes I did do that, now each player contains 4 ints which are pawns.. And a bunch of functions.

 

How can I make the 4 ints loopable?

 

For exmaple I want to loop through them using a for each loop..

 

What type of object container is loopable?

 

Foreach(int pawn in Pawns)

{

}

 
 
 

make an array.

 

int[] players = new int[5];
players[0] = 1;
players[1] = 2;
players[2] = 3;
players[3] = 4;
for(int i = 0; i < (players.Length-1); i++){
    Console.WriteLine(players[i]);
            
}

 

though after reading your post you need array in arrays :) one sec

 

edit. So after thinking you will need to put a dictionary in each array then loop the array. My step son is being sick* just now now so can no longer work a sample for you.

 

 

*like projectile vomiting, going to be a long night.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

20 hours ago, vorticalbox said:

make an array.

 


int[] players = new int[5];
players[0] = 1;
players[1] = 2;
players[2] = 3;
players[3] = 4;
for(int i = 0; i < (players.Length-1); i++){
    Console.WriteLine(players[i]);
            
}

 

though after reading your post you need array in arrays :) one sec

 

edit. So after thinking you will need to put a dictionary in each array then loop the array. My step son is being sick* just now now so can no longer work a sample for you.

 

 

*like projectile vomiting, going to be a long night.

I know about arrays and lists, but in this specific case I would like to avoid using them. Is there any other way? Where they can all be integers for themselves in another loopable object(container)

CPU & COOLER - INTEL i9 12900K | NZXT KRAKEN X62

MBO - MSI Z690 EDGE

GPU - ASUS GEFORCE RTX 3080 TUF

RAM - 2x16GB KINGSTON FURY 3200MHZ

PSU - PHANTEKS REVOLT PRO 1000W 80 PLUS GOLD

SSD #1 - CORSAIR SN850 1TB

SSD #2 - CORSAIR SN850X 4TB

SSD #3 - INTEL 660p 2TB

CASE - PHANTEKS ECLIPSE P500A D-RGB

MOUSE #1 - LOGITECH G502 X Wireless

KEYBOARD - AKKO 5108B PLUS

SPEAKERS - SVS PB-1000 + 2x ADAM A3X

HEADSET #1 - SENNHEISER IE-300

HEADSET #2 - FOSTEX TR-X00 PURPLEHREART

AMP/DAC - MAYFLOWER ARC

OS - WINDOWS 10 PRO

DISPLAY 1 - LG OLED42C2

DISPLAY 2 - XIAOMI 2K GAMING

PHONE - SAMSUNG GALAXY S23+ 

Link to comment
Share on other sites

Link to post
Share on other sites

You probably could do that by implementing some interfaces like IEnumerable, but Is there a good reason to ditch on existing array mechanics and create new one, probably not as good or even buggy?

Link to comment
Share on other sites

Link to post
Share on other sites

46 minutes ago, berny22 said:

I know about arrays and lists, but in this specific case I would like to avoid using them. Is there any other way? Where they can all be integers for themselves in another loopable object(container)

why would you want to avoid them?

 

The way I would do this is to have an array and each item be a dictionary with "p1_pawn" = Something then access it with players[0]["p1_pawn"].

 

as koka posted you could make a class for players which would avoid using arrays. Once I'm back on my pc ill make a python sample as I know that much better.

 

 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

class player:
    def __init__(self, name):
        self.name = name
        self.pawns = [0,1,2,3,4]

#main
player1 = player('jack')
print(player1.name)
for i in range(len(player1.pawns)): print("pawn {0} int : {1}".format(i, player1.pawns[i]))

player2 = player('jill')
print(player2.name)
for i in range(len(player1.pawns)): print("pawn {0} int : {1}".format(i, player1.pawns[i]))

player1.pawns[0] = 4
print("player {0} pawn1 = {1}".format(player1.name,player1.pawns[0]))

output

jack
pawn 0 int : 0
pawn 1 int : 1
pawn 2 int : 2
pawn 3 int : 3
pawn 4 int : 4
jill
pawn 0 int : 0
pawn 1 int : 1
pawn 2 int : 2
pawn 3 int : 3
pawn 4 int : 4
player jack pawn1 = 4

 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×