commit fdc6dd2004f109db1cbc2a16442eece57f08b598 Author: Colton Staiduhar Date: Fri Apr 24 15:44:16 2026 -0400 Court and Player Number diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f9dfa2f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.o +netpong +netpong.dSYM/ \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..59ef71d --- /dev/null +++ b/Makefile @@ -0,0 +1,32 @@ +# Compiler and flags +CC = gcc +CFLAGS = -Wall -g + +NETPONG_SRC = main.c court.c $(wildcard network/*.c) + +LIBS = -lncurses + + +# Object files +NETPONG_OBJ = $(NETPONG_SRC:.c=.o) + +# Default target +all: netpong + +# Build NetPong +netpong: $(NETPONG_OBJ) + $(CC) $(CFLAGS) -o netpong $(NETPONG_OBJ) $(LIBS) + +# Generic compile rule +%.o: %.c smsh.h varlib.h + $(CC) $(CFLAGS) -c $< + +# Clean up +clean: + rm -f *.o netpong network/*.o + +Server: + ./netpong + +Client: + ./netpong -c 127.0.0.1 \ No newline at end of file diff --git a/court.c b/court.c new file mode 100644 index 0000000..465466c --- /dev/null +++ b/court.c @@ -0,0 +1,33 @@ +#include "game.h" + +#include +#include +#include +#include +#include + +void DrawWalls(struct GameData data) +{ + for (int i = LEFT_COL; i <= RIGHT_COL; i++) { + move(TOP_ROW, i); + addch('='); + move(BOT_ROW, i); + addch('-'); + } + + int col = LEFT_COL; + if (data.playerNumber > 0) + col = RIGHT_COL; + for (int i = TOP_ROW; i <= BOT_ROW; i++) { + move(i, col); + addch('|'); + } + + refresh(); +} +void DrawHeader(struct GameData data) +{ + move(TOP_ROW - 2, LEFT_COL); + addch('P'); + addch('0' + (data.playerNumber + 1)); +} \ No newline at end of file diff --git a/game.h b/game.h new file mode 100644 index 0000000..0aed6ff --- /dev/null +++ b/game.h @@ -0,0 +1,22 @@ +#ifndef GAME_H +#define GAME_H 1 + +// Setup game board +#define TOP_ROW 4 +#define BOT_ROW 21 +#define LEFT_COL 9 +#define RIGHT_COL 70 + +struct GameData +{ + int playerNumber; + char* domain; + int port; + +}; + + +void DrawWalls(struct GameData); +void DrawHeader(struct GameData); + +#endif \ No newline at end of file diff --git a/main.c b/main.c new file mode 100644 index 0000000..f6b7b1a --- /dev/null +++ b/main.c @@ -0,0 +1,60 @@ +#include "game.h" +#include +#include +#include +#include +#include + +/** + * Main Fucntion + */ +int main(int argc, char* argv[]) +{ + // Create GameData Object + struct GameData data; + + // Detect Server or Client + switch (argc) { + case 2: + // Start Server + data.playerNumber = 0; + data.port = atoi(argv[1]); + break; + case 3: + // Start Client + data.playerNumber = 1; + data.domain = argv[1]; + data.port = atoi(argv[2]); + break; + default: + data.playerNumber = 0; + printf("Please read the following usage\n"); + printf("Server: %s \n", argv[0]); + printf("Client: %s \n", argv[0]); + return 1; + } + + srand(getpid()); + + // Setup Terminal + if (initscr() == NULL) { + perror("initscr failed"); + exit(1); + } + noecho(); + cbreak(); + nodelay(stdscr, TRUE); + + DrawWalls(data); + DrawHeader(data); + + int socket_fd = 0; + + while (1) { + int ch = getch(); + if (ch == 'q') + break; + } + + endwin(); +} \ No newline at end of file