DEV Community

Cover image for Deployed a pingpong Game on XinFin XDC Network.
MahaLakshmi Perumal
MahaLakshmi Perumal

Posted on

1

Deployed a pingpong Game on XinFin XDC Network.

Deployed a PingPong game on XinFin XDC Network. Working with games is more interesting then playing that game :P

Check the code here:
pragma solidity >=0.4.25 <0.6.0;
contract Starter
{
enum StateType { GameProvisioned, Pingponging, GameFinished}
StateType public State;
string public PingPongGameName;
address public GameStarter;
Player public GamePlayer;
int public PingPongTimes;
constructor (string memory gameName) public{
PingPongGameName = gameName;
GameStarter = msg.sender;
GamePlayer = new Player(PingPongGameName);
State = StateType.GameProvisioned;
}
function StartPingPong(int pingPongTimes) public
{
PingPongTimes = pingPongTimes;
State = StateType.Pingponging;
GamePlayer.Ping(pingPongTimes);
}
function Pong(int currentPingPongTimes) public
{
int remainingPingPongTimes = currentPingPongTimes - 1;
if(remainingPingPongTimes > 0)
{
State = StateType.Pingponging;
GamePlayer.Ping(remainingPingPongTimes);
}
else
{
State = StateType.GameFinished;
GamePlayer.FinishGame();
}
}
function FinishGame() public
{
State = StateType.GameFinished;
}
}
contract Player
{
enum StateType {PingpongPlayerCreated, PingPonging, GameFinished}
StateType public State;
address public GameStarter;
string public PingPongGameName;
constructor (string memory pingPongGameName) public {
GameStarter = msg.sender;
PingPongGameName = pingPongGameName;
State = StateType.PingpongPlayerCreated;
}
function Ping(int currentPingPongTimes) public
{
int remainingPingPongTimes = currentPingPongTimes - 1;
Starter starter = Starter(msg.sender);
if(remainingPingPongTimes > 0)
{
State = StateType.PingPonging;
starter.Pong(remainingPingPongTimes);
}
else
{
State = StateType.GameFinished;
starter.FinishGame();
}
}
function FinishGame() public
{
State = StateType.GameFinished;
}
}

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay