用Python创建2人游戏 [英] Creating a 2 player game in Python

查看:110
本文介绍了用Python创建2人游戏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的朋友挑战我制作流行游戏战舰"的一个版本,使我们可以相互对抗.如果您不了解游戏,那不是很重要,因为对我而言,最困难的部分不是制作游戏,而是弄清楚如何在计算机上相互对抗.我以前只为一个玩家(我正在使用Python)制作过同一款游戏,所以我现在想知道的是:

My friend challenged me to make a version of the popular game "Battleships" that we could play against each other. If you don't know the game, it's not really important because the hard part for me would be not to make the game but to figure out how we can play it against each other both from our computers. I have previously made the same game, only for one player (I'm using Python) so what I want to find out now is:

  • 最简单的方法是什么?(我在考虑Hamachi).
  • 我应该从何处开始?
  • What is the easiest way? (I was thinking about Hamachi).
  • Where and with what should I start with?

先谢谢您了:)

推荐答案

我建议首先制作一个非网络版本的游戏,该版本在同一程序实例/窗口中支持2个玩家.这样,您就可以重新建模/设计代码,从而首先支持2个播放器.

I would suggest starting out by making a non-networked version of the game that supports 2 players in the same program instance/window. This way you'll be able to re-model/design your code to support 2 players in the first place.

如果这行得通,则必须选择要使用的网络库(或原始TCP/套接字),稍微考虑一下问题,然后重构/拆分程序,以便将2个播放器分成2个通过网络相互通信的独立程序.

If that's working, you have to choose a networking library to use (or raw TCP/sockets), think about the problem a little bit, and refactor/split the program in such way that you can separate the 2 players into 2 separate programs communicating with each other over network.

对于网络而言,RPC(远程过程调用)可能是您最容易使用的选择.有关选项,请查看:当前的选择是什么在Python中进行RPC?.或者,您可能只想使用诸如socket之类的非常原始的东西,或者诸如ZeroMQ之类的不太原始的东西.

For networking, RPC (Remote Procedure Call) is probably the easiest to use choice for you; for options, check out: What is the current choice for doing RPC in Python?. Or you might just want to go with something very primitive such as socket, or a bit less primitive such as ZeroMQ.

您可能对此也有兴趣: http://pygnetic.readthedocs.org/en/最新/:

You might also be interested in this: http://pygnetic.readthedocs.org/en/latest/:

pygnetic是一个旨在帮助Pygame开发网络游戏和应用程序的库

pygnetic is a library designed to help in the development of network games and applications in Pygame

这篇关于用Python创建2人游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆