d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Peer-to-peer C++
Prev123
Add Reply New Topic New Poll
Member
Posts: 11,153
Joined: Aug 23 2008
Gold: 4,230.00
Oct 17 2018 12:44am
Quote (Muted @ Oct 17 2018 08:41am)
Why would you use system("CLS")?

Linux uses clear and not cls.


Ah. I said making a console program which makes it sound like Linux. I guess I should have phrased it as a CLI program? I am programming in windows.
Member
Posts: 31,680
Joined: Nov 10 2007
Gold: 1.00
Oct 17 2018 12:53am
Quote (kasey21 @ 17 Oct 2018 01:44)
Ah. I said making a console program which makes it sound like Linux. I guess I should have phrased it as a CLI program? I am programming in windows.


I assumed as much...


Quote (Muted @ 17 Oct 2018 01:03)
IIRC: 25h x 80w is the default size from Windows 95+.


Technically: system(const char*) is from the C-library, so... I guess I should simply accept that (despite it being horrible in many ways); but do not allow me to discourage you with that.

There are quite a few ways you could output the game state ("images") to the screen and update it per-move. Although you're quite limited (without a fun imagination).

I'm assuming, based on your statements: You're wanting to draw some sort of grid (and I do not remember how large in terms of X * Y cells exist on a standard Battleship board).

I would suggest that you create quite a few objects to handle this:
"sprites" - Anything displayable (a water tile? a water tile that was hit (missed shot)? a ship piece? a ship piece that was hit?)
"ships" (composed of array(s) of sprites)

The networking part should equally be simple to handle for "PvP" as you said; you only need to share (UDP?) the desired X/Y coordinate that was attacked.

Player 1 'attacks' coordinate: [0, 0]
Player 2 receives message -> "attack at 0, 0"

If player 2's ship was hit: Player 2 responds with a message -> "hit ship at 0, 0" (if it was a killing blow: send another message or send the data all in one message)
If player 2's ship was not hit: You can default with a timeout or waste bandwith and have player 2 reply that "no ship was hit."

The same logic applies when player 2's turn is active.

E/

The real fun begins when you have 8 players all playing against each other at once! Simultaneous moves (to speed up game-time). Similar to Civilization IV's style. :)

This post was edited by Muted on Oct 17 2018 12:54am
Member
Posts: 598
Joined: Jul 2 2013
Gold: 0.00
Dec 30 2018 04:31am
lmk if there is a github repo for this, I am very interested.
Go Back To Programming & Development Topic List
Prev123
Add Reply New Topic New Poll