Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Build game board with linked tiles

Hello, alright I wasnt sure about how to call this thread. I am having an assessment where I have to create a simple game.

We have a board:

Spoiler (Click to View)

A board has 78 squares. Every square has a LeftSquare, RightSquare, UpSquare and DownSquare so it actually creates a path.

But I am kinda clueless where to start.

Solution I have thought of:
Creating 78 square objects with coordinates as name. And setting the Left, Right etc in a big piece of code.

But there must be a more efficient way.

Anyone that has an idea?

Let me know. Thanks!
[Image: jYK9GP1.gif]
What about a 2d array? Elements at upper or lower bounds of either dimension will have direction limits.
Where are the 78 'squares'?
Spoiler (Click to View)

What are the rules of the game?
(Jan 6, 2017 10:46 AM)Zilog80 Wrote:  Where are the 78 'squares'?
Spoiler (Click to View)

What are the rules of the game?

Lmfao I cant count. Rules doesnt really matter. Players need to be able to walk with 1 pawn at the time.


(Jan 6, 2017 10:08 AM)Owl Wrote:  What about a 2d array? Elements at upper or lower bounds of either dimension will have direction limits.

We have to use linked lists.
[Image: jYK9GP1.gif]
This is only a fast approach:

You should define a 'square' class as follows:

Code
ID: int // Unique Id for that square
Left: int? // Represents Left square ID. If no left square available this property value will be Null
Right: int? // same as above but for right square
Top: int? // same for top square
Bottom: int? // same for bottom square

Take my numbered board game pic, square #2 should be:

Code
ID = 2;
Left = null;
Right = 3;
Top = null;
Bottom = 11;

So, you are on square #2 and want to move:

Code
Press "A" or <- for moving to left:
if square.Left == null ----> hey bro, you can't move to left

Press "W" or up for moving to top:
if square.Top == null ----> hey bro, you can't move to top

Press "S" or down for moving down (bottom)
new player square change from #2 to #11

Surely there will be better approaches but that one should work.
Let me know if you need more help. I could code some prototype (not pseudo-code like examples posted) if you are stuck.
What I would do is start with a map of some sort.

A text file or image file which you'll read with the program, which translates positions in the map into positions on the screen.
(Jan 6, 2017 05:20 PM)Zilog80 Wrote:  This is only a fast approach:

You should define a 'square' class as follows:

Code
ID: int // Unique Id for that square
Left: int? // Represents Left square ID. If no left square available this property value will be Null
Right: int? // same as above but for right square
Top: int? // same for top square
Bottom: int? // same for bottom square

Take my numbered board game pic, square #2 should be:

Code
ID = 2;
Left = null;
Right = 3;
Top = null;
Bottom = 11;

So, you are on square #2 and want to move:

Code
Press "A" or <- for moving to left:
if square.Left == null ----> hey bro, you can't move to left

Press "W" or up for moving to top:
if square.Top == null ----> hey bro, you can't move to top

Press "S" or down for moving down (bottom)
new player square change from #2 to #11

Surely there will be better approaches but that one should work.
Let me know if you need more help. I could code some prototype (not pseudo-code like examples posted) if you are stuck.

This looks very good. Will look into it when I wake up. Thanks!
[Image: jYK9GP1.gif]
Fast prototype:

[Image: LjsmASl.gif]

Source:
http://pastebin.com/a1PdjeaL

Resource & Form dessign:
https://imgur.com/a/aupvO

The source code is self-explainatory. Anyway if you have any question let me know.

The prototype could be improved a lot, but hope it helps 👍
(Jan 7, 2017 05:37 AM)Zilog80 Wrote:  -snip-

Holy shit. This looks amazing. Thank you verry much!
[Image: jYK9GP1.gif]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Java] by Juice.Mar 10, 2020 07:02 PM 0 136 Mar 10, 2020 07:02 PM
Last Post: Juice.
[C] by g4143Dec 28, 2019 09:24 AM 1 349 Dec 28, 2019 09:24 AM
Last Post: an balker
[C] by Enl1ghtedJan 14, 2019 02:50 AM 2 176 Jan 14, 2019 02:50 AM
Last Post: Enl1ghted