【发布时间】:2022-01-18 22:13:43
【问题描述】:
这是学校的最后总结(是的,这是值得的最后一个项目,因为去年我的编码课因为 Covid 而被淘汰)并且我尽可能远离循环,我想知道如何让这个说玩家一有两个赢了。顺便说一句,这是在控制台 HSA 中,所以我的能力有相当大的参数,而且我不擅长编码的事实也阻碍了我。我上这门课更多是为了休闲,因为我喜欢我们去年在网上做的小编码。我们使用 Chromebook 进行编码,您可以想象那是多么糟糕
int startGame;
c.println ("Welcome to Tic Tac Toe But With [] & O!");
c.println ("Each sqaure in the 9X9 grid is just labelled by its placement");
c.println ("So you would type 5 if you want in the first square and so on...");
c.println ("This is Player V. Player so Find a Friend!");
c.println ("________________________________________________________________");
c.println ("Press 1 to start the game");
startGame = c.readInt();
if(startGame == 1){
c.clear();
playOne();
playTwo();
playOne();
playTwo();
playOne();
playTwo();
playOne();
playTwo();
playOne();
}
else{
c.println("Goodbye!");
}
}
public static void playTwo()
{
int playerTwo;
c.println ("Player Two, Where would you like to put your [] ?");
playerTwo = c.readInt ();
c.fillRect (05, 510, 287, 5);
c.fillRect (05, 605, 287, 5);
c.fillRect (195, 420, 5, 287);
c.fillRect (95, 420, 5, 287);
if (playerTwo == 1)
{
c.fillRect (26, 440, 50, 50);
}
if (playerTwo == 2)
{
c.fillRect (124, 440, 50, 50);
}
if (playerTwo == 3)
{
c.fillRect (220, 440, 50, 50);
}
if (playerTwo == 4)
{
c.fillRect (26, 535, 50, 50);
}
if (playerTwo == 5)
{
c.fillRect (124, 535, 50, 50);
}
if (playerTwo == 6)
{
c.fillRect (220, 535, 50, 50);
}
if (playerTwo == 7)
{
c.fillRect (26, 632, 50, 50);
}
if (playerTwo == 8)
{
c.fillRect (124, 632, 50, 50);
}
if (playerTwo == 9)
{
c.fillRect (220, 632, 50, 50);
}
/*if(playerTwo == 1 && playerTwo == 2 && playerTwo == 3)
{
c.clear();
c.println("Player Two Won!");
}
if(playerTwo == 1 && playerTwo == 4 && playerTwo == 7);
{
c.clear();
c.println("Player Two Won!");
}
if(playerTwo == 1 && playerTwo == 5 && playerTwo == 9);
{
c.clear();
c.println("Player Two Won!");
}
if(playerTwo == 2 && playerTwo == 5 && playerTwo == 8);
{
c.clear();
c.println("Player Two Won!");
}
if(playerTwo == 3 && playerTwo == 5 && playerTwo == 7);
{
c.clear();
c.println("Player Two Won!");
}
if(playerTwo == 3 && playerTwo == 6 && playerTwo == 9);
{
c.clear();
c.println("Player Two Won!");
}
if(playerTwo == 4 && playerTwo == 5 && playerTwo == 6);
{
c.clear();
c.println("Player Two Won!");
}
if(playerTwo == 7 && playerTwo == 8 && playerTwo == 9);
{
c.clear();
c.println("Player Two Won!");
}*/
}
public static void playOne()
{
int playerOne;
c.println ("Player 1, Where would you like to put your O ?");
playerOne = c.readInt ();
c.fillRect (05, 510, 287, 5);
c.fillRect (05, 605, 287, 5);
c.fillRect (195, 420, 5, 287);
c.fillRect (95, 420, 5, 287);
if (playerOne == 1)
{
c.fillOval (26, 440, 50, 50);
}
if (playerOne == 2)
{
c.fillOval (124, 440, 50, 50);
}
if (playerOne == 3)
{
c.fillOval (220, 440, 50, 50);
}
if (playerOne == 4)
{
c.fillOval (26, 535, 50, 50);
}
if (playerOne == 5)
{
c.fillOval (124, 535, 50, 50);
}
if (playerOne == 6)
{
c.fillOval (220, 535, 50, 50);
}
if (playerOne == 7)
{
c.fillOval (26, 632, 50, 50);
}
if (playerOne == 8)
{
c.fillOval (124, 632, 50, 50);
}
if (playerOne == 9)
{
c.fillOval (220, 632, 50, 50);
}
/*if(playerOne == 1 && playerOne == 2 && playerOne == 3)
{
c.clear();
c.println("Player One Won!");
}
if(playerOne == 1 && playerOne == 4 && playerOne == 7);
{
c.clear();
c.println("Player One Won!");
}
if(playerOne == 1 && playerOne == 5 && playerOne == 9);
{
c.clear();
c.println("Player One Won!");
}
if(playerOne == 2 && playerOne == 5 && playerOne == 8);
{
c.clear();
c.println("Player One Won!");
}
if(playerOne == 3 && playerOne == 5 && playerOne == 7);
{
c.clear();
c.println("Player One Won!");
}
if(playerOne == 3 && playerOne == 6 && playerOne == 9);
{
c.clear();
c.println("Player One Won!");
}
if(playerOne == 4 && playerOne == 5 && playerOne == 6);
{
c.clear();
c.println("Player One Won!");
}
if(playerOne == 7 && playerOne == 8 && playerOne == 9);
{
c.clear();
c.println("Player One Won!");
}*/
}
}
【问题讨论】:
-
Java !== JavaScript
标签: java if-statement integer